Skip to content

Conversation

charleskorn
Copy link
Contributor

@charleskorn charleskorn commented Jul 10, 2024

What this PR does

This PR adds support for the without keyword for aggregations in Mimir's query engine.

It also resolves the potential for hash collisions when computing aggregation groups. This decreases performance somewhat, but is the cheapest way I can see to avoid hash collisions.

If we're happy with the seriesToGroupLabelsStringFunc approach here, I will investigate reusing it for binary operations in a separate PR.

Performance comparison of this PR vs Prometheus' engine
goos: darwin
goarch: arm64
pkg: github.com/grafana/mimir/pkg/streamingpromql/benchmarks
                                                                                                         │      Prometheus      │               Mimir                │
                                                                                                         │        sec/op        │   sec/op     vs base               │
Query/sum(a_1),_instant_query                                                                                      139.6µ ±  2%   140.3µ ± 8%        ~ (p=0.937 n=6)
Query/sum(a_1),_range_query_with_100_steps                                                                         154.2µ ±  4%   153.1µ ± 2%        ~ (p=0.937 n=6)
Query/sum(a_1),_range_query_with_1000_steps                                                                        257.0µ ±  2%   236.0µ ± 8%   -8.18% (p=0.004 n=6)
Query/sum(a_100),_instant_query                                                                                    851.1µ ±  2%   855.9µ ± 1%        ~ (p=0.485 n=6)
Query/sum(a_100),_range_query_with_100_steps                                                                       1.497m ±  1%   1.438m ± 3%   -3.95% (p=0.009 n=6)
Query/sum(a_100),_range_query_with_1000_steps                                                                      7.104m ±  0%   6.749m ± 1%   -5.00% (p=0.002 n=6)
Query/sum(a_2000),_instant_query                                                                                   11.68m ±  1%   11.39m ± 2%   -2.52% (p=0.009 n=6)
Query/sum(a_2000),_range_query_with_100_steps                                                                      22.93m ±  1%   21.83m ± 1%   -4.76% (p=0.002 n=6)
Query/sum(a_2000),_range_query_with_1000_steps                                                                     139.1m ±  1%   118.3m ± 1%  -14.99% (p=0.002 n=6)
Query/sum_without_(l)(h_1),_instant_query                                                                          171.9µ ±  1%   169.8µ ± 2%   -1.20% (p=0.002 n=6)
Query/sum_without_(l)(h_1),_range_query_with_100_steps                                                             220.1µ ±  1%   213.4µ ± 2%   -3.03% (p=0.002 n=6)
Query/sum_without_(l)(h_1),_range_query_with_1000_steps                                                            666.1µ ±  7%   599.9µ ± 2%   -9.94% (p=0.002 n=6)
Query/sum_without_(l)(h_100),_instant_query                                                                        4.035m ±  3%   3.943m ± 0%   -2.28% (p=0.002 n=6)
Query/sum_without_(l)(h_100),_range_query_with_100_steps                                                           7.641m ±  1%   7.347m ± 1%   -3.86% (p=0.002 n=6)
Query/sum_without_(l)(h_100),_range_query_with_1000_steps                                                          41.28m ±  3%   38.40m ± 0%   -6.97% (p=0.002 n=6)
Query/sum_without_(l)(h_2000),_instant_query                                                                       74.57m ±  1%   72.93m ± 0%   -2.20% (p=0.002 n=6)
Query/sum_without_(l)(h_2000),_range_query_with_100_steps                                                          147.0m ±  1%   139.9m ± 1%   -4.85% (p=0.002 n=6)
Query/sum_without_(l)(h_2000),_range_query_with_1000_steps                                                         875.9m ±  0%   735.7m ± 1%  -16.00% (p=0.002 n=6)
Query/sum_without_(le)(h_1),_instant_query                                                                         170.1µ ±  1%   166.8µ ± 6%        ~ (p=0.394 n=6)
Query/sum_without_(le)(h_1),_range_query_with_100_steps                                                            215.6µ ±  0%   210.9µ ± 4%        ~ (p=0.065 n=6)
Query/sum_without_(le)(h_1),_range_query_with_1000_steps                                                           632.5µ ±  1%   588.7µ ± 6%   -6.93% (p=0.002 n=6)
Query/sum_without_(le)(h_100),_instant_query                                                                       4.082m ±  1%   3.952m ± 0%   -3.19% (p=0.002 n=6)
Query/sum_without_(le)(h_100),_range_query_with_100_steps                                                          7.873m ±  2%   7.415m ± 4%   -5.82% (p=0.002 n=6)
Query/sum_without_(le)(h_100),_range_query_with_1000_steps                                                         42.48m ±  1%   38.33m ± 1%   -9.77% (p=0.002 n=6)
Query/sum_without_(le)(h_2000),_instant_query                                                                      75.44m ±  2%   74.67m ± 1%        ~ (p=0.132 n=6)
Query/sum_without_(le)(h_2000),_range_query_with_100_steps                                                         150.5m ±  1%   140.0m ± 1%   -6.94% (p=0.002 n=6)
Query/sum_without_(le)(h_2000),_range_query_with_1000_steps                                                        897.8m ±  0%   735.8m ± 1%  -18.05% (p=0.002 n=6)
Query/sum_by_(l)(h_1),_instant_query                                                                               169.9µ ±  5%   167.8µ ± 6%        ~ (p=0.310 n=6)
Query/sum_by_(l)(h_1),_range_query_with_100_steps                                                                  215.5µ ±  1%   209.7µ ± 4%        ~ (p=0.065 n=6)
Query/sum_by_(l)(h_1),_range_query_with_1000_steps                                                                 633.4µ ±  0%   586.6µ ± 1%   -7.39% (p=0.002 n=6)
Query/sum_by_(l)(h_100),_instant_query                                                                             4.101m ±  0%   3.949m ± 0%   -3.69% (p=0.002 n=6)
Query/sum_by_(l)(h_100),_range_query_with_100_steps                                                                7.790m ±  1%   7.383m ± 4%   -5.23% (p=0.002 n=6)
Query/sum_by_(l)(h_100),_range_query_with_1000_steps                                                               42.30m ±  2%   38.65m ± 1%   -8.62% (p=0.002 n=6)
Query/sum_by_(l)(h_2000),_instant_query                                                                            74.57m ±  1%   74.18m ± 1%        ~ (p=0.240 n=6)
Query/sum_by_(l)(h_2000),_range_query_with_100_steps                                                               151.6m ±  2%   140.3m ± 1%   -7.40% (p=0.002 n=6)
Query/sum_by_(l)(h_2000),_range_query_with_1000_steps                                                              904.2m ±  3%   735.0m ± 1%  -18.71% (p=0.002 n=6)
Query/sum_by_(le)(h_1),_instant_query                                                                              172.0µ ±  1%   168.5µ ± 1%   -2.02% (p=0.002 n=6)
Query/sum_by_(le)(h_1),_range_query_with_100_steps                                                                 236.0µ ±  6%   212.8µ ± 2%   -9.81% (p=0.002 n=6)
Query/sum_by_(le)(h_1),_range_query_with_1000_steps                                                                694.3µ ±  7%   603.0µ ± 4%  -13.16% (p=0.002 n=6)
Query/sum_by_(le)(h_100),_instant_query                                                                            4.180m ±  1%   3.955m ± 1%   -5.38% (p=0.002 n=6)
Query/sum_by_(le)(h_100),_range_query_with_100_steps                                                               7.851m ±  1%   7.448m ± 2%   -5.13% (p=0.002 n=6)
Query/sum_by_(le)(h_100),_range_query_with_1000_steps                                                              42.18m ±  5%   38.68m ± 1%   -8.29% (p=0.002 n=6)
Query/sum_by_(le)(h_2000),_instant_query                                                                           75.80m ±  5%   73.05m ± 0%   -3.62% (p=0.002 n=6)
Query/sum_by_(le)(h_2000),_range_query_with_100_steps                                                              149.0m ±  3%   140.2m ± 0%   -5.88% (p=0.002 n=6)
Query/sum_by_(le)(h_2000),_range_query_with_1000_steps                                                             894.4m ±  2%   740.7m ± 0%  -17.19% (p=0.002 n=6)
Query/sum(a_1_+_b_1),_instant_query                                                                                249.9µ ±  6%   230.6µ ± 4%   -7.73% (p=0.002 n=6)
Query/sum(a_1_+_b_1),_range_query_with_100_steps                                                                   293.3µ ±  4%   250.7µ ± 1%  -14.53% (p=0.002 n=6)
Query/sum(a_1_+_b_1),_range_query_with_1000_steps                                                                  757.4µ ± 12%   395.3µ ± 3%  -47.81% (p=0.002 n=6)
Query/sum(a_100_+_b_100),_instant_query                                                                            1.640m ±  1%   1.605m ± 1%   -2.12% (p=0.002 n=6)
Query/sum(a_100_+_b_100),_range_query_with_100_steps                                                               5.164m ±  1%   2.745m ± 1%  -46.85% (p=0.002 n=6)
Query/sum(a_100_+_b_100),_range_query_with_1000_steps                                                              37.37m ±  2%   13.11m ± 1%  -64.92% (p=0.002 n=6)
Query/sum(a_2000_+_b_2000),_instant_query                                                                          25.01m ±  1%   25.00m ± 1%        ~ (p=0.818 n=6)
Query/sum(a_2000_+_b_2000),_range_query_with_100_steps                                                             96.59m ±  2%   46.06m ± 1%  -52.31% (p=0.002 n=6)
Query/sum(a_2000_+_b_2000),_range_query_with_1000_steps                                                            804.1m ±  0%   243.1m ± 0%  -69.77% (p=0.002 n=6)
Query/sum_by_(le)(rate(h_1[1m])),_instant_query                                                                    149.5µ ±  5%   135.9µ ± 1%   -9.09% (p=0.002 n=6)
Query/sum_by_(le)(rate(h_1[1m])),_range_query_with_100_steps                                                       245.6µ ±  2%   187.4µ ± 1%  -23.68% (p=0.002 n=6)
Query/sum_by_(le)(rate(h_1[1m])),_range_query_with_1000_steps                                                     1009.2µ ±  3%   634.9µ ± 8%  -37.09% (p=0.002 n=6)
Query/sum_by_(le)(rate(h_100[1m])),_instant_query                                                                  2.085m ±  1%   1.583m ± 3%  -24.09% (p=0.002 n=6)
Query/sum_by_(le)(rate(h_100[1m])),_range_query_with_100_steps                                                     8.970m ±  8%   5.644m ± 1%  -37.08% (p=0.002 n=6)
Query/sum_by_(le)(rate(h_100[1m])),_range_query_with_1000_steps                                                    76.44m ±  2%   42.31m ± 1%  -44.65% (p=0.002 n=6)
Query/sum_by_(le)(rate(h_2000[1m])),_instant_query                                                                 36.94m ±  1%   26.43m ± 1%  -28.45% (p=0.002 n=6)
Query/sum_by_(le)(rate(h_2000[1m])),_range_query_with_100_steps                                                    182.5m ±  4%   105.9m ± 1%  -41.98% (p=0.002 n=6)
Query/sum_by_(le)(rate(h_2000[1m])),_range_query_with_1000_steps                                                  1749.1m ± 13%   808.7m ± 1%  -53.77% (p=0.002 n=6)
Query/sum_without_(l)(rate(a_1[1m])),_instant_query                                                                123.5µ ± 14%   117.9µ ± 5%        ~ (p=0.065 n=6)
Query/sum_without_(l)(rate(a_1[1m])),_range_query_with_100_steps                                                   147.3µ ±  3%   131.1µ ± 7%  -10.99% (p=0.002 n=6)
Query/sum_without_(l)(rate(a_1[1m])),_range_query_with_1000_steps                                                  306.7µ ±  5%   220.8µ ± 6%  -28.01% (p=0.002 n=6)
Query/sum_without_(l)(rate(a_100[1m])),_instant_query                                                              514.1µ ±  1%   374.1µ ± 7%  -27.23% (p=0.002 n=6)
Query/sum_without_(l)(rate(a_100[1m])),_range_query_with_100_steps                                                 1.720m ±  5%   1.115m ± 1%  -35.14% (p=0.002 n=6)
Query/sum_without_(l)(rate(a_100[1m])),_range_query_with_1000_steps                                               13.152m ±  7%   7.303m ± 1%  -44.47% (p=0.002 n=6)
Query/sum_without_(l)(rate(a_2000[1m])),_instant_query                                                             6.025m ±  1%   4.112m ± 1%  -31.75% (p=0.002 n=6)
Query/sum_without_(l)(rate(a_2000[1m])),_range_query_with_100_steps                                                30.69m ±  7%   16.96m ± 0%  -44.73% (p=0.002 n=6)
Query/sum_without_(l)(rate(a_2000[1m])),_range_query_with_1000_steps                                               260.5m ±  7%   131.2m ± 1%  -49.62% (p=0.002 n=6)
Query/sum_without_(l)(rate(a_1[1m]))_/_sum_without_(l)(rate(b_1[1m])),_instant_query                               237.6µ ±  4%   223.4µ ± 1%   -5.96% (p=0.002 n=6)
Query/sum_without_(l)(rate(a_1[1m]))_/_sum_without_(l)(rate(b_1[1m])),_range_query_with_100_steps                  294.7µ ±  1%   247.6µ ± 1%  -15.99% (p=0.002 n=6)
Query/sum_without_(l)(rate(a_1[1m]))_/_sum_without_(l)(rate(b_1[1m])),_range_query_with_1000_steps                 859.1µ ±  1%   417.1µ ± 1%  -51.45% (p=0.002 n=6)
Query/sum_without_(l)(rate(a_100[1m]))_/_sum_without_(l)(rate(b_100[1m])),_instant_query                           993.3µ ±  4%   779.6µ ± 6%  -21.52% (p=0.002 n=6)
Query/sum_without_(l)(rate(a_100[1m]))_/_sum_without_(l)(rate(b_100[1m])),_range_query_with_100_steps              3.291m ±  3%   2.113m ± 1%  -35.81% (p=0.002 n=6)
Query/sum_without_(l)(rate(a_100[1m]))_/_sum_without_(l)(rate(b_100[1m])),_range_query_with_1000_steps             23.71m ±  3%   13.71m ± 1%  -42.19% (p=0.002 n=6)
Query/sum_without_(l)(rate(a_2000[1m]))_/_sum_without_(l)(rate(b_2000[1m])),_instant_query                        11.872m ±  1%   8.231m ± 0%  -30.67% (p=0.002 n=6)
Query/sum_without_(l)(rate(a_2000[1m]))_/_sum_without_(l)(rate(b_2000[1m])),_range_query_with_100_steps            57.45m ±  5%   34.17m ± 1%  -40.53% (p=0.002 n=6)
Query/sum_without_(l)(rate(a_2000[1m]))_/_sum_without_(l)(rate(b_2000[1m])),_range_query_with_1000_steps           482.3m ±  0%   261.5m ± 1%  -45.78% (p=0.002 n=6)
geomean                                                                                                            6.060m         4.830m       -20.30%


                                                                                                         │      Prometheus      │                Mimir                │
                                                                                                         │          B           │      B        vs base               │
