Skip to content

Add test: ORDER BY <expression> (non-plain-column) skip branch in pushOrderByIntoView is untested - #109600

Merged
yariks5s merged 2 commits into
ClickHouse:masterfrom
clickgapai:qa-bot/coverage-pr94102
Jul 10, 2026
Merged

yariks5s merged 2 commits into
ClickHouse:masterfrom
clickgapai:qa-bot/coverage-pr94102

Conversation

@clickgapai

@clickgapai clickgapai commented Jul 7, 2026 •

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 #94102.
That PR The PR adds pushOrderByIntoView in src/Planner/PlannerJoinTree.cpp, a Planner-stage rewrite that pushes an outer query's ORDER BY/LIMIT into a simple VIEW's inner query AST so that a VIEW over a Distributed table can use the merge-sorted-streams optimization instead of a full coordinator s

1. ORDER BY <expression> (non-plain-column) skip branch in pushOrderByIntoView is untested
src/Planner/PlannerJoinTree.cpp:1031
Risk: PlannerJoinTree.cpp:1029-1031 computes col = sort->getExpression()->as<ColumnNode>() and returns when !col. If this !col guard were dropped or broken, execution would continue to col->getColumnSource() (line 1030) and later col->getColumnName() (lines 1137/1168) on a null pointer, causing a SIGSEGV during planning of a very common query shape (SELECT ... FROM view ORDER BY <expr> LIMIT n); alternatively an incorrectly-pushed expression sort could truncate the wrong rows per shard …
What's unique vs PR tests: The PR's 04241 test covers ~25 disable/enable cases but every ORDER BY in it is a plain column (ts, id, x, v.ts). None exercises the ORDER BY <expression> guard at line 1030-1031. This test is the only one that drives an expression ORDER BY (id % 10) through pushOrderByIntoView and asserts the pushdown is skipped.
Tags: -- Tags: no-random-settings — no-random-settings: the assertion counts 'Sorting for ORDER BY' plan steps, which is only deterministic under fixed plan-optimization settings; random settings could alter the plan shape and flake the reference
Try it on ClickHouse Fiddle

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)

Version info

  • Merged into: 26.7.1.775 (included in 26.7 and later)

@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? ✅
src/Planner/PlannerJoinTree.cpp:1030-1031 — if (!col || col->getColumnSource().get() != table_expression.get()) return; — the !col sub-branch (ORDER BY item is not a ColumnNode) is never exercised by any test.

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: 04507_view_orderby_expression_no_pushdown.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.

@yariks5s yariks5s added the can be tested Allows running workflows for external contributors label Jul 7, 2026
@yariks5s yariks5s self-assigned this Jul 7, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5a436ea]

Summary: ✅


AI Review

Summary

This PR adds a focused stateless regression test for the pushOrderByIntoView guard that rejects non-column ORDER BY expressions. The current test shape is sound: it isolates the expression-vs-column difference on the same simple view, keeps the query-plan assertion deterministic with no-random-settings, and the LLVM coverage artifact for this PR shows newly covered PlannerJoinTree.cpp:1031, which is the intended !col early-return branch.

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 7, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.02% 86.04% +0.02%
Functions 91.47% 91.47% +0.00%
Branches 78.26% 78.30% +0.04%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 120 line(s), 3 function(s) across 53 file(s) · Details

Top files
  • src/Interpreters/HashJoin/HashJoin.cpp: 10 line(s)
  • src/Functions/array/arrayNorm.cpp: 7 line(s)
  • src/Interpreters/FileCache/FileSegment.cpp: 6 line(s), 1 function(s)
  • src/AggregateFunctions/AggregateFunctionSumMap.cpp: 6 line(s)
  • src/Analyzer/Resolve/QueryAnalyzer.cpp: 6 line(s)

Full report

@yariks5s
yariks5s enabled auto-merge July 10, 2026 15:32
@yariks5s
yariks5s added this pull request to the merge queue Jul 10, 2026
Merged via the queue into ClickHouse:master with commit 1d27e24 Jul 10, 2026
346 of 347 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 10, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…pr94102

Add test: `ORDER BY <expression>` (non-plain-column) skip branch in `pushOrderByIntoView` is untested
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.

3 participants