Repository navigation
Conversation
…el replicas Selecting an ALIAS column of the table expression that parallel replicas ship as a GLOBAL JOIN temporary table failed with Code: 16. DB::Exception: There is no column or subcolumn a_v in table. (NO_SUCH_COLUMN_IN_TABLE) The issue reports it for RIGHT / RIGHT SEMI / RIGHT ANTI with parallel_replicas_prefer_local_join = 0, but none of that is required: a GLOBAL INNER JOIN at default settings fails too, with the alias on either side. What matters is that the alias-owning table expression is the one being shipped. CollectColumnSourceToColumnsVisitor reduced every referenced column to a NameAndTypePair, so the resolved expression of an ALIAS ColumnNode was discarded before buildSubqueryToReadColumnsFromTableExpression rebuilt the projections. The shard therefore received a ColumnNode with no expression child, isAliasColumn returned false because it tests exactly that, CollectSourceColumnsVisitor took the ordinary-column branch instead of addAliasColumn, and MergeTree tried to read the alias as a physical column. The plain distributed caller is unaffected because StorageDistributed runs ReplaseAliasColumnsVisitor first, which leaves no alias ColumnNode to lose; neither parallel-replicas caller has such a pre-pass. Record the resolved expression alongside the name and type, under isAliasColumn's own source-type guard so a JOIN / CROSS_JOIN / ARRAY_JOIN sourced ListNode is not mistaken for an alias body, and re-attach it to the rebuilt projections. Both construction sites need it: the table branch via ColumnNode::setExpression, and the ARRAY_JOIN branch via the three-argument constructor. Reverting only the second one reintroduces the failure for ARRAY JOIN queries, so it is not redundant. cloneAndReplace copies a node's children and only rewires the weak source, so a preserved expression would survive onto columns whose source is now the materialized temporary table. That table is built from a plain column list with no ALIAS defaults, so the value is already computed there, and leaving the expression attached makes the alias evaluated a second time on the local-plan path while the AST path reads the stored value. Clear it again on exactly the temporary tables created here, matched by identity rather than by temporary-table name: CREATE TEMPORARY TABLE, recursive CTEs and materialized CTEs also set that name and must not be touched. The MULTIPLE_EXPRESSIONS_FOR_ALIAS failure that the plain distributed path has when the same alias name resolves on both sides of a join is issue ClickHouse#107990 and has its own open PR; no line it touches is modified here. Tests: 04760 asserts values, column names and types over the alias, join-kind and dispatch matrix, including nested subqueries which route through the other shipping caller. 04761 asserts the alias evaluation count, which is what catches the second evaluation described above; a value-only test cannot see it. Both pin automatic_parallel_replicas_mode and parallel_replicas_local_plan, otherwise the test runner's randomization moves the queries off the path under test. Closes: ClickHouse#112246
The shipping path these tests exercise (buildQueryTreeForShard, reached from ClusterProxy/executeQuery.cpp and findParallelReplicasQuery.cpp) exists only on the analyzer path: with allow_experimental_analyzer = 0 the query is planned by InterpreterSelectQuery and never enters that file. Two stateless CI jobs run with that profile (ci/defs/job_configs.py:762,775, linked by tests/config/install.sh:296-298). Measured on a 1-shard/3-replica localhost cluster with the old-analyzer profile active: unpinned, both tests FAIL there with "Code: 47 UNKNOWN_IDENTIFIER: Unknown column: a_v", because the old resolver cannot resolve a table-qualified ALIAS column across a JOIN - a shape every query in both tests uses. With the pin they pass, and they still fail with the PR's own "Code: 16 NO_SUCH_COLUMN_IN_TABLE" on a binary without the fix, so liveness is preserved. enable_analyzer is pinned rather than the test being skipped with no-old-analyzer, because a skip would buy no coverage in those jobs. In the laziness test the flag goes on every arm including the enable_parallel_replicas=0 control, so the three arms differ in the dispatch mode alone. No reference byte and no source line changes. Co-Authored-By: Claude Fable 5 <[email protected]>
Internal second-model review (2 rounds; 1 major agreed and fixed, 2 nits agreed, 1 nit disagreed)An independent cold review plus a second-model gate ran over this change twice Agreed and fixed
Agreed, noted, not blocking 💡 The 💡 Draft PR #107700 touches the same file and adds an alias-inlining pre-pass at Disagreed, with evidence 💡 A suggestion to memoize the new tree walk in Checked and clean The alias-column guard is byte-equivalent to the planner's own Session id: cron:clickhouse-review-slot-50:20260804-171931 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-41:20260804-115000 |
|
cc @yakov-olkhovskiy @nickitat, could you review this? Shipping a GLOBAL JOIN side under parallel replicas rebuilds the subquery projections from names and types only, which drops an ALIAS column's resolved expression, so the shard classifies it as physical and MergeTree throws NO_SUCH_COLUMN_IN_TABLE; the fix carries the expression through and then clears it on the columns retargeted to the materialized temporary table so the alias is still evaluated exactly once. |
|
Workflow [PR], commit [00a48df] Summary: ❌
AI ReviewSummaryThis PR preserves resolved Final Verdict
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 69/71 (97.18%) · Uncovered code |
The amd_debug flaky check failed 2 of 100 runs of 04760_parallel_replicas_global_join_alias_column with "Test runs too long (> 180s)". Both failing runs drew --max_threads 32, which the runner picks with probability 0.03 (tests/clickhouse-test: "max_threads": lambda: 32 if random.random() < 0.03 else random.randint(1, 3)). Per-run durations from the job report: 48 passing runs spanned 69.7-104.1s while the two failures were 198.2s and 210.8s, so the distribution is bimodal rather than a threshold straddle, and the two outliers coincide exactly with the only setting drawn at ~3%. The cost is per-query cluster dispatch overhead, not data volume: recreating the fixture at 10 rows instead of 100 leaves the per-query cost unchanged (0.166s vs 0.174s), so shrinking the fixture cannot help. Oversubscription is what amplifies max_threads=32: pinning the server to 8 CPUs instead of 96 moves the 32-vs-4 ratio from 1.09x to 1.36x, and the CI runner is smaller still, which matches the ~2.1x seen there. Clamping the setting is the per-setting remedy the maintainers ask for instead of a blanket no-random-settings tag, and max_threads has in-tree precedent in 03469_json_read_subcolumns_combined_2_compact_merge_tree. Measured over 200 forced-failure samples each: without the clamp max_threads=32 is drawn 11 times, with it 0 times and one clamped 4. Every assertion and the .reference file are unchanged, and the test still reddens on the pre-fix binary with the Code: 16 this PR fixes.
Fixed the flaky-check runtime failure on 04760
The per-run durations show the shape of the problem: 48 passing runs span 69.7-104.1s, then Two measurements decided the remedy:
So the fix clamps that one setting instead of tagging the test
The oracle is untouched: Validation: over 200 forced-failure samples per arm, I did not add the Session id: cron:clickhouse-maint-slot-19:20260804-202100 |
CI finish ledger - 00a48dfCI fully finished on this head: 174 of 174 check-runs completed (154 success, 17 skipped, Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
None of these is reachable from this PR's diff: two are fuzzer-generated queries against tables Session id: cron:our-pr-ci-monitor:20260805-023000 |
`04757` grows the shapes it was missing relative to #113364's own matrix: two `ALIAS` columns with identical bodies, `ARRAY JOIN` on either side, `GLOBAL RIGHT JOIN`, and `GLOBAL JOIN ... USING` both selecting the key and selecting an `ALIAS` column beside it. `04758` is the #107990 regression test from #108025, covering the same-named `ALIAS` column referenced from `JOIN ON` / `WHERE` / `GROUP BY` / `ORDER BY` / a projection expression / a `GLOBAL JOIN` subquery over real `Distributed` tables. It reports six `MULTIPLE_EXPRESSIONS_FOR_ALIAS` on master. `04759` is the laziness test from #113364: an `ALIAS` column of a shipped table expression must be computed once per row on every dispatch path. Inlining keeps that property, so the reference is identical to that pull request's. On master the `parallel_replicas_local_plan=1` arm throws instead of reporting a count. Co-authored-by: Yakov Olkhovskiy <[email protected]>
The SQL rewrite read `SleepFunctionCalls` from `system.query_log`, which does not hold up. Which entry carries the counter depends on the dispatch path - the initiator aggregates the replicas' events when shipping a plan but not when shipping SQL - so the replicas' own entries have to be summed, and in CI they are not reliably in `query_log` by the time the initiator's query returns: the arm that ships SQL reported 0 instead of 20. The runner also sets its own `log_comment` per test, which the prefix filter picked up as a spurious extra row. The client's `--print-profile-events` aggregate is delivered in band with the query, so it has neither problem. Restore the shell form, which is the one #113364 has already had green in CI. Co-authored-by: Yakov Olkhovskiy <[email protected]>
|
Checked by measurement rather than by reading the two diffs: #107700 fully covers this PR, and covers strictly more. No objection to the close. Method: three debug builds in one worktree, same server config and the same fixture data. Base is pristine master at my base 45-shape matrix (5 join kinds, both sides,
My two tests on your build: Your four tests on my build: Regression sweep: Double evaluation, the one thing I expected inlining could get wrong given mine carries the resolved expression instead. Measured with a Two findings that are properties of the bug rather than of either patch, both already handled in your tests, recorded here only so they are not lost:
|
|
Fixing PR for the STID 8765-7341 Root cause: The safety check at Two notes for whoever picks this up later. Its repair of this particular shape is incidental: its new Reproducer, for the record: a |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
NO_SUCH_COLUMN_IN_TABLEwhen a query with parallel replicas selects anALIAScolumn of a table that is shipped as aGLOBAL JOINtemporary table. Closes #112246.Description
Closes: #112246
Under parallel replicas, selecting an
ALIAScolumn of the table expression shipped as aGLOBAL JOINtemporary table failed:The issue title names
RIGHT/RIGHT SEMI/RIGHT ANTIwithparallel_replicas_prefer_local_join = 0, but none of that is required: aGLOBAL INNER JOINat default settings fails too, on either side. What matters is only that the alias-owning table expression is the shipped one.Root cause: rebuilding the shipped subquery reduces each referenced column to a name and a type, dropping the
ALIAScolumn's resolved expression. The column is then classified as physical, because that classification tests exactly whether the expression is present, and MergeTree fails to read it. The plain distributed path is unaffected because it inlines alias columns beforehand; neither parallel-replicas caller does.The fix carries the resolved expression into the shipped subquery, so the analyzer's existing handling computes the alias right after reading, as on every path that does not ship. It then clears the expression on the columns that now point at the materialized temporary table, so the alias is evaluated exactly once whichever way the query is dispatched.
Validation: both reported reproducers fail before and pass after; a 45-shape matrix (either side, five join kinds,
Nullable,LowCardinality, alias-on-alias, alias overMATERIALIZED, a declared type differing from the body's,ARRAY JOIN,GLOBAL IN,JOIN USING, nested subqueries, all dispatch modes) goes from 29 failures to none, and 21 neighbouring distributed and alias tests are byte-identical. The two added tests assert values, names and types, and the alias evaluation count.The
MULTIPLE_EXPRESSIONS_FOR_ALIASfailure the plain distributed path has with the same alias name on both sides of a join is #107990, which has its own open PR; it is untouched here.