Query/sum(a_1),_instant_query                                                                                      71.81Mi ± 1%   71.73Mi ± 2%        ~ (p=0.974 n=6)
Query/sum(a_1),_range_query_with_100_steps                                                                         71.50Mi ± 2%   70.77Mi ± 1%        ~ (p=0.485 n=6)
Query/sum(a_1),_range_query_with_1000_steps                                                                        70.64Mi ± 2%   69.50Mi ± 1%   -1.61% (p=0.041 n=6)
Query/sum(a_100),_instant_query                                                                                    65.43Mi ± 1%   64.55Mi ± 1%   -1.35% (p=0.002 n=6)
Query/sum(a_100),_range_query_with_100_steps                                                                       65.21Mi ± 1%   64.70Mi ± 1%   -0.79% (p=0.002 n=6)
Query/sum(a_100),_range_query_with_1000_steps                                                                      67.97Mi ± 1%   64.56Mi ± 1%   -5.01% (p=0.002 n=6)
Query/sum(a_2000),_instant_query                                                                                   68.18Mi ± 4%   66.12Mi ± 2%   -3.03% (p=0.041 n=6)
Query/sum(a_2000),_range_query_with_100_steps                                                                      73.54Mi ± 3%   64.83Mi ± 1%  -11.85% (p=0.002 n=6)
Query/sum(a_2000),_range_query_with_1000_steps                                                                    130.39Mi ± 1%   69.26Mi ± 4%  -46.88% (p=0.002 n=6)
Query/sum_without_(l)(h_1),_instant_query                                                                          69.23Mi ± 1%   68.69Mi ± 1%        ~ (p=0.065 n=6)
Query/sum_without_(l)(h_1),_range_query_with_100_steps                                                             69.38Mi ± 2%   68.23Mi ± 0%        ~ (p=0.132 n=6)
Query/sum_without_(l)(h_1),_range_query_with_1000_steps                                                            66.82Mi ± 1%   66.55Mi ± 1%        ~ (p=0.255 n=6)
Query/sum_without_(l)(h_100),_instant_query                                                                        66.13Mi ± 1%   65.65Mi ± 1%   -0.73% (p=0.006 n=6)
Query/sum_without_(l)(h_100),_range_query_with_100_steps                                                           68.21Mi ± 1%   65.76Mi ± 1%   -3.60% (p=0.002 n=6)
Query/sum_without_(l)(h_100),_range_query_with_1000_steps                                                          85.62Mi ± 1%   66.23Mi ± 2%  -22.65% (p=0.002 n=6)
Query/sum_without_(l)(h_2000),_instant_query                                                                       70.76Mi ± 2%   69.82Mi ± 0%        ~ (p=0.394 n=6)
Query/sum_without_(l)(h_2000),_range_query_with_100_steps                                                         110.44Mi ± 1%   69.65Mi ± 1%  -36.93% (p=0.002 n=6)
Query/sum_without_(l)(h_2000),_range_query_with_1000_steps                                                        406.73Mi ± 0%   72.62Mi ± 1%  -82.14% (p=0.002 n=6)
Query/sum_without_(le)(h_1),_instant_query                                                                         69.62Mi ± 1%   69.16Mi ± 1%   -0.66% (p=0.002 n=6)
Query/sum_without_(le)(h_1),_range_query_with_100_steps                                                            68.98Mi ± 2%   68.23Mi ± 1%   -1.09% (p=0.002 n=6)
Query/sum_without_(le)(h_1),_range_query_with_1000_steps                                                           67.05Mi ± 1%   66.14Mi ± 2%   -1.36% (p=0.026 n=6)
Query/sum_without_(le)(h_100),_instant_query                                                                       66.03Mi ± 1%   65.73Mi ± 1%        ~ (p=0.058 n=6)
Query/sum_without_(le)(h_100),_range_query_with_100_steps                                                          68.55Mi ± 1%   66.38Mi ± 1%   -3.16% (p=0.002 n=6)
Query/sum_without_(le)(h_100),_range_query_with_1000_steps                                                         87.92Mi ± 2%   68.95Mi ± 1%  -21.57% (p=0.002 n=6)
Query/sum_without_(le)(h_2000),_instant_query                                                                      71.56Mi ± 2%   70.43Mi ± 2%        ~ (p=0.108 n=6)
Query/sum_without_(le)(h_2000),_range_query_with_100_steps                                                        118.12Mi ± 1%   77.95Mi ± 1%  -34.01% (p=0.002 n=6)
Query/sum_without_(le)(h_2000),_range_query_with_1000_steps                                                        439.8Mi ± 0%   131.2Mi ± 5%  -70.18% (p=0.002 n=6)
Query/sum_by_(l)(h_1),_instant_query                                                                               69.77Mi ± 1%   68.64Mi ± 1%   -1.62% (p=0.009 n=6)
Query/sum_by_(l)(h_1),_range_query_with_100_steps                                                                  69.02Mi ± 1%   68.22Mi ± 1%   -1.15% (p=0.004 n=6)
Query/sum_by_(l)(h_1),_range_query_with_1000_steps                                                                 66.88Mi ± 1%   66.11Mi ± 2%   -1.14% (p=0.039 n=6)
Query/sum_by_(l)(h_100),_instant_query                                                                             66.19Mi ± 1%   65.72Mi ± 1%   -0.71% (p=0.041 n=6)
Query/sum_by_(l)(h_100),_range_query_with_100_steps                                                                68.67Mi ± 2%   66.15Mi ± 2%   -3.67% (p=0.002 n=6)
Query/sum_by_(l)(h_100),_range_query_with_1000_steps                                                               87.01Mi ± 1%   69.30Mi ± 2%  -20.35% (p=0.002 n=6)
Query/sum_by_(l)(h_2000),_instant_query                                                                            70.12Mi ± 3%   70.46Mi ± 2%        ~ (p=1.000 n=6)
Query/sum_by_(l)(h_2000),_range_query_with_100_steps                                                              117.10Mi ± 1%   78.97Mi ± 3%  -32.56% (p=0.002 n=6)
Query/sum_by_(l)(h_2000),_range_query_with_1000_steps                                                              439.8Mi ± 0%   133.7Mi ± 4%  -69.61% (p=0.002 n=6)
Query/sum_by_(le)(h_1),_instant_query                                                                              69.60Mi ± 1%   68.97Mi ± 1%        ~ (p=0.061 n=6)
Query/sum_by_(le)(h_1),_range_query_with_100_steps                                                                 68.93Mi ± 1%   68.26Mi ± 1%   -0.97% (p=0.002 n=6)
Query/sum_by_(le)(h_1),_range_query_with_1000_steps                                                                67.19Mi ± 1%   65.93Mi ± 1%   -1.87% (p=0.002 n=6)
Query/sum_by_(le)(h_100),_instant_query                                                                            66.27Mi ± 2%   65.77Mi ± 1%        ~ (p=0.180 n=6)
Query/sum_by_(le)(h_100),_range_query_with_100_steps                                                               68.27Mi ± 2%   65.59Mi ± 2%   -3.91% (p=0.002 n=6)
Query/sum_by_(le)(h_100),_range_query_with_1000_steps                                                              85.45Mi ± 4%   67.19Mi ± 2%  -21.37% (p=0.002 n=6)
Query/sum_by_(le)(h_2000),_instant_query                                                                           70.65Mi ± 2%   69.36Mi ± 1%   -1.82% (p=0.026 n=6)
Query/sum_by_(le)(h_2000),_range_query_with_100_steps                                                             110.01Mi ± 1%   69.55Mi ± 1%  -36.78% (p=0.002 n=6)
Query/sum_by_(le)(h_2000),_range_query_with_1000_steps                                                            406.40Mi ± 0%   71.93Mi ± 2%  -82.30% (p=0.002 n=6)
Query/sum(a_1_+_b_1),_instant_query                                                                                71.78Mi ± 1%   71.98Mi ± 1%        ~ (p=0.240 n=6)
Query/sum(a_1_+_b_1),_range_query_with_100_steps                                                                   71.25Mi ± 0%   71.16Mi ± 1%        ~ (p=0.558 n=6)
Query/sum(a_1_+_b_1),_range_query_with_1000_steps                                                                  67.44Mi ± 2%   69.51Mi ± 2%   +3.07% (p=0.002 n=6)
Query/sum(a_100_+_b_100),_instant_query                                                                            65.53Mi ± 0%   65.34Mi ± 1%        ~ (p=0.407 n=6)
Query/sum(a_100_+_b_100),_range_query_with_100_steps                                                               66.25Mi ± 1%   65.04Mi ± 1%   -1.83% (p=0.002 n=6)
Query/sum(a_100_+_b_100),_range_query_with_1000_steps                                                              73.03Mi ± 2%   64.46Mi ± 1%  -11.74% (p=0.002 n=6)
Query/sum(a_2000_+_b_2000),_instant_query                                                                          68.58Mi ± 1%   67.93Mi ± 2%        ~ (p=0.394 n=6)
Query/sum(a_2000_+_b_2000),_range_query_with_100_steps                                                             89.65Mi ± 1%   68.63Mi ± 3%  -23.44% (p=0.002 n=6)
Query/sum(a_2000_+_b_2000),_range_query_with_1000_steps                                                           204.57Mi ± 0%   79.00Mi ± 4%  -61.38% (p=0.002 n=6)
Query/sum_by_(le)(rate(h_1[1m])),_instant_query                                                                    69.29Mi ± 1%   69.24Mi ± 1%        ~ (p=0.665 n=6)
Query/sum_by_(le)(rate(h_1[1m])),_range_query_with_100_steps                                                       68.84Mi ± 1%   68.84Mi ± 1%        ~ (p=0.457 n=6)
Query/sum_by_(le)(rate(h_1[1m])),_range_query_with_1000_steps                                                      66.46Mi ± 1%   65.89Mi ± 1%        ~ (p=0.082 n=6)
Query/sum_by_(le)(rate(h_100[1m])),_instant_query                                                                  66.41Mi ± 1%   66.02Mi ± 2%        ~ (p=0.119 n=6)
Query/sum_by_(le)(rate(h_100[1m])),_range_query_with_100_steps                                                     67.52Mi ± 1%   65.17Mi ± 2%   -3.48% (p=0.002 n=6)
Query/sum_by_(le)(rate(h_100[1m])),_range_query_with_1000_steps                                                    83.19Mi ± 3%   66.12Mi ± 2%  -20.52% (p=0.002 n=6)
Query/sum_by_(le)(rate(h_2000[1m])),_instant_query                                                                 72.14Mi ± 1%   71.88Mi ± 1%        ~ (p=0.589 n=6)
Query/sum_by_(le)(rate(h_2000[1m])),_range_query_with_100_steps                                                   108.57Mi ± 3%   69.08Mi ± 1%  -36.37% (p=0.002 n=6)
Query/sum_by_(le)(rate(h_2000[1m])),_range_query_with_1000_steps                                                  268.34Mi ± 1%   71.63Mi ± 2%  -73.30% (p=0.002 n=6)
Query/sum_without_(l)(rate(a_1[1m])),_instant_query                                                                71.50Mi ± 0%   71.86Mi ± 2%        ~ (p=0.180 n=6)
Query/sum_without_(l)(rate(a_1[1m])),_range_query_with_100_steps                                                   70.94Mi ± 2%   71.15Mi ± 1%        ~ (p=0.394 n=6)
Query/sum_without_(l)(rate(a_1[1m])),_range_query_with_1000_steps                                                  69.30Mi ± 1%   69.31Mi ± 2%        ~ (p=0.784 n=6)
Query/sum_without_(l)(rate(a_100[1m])),_instant_query                                                              65.94Mi ± 1%   65.20Mi ± 1%        ~ (p=0.240 n=6)
Query/sum_without_(l)(rate(a_100[1m])),_range_query_with_100_steps                                                 65.40Mi ± 2%   64.43Mi ± 1%   -1.48% (p=0.024 n=6)
Query/sum_without_(l)(rate(a_100[1m])),_range_query_with_1000_steps                                                65.48Mi ± 2%   64.20Mi ± 1%   -1.97% (p=0.002 n=6)
Query/sum_without_(l)(rate(a_2000[1m])),_instant_query                                                             68.44Mi ± 3%   66.73Mi ± 1%        ~ (p=0.132 n=6)
Query/sum_without_(l)(rate(a_2000[1m])),_range_query_with_100_steps                                                72.77Mi ± 2%   65.38Mi ± 1%  -10.16% (p=0.002 n=6)
Query/sum_without_(l)(rate(a_2000[1m])),_range_query_with_1000_steps                                              125.64Mi ± 3%   68.52Mi ± 2%  -45.46% (p=0.002 n=6)
Query/sum_without_(l)(rate(a_1[1m]))_/_sum_without_(l)(rate(b_1[1m])),_instant_query                               71.12Mi ± 1%   71.23Mi ± 1%        ~ (p=0.394 n=6)
Query/sum_without_(l)(rate(a_1[1m]))_/_sum_without_(l)(rate(b_1[1m])),_range_query_with_100_steps                  70.20Mi ± 1%   70.70Mi ± 1%        ~ (p=0.310 n=6)
Query/sum_without_(l)(rate(a_1[1m]))_/_sum_without_(l)(rate(b_1[1m])),_range_query_with_1000_steps                 67.70Mi ± 1%   68.72Mi ± 1%   +1.50% (p=0.002 n=6)
Query/sum_without_(l)(rate(a_100[1m]))_/_sum_without_(l)(rate(b_100[1m])),_instant_query                           66.11Mi ± 1%   65.69Mi ± 0%   -0.64% (p=0.013 n=6)
Query/sum_without_(l)(rate(a_100[1m]))_/_sum_without_(l)(rate(b_100[1m])),_range_query_with_100_steps              65.38Mi ± 2%   64.89Mi ± 0%   -0.74% (p=0.015 n=6)
Query/sum_without_(l)(rate(a_100[1m]))_/_sum_without_(l)(rate(b_100[1m])),_range_query_with_1000_steps             66.41Mi ± 2%   64.51Mi ± 3%   -2.87% (p=0.009 n=6)
Query/sum_without_(l)(rate(a_2000[1m]))_/_sum_without_(l)(rate(b_2000[1m])),_instant_query                         67.52Mi ± 1%   67.12Mi ± 1%        ~ (p=0.394 n=6)
Query/sum_without_(l)(rate(a_2000[1m]))_/_sum_without_(l)(rate(b_2000[1m])),_range_query_with_100_steps            74.07Mi ± 1%   66.74Mi ± 2%   -9.89% (p=0.002 n=6)
Query/sum_without_(l)(rate(a_2000[1m]))_/_sum_without_(l)(rate(b_2000[1m])),_range_query_with_1000_steps          127.55Mi ± 1%   74.03Mi ± 2%  -41.96% (p=0.002 n=6)
geomean                                                                                                            83.10Mi        69.35Mi       -16.54%

