Skip to content

Fix a set skip index dropping matching granules for a derived indexHint over an alias named like a column - #128079

Merged
fm4v merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/set-index-hint-import-without-name-binding
Nov 18, 2026
Merged

fm4v merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/set-index-hint-import-without-name-binding

Conversation

@groeneai

@groeneai groeneai commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #128071
Related: #126219

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed missing rows with a set skip index when an outer WHERE compares columns of a subquery that gives a column the name of another one (SELECT w AS k ...), for example over remote(), and optimize_and_compare_chain or optimize_or_like_chain derives an indexHint from 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 < 3 returns 0 instead of 5. #126219 fixed this shape for the primary key and minmax, not for the set index, and on master the same query without remote() now returns 0 too (also below GROUP BY / LIMIT BY, and for OR-LIKE hints; 26.10 is correct there).

k < v AND v < 3 derives indexHint(k < 3). Since #126219 the hint's own DAG is rebound through the projection and holds k as an alias of w. The set index imported that DAG with ActionsDAG::mergeNodes, which binds every node by name, so the alias was bound to the physical column k read by t.k < 1000, and the exact per-value check evaluated k < 3 on k.

The import now uses ActionsDAG::unite, which binds nothing by name. Key columns are already bound by their alias-free name in atomFromDAG, the way KeyCondition and the other skip indexes read the hint, so a hint over k itself 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_column fails 5 of 8 lines without the fix and passes with it (also with serialize_query_plan = 1); minmax and bloom_filter controls are unaffected; 50/50 randomized runs.


Workflow [PR]
Sync PR [sync-upstream/pr/128079]

Version info

  • Merged into: 26.11.1.2748-master (included in 26.11 and later)
  • Backported to: 26.10.7.8

