Repository navigation
Fix lost rows and LOGICAL_ERROR for a distributed window query whose table column is used only in indexHint - #124982
Conversation
A window over a multi-shard remote()/Distributed read whose table column is referenced only inside indexHint aborted the initiator with "Invalid number of columns in chunk pushed to OutputPort. Expected 0, found 1" (STID 2270-30fd). The shard and the initiator decided "this table expression carries only its row count" from what the storage reads. CollectSourceColumnsVisitor skips indexHint arguments only for a MergeTree TableNode, so the shard (real MergeTree) synthesized a column and added __row_count_marker, while the initiator (StorageDummy) read the column, had nothing row-count-only and kept an empty header. For a non-MergeTree source neither side added the marker and the remote rows were silently dropped. Decide it from the query tree instead: a table expression whose columns are all referenced only inside indexHint records them as row-count-only, the role the synthesized column plays for MergeTree, and the row-count-only identifier becomes a set. Physical reads do not change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Count nested indexHint calls instead of using a flag, so a column after an inner hint still counts as referenced only inside indexHint; an inlined ALIAS expression no longer decrements the depth on leave. Pass the depth to the visitor of an ALIAS expression, so the columns of an ALIAS used inside indexHint are hint-only there too. Do not count an ALIAS column as an outside reference when its expression, with nested ALIAS columns expanded, uses table columns only inside indexHint, which is what the shard sees after the ALIAS is inlined. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Pin serialize_query_plan = 0 on the two 05345 assertions that compare a remote count with a local one: with a serialized plan the shards do not prune granules by indexHint, so the remote count does not match twice the local read under the distributed plan test profile. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the clause describing the MergeTree branch from the row-count-only comment in PlannerJoinTree.cpp. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (click to expand)Round 1 (head
Round 2 (head
Round 3 (head Also noticed: with |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261009-184800 |
|
Workflow [PR], commit [344d8b9] Summary: ✅
AI ReviewSummaryThe PR fixes lost rows and inconsistent mergeable-stage headers when distributed window queries reference columns only inside Final VerdictStatus: ✅ Approve |
CI finish ledger - d7d5e99Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261010-023009 |
|
Follow-up to the ledger above for The test was stuck in its |
…buted-index-hint-only-row-count # Conflicts: # src/Planner/TableExpressionData.h
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes16 object files changed (+42.19 KiB total), 0 added.
711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units57 translation units recompiled, 692 s compile time in total, 57 of them have a recent master baseline. |
Related: #113469
Related: #119373
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a window function over a multi-shard
remote(),cluster()orDistributedread that references a table column only insideindexHint, for exampleSELECT count() OVER () FROM remote(...) QUALIFY indexHint(k = 7): it returned no rows from the remote shards or failed withLOGICAL_ERROR.Description
On 26.9.9.28,
SELECT count() OVER () FROM remote('127.0.0.{1,2}', currentDatabase(), t) QUALIFY indexHint(k = 7)returns no rows instead of 200. On master the same query fails withLogical error: 'Invalid number of columns in chunk pushed to OutputPort. Expected 0, found 1', found by AST fuzzer (amd_tsan) on an unrelated PR (STID 2270-30fd).Root cause: #113469 replaces a mergeable-stage header that carries only a row count with
__row_count_marker, and decides "only a row count" from what the storage reads.indexHintarguments are not read from a MergeTree table, so the shard adds the marker, while the initiator plans against aStorageDummy, reads the column, and expects an empty header. For a non-MergeTree table neither side adds the marker and the remote rows are dropped.The fix decides it from the query tree, which both sides share: when every column a table expression reads is referenced only inside
indexHint, those columns are row-count-only too, like the column synthesized for a MergeTree table. The visitor now also keeps the hint scope after a nested hint and inside anALIASexpression, and looks through anALIAScolumn whose expression uses columns only insideindexHint, as the shard query inlines it. MergeTree still skipsindexHintarguments, now also behind a nested hint. Mixed versions keep the trade-off of #113469: an older initiator reading this shape from an upgraded non-MergeTree shard getsLOGICAL_ERRORinstead of losing the rows.The new test covers
remote()andDistributed, QUALIFY/WHERE/PREWHERE, MergeTree, Memory andview()sources,ALIAScolumns,serialize_query_plan,prefer_localhost_replica = 1and nested hints in either order. 17 of 18 cases fail without the fix (12 withLOGICAL_ERROR, 5 with no rows); the 18th guards the hint scope of a local PREWHERE. All pass with the fix, and 50 randomized runs pass.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/124982]