Performance comparison of this PR with main
goos: darwin
goarch: arm64
pkg: github.com/grafana/mimir/pkg/streamingpromql/benchmarks
                                                                          │  main.txt   │  after-with-no-string-alloc.txt   │
                                                                          │   sec/op    │   sec/op     vs base              │
Query/sum(a_1),_instant_query/Mimir-10                                      140.2µ ± 2%   140.3µ ± 8%       ~ (p=1.000 n=6)
Query/sum(a_1),_range_query_with_100_steps/Mimir-10                         153.5µ ± 2%   153.1µ ± 2%       ~ (p=0.818 n=6)
Query/sum(a_1),_range_query_with_1000_steps/Mimir-10                        232.7µ ± 1%   236.0µ ± 8%       ~ (p=0.485 n=6)
Query/sum(a_100),_instant_query/Mimir-10                                    843.1µ ± 1%   855.9µ ± 1%  +1.51% (p=0.009 n=6)
Query/sum(a_100),_range_query_with_100_steps/Mimir-10                       1.470m ± 3%   1.438m ± 3%       ~ (p=0.180 n=6)
Query/sum(a_100),_range_query_with_1000_steps/Mimir-10                      6.714m ± 1%   6.749m ± 1%       ~ (p=0.394 n=6)
Query/sum(a_2000),_instant_query/Mimir-10                                   11.51m ± 1%   11.39m ± 2%       ~ (p=0.180 n=6)
Query/sum(a_2000),_range_query_with_100_steps/Mimir-10                      22.08m ± 1%   21.83m ± 1%       ~ (p=0.065 n=6)
Query/sum(a_2000),_range_query_with_1000_steps/Mimir-10                     119.4m ± 1%   118.3m ± 1%       ~ (p=0.065 n=6)
Query/sum_by_(l)(h_1),_instant_query/Mimir-10                               166.2µ ± 1%   167.8µ ± 6%       ~ (p=0.240 n=6)
Query/sum_by_(l)(h_1),_range_query_with_100_steps/Mimir-10                  206.0µ ± 1%   209.7µ ± 4%  +1.76% (p=0.026 n=6)
Query/sum_by_(l)(h_1),_range_query_with_1000_steps/Mimir-10                 588.0µ ± 2%   586.6µ ± 1%       ~ (p=0.818 n=6)
Query/sum_by_(l)(h_100),_instant_query/Mimir-10                             3.991m ± 1%   3.949m ± 0%  -1.05% (p=0.002 n=6)
Query/sum_by_(l)(h_100),_range_query_with_100_steps/Mimir-10                7.433m ± 1%   7.383m ± 4%       ~ (p=0.589 n=6)
Query/sum_by_(l)(h_100),_range_query_with_1000_steps/Mimir-10               38.35m ± 1%   38.65m ± 1%       ~ (p=0.065 n=6)
Query/sum_by_(l)(h_2000),_instant_query/Mimir-10                            74.60m ± 1%   74.18m ± 1%  -0.57% (p=0.041 n=6)
Query/sum_by_(l)(h_2000),_range_query_with_100_steps/Mimir-10               140.2m ± 1%   140.3m ± 1%       ~ (p=0.937 n=6)
Query/sum_by_(l)(h_2000),_range_query_with_1000_steps/Mimir-10              734.2m ± 0%   735.0m ± 1%       ~ (p=1.000 n=6)
Query/sum_by_(le)(h_1),_instant_query/Mimir-10                              165.9µ ± 7%   168.5µ ± 1%       ~ (p=0.065 n=6)
Query/sum_by_(le)(h_1),_range_query_with_100_steps/Mimir-10                 208.4µ ± 1%   212.8µ ± 2%  +2.14% (p=0.002 n=6)
Query/sum_by_(le)(h_1),_range_query_with_1000_steps/Mimir-10                591.3µ ± 2%   603.0µ ± 4%  +1.97% (p=0.041 n=6)
Query/sum_by_(le)(h_100),_instant_query/Mimir-10                            3.952m ± 0%   3.955m ± 1%       ~ (p=0.937 n=6)
Query/sum_by_(le)(h_100),_range_query_with_100_steps/Mimir-10               7.364m ± 0%   7.448m ± 2%       ~ (p=0.065 n=6)
Query/sum_by_(le)(h_100),_range_query_with_1000_steps/Mimir-10              38.58m ± 0%   38.68m ± 1%       ~ (p=0.394 n=6)
Query/sum_by_(le)(h_2000),_instant_query/Mimir-10                           73.47m ± 0%   73.05m ± 0%  -0.56% (p=0.004 n=6)
Query/sum_by_(le)(h_2000),_range_query_with_100_steps/Mimir-10              141.0m ± 1%   140.2m ± 0%       ~ (p=0.699 n=6)
Query/sum_by_(le)(h_2000),_range_query_with_1000_steps/Mimir-10             737.8m ± 1%   740.7m ± 0%       ~ (p=0.093 n=6)
Query/sum(a_1_+_b_1),_instant_query/Mimir-10                                229.9µ ± 1%   230.6µ ± 4%       ~ (p=0.394 n=6)
Query/sum(a_1_+_b_1),_range_query_with_100_steps/Mimir-10                   249.2µ ± 1%   250.7µ ± 1%  +0.58% (p=0.041 n=6)
Query/sum(a_1_+_b_1),_range_query_with_1000_steps/Mimir-10                  388.1µ ± 1%   395.3µ ± 3%  +1.85% (p=0.002 n=6)
Query/sum(a_100_+_b_100),_instant_query/Mimir-10                            1.607m ± 1%   1.605m ± 1%       ~ (p=0.310 n=6)
Query/sum(a_100_+_b_100),_range_query_with_100_steps/Mimir-10               2.744m ± 1%   2.745m ± 1%       ~ (p=0.818 n=6)
Query/sum(a_100_+_b_100),_range_query_with_1000_steps/Mimir-10              13.11m ± 0%   13.11m ± 1%       ~ (p=0.937 n=6)
Query/sum(a_2000_+_b_2000),_instant_query/Mimir-10                          24.99m ± 1%   25.00m ± 1%       ~ (p=0.937 n=6)
Query/sum(a_2000_+_b_2000),_range_query_with_100_steps/Mimir-10             46.32m ± 1%   46.06m ± 1%       ~ (p=0.394 n=6)
Query/sum(a_2000_+_b_2000),_range_query_with_1000_steps/Mimir-10            243.8m ± 0%   243.1m ± 0%       ~ (p=0.065 n=6)
Query/sum_by_(le)(rate(h_1[1m])),_instant_query/Mimir-10                    134.4µ ± 1%   135.9µ ± 1%  +1.09% (p=0.041 n=6)
Query/sum_by_(le)(rate(h_1[1m])),_range_query_with_100_steps/Mimir-10       187.6µ ± 1%   187.4µ ± 1%       ~ (p=0.937 n=6)
Query/sum_by_(le)(rate(h_1[1m])),_range_query_with_1000_steps/Mimir-10      629.9µ ± 1%   634.9µ ± 8%  +0.80% (p=0.002 n=6)
Query/sum_by_(le)(rate(h_100[1m])),_instant_query/Mimir-10                  1.513m ± 1%   1.583m ± 3%  +4.63% (p=0.002 n=6)
Query/sum_by_(le)(rate(h_100[1m])),_range_query_with_100_steps/Mimir-10     5.606m ± 1%   5.644m ± 1%       ~ (p=0.065 n=6)
Query/sum_by_(le)(rate(h_100[1m])),_range_query_with_1000_steps/Mimir-10    42.41m ± 0%   42.31m ± 1%       ~ (p=0.180 n=6)
Query/sum_by_(le)(rate(h_2000[1m])),_instant_query/Mimir-10                 26.04m ± 1%   26.43m ± 1%  +1.51% (p=0.004 n=6)
Query/sum_by_(le)(rate(h_2000[1m])),_range_query_with_100_steps/Mimir-10    106.7m ± 1%   105.9m ± 1%  -0.80% (p=0.041 n=6)
Query/sum_by_(le)(rate(h_2000[1m])),_range_query_with_1000_steps/Mimir-10   816.8m ± 1%   808.7m ± 1%  -0.99% (p=0.004 n=6)
geomean                                                                     5.212m        5.227m       +0.30%

                                                                          │   main.txt   │   after-with-no-string-alloc.txt   │
                                                                          │      B       │      B        vs base              │
