Repository navigation
Fix THERE_IS_NO_COLUMN through remote() and parallel replicas for tuple comparisons with a false or NULL constant element - #125195
Conversation
… ComparisonTupleEliminationPass The pass runs after constant folding and builds element comparisons with resolveOrdinaryFunctionNodeByName, which does not fold. A comparison such as equals(1, 2), equals(n, NULL) or one with a __getScalar argument stays a function on the initiator, but a remote shard or parallel replica re-analyzes the shipped query text and folds it. The secondary server then names the folded constant after its source expression, with unread columns unqualified, so the initiator fails with NOT_FOUND_COLUMN_IN_BLOCK / THERE_IS_NO_COLUMN. When resolveFunction could fold the comparison (all arguments constant, getConstantResultForNonConstArguments returns a constant, or a direct __getScalar argument), the pass now keeps the original tuple comparison. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… pass-created comparison folds The previous commit declined every comparison with a direct __getScalar argument, which dropped the rewrite for a non-NULL Array / Tuple / LowCardinality scalar facing a column, although a remote server does not fold that comparison either. Extract the scalar lookup resolveFunction uses for constant folding into tryGetScalarConstantColumn and use it in canBeConstantFolded, so the pass sees the scalar's value exactly as a fresh analysis does. resolveFunction's behaviour is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… 05350 Lines 1-2 read min(s) so the remote server never reads n: otherwise it reads its cheapest column for the row count, which can be n, and the names then match by accident. Lines 3-4 cover a NULL literal and a NULL LowCardinality scalar facing a column. Line 5 checks that a non-NULL scalar facing the key column is still rewritten and uses the primary key. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ss it makes and fold Declining every element comparison that a fresh analysis would fold also dropped the rewrite for a true constant pair, e.g. `02030_tuple_filter`'s `(1, (1, (id, value))) = (1, (1, (1, 'A')))`, which then lost the primary key (`force_primary_key` gave INDEX_NOT_USED). Such a pair is harmless on a remote server: it folds to a constant whose source expression contains no column, so both sides name it the same way, and `and(x, 1)` is not folded. The pass now asks the folding decision of `resolveFunction` (execution for constant arguments, otherwise `getConstantResultForNonConstArguments`, with its aggregate / arrayJoin / dummy / 1 MiB guards) on the nodes the remote folds: the element comparisons, then `and` with their folded results. It declines only when an element containing a column folds (NULL facing a column) or when the `and` folds (a native-number false pair). A single- element tuple still declines any fold of the comparison that replaces it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Adds a single-element NULL comparison through remote() (declined: it folds to a NULL whose source contains a column), and four primary-key lines that must keep the rewrite: a true constant pair, a false LowCardinality pair (`and` does not fold it), an arrayJoin element (resolveFunction does not fold such a node), and a column-free NULL fold. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Remove two comment lines in ComparisonTupleEliminationPass.cpp that narrate the new code; the tryFoldFunction doc comment already says when nullptr is returned. 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; 0 findings) plus my own cold review (2 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-10:20261011-125600 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261011-114200 |
|
Workflow [PR], commit [1a98856] Summary: ✅
AI ReviewSummaryThis PR teaches Findings
Final VerdictRequest changes — the same-version fix looks good, but the declined shapes still lack a rolling-upgrade-safe compatibility path. |
| if (folding_result && hasColumnNode(equals_function)) | ||
| return {}; | ||
| and_arguments.emplace_back(std::move(folding_result), equals_function->getResultType(), ""); | ||
| } | ||
|
|
||
| auto result_function = std::make_shared<FunctionNode>("and"); | ||
| result_function->markAsOperator(); | ||
| result_function->getArguments().getNodes() = std::move(tuple_arguments_equals_functions); | ||
| resolveOrdinaryFunctionNodeByName(*result_function, result_function->getFunctionName(), getContext()); | ||
|
|
||
| if (tryFoldFunction(result_function, and_arguments)) | ||
| return {}; |
There was a problem hiding this comment.
This fixes the same-version remote() / parallel-replicas re-analysis, but these decline paths are still not rolling-upgrade-safe. A new initiator now keeps the tuple comparison for the declined shapes, while an older shard still rewrites the same expression to and(equals(...), ...); distributed execution matches remote blocks by name, so the mixed-version cluster still hits NOT_FOUND_COLUMN_IN_BLOCK / THERE_IS_NO_COLUMN until every shard is upgraded.
We already carry tests/integration/test_analyzer_compatibility/test.py for this exact class of analyzer-side naming skew. Please either preserve a wire-compatible header shape when talking to older peers (the same problem also applies to the single-element decline below), or add an explicit mixed-version test that proves these declined shapes cannot cross a version boundary.
There was a problem hiding this comment.
This is a corner case. Tolerable.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units81 translation units recompiled, 528 s compile time in total, 81 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.05 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
|
@groeneai @alexey-milovidov — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
|
#125936 is fixed by #124854 (open, approved), which now closes it; measurements: #125936 (comment) |
Related: #124546
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
THERE_IS_NO_COLUMNandNOT_FOUND_COLUMN_IN_BLOCKerrors in queries overremote()or with parallel replicas that compare tuples where one pair of elements is constant and false, such as(n, 1) = (n, 2), or whereNULLis compared with a column, such as(n, s) = (NULL, s).Description
On 26.8.21.12,
SELECT NOT ((n, 1) = (n, 2)) AS r, min(s) FROM remote('127.0.0.{1,2}', currentDatabase(), t) GROUP BY rfails withTHERE_IS_NO_COLUMN. With parallel replicas the same defect makes05350_comparison_tuple_elimination_shared_aliasfail in about 1 of 130 runs (PR #105667).ComparisonTupleEliminationPassruns after constant folding and buildsand(equals(n, n), equals(1, 2))without folding it. A remote server analyzes the query again, folds1 = 2and then theandto a constant, and names that constant after its source expression, wherenis unqualified because the remote does not read it. The initiator then looks for__table1.nand does not find it.n = NULLfolds toNULLand breaks the same way.The pass now applies
resolveFunction's own folding decision and guards to the nodes it creates: the element comparisons, thenandwith their results. It keeps the original tuple comparison when a folded result would depend on a column. Constant pairs that do not makeandfold (true,NULL,LowCardinality) are still rewritten as before, so the primary key is still used. The__getScalarlookup is shared withresolveFunctionthrough a new helper. One cost: an always-false comparison such asWHERE (n, 1) = (5, 2)is no longer folded to0, so the table is read and filtered.The test gains a
remote()query for each declined shape (all fail on master) and aforce_primary_keyquery for each kept shape. 100/100 runs passed (50 with random settings), and an A/B run of 1599 related tests on master and on the fix gave the same results apart from this test.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/125195]
Version info
26.10.1.2435-master(included in26.10and later)