`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]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
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).

# Sev Finding Verdict Evidence / action
1 💡 A user-written indexHint over a name that is not a physical column at the read (an ALIAS column) is no longer bound to the filter's node of the same name, so the set index stops pruning on it AGREE, not blocking Pruning only, never a wrong result. KeyCondition and the other skip indexes never resolved such a name either; binding by name is the defect fixed here. No change.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-8:20261028-171300

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The issue script returns 0 0 0 instead of 5 3 3 on every run on master 64cc34b9e98f1 (clickhouse local, debug); EXPLAIN indexes = 1 shows ik keeping 1/25 granules.
b Root cause explained? The derived indexHint(k < 3) holds k as an alias of w after #126219's rebinding; getArguments imported the hint DAG with ActionsDAG::mergeNodes, which binds nodes by name, so the alias was bound to the physical k and the exact per-value check evaluated k < 3 on k.
c Fix matches root cause? Yes. The import no longer binds by name (ActionsDAG::unite); key columns are bound by alias-free name in atomFromDAG, as every other hint reader already does. No guard, no setting.
d Test intent preserved / new tests added? New 05457_set_index_derived_hint_alias_named_like_column: the issue shapes, remote(), OR-LIKE, two anti-vacuity preconditions and a pruning liveness line. No existing test changed.
e Both directions demonstrated? Without the fix 5 of 8 lines differ; with it the output is byte-identical (local and server, serialize_query_plan 0 and 1). Disabling the hint import reddens only the liveness line.
f Fix is general across code paths? The other readers of a hint's DAG do not bind by name; minmax and bloom_filter controls are correct on both builds; prewhere on/off, a JOIN above the subquery and OR-LIKE hints are fixed by the same change.
g Fix generalizes across inputs (params/datatypes/wrappers)? UInt32 and String set indexes; Float64/Nullable/UInt64 aliases (correct before and after); all 8 combinations of use_skip_indexes_on_data_read, secondary_indices_enable_bulk_filtering, use_skip_indexes_for_disjunctions.
h Backward compatible? (maintainer-approved exception only) Yes, no setting, format or protocol change.
i Invariants and contracts preserved? The index actions keep one input per key column name; the scratch DAG's extra nodes are never read; node pointers stay valid across the splice; nested hints are imported per level.

Session id: cron:clickhouse-impl-slot-40:20261028-164500

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @al13n321 @KochetovNicolai, could you review this and add the can be tested label so CI runs? Since #126219 a derived indexHint keeps a projection alias in its own DAG, and the set index imported that DAG with ActionsDAG::mergeNodes, which binds nodes by name, so an alias named like a physical column (w AS k) was evaluated on the column k and matching granules were dropped; the import now uses ActionsDAG::unite.

@clickhouse-gh

clickhouse-gh Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9eaad26]

Summary: ✅


AI Review

Summary

Reviewed #128079 at 9eaad269260fd7a9c512f92fc4143d7e9cb2a9b1. The change prevents a set skip index from interpreting a derived indexHint alias as an unrelated physical column by importing the hint with ActionsDAG::unite. The focused regression covers alias collisions, GROUP BY, LIMIT BY, remote, OR-LIKE hints, and continued index pruning. No actionable findings.

Missing context / blind spots
  • ⚠️ Broader CI for the current head is still pending. The new regression passes in the current head's Fast test; the original patch also passes 50 debug repetitions and bugfix validation. Runtime verification used CI results; no local build was available.
Final Verdict

Status: ✅ Approve. No changes requested.

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default comp-skip-index Skipping indexes (minmax, set, bloom) and their evaluation. labels Oct 28, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 28, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 9eaad2692 with master 5252bd271 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.61, programs/clickhouse-keeper ×0.65 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse DB::registerFunctionConversion(DB::FunctionFactory&) 5.6 s 12.6 s +9.2 s (+272%)
programs/clickhouse _ZN6detail10static_forITk7is_enumN2DB23AttributeUnderlyingTypeEZNS1_29callOnDictionaryAttributeType… 3.3 s 7.1 s +5.1 s (+251%)
Compile time of recompiled translation units

7 translation units recompiled, 14 s compile time in total, 7 of them have a recent master baseline.

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 796bacc

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Fast test (arm_darwin) / 05397_clickhouse_local_locked_path_untouched flaky, not from this PR (its diff does not touch 05397): macOS has no flock(1), so the test never holds the lock and the Another server instance in same directory is already running line is missing #128088 (mine, open)
Stateless tests (arm_binary, parallel) / 05055_format_schema_source_query_background_access flaky, not from this PR (its diff does not touch 05055): the randomized session_timezone Africa/Khartoum puts the session date ahead of the server date, so the text_log filter misses the row; it passed 21 of 21 times without randomized settings. The tested merge tree predates the fix #127797 (mine, merged)
Mergeable Check, PR praktika rollups of the rows above #128088, #127797 (the owners of the rows above)

The flaky check passed the new test 05457_set_index_derived_hint_alias_named_like_column 50 of 50 times on all five builds. The earlier Config Workflow and Finish Workflow failures were the attempts before the can be tested label. CIDB has no other FAIL or ERROR row on this head.

Session id: cron:our-pr-ci-monitor:20261029-013003

@fm4v
fm4v added this pull request to the merge queue Nov 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 17, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

The merge queue removal came from 05507_autopr_direct_read_from_text_index in Stateless tests (amd_binary, flaky check), 1 failed run out of 31 (report). This PR does not touch that test: it failed 7 more times in the last 3 weeks on master and unrelated PRs, and #132192 fixes it. The first merge queue run of this PR was green, so it can be re-queued.

@fm4v
fm4v added this pull request to the merge queue Nov 18, 2026
Merged via the queue into ClickHouse:master with commit d5221bf Nov 18, 2026
187 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 18, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 18, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 18, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 18, 2026
Backport #128079 to 26.10: Fix a `set` skip index dropping matching granules for a derived `indexHint` over an alias named like a column
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-skip-index Skipping indexes (minmax, set, bloom) and their evaluation. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.10-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

set index drops matching granules: rebound indexHint alias bound by name

6 participants