Skip to content

Fix wrong window function result when indexHint is pushed below the window - #122975

Merged
yariks5s merged 10 commits into
masterfrom
yarik/fix-index-hint-pushdown-deps
Oct 7, 2026
Merged

yariks5s merged 10 commits into
masterfrom
yarik/fix-index-hint-pushdown-deps

Conversation

@yariks5s

@yariks5s yariks5s commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

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):

Fix wrong window function results when a QUALIFY condition, or a comparison derived from it by optimize_and_compare_chain, turned into an indexHint that pruned rows below the window, Closes #121177


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

Version info

  • Merged into: 26.10.1.1763-master (included in 26.10 and later)

@clickhouse-gh

clickhouse-gh Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d96fa0b]

Summary: ✅


AI Review

Summary

This PR blocks indexHint pushdown through WindowStep, AggregatingStep, and LimitByStep, and adds focused regressions for the window / GROUP BY cases. The implementation looks consistent with the bug being fixed, but the LimitByStep branch is still unproven: the new stateless test never exercises that path.

Tests
  • ⚠️ [src/Processors/QueryPlan/Optimizations/filterPushDown.cpp:1260] The new LimitByStep guard has no focused regression. 05291_index_hint_below_window.sql covers WindowStep and GROUP BY, but nothing would fail if a future refactor accidentally re-enabled indexHint pushdown only for LIMIT BY. Please add a minimal LIMIT BY repro alongside the existing cases.
Final Verdict
  • Status: ⚠️ Request changes
  • Add a focused LIMIT BY regression alongside the existing window / GROUP BY cases.

LLVM Coverage Report

Measured on commit d96fa0b.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 79.60% 79.60% +0.00%

Changed lines: Changed C/C++ lines covered: 51/51 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. labels Sep 29, 2026
@nihalzp nihalzp self-assigned this Sep 30, 2026
Comment thread src/Interpreters/ActionsDAG.cpp Resolved
Comment thread src/Interpreters/ActionsDAG.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added comp-query-optimizer Query plan optimization: physical plan steps, plan-level rewrites and optimizations (QueryPlan pa... and removed comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. labels Sep 30, 2026
Comment thread src/Interpreters/ActionsDAG.cpp Resolved
Comment thread src/Interpreters/ActionsDAG.cpp Resolved
Comment thread src/Interpreters/ActionsDAG.h Resolved
@clickhouse-gh

clickhouse-gh Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing d96fa0b91 with master 6ad0aa3dd (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.

Compile time of recompiled translation units

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

Job report

@yariks5s
yariks5s added this pull request to the merge queue Oct 7, 2026
Merged via the queue into master with commit af71dec Oct 7, 2026
150 checks passed
@yariks5s
yariks5s deleted the yarik/fix-index-hint-pushdown-deps branch October 7, 2026 20:09
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 7, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

@yariks5s @nihalzp — ClickGap found the following in this PR:

Close anything that's wrong or already addressed.

leshikus pushed a commit to leshikus/ClickHouse that referenced this pull request Oct 13, 2026
This reverts commit 338b873 (ClickHouse#110114),
reversing changes made to 662a0a0.

A filter pushed below the window can reach the probe side of a hash join,
which is read only after the build side, so an always-false filter such as
IN over an empty subquery no longer stops the query before the build (ClickHouse#123875).

Conflict resolution: ClickHouse#122975 later changed the reverted branch; the whole
branch is removed, its other call sites and its test stay.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-ClickHouse__ClickHouse that referenced this pull request Oct 28, 2026
Since ClickHouse#122975 a filter pushed below AggregatingStep / MergingAggregatedStep /
LimitByStep refuses every indexHint, because a user-written hint is row-level
TRUE and pruning by it below a key step can drop part of a group. That also
refuses the hints optimize_and_compare_chain derives (`a < b AND b < 10` adds
`indexHint(a < 10)`), and since a hint blocks its ancestors, an OR holding one,
so such HAVING / outer WHERE filters read the whole table.

A derived hint is implied by the other conjuncts of its `and`, so the granules
it prunes contain only rows of groups the filter rejects anyway. Mark such
hints in FunctionIndexHint, carry the mark through the planner and
buildFilterActionsDAG, and admit only marked hints at key steps. The planner
deduplicates equal hints by name, so a user hint equal to a derived one
clears the mark of the shared node.

Closes ClickHouse#124502

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-query-optimizer Query plan optimization: physical plan steps, plan-level rewrites and optimizations (QueryPlan pa... pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

4 participants