Query/sum(a_1),_instant_query/Mimir-10                                      71.38Mi ± 1%   71.73Mi ± 2%       ~ (p=0.619 n=6)
Query/sum(a_1),_range_query_with_100_steps/Mimir-10                         70.22Mi ± 1%   70.77Mi ± 1%  +0.78% (p=0.026 n=6)
Query/sum(a_1),_range_query_with_1000_steps/Mimir-10                        68.88Mi ± 1%   69.50Mi ± 1%       ~ (p=0.065 n=6)
Query/sum(a_100),_instant_query/Mimir-10                                    64.41Mi ± 0%   64.55Mi ± 1%       ~ (p=0.509 n=6)
Query/sum(a_100),_range_query_with_100_steps/Mimir-10                       64.23Mi ± 1%   64.70Mi ± 1%  +0.72% (p=0.035 n=6)
Query/sum(a_100),_range_query_with_1000_steps/Mimir-10                      64.58Mi ± 2%   64.56Mi ± 1%       ~ (p=0.589 n=6)
Query/sum(a_2000),_instant_query/Mimir-10                                   65.60Mi ± 1%   66.12Mi ± 2%       ~ (p=0.485 n=6)
Query/sum(a_2000),_range_query_with_100_steps/Mimir-10                      65.18Mi ± 2%   64.83Mi ± 1%       ~ (p=0.240 n=6)
Query/sum(a_2000),_range_query_with_1000_steps/Mimir-10                     69.77Mi ± 1%   69.26Mi ± 4%  -0.73% (p=0.015 n=6)
Query/sum_by_(l)(h_1),_instant_query/Mimir-10                               69.31Mi ± 2%   68.64Mi ± 1%       ~ (p=0.061 n=6)
Query/sum_by_(l)(h_1),_range_query_with_100_steps/Mimir-10                  68.09Mi ± 2%   68.22Mi ± 1%       ~ (p=0.589 n=6)
Query/sum_by_(l)(h_1),_range_query_with_1000_steps/Mimir-10                 66.02Mi ± 1%   66.11Mi ± 2%       ~ (p=0.677 n=6)
Query/sum_by_(l)(h_100),_instant_query/Mimir-10                             65.34Mi ± 1%   65.72Mi ± 1%       ~ (p=0.331 n=6)
Query/sum_by_(l)(h_100),_range_query_with_100_steps/Mimir-10                66.63Mi ± 2%   66.15Mi ± 2%       ~ (p=0.310 n=6)
Query/sum_by_(l)(h_100),_range_query_with_1000_steps/Mimir-10               69.43Mi ± 1%   69.30Mi ± 2%       ~ (p=0.818 n=6)
Query/sum_by_(l)(h_2000),_instant_query/Mimir-10                            70.53Mi ± 2%   70.46Mi ± 2%       ~ (p=0.485 n=6)
Query/sum_by_(l)(h_2000),_range_query_with_100_steps/Mimir-10               78.86Mi ± 3%   78.97Mi ± 3%       ~ (p=0.818 n=6)
Query/sum_by_(l)(h_2000),_range_query_with_1000_steps/Mimir-10              135.5Mi ± 5%   133.7Mi ± 4%       ~ (p=1.000 n=6)
Query/sum_by_(le)(h_1),_instant_query/Mimir-10                              69.12Mi ± 1%   68.97Mi ± 1%       ~ (p=0.485 n=6)
Query/sum_by_(le)(h_1),_range_query_with_100_steps/Mimir-10                 68.09Mi ± 1%   68.26Mi ± 1%       ~ (p=0.818 n=6)
Query/sum_by_(le)(h_1),_range_query_with_1000_steps/Mimir-10                66.27Mi ± 1%   65.93Mi ± 1%       ~ (p=0.197 n=6)
Query/sum_by_(le)(h_100),_instant_query/Mimir-10                            65.97Mi ± 1%   65.77Mi ± 1%       ~ (p=0.368 n=6)
Query/sum_by_(le)(h_100),_range_query_with_100_steps/Mimir-10               65.66Mi ± 1%   65.59Mi ± 2%       ~ (p=0.619 n=6)
Query/sum_by_(le)(h_100),_range_query_with_1000_steps/Mimir-10              66.79Mi ± 3%   67.19Mi ± 2%       ~ (p=0.394 n=6)
Query/sum_by_(le)(h_2000),_instant_query/Mimir-10                           68.97Mi ± 2%   69.36Mi ± 1%       ~ (p=0.851 n=6)
Query/sum_by_(le)(h_2000),_range_query_with_100_steps/Mimir-10              69.45Mi ± 1%   69.55Mi ± 1%       ~ (p=0.818 n=6)
Query/sum_by_(le)(h_2000),_range_query_with_1000_steps/Mimir-10             71.46Mi ± 1%   71.93Mi ± 2%       ~ (p=0.139 n=6)
Query/sum(a_1_+_b_1),_instant_query/Mimir-10                                71.95Mi ± 1%   71.98Mi ± 1%       ~ (p=0.727 n=6)
Query/sum(a_1_+_b_1),_range_query_with_100_steps/Mimir-10                   71.51Mi ± 1%   71.16Mi ± 1%       ~ (p=0.065 n=6)
Query/sum(a_1_+_b_1),_range_query_with_1000_steps/Mimir-10                  69.72Mi ± 1%   69.51Mi ± 2%       ~ (p=0.937 n=6)
Query/sum(a_100_+_b_100),_instant_query/Mimir-10                            65.22Mi ± 1%   65.34Mi ± 1%       ~ (p=0.818 n=6)
Query/sum(a_100_+_b_100),_range_query_with_100_steps/Mimir-10               65.38Mi ± 1%   65.04Mi ± 1%       ~ (p=0.584 n=6)
Query/sum(a_100_+_b_100),_range_query_with_1000_steps/Mimir-10              64.53Mi ± 1%   64.46Mi ± 1%       ~ (p=0.937 n=6)
Query/sum(a_2000_+_b_2000),_instant_query/Mimir-10                          68.23Mi ± 2%   67.93Mi ± 2%       ~ (p=0.974 n=6)
Query/sum(a_2000_+_b_2000),_range_query_with_100_steps/Mimir-10             68.36Mi ± 1%   68.63Mi ± 3%       ~ (p=1.000 n=6)
Query/sum(a_2000_+_b_2000),_range_query_with_1000_steps/Mimir-10            77.09Mi ± 3%   79.00Mi ± 4%       ~ (p=0.240 n=6)
Query/sum_by_(le)(rate(h_1[1m])),_instant_query/Mimir-10                    69.59Mi ± 2%   69.24Mi ± 1%       ~ (p=0.699 n=6)
Query/sum_by_(le)(rate(h_1[1m])),_range_query_with_100_steps/Mimir-10       68.97Mi ± 1%   68.84Mi ± 1%       ~ (p=0.937 n=6)
Query/sum_by_(le)(rate(h_1[1m])),_range_query_with_1000_steps/Mimir-10      65.96Mi ± 0%   65.89Mi ± 1%       ~ (p=0.372 n=6)
Query/sum_by_(le)(rate(h_100[1m])),_instant_query/Mimir-10                  65.58Mi ± 1%   66.02Mi ± 2%       ~ (p=0.366 n=6)
Query/sum_by_(le)(rate(h_100[1m])),_range_query_with_100_steps/Mimir-10     65.13Mi ± 1%   65.17Mi ± 2%       ~ (p=0.485 n=6)
Query/sum_by_(le)(rate(h_100[1m])),_range_query_with_1000_steps/Mimir-10    66.51Mi ± 1%   66.12Mi ± 2%       ~ (p=0.485 n=6)
Query/sum_by_(le)(rate(h_2000[1m])),_instant_query/Mimir-10                 71.50Mi ± 1%   71.88Mi ± 1%       ~ (p=0.240 n=6)
Query/sum_by_(le)(rate(h_2000[1m])),_range_query_with_100_steps/Mimir-10    68.02Mi ± 3%   69.08Mi ± 1%       ~ (p=0.093 n=6)
Query/sum_by_(le)(rate(h_2000[1m])),_range_query_with_1000_steps/Mimir-10   71.68Mi ± 2%   71.63Mi ± 2%       ~ (p=0.937 n=6)
geomean                                                                     69.28Mi        69.34Mi       +0.09%

