Repository navigation
MergeTreeWhereOptimizer: group PREWHERE conjuncts by column set before selectivity estimation - #106337
Conversation
…e selectivity estimation
|
Workflow [PR], commit [50c3f0a] Summary: ✅
AI ReviewSummaryThis PR changes Final VerdictStatus: ✅ Approve |
| } | ||
| }; | ||
|
|
||
| /// Move condition and all other conditions depend on the same set of columns. |
There was a problem hiding this comment.
This part of code will group conditions by columns set. This PR do the grouping before selectivity estimation so this code can be removed
e7944a1 to
ce739a6
Compare
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 152/171 (88.89%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 37 line(s) · Uncovered code |
e692fa1
…y-column-set MergeTreeWhereOptimizer: group PREWHERE conjuncts by column set before selectivity estimation
Resolve the conflicts of backporting #110695 ("Combine I/O cost with selectivity in PREWHERE condition ordering") to 26.3. The release branch has no grouping of PREWHERE conjuncts by column set (#106337), so: - `cost_with_selectivity` is computed per conjunct in `analyzeImpl`, right before the condition is added. - The early return of `analyze` for disabled reordering is not taken: it belongs to the grouping, and every conjunct already gets its cost in `analyzeImpl`. - `Condition::toString` keeps the single `node`. - Tests 04053, 04266 and 04304 cover features absent on 26.3 and stay deleted. - The new tests drop `explain_query_plan_default`, which 26.3 does not have; its `EXPLAIN` output is the legacy one already. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
MergeTreeWhereOptimizer::analyzeImpl split the WHERE AND-chain into individual conjuncts and estimated each one's selectivity in isolation. For a query like
with a uniformly distributed over [0, 5000) and b having 200 distinct values, the estimator saw:
Because both a-conditions were individually less selective than b = 1, the optimizer placed b = 1 first in PREWHERE. But the combined range a ∈ (2500, 2502) selects only a = 2501 — ~0.02% selectivity — which is far better than b = 1. The a-conditions should be
evaluated first.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The PREWHERE optimizer now groups conjuncts that reference the same column set
before estimating selectivity, so that conditions like
a > 2500 AND a < 2502are evaluated together as a combined range (~0.02% selectivity) rather than as
two independent predicates (~50% each). This produces a more accurate ordering
of PREWHERE conditions when column statistics are available.
Version info
26.6.1.1143