Repository navigation
Conversation
…ble functions A cluster table function (`s3Cluster`, `urlCluster`, `fileCluster`, the data lake ones, and a `url`/`s3` read converted by `parallel_replicas_for_cluster_engines`) forwards the query text to every replica, and each replica resolves the tables in it on its own. All three fan-outs whose source is a cluster table function built their `RemoteQueryExecutor`s with an empty external-tables map, so a temporary table the query reads never reached the replicas: - `ReadFromCluster::initializePipeline` (SELECT), - `InterpreterInsertQuery::distributedWriteIntoReplicatedMergeTreeOrDataLakeFromClusterStorage` (`INSERT ... SELECT` with `parallel_distributed_insert_select` into a Replicated or data lake table), - `StorageDistributed::distributedWriteFromClusterStorage` (the same into a `Distributed` table). `x IN (SELECT ... FROM tmp)` then failed on the replica with `UNKNOWN_TABLE`, which the forced `skip_unavailable_shards` hides, so every replica was dropped and the query returned no rows at all; `x IN tmp` failed with `UNKNOWN_IDENTIFIER`; the Replicated `INSERT ... SELECT` inserted nothing and the `Distributed` one failed with `UNKNOWN_TABLE`. Send each replica the temporary tables that the forwarded query names, via one helper, `ClusterProxy::getExternalTablesUsedInQuery`, used at all three sites. Only the named tables are sent, not `getExternalTables()` as a whole (which is what the `Distributed` fan-out does, see ClickHouse#43339): shipping every temporary table of the session would add its size times the replica count to every cluster table function query. Measured with an unrelated 200000-row temporary table: 2942 bytes sent by the initiator with this change, 4803828 when every temporary table is sent. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the doc comment of getExternalTablesUsedInQuery to one line and state the identifier-name match exactly. 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, then 0 on a re-run against the corrected description) and my own cold review (1 note).
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20260929-010700 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20260928-210900 |
|
Workflow [PR], commit [e1a6d15] Summary: ❌
AI ReviewSummaryThe PR forwards named temporary tables through the three cluster-storage fan-outs and adds regression coverage. Dependency discovery remains incomplete for SQL UDFs and subquery-local parser settings, leaving queries able to omit data silently. The previously reported view limitation also remains. Missing context / blind spots
Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block. Preserve dependencies introduced by SQL UDF expansion and effective nested settings, with focused regression coverage. The documented view limitation should also stop producing silent empty results. |
Build profile diff (arm_release)Commit See the job log for details. |
The replicas of a cluster table function apply `additional_table_filters`
themselves (the setting travels in the settings packet), so a filter such as
`{'_table_function.fileCluster': 'n IN (SELECT id FROM tmp)'}` reads `tmp` on
the replica. `getExternalTablesUsedInQuery` looked only at the identifiers of
the forwarded query and dropped `tmp`: the subquery form returned no rows (the
forced `skip_unavailable_shards` ignores the replicas' `UNKNOWN_TABLE`),
`n IN tmp` failed with `UNKNOWN_IDENTIFIER`, and the
`parallel_distributed_insert_select` paths inserted nothing into a Replicated
table or failed with `UNKNOWN_TABLE` for a `Distributed` one.
Also keep a temporary table whose name occurs anywhere in the text of an
`additional_table_filters` value. The text is not parsed: parsing every entry
would reject a query over an entry for another table that exceeds
`max_parser_depth` or `max_parser_backtracks`, an entry that is never parsed
today. A name that only occurs as a substring sends one table too many, never
one too few (short of an identifier spelled with escape sequences).
Review: ClickHouse#122791 (comment)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
`getExternalTablesUsedInQuery` kept a temporary table when its name occurred anywhere in the text of an `additional_table_filters` value, so a name inside a string literal or inside another identifier (`t` in `status`) was enough to send the whole table to every replica. Parse each value and collect its identifier names instead, the same rule as for the forwarded query. Every entry is still considered, not only the one keyed by the cluster table function: a replica applies the entries of every table it reads, including the tables of subqueries and of views, and a table it misses brings back the empty result. For the same reason the values set in the `SETTINGS` of a subquery are read too; they are part of the forwarded query, not of the context. An entry that does not parse contributes no names and does not fail the query, because a replica that applies it fails to parse it as well, whatever is sent; `LOGICAL_ERROR` and `MEMORY_LIMIT_EXCEEDED` are still rethrown. Review: ClickHouse#122791 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@devcrafter one design choice for this PR: the replicas resolve temporary tables by name, so it sends only the ones named in the forwarded query or in |
| { | ||
| if (const auto * set_query = ast.as<ASTSetQuery>()) | ||
| if (const auto * additional_filters = set_query->changes.tryGet("additional_table_filters")) | ||
| collectAdditionalFiltersIdentifierNames(SettingFieldMap(*additional_filters).value, settings, names); |
There was a problem hiding this comment.
collectNestedAdditionalFiltersIdentifierNames reuses the outer settings here, but a subquery runs under its own SETTINGS context (ApplyWithSubqueryVisitor::getSubqueryContext applies those changes before analysis). That means a query whose only reference to tmp is inside a subquery-local additional_table_filters entry that needs a raised max_parser_depth / max_parser_backtracks still drops tmp: this helper parses the filter under the outer limits, suppresses that parse failure, and erases the table, while the replica can parse and apply the same filter under the subquery-local limits.
Can we parse a nested additional_table_filters value under the ASTSetQuery's effective parser settings and add a regression for that shape?
| return external_tables; | ||
|
|
||
| IdentifierNameSet names; | ||
| query->collectIdentifierNames(names); |
There was a problem hiding this comment.
query->collectIdentifierNames only sees the forwarded SQL AST. With the default analyzer_inline_views = 0, a view that exists on the replicas but whose stored query reads a temporary table still contributes only the view name here, so tmp gets erased below and the shard returns the same silent empty result this PR is trying to fix.
For example, a replicated / ON CLUSTER view v AS SELECT id FROM tmp, then ... WHERE n IN (SELECT id FROM v) over fileCluster(...), still depends on tmp even though the forwarded query text names only v. If the contract is "send the temporary tables the query reads", this helper still needs to follow view expansion as well, or conservatively stop pruning when an unresolved view is referenced.
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
…end-temporary-tables
| select_to_send.list_of_selects->children.at(0), src_snapshot, local_context, src_storage_cluster->getClusterName()); | ||
| } | ||
|
|
||
| const Tables external_tables = ClusterProxy::getExternalTablesUsedInQuery(query_to_send, local_context); |
There was a problem hiding this comment.
Include SQL UDF dependencies before pruning temporary tables.
This call inspects the unexpanded INSERT AST. Unlike the regular SELECT path, neither optimized insert path replaces SQL UDF calls with their analyzed bodies before calling getExternalTablesUsedInQuery. For example, after CREATE FUNCTION has_tmp AS x -> x IN (SELECT id FROM tmp), an INSERT INTO dst SELECT n FROM fileCluster(...) WHERE has_tmp(n) SETTINGS parallel_distributed_insert_select = 2 contains no tmp identifier in the scanned AST. The helper removes tmp, so the replicas fail to resolve it; the Replicated destination path enables skip_unavailable_shards and can report success while inserting nothing.
The filter scan has the same gap: parsing an additional_table_filters value of has_tmp(n) collects n, while the replica's analyzer later expands the UDF and reads tmp.
Please expand SQL UDF dependencies on a copy of both the forwarded AST and parsed filter ASTs before pruning, with recursion protection, or preserve external tables when dependencies cannot be established. Add a focused regression using the same predicate directly and through a SQL UDF for the optimized insert paths and an additional filter.
CI finish ledger - e1a6d15Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261024-093006 |
Related: #122579
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Cluster table functions (
s3Cluster,urlCluster,fileCluster,azureBlobStorageCluster,hdfsCluster, the data lake*Clusterfunctions, andurl/s3reads distributed byparallel_replicas_for_cluster_engines) now send the replicas the temporary tables the query refers to. Previouslyx IN (SELECT ... FROM tmp)over a temporary table returned an empty result,x IN tmpfailed withUNKNOWN_IDENTIFIER, andINSERT ... SELECTfrom such a function withparallel_distributed_insert_selectinserted nothing into a Replicated table or failed withUNKNOWN_TABLEfor aDistributedone.Description
On 26.8.10.6 and master, a query over a cluster table function that reads a temporary table in an
INsubquery returns no rows at all, with no error:A cluster table function forwards the query text, and each replica resolves its tables itself. The three fan-outs whose source is a cluster table function (
ReadFromCluster, and theparallel_distributed_insert_selectpaths into a Replicated/data lake table and into aDistributedtable) passed an empty external-tables map, so the replica failed withUNKNOWN_TABLE, which the forcedskip_unavailable_shardstreats as a missing shard: every replica was dropped.A helper,
ClusterProxy::getExternalTablesUsedInQuery, returns the temporary tables whose names occur as identifiers in the forwarded query (a column of the same name counts too) or in anadditional_table_filtersvalue, also one set in a subquery'sSETTINGS, and all three sites send them. UnlikeDistributed(#43339), the other temporary tables are not sent: with an unrelated 200000-row one, the initiator sends 2942 bytes instead of 4803828.The new test fails on master and passes here; each call site, the name filter and the
additional_table_filtersnames have their own reference lines.Not covered (each behaves as on master): non-Memory temporary tables (only Memory tables are sent, as documented), a temporary table read only by the stored query of a view (unless
analyzer_inline_views = 1) or by a SQL UDF used in anadditional_table_filtersvalue or in anINSERT ... SELECTwithparallel_distributed_insert_select, andINSERT ... SELECTwhose source is aDistributedtable or a parallel-replicas read (those fail loudly).Workflow [PR]
Sync PR [sync-upstream/pr/122791]