Repository navigation
Fix missing rows when a projection present in only some parts is rejected - #124022
Conversation
…cted optimizeUseNormalProjections narrowed the parent ReadFromMergeTree to the parts the chosen projection does not cover (filterPartsByProjection) and recorded the projection in the query access info before the last point where it can still give up: when the projection stream and the table stream have different headers, the Union path rejects the projection and returns. The projection read was discarded, but the parent read kept the reduced part set, so the parts covered by the projection were read by nobody, and system.query_log.projections named an unused projection. The headers differ with query_plan_remove_unused_columns = 0, which compatibility <= 25.11 sets: on 26.8.10.6, SELECT count() FROM (SELECT a FROM t WHERE b = 5) returned 10 instead of 20 when PROJECTION p (SELECT * ORDER BY b) was added after the first insert. The AST fuzzer found it as a NoREC mismatch on a commit_order projection on PR ClickHouse#117394. Compute has_parent_parts without mutating the parent analysis (filterPartsByProjection keeps exactly the parts in parent_parts), and narrow the parent read and record the projection only after the projection read is wired into the plan, so a rejection has no side effects. Which projection is chosen does not change. 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; 1 finding).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261005-115600 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261005-111506 |
|
Workflow [PR], commit [4db04eb] Summary: ✅
AI ReviewSummaryThis PR fixes Final Verdict
LLVM Coverage ReportMeasured on commit 4db04eb.
Changed lines: Changed C/C++ lines covered: 21/21 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 15 s compile time in total, 7 of them have a recent master baseline. |
5a45502
Related: #117394
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed some
SELECTqueries silently returning fewer rows when the table has a projection that exists only in some of its parts (for example, one added withALTER TABLE ... ADD PROJECTIONafter data was inserted) andquery_plan_remove_unused_columnsis0, whichcompatibilityup to25.11sets.Description
On 26.8.10.6 (also 26.3.33.24, 26.5, 26.6), with
compatibility = '25.8',SELECT count() FROM (SELECT a FROM t WHERE b = 5)returns 10 instead of 20 whenPROJECTION p (SELECT * ORDER BY b)was added after the first insert. The AST fuzzer hit the same defect as a NoREC mismatch on acommit_orderprojection (count 276 vs 308): job.log, on #117394.optimizeUseNormalProjectionsremoved the parts covered by the chosen projection from the table read (filterPartsByProjection) before its last bail-out: when the projection stream and the table stream have different headers (as withquery_plan_remove_unused_columns = 0), it rejects the projection and returns, but the table read keeps the reduced part set, so those parts are read by nobody. The rejected projection was also reported insystem.query_log.projections.Now the part set is narrowed and the projection recorded only after the projection read is in the plan, so a rejection changes nothing. Which projection is chosen does not change:
force_optimize_projection = 1reports the same rejection.The new test covers a regular projection, a
commit_orderprojection with the fuzzer's_block_numberfilter, and theprefer_optimize_projectioncase of03324_union_block_structure_mismatch. It fails on master in 50/50 randomized runs and passes in 50/50 with the fix, also with parallel replicas. The 302 other projection-related tests I ran give the same results before and after.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/124022]
Version info
26.10.1.2114-master(included in26.10and later)