Repository navigation
Optimize LIMIT BY by removing redundant key expressions - #106818
Conversation
…e_functions_in_limit_by`
|
Workflow [PR], commit [8ad62d4] Summary: ✅
AI ReviewSummaryThis PR adds analyzer passes and settings to simplify Missing context / blind spots
Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block Minimum required actions: preserve |
|
📊 Cloud Performance Report 🟢 AI verdict: This sync PR adds LIMIT BY query-tree optimization passes and moves the GROUP BY key logic into shared helpers — behavior-preserving for queries that don't use LIMIT BY. None of the flagged ClickBench/TPC-H queries use LIMIT BY, so the change can't directly speed them up. Q22's -23% improvement sits on a very high-variance query and is downgraded as run-to-run noise. The other three (Q23 -32%, TPC-H Q7 -36%, Q20 -50%) are large and consistent enough that their verdicts stand, but since the PR doesn't touch their execution path, the magnitudes most likely reflect measurement conditions rather than a direct effect of this change. clickbench🟢 1 improved · Flagged queries (2 of 43)
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🟢 2 improved Flagged queries (2 of 22)
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. Debug info
|
vdimir
left a comment
There was a problem hiding this comment.
Since we're reusing the same code for GROUP BY, it should be totally safe, LGTM
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 149/154 (96.75%) | Lost baseline coverage: none · Uncovered code |
3eb4c7b
LIMIT n BY ...evaluates and hashes its key expressions for every row. When a key is a function of another key, or wraps a key in an injective function, it adds nothing to the partitioning but is still computed per row. This PR adds two analyzer passes (theLIMIT BYcounterparts of the existingGROUP BYoptimizations) that simplify the key list:optimize_limit_by_function_keys: drops a key that is a deterministic function of the other keys, e.g.LIMIT 5 BY x, f(x)becomesLIMIT 5 BY x.optimize_injective_functions_in_limit_by: replaces an injective function of a key by its argument, e.g.LIMIT 5 BY toString(x)becomesLIMIT 5 BY x.Both are enabled by default.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Speed up
LIMIT BYqueries by removing redundant key expressions: a key that is a deterministic function of the other keys is dropped (e.g.LIMIT 5 BY x, f(x)becomesLIMIT 5 BY x), and an injective function of a key is replaced by its argument (e.g.LIMIT 5 BY toString(x)becomesLIMIT 5 BY x). This evaluates fewer and cheaper expressions per row. Controlled by the new settingsoptimize_limit_by_function_keysandoptimize_injective_functions_in_limit_by, both enabled by default.Version info
26.6.1.839