Skip to content

Add test: Non-deterministic LIMIT BY-key predicate blocked from pushdown (the step_changes_the_number_of_rows=true gate) is untested - #110181

Merged
alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
clickgapai:qa-bot/coverage-pr110116
Aug 1, 2026
Merged

alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
clickgapai:qa-bot/coverage-pr110116

Conversation

@clickgapai

Copy link
Copy Markdown
Contributor

Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment.

This is a test-only PR — no source code changes. Please review: test quality, whether the claimed coverage gaps are real, and whether test output makes sense.

Adds test coverage for 1 untested code path(s), found during automated review of PR #110116.
That PR The PR adds a LimitByStep case to tryPushDownFilter in filterPushDown.cpp: a WHERE conjunct whose inputs are a subset of the LIMIT BY key columns (LimitByStep::getColumns()) is pushed below the LimitByStep, so it can reach storage as a primary-key condition. The push is gated to `OFFSE

1. Non-deterministic LIMIT BY-key predicate blocked from pushdown (the step_changes_the_number_of_rows=true gate) is untested
src/Processors/QueryPlan/Optimizations/filterPushDown.cpp:1038, src/Processors/QueryPlan/Optimizations/filterPushDown.cpp:160
Risk: Call chain: tryPushDownFilter -> LimitByStep case (filterPushDown.cpp:1038) -> tryAddNewFilterStep(parent_node, true, ...) -> splitFilter sets allow_deterministic_functions = !true = false (line 160) -> splitActionsForFilterPushDown refuses to push non-deterministic conjuncts. RISK: if this argument were flipped to false, a per-row non-deterministic key predicate would be pushed below LIMIT BY and evaluated on all input rows before the per-group top-N, changing which rows …
What's unique vs PR tests: PR test 04366 only uses deterministic predicates (key = '5', intDiv(1, toInt32(key))), which exercise the pushed branch. This test adds the negative case: a per-row non-deterministic key predicate that the step_changes_the_number_of_rows=true gate must KEEP above LIMIT BY — the specific behavior the true argument encodes and which no existing test covers.

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

Not applicable — test-only change.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

@clickgapai

Copy link
Copy Markdown
Contributor Author

Pre-PR Validation Gate (per ClickGap pipeline):

a) Deterministic repro? ✅
Test exercises the previously-uncovered branch and passes (correct behaviour).

b) Root cause explained? ✅
filterPushDown.cpp:1038 if (auto updated_steps = tryAddNewFilterStep(parent_node, true, nodes, keys)) — the true (deterministic-only) branch is correct but has zero test coverage; PR test 04366 only uses deterministic predicates.

c) Fix matches root cause? ✅
N/A for coverage gap — this PR adds a regression test, not a fix. Asserts current correct behaviour at the cited line.

d) Test intent preserved? / New tests added? ✅
New regression test added: 04512_filter_push_down_limit_by_nondeterministic.sql.

e) Both directions demonstrated? ✅
Test passes (MATCH) on master proving current correctness; would fail if the cited branch regressed. Single-direction is the correct shape for a coverage gap test.

f) Fix is general, not a narrow patch? ✅
Test asserts the invariant at the cited line — covers the branch, not a specific input shape.

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Jul 29, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5e0bf35]

Summary: ✅


AI Review

Summary

This PR adds a stateless regression test for the LimitByStep filter-pushdown rule that must keep non-deterministic predicates on LIMIT BY key columns above LimitBy. I reviewed the current diff, the underlying filterPushDown.cpp branch, the prior inline discussion, and the current green CI report; the revised EXPLAIN order check now distinguishes the original regression correctly, and I did not find any remaining review issue that warrants an inline comment.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jul 29, 2026
@alexey-milovidov alexey-milovidov self-assigned this Aug 1, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 1, 2026
Merged via the queue into ClickHouse:master with commit 4760ac5 Aug 1, 2026
179 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 1, 2026
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 pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants