Repository navigation
Conversation
…rom metadata `CREATE VIEW` leaves a table name unqualified on purpose when it resolves to a temporary table of the creating session, so that every reading session resolves it to its own temporary table. Since ClickHouse#114923, `qualifyNamesFromLegacyMetadata` qualified every name of a view's SELECT with the view's database when the definition was loaded from metadata, under a session-less context. After a restart or `ATTACH DATABASE`, the view then read `<view db>.<name>`: `UNKNOWN_TABLE` / `UNKNOWN_IDENTIFIER`, or a permanent table of the same name in the view's database instead of the session's temporary table. Nothing reads an ordinary view's SELECT at attach time; it is resolved only under the reading query, as on 26.9. So the load-time repair now covers the SELECT of materialized views only, and the column defaults and constraints of every table, which are analyzed at attach. The dependency graphs are unchanged, because they resolve a bare name against the owning database anyway. Closes ClickHouse#129449 Co-Authored-By: Claude Opus 5.5 <[email protected]>
After a reload, the view must read the session's temporary table, not the permanent table of the same name in the view's database. Each view's whole result is now checked as one `groupArray` row. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (2 rounds): 1 issue fixed, 1 out of scope
Round 2 (test-only delta): no findings. |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261105-122300 |
|
cc @alexey-milovidov @tavplubix, could you review this and add the |
|
Workflow [PR], commit [93d9ee2] Summary: ❌
AI ReviewSummaryThis PR restores session temporary-table resolution through ordinary views after metadata reload, while preserving owning-database resolution for legacy definitions and Consumers traced for the query-dependent metadata:
Missing context / blind spots
Final VerdictStatus: ✅ Approve. No new inline findings or thread changes. The normal CI gate still needs its full rerun. |
Build profile diff (arm_release)Comparing commit See the job log for details. |
CI finish ledger - 5f077f9Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261105-190008 |
Three more views read the session's temporary objects by an unqualified name: one over a temporary view, one over another view of the database that reads the temporary table, and one calling `dictGet` on the temporary table. On master each fails with `UNKNOWN_TABLE` after the reload; with the fix each reads the new session's objects. Six controls cover views over a materialized view, a refreshable materialized view, a dictionary, a `ReplicatedMergeTree` table, a table of a `Replicated` database, and a view inside a `Replicated` database. They pass both on master and with the fix. A view inside a `Replicated` database over a temporary table is not covered: `CREATE VIEW` there stores the name qualified with the database, so the creating session cannot read it either, before any reload, on master and with the fix. Requested in ClickHouse#129485 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
The previous commits stopped qualifying the SELECT of an ordinary view loaded from metadata, so that a name left unqualified at CREATE because it was a temporary table keeps resolving to the temporary table of the reading session. That also dropped the 26.10 repair of legacy metadata (names introduced by SQL UDF expansion before they were qualified at CREATE): such a view resolved the name against the current database of the reader again, and a table whose CONSTRAINT reads it failed to attach (UNKNOWN_TABLE, ASYNC_LOAD_WAIT_FAILED). Now `StorageView` repairs the stored SELECT itself when the definition is read back from metadata, as `qualifyNamesFromLegacyMetadata` did, and keeps the stored one. `getInMemoryMetadataPtr` re-qualifies the stored SELECT under the reading context when that context has temporary tables, so a temporary table of the session takes precedence, as it does at CREATE. A `DEFINER` or `NONE` view keeps the qualified SELECT: its body runs in a context without the temporary tables of the reader, so a bare name would resolve against the current database of the reader. `alter` keeps using the stored metadata. The test gains a table with a CONSTRAINT that reads such a view (it attaches after DETACH/ATTACH DATABASE), the same view read without the temporary table, `SQL SECURITY DEFINER` and `NONE` views, and an `ALTER` from a session with the temporary table. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 61167d7Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
No job was dropped, and Session id: cron:our-pr-ci-monitor:20261107-023005 |
tavplubix
left a comment
There was a problem hiding this comment.
I'm not sure if we needed #114923 in the first place
A scalar subquery in CHECK never works for inserts. Its only effect is that it runs at CREATE and at every attach.
That's what makes the table fragile at startup, and it's the case #114923 and its load-time repair were built around.
So #114923 hardened loading for a construct that can't accept an insert, and the "legacy repair" it added to support that caused #129449 and the joinGet regressions.
Rejecting scalar subqueries in CHECK/ASSUME at CREATE and ALTER ADD CONSTRAINT, as #85575 suggested, would be the simpler fix.
Tables that already have one would still need to load, so it couldn't be an error on attach.
If you want, I can draft an issue proposing it, with links to #85575, #114923 and #129449.
|
@tavplubix I measured the premise:
Reverting the whole load-time repair of #114923 would also return materialized views, column defaults and constraints written before 26.10 to 26.9 resolution, and the dependency graphs are built from the repaired names, so I would not do that here. I did not find a reported Which one do you prefer, 1 or 2? |
CI finish ledger - 93d9ee2Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261109-133006 |
Reverting #114923 does. @PedroTadim please double-check. Also please check what happens if I pass a temporary table to the scalar subquery in CHECK in #114923 description
None of them, both are wrong. |
Measured with
So #114923 does not help here, and it adds a wrong dependency. The revert does fix #129449: the reproducer returns
I'll open the full revert and link it here. If you want the SQL UDF part kept, say so. With the revert, this PR is not needed. |
|
Closing this PR in favor of the revert |
|
The revert is #130531. |
Fix a view over a temporary table failing with
UNKNOWN_TABLEafter a restartCloses: #129449
Related: #114923
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a view that reads a temporary table by its unqualified name failing with
UNKNOWN_TABLE(or reading a table of the same name in the view's database) after a server restart orATTACH DATABASE, because the name was qualified with the view's database when the view was loaded. Closes #129449.Description
On 26.10.2.103-stable, a view that reads a session temporary table by its unqualified name fails with
UNKNOWN_TABLEafter a server restart (#129449), or reads a table of that name in the view's database.Caused by #114923 (CI build of its merge
659cc1c2fails, of its first parentf75df105passes):qualifyNamesFromLegacyMetadata, which repairs names that SQL UDF expansion left bare in older metadata, also qualified an ordinary view's SELECT with the view's database on load, where no session exists.CREATE VIEWleaves a temporary table's name unqualified on purpose.StorageViewnow does that repair itself and keeps the SELECT as stored. When the reading query has temporary tables, the stored SELECT is re-qualified under that query, so a temporary table of the session takes precedence, as atCREATE. Otherwise the name resolves to the view's database, as on 26.10, also in another table'sCONSTRAINTevaluated at attach.SQL SECURITY DEFINERandNONEviews always use the repaired SELECT, since they run without the reader's temporary tables. Materialized views, column defaults, constraints and the dependency graphs are unchanged.Validation: the test reloads views with
DETACH/ATTACH DATABASE. Eight read temporary objects (FROM, JOIN,IN, scalar subquery,dictGet, a temporary view, a view over a view, a temporary table named like a table of the view's database): each fails on master and passes with the fix, also with randomized settings, as does the issue's repro across a real restart. Passing on both: six controls (materialized views, dictionary,ReplicatedMergeTree,Replicateddatabase), a table whoseCONSTRAINTreads such a view attaching (it failed on the previous head of this PR), andDEFINER/NONEviews and a reader without the temporary table reading the view's database, also after anALTERfrom a session that has it.Workflow [PR]
Sync PR [sync-upstream/pr/129485]