Repository navigation
Conversation
|
Workflow [PR], commit [823d37c] Summary: ✅
AI ReviewSummaryThis PR fixes part of the parameterized-view qualification round-trip: formatting stored view definitions and Findings❌ Blockers
Tests
Final Verdict
LLVM Coverage ReportMeasured on commit 823d37c.
Changed lines: Changed C/C++ lines covered: 59/62 (95.16%) · Uncovered code |
Build profile diff (arm_release)Commit See the job log for details. |
… as one quoted token
| if (isParameterizedView() && storage_id.hasDatabase() | ||
| if (isParameterizedView() | ||
| && storage_id.hasDatabase() | ||
| && Identifier{table_function_name}.getPartsSize() == 1) |
There was a problem hiding this comment.
TableFunctionNode::toASTImpl still misses the case where the query tree already carries a qualified parameterized-view name. For a direct SELECT * FROM db.pv(p = 1), QueryTreeBuilder stores table_function_name == "db.pv", so this getPartsSize() == 1 guard is false and the emitted ASTFunction keeps isCompoundName == false. Any query_tree->toAST() user (EXPLAIN QUERY TREE ... dump_ast, ClusterProxy::executeQuery, etc.) then formats the call back as `db.pv`(p = 1).
That is not only cosmetic with the new Context::executeTableFunction fallback: a receiver that still resolves table functions through that legacy path now tries the literal current-database view db.pv first. If both current_db.db.pv and db.pv exist, the forwarded analyzed query binds the wrong parameterized view. setIsCompoundName(true) needs to depend on the final emitted name having two parts, not on the original table_function_name having one part.
| StoragePtr table; | ||
| for (const auto & [candidate_database, candidate_table] : candidates) | ||
| { | ||
| table = DatabaseCatalog::instance().tryGetTable({candidate_database, candidate_table}, getQueryContext()); |
There was a problem hiding this comment.
The new two-candidate lookup still stops at the first existing table, even if that storage is not a parameterized view.
A concrete trace is:
currentDatabase()contains a plain table or non-parameterized view named`db.pv`- database
dbcontains the parameterized viewpv - stored old metadata or another round-trip produces
`db.pv`(p = 1)
Here candidates becomes {current_db, "db.pv"} and {"db", "pv"}. The loop breaks on the first storage at current_db.db.pv, the isParameterizedView() branch is skipped, and execution falls through to TableFunctionFactory::get, so the split db.pv candidate is never tried.
That means the "repair already-collapsed metadata" part of the fix is still incomplete whenever a plain dotted-name table shadows the literal reading. The lookup should keep scanning until it finds a parameterized view, not stop at the first arbitrary storage.
| # the name and when the whole name arrives inside one quoted identifier: an AST round-trip (view | ||
| # metadata, `ON CLUSTER` DDL, a query shipped to another server) collapses `db.pv` into the single | ||
| # quoted token `db.pv`. | ||
| echo "--- resolution" |
There was a problem hiding this comment.
05153 no longer covers the two paths this PR still relies on fixing: the legacy --enable_analyzer 0 resolution in Context::executeTableFunction, and the query_tree->toAST() / forwarded-query round-trip for an already-qualified parameterized-view name.
The current assertions all pass on the default analyzer path plus formatting / EXPLAIN SYNTAX, so they would not fail on either remaining bug above. Please keep an explicit legacy-analyzer case and add one focused dump_ast or equivalent round-trip assertion for the qualified query-tree path.
…ormatting The formatter wrote the compound name of `db.view(...)` as one quoted identifier, `` `db.view`(...) ``, which parses back as a one-part name. Stored definitions, Replicated database DDL and queries sent to other servers then carried the ambiguous spelling, and a server that splits such a name only for a compound identifier (any release before the previous commit) failed with UNKNOWN_FUNCTION. ASTFunction now writes a compound name part by part, and TableFunctionNode marks a two-part parameterized view name as compound when the analyzer converts the query tree back to an AST. Context::executeTableFunction and the EXPLAIN SYNTAX view inlining also fall back to the whole name in the current database when the split name does not resolve, so a view whose own name contains a dot, `` `v.x`(...) ``, is still found where it was before (the old analyzer on releases that still have it). Related: ClickHouse#119027 Co-Authored-By: Claude Opus 5.5 <[email protected]>
… and EXPLAIN SYNTAX like SELECT does A stored query writes `db.view(...)` as `` `db.view`(...) ``, which parses back as a one-part name without the parser's compound-name flag (Replicated database DDL entries, Atomic metadata after a restart or ATTACH). The analyzer splits such a name on the dot with extractDatabaseAndTableNameForParameterizedView, but Context::executeTableFunction and the EXPLAIN SYNTAX view inlining split it only when the flag is set, so they looked for a view literally named `db.view` in the current database and failed with UNKNOWN_FUNCTION. INSERT ... SELECT reaches executeTableFunction through JoinedTables::getLeftTableStorage whenever parallel_distributed_insert_select is not 0 (the default): the replicated and Distributed destination checks resolve the source there. So an INSERT into ReplicatedMergeTree or Distributed, and the refresh of a refreshable materialized view into a replicated table, failed. Both places now call the analyzer's helper. Names with three or more parts still fall through to the table function factory, as before. Closes ClickHouse#128872 Related: ClickHouse#119027, ClickHouse#118193 Co-Authored-By: Claude Opus 5.5 <[email protected]>
A qualified parameterized view reference
db.view(params)was formatted back as the singlequoted token
`db.view`(params), becauseASTFunctionkeeps only a boolean saying thatthe parser saw the dot outside backticks, and that bit does not survive format-and-parse.
Storing a view,
ON CLUSTERDDL and shipping a query fragment to a replica all go throughsuch a round-trip, so
CREATE VIEW v AS SELECT * FROM db.pv(p = 1)was stored with thequalification collapsed. The analyzer tolerates the collapsed spelling because it always
splits the name on the dot, but
Context::executeTableFunctiononly split it when theparser had flagged the name as compound, so on the old analyzer the reference resolved to
a table literally named
db.pvand failed withUNKNOWN_FUNCTION.ASTFunction::formatImplnow quotes the parts of a compound name separately, so thereference round-trips unchanged, and
Context::executeTableFunctionconsiders both readingsof a dotted name —
database.table, and the literal name in the current database —preferring the one the parser saw, which repairs views whose metadata already carries the
collapsed spelling.
TableFunctionNode::toASTImplmarks a qualified parameterized-view nameas compound so fragments sent to replicas format the same way.
Related: #87267
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A database-qualified reference to a parameterized view, such as
SELECT * FROM db.pv(p = 1), is no longer stored with its qualification collapsed into a single quoted identifier, and such a collapsed reference in existing metadata now resolves again instead of failing withUnknown table function db.pv.Workflow [PR]
Sync PR [sync-upstream/pr/119027]