Repository navigation
Fix a set skip index dropping matching granules for a derived indexHint over an alias named like a column - #128079
Conversation
`k < v AND v < 3` derives `indexHint(k < 3)`. Since ClickHouse#126219 the hint's own DAG is rebound through the projection and keeps aliases, so for `SELECT w AS k ...` it holds `k` as an alias of `w`. `getArguments` in the set index imported that DAG with `ActionsDAG::mergeNodes`, which binds every node to an existing node of the same name. When the read also references the physical `k` (`t.k < 1000`), the alias was bound to that column, and the exact per-value evaluation tested `k < 3` on `k`, dropping granules whose rows match (ClickHouse#128071). Import the hint's nodes with `ActionsDAG::unite`, which matches nothing by name. Key columns are bound by their alias-free name in `atomFromDAG`, the same way `KeyCondition` and the RPN-based skip indexes read the hint, so a hint over the key column itself still prunes. This also fixes the `remote()` local-replica shape with a set index, which still returned 0 instead of 5 on master after ClickHouse#126219. Closes ClickHouse#128071 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review (1 nit).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261028-171300 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261028-164500 |
|
cc @al13n321 @KochetovNicolai, could you review this and add the |
|
Workflow [PR], commit [9eaad26] Summary: ✅
AI ReviewSummaryReviewed #128079 at Missing context / blind spots
Final VerdictStatus: ✅ Approve. No changes requested. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units7 translation units recompiled, 14 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger - 796baccEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The flaky check passed the new test Session id: cron:our-pr-ci-monitor:20261029-013003 |
|
The merge queue removal came from |
Backport #128079 to 26.10: Fix a `set` skip index dropping matching granules for a derived `indexHint` over an alias named like a column
Closes: #128071
Related: #126219
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed missing rows with a
setskip index when an outerWHEREcompares columns of a subquery that gives a column the name of another one (SELECT w AS k ...), for example overremote(), andoptimize_and_compare_chainoroptimize_or_like_chainderives anindexHintfrom it.Description
On 26.8 and 26.9, with
INDEX ik k TYPE set(0),SELECT count() FROM (SELECT w AS k, v FROM remote('127.0.0.1', currentDatabase(), t) AS t WHERE t.k < 1000) WHERE k < v AND v < 3returns 0 instead of 5. #126219 fixed this shape for the primary key andminmax, not for thesetindex, and on master the same query withoutremote()now returns 0 too (also belowGROUP BY/LIMIT BY, and for OR-LIKE hints; 26.10 is correct there).k < v AND v < 3derivesindexHint(k < 3). Since #126219 the hint's own DAG is rebound through the projection and holdskas an alias ofw. Thesetindex imported that DAG withActionsDAG::mergeNodes, which binds every node by name, so the alias was bound to the physical columnkread byt.k < 1000, and the exact per-value check evaluatedk < 3onk.The import now uses
ActionsDAG::unite, which binds nothing by name. Key columns are already bound by their alias-free name inatomFromDAG, the wayKeyConditionand the other skip indexes read the hint, so a hint overkitself still prunes (1 of 25 granules in the test). A backport of #126219 needs this PR too.Validation:
05457_set_index_derived_hint_alias_named_like_columnfails 5 of 8 lines without the fix and passes with it (also withserialize_query_plan = 1);minmaxandbloom_filtercontrols are unaffected; 50/50 randomized runs.Workflow [PR]
Sync PR [sync-upstream/pr/128079]
Version info
26.11.1.2748-master(included in26.11and later)26.10.7.8