Which issue(s) this PR fixes or relates to

(none)

Checklist

  • Tests updated.
  • [n/a] Documentation added.
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX].
  • [n/a] about-versioning.md updated with experimental features.

@charleskorn charleskorn changed the title Mimir query engine: aggregations with without Mimir query engine: add support for aggregations with without, and resolve potential hash collisions Jul 10, 2024
@charleskorn charleskorn force-pushed the charleskorn/mqe-aggregation-with-without branch from b66fb76 to 87df177 Compare July 11, 2024 01:04
@charleskorn charleskorn marked this pull request as ready for review July 11, 2024 01:56
@charleskorn charleskorn requested a review from a team as a code owner July 11, 2024 01:56
@charleskorn charleskorn changed the title Mimir query engine: add support for aggregations with without, and resolve potential hash collisions Mimir query engine: add support for aggregations with without, and resolve potential for hash collisions Jul 11, 2024
Copy link
Contributor

@jhesketh jhesketh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Just a few nits/tweaks/questions.

Copy link
Contributor

@jhesketh jhesketh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add some test cases where duplicate groups exist. For example:

sum without (env, __name__, __abc__, env) metric{}

(I used __name__ explicitly since it is added. I also used __abc__ since it'll be sorted to before __name__).

@charleskorn charleskorn force-pushed the charleskorn/mqe-aggregation-with-without branch from a38c176 to 3213a0f Compare July 16, 2024 03:27
@charleskorn
Copy link
Contributor Author

We should add some test cases where duplicate groups exist. For example:

sum without (env, __name__, __abc__, env) metric{}

(I used __name__ explicitly since it is added. I also used __abc__ since it'll be sorted to before __name__).

Good idea, added in fff95c4.

Copy link
Contributor

@jhesketh jhesketh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. LGTM!

There's a few tests that aren't done on both by and without (such as the __aaa__ one), but I don't think they are necessary.

Would appreciate if this can be behind #8577

@charleskorn charleskorn enabled auto-merge (squash) July 17, 2024 01:07
@charleskorn charleskorn merged commit 13c11a3 into main Jul 17, 2024
29 checks passed
@charleskorn charleskorn deleted the charleskorn/mqe-aggregation-with-without branch July 17, 2024 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants