Repository navigation
Dynamic filter pushdown for PromQL group_left binary operations - #121107
valerypetrov wants to merge 24 commits into
Conversation
|
Workflow [PR], commit [30ca3ce] Summary: ✅
AI ReviewSummaryThe PR filters eligible right-side series of PromQL Missing context / blind spots
Final Verdict✅ Approve. No code changes requested. Current-head CI must complete before merging. |
…ages in group_left
`tables()` hands back an `ASTPtr`, so binding it to `auto *` did not compile, and `getExpression` is private: the public reader for the WHERE clause is `where()`, which is what the two call sites use now. `setExpression` is public and stays. Both `getExpression` call sites are fixed, not only the one the log printed first: the second sits in the branch that merges the pushed-down filter into an existing WHERE. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QtEKPyQDMCBZfJkiJcs789
|
📊 Cloud Performance Report 🟢 AI verdict: This PR only changes how PromQL group_left binary operators are translated to SQL (it pushes the left side's join groups down into the right side) and adds PromQL tests. None of the clickbench or tpch_adapted_1_official queries call prometheusQuery, so none of them run the changed code. ClickBench Q20 shows a -43.2% improvement with CPU time roughly halved (125 ms against master's usual 213-236 ms). The shift is large enough that the verdict cannot be overridden, but it cannot come from this diff; the most likely cause is a different build base, and a rerun against the exact base commit should confirm it. Q33 (-6.2%) and Q34 (-5.3%) fall inside master's normal variance, have noisy histories, and were correctly left as no change. clickbench🟢 1 improved Flagged queries (1 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes5 object files changed (+29.27 KiB total), 0 added.
711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units7 translation units recompiled, 8 s compile time in total, 7 of them have a recent master baseline. |
Eight stateless jobs failed on 05233 with the same two-line diff, reproducible
77 out of 77 runs and unaffected by settings randomization.
Subquery case: a `[5m:1m]` subquery evaluated at t=110 has its steps on epoch
multiples of 60s, so the last step inside the lookback is t=60, before the
first `target_info` sample at t=100. The right side was empty, so `group_left`
returned nothing and the two expected rows never appeared. Using a 10s step
puts a step on a sample and restores them. Deleting the two reference lines
would also go green, but would leave the case degenerate: an empty right side
returns nothing whether or not the pushdown is correct.
Rate case: the expected 0.2 is not what the engine produces. Measured on a
build without this branch, `rate(requests{host="h1"}[50s])` at t=110 is 0.3 and
`rate(rate_target[50s])` is 0.06, so the product is 0.018. Prometheus agrees:
the 10s sampled span extrapolates by half an interval to 15s, giving
10 * 1.5 / 50 and 2 * 1.5 / 50.
Both corrected values were measured, not derived.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QtEKPyQDMCBZfJkiJcs789
With group_left the right side is now filtered by the join groups of the left side. This test has 50000 right-side series and only two of them match, so it measures the work the pushdown saves. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…hat they still raise The right side is filtered by the left side's join groups before the duplicate check, so a duplicate in a group the left side lacks is not an error. The comment now says so, and the test checks that a duplicate in a matched group still raises, with and without offset. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Should be ready for review. |
Filtering the right side by the left join groups before the duplicate check hid duplicates in join groups that the left side does not have. Prometheus reports them whenever both sides are non-empty. The check now runs on the unfiltered right side and is skipped only when the left side is empty. The pushdown into the selector is kept. It also lets through the join groups that have more than one series in the selector, found by an extra read of the selector's groups, so every duplicate still reaches the check. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…mic-filter-pushdown Master now checks duplicate series per step and builds both sides in one loop. The pushdown now runs inside that loop on the right side of group_left, and the empty-left rule became a WHERE on the right side. Co-Authored-By: Claude Opus 5.5 <[email protected]>
With on () the join group is always the zero group, so the pushed filter keeps every right series once the left side is not empty, while the duplicate candidates still cost an extra read of the right selector. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The pushdown adds a read of the right selector to find duplicate candidates, so a plan for on () must have fewer reads than the same query with on (dc). Co-Authored-By: Claude Opus 5.5 <[email protected]>
The flaky check runs one changed test in many copies at once, and 05233 took 180-260 s there, over the 180 s limit for a test. Every PromQL query of it is planned for several seconds under that load. The duplicate and empty-left cases now live in their own test, so each file stays well under the limit. No case is changed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The duplicate check of the right side of group_left runs only when the left side is not empty, as in Prometheus. The emptiness was a row count, but a row of a filtered left side such as `requests > 1000` can stay with every value NULL. Such a left side has no sample, so Prometheus returns an empty result, while the check here still ran and raised on a right-side duplicate. Now only rows with at least one value are counted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Prometheus evaluates a range query step by step and returns nothing for a step where the left side of a binary operator is empty, without checking the right side for duplicates there. The right side was gated on the left side having a sample at any step, so a range query raised on a right-side duplicate that exists only at a step where the left side is empty. The right values are now kept only at steps where the left side has a sample. The pushed-down left join groups now come only from left rows that have a value, so a left series removed by a filter no longer keeps its right-side series in the join. Co-Authored-By: Claude Opus 5.5 <[email protected]>
In the asan flaky check (50 runs, 8 parallel jobs) 05233 took 141-190 s per run, and 5 of 42 runs went over the 180 s limit for a test. Every PromQL query in it is planned for several seconds there. The right-side subquery, offset and fixed @ cases move with their EXPLAIN checks to 05233_promql_dynamic_filter_pushdown_group_left_wrappers, which leaves 10 queries in 05233 and 6 in the new file. No case is changed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…mic-filter-pushdown Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@groeneai , check what's wrong with CI, prepare fix if applicable. |
|
The only red is
Your own test looks good: |
Master now checks duplicate series of binary operators after the JOIN and reports them only at steps where the matched series of the other side has a value. That replaces this branch's own duplicate handling, so the extra read of the right selector and the per-step mask of the right side are dropped, and only the pushdown of the left join groups into the right side is kept on top of master's vector matching. The tests now expect master's rule: a duplicate in a join group the left side does not have is not reported. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…mic-filter-pushdown
Co-Authored-By: Claude Opus 5.5 <[email protected]>
PromQL Compliance ReportBaseline: S3 master
Extended support (upstream engine tests): native-histogram exclusions: 149; excluded assertions: 248; upstream Note: Prometheus compliance score is unchanged vs baseline. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Speed up PromQL binary operations with
group_leftby filtering the right-side series by the left-side join groups before evaluation. Applies when the right side is a selector or a chain ofoffset, subqueries andlast_over_timeover one, except for matching withon ().Detailed description for reviewers:
The left side is materialized once, and
join_group IN (SELECT join_group FROM left WHERE <the row has a value>)is added to the right side's selector and range-aggregation stages when every wrapper keepsgroupunchanged (selector,offset, subquery,last_over_time).on ()is skipped, because its join group is always the same.group_rightis unchanged. Duplicate series are still checked by master's code after the join, so results and errors are the same as on master: the 05233_* tests give the same output on this PR and on master, apart from oneEXPLAINcheck of the pushdown.promql_group_left_dynamic_filter(50,000target_infoseries, 2 match), CI performance comparison at 3eced9f: 0.46 s to 0.22 s (selector) and 0.39 s to 0.20 s (offset) on amd_release, 0.26 s to 0.17 s (both) on arm_release; peak memory about 870 MB to 70 MB.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/121107]