Skip to content

Revert "Make a table read by a scalar subquery in a CONSTRAINT a loading dependency" - #130531

Merged
PedroTadim merged 7 commits into
ClickHouse:masterfrom
groeneai:groeneai/revert-114923
Nov 13, 2026
Merged

PedroTadim merged 7 commits into
ClickHouse:masterfrom
groeneai:groeneai/revert-114923

Conversation

@groeneai

@groeneai groeneai commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Reverts #114923

Closes: #129449
Related: #129485
Related: #114918
Related: #123489

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Description

After a restart, a view reading a session temporary table by a bare name fails with UNKNOWN_TABLE (#129449): #114923 qualifies such names with the view's database at metadata load. As asked on #129485, this reverts it; #114918 and #123489 come back.

Hand-resolved: commit 1 is git revert -m 1 659cc1c2f3c, keeping the bound of #122362, the WITH scoping of #114908, and the string overload of qualifyDictionaryNameWithDatabase that #121567 now uses. Commit 2 removes the #114908 helpers only the reverted pass used, and tests 05233 and 05317, which fail after commit 1.

Validation (debug build): the #129449 reproducer fails on master and passes here; 458 of 470 related stateless tests pass, 1 is skipped, 11 also fail on master (local setup).

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/130531]

Version info

  • Merged into: 26.11.1.2237-master (included in 26.11 and later)
  • Backported to: 26.10.5.27

groeneai and others added 2 commits November 10, 2026 14:04
…nt-subquery-loading-dependency"

This reverts commit 659cc1c, reversing
changes made to f75df10.

Conflicts resolved by removing only what ClickHouse#114923 added: the narrow
qualification pass in AddDefaultDatabaseVisitor.h is removed together with
the parts ClickHouse#114908 later added inside it; InterpreterCreateQuery.cpp keeps
the expansion bound of ClickHouse#122362 on the neighbouring call; the string overload
of qualifyDictionaryNameWithDatabase in ExternalDictionariesLoader is kept,
because the dictionary usage record of ClickHouse#121567 is built on it.
04908_constraint_subquery_loading_dependency.sh (edited by ClickHouse#124408) is
deleted with the rest of the test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With the revert, the only caller of `addWithAliases` passes
`only_recursive_with_hides_table = true`, so `collectWithExpressionAliases`
is never called and `with_expression_aliases` is never written:
`isExpressionAlias(name)` equals `expression_aliases.contains(name)` on every
remaining path. Remove the parameter, the member and both helpers (added by
ClickHouse#114908 for the removed pass); the full traversal behaves as before. The
second sentence of the comment on the string overload of
`qualifyDictionaryNameWithDatabase` named the removed metadata-load caller.

05233_udf_expansion_with_alias_scope (ClickHouse#114908) and
05317_udf_dictget_alias_column_lightweight_delete (ClickHouse#123563, issue ClickHouse#123489)
test the qualification of the names a SQL UDF brings into a CREATE, which
the revert removes; both fail on the revert commit and are deleted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @tavplubix @PedroTadim: this is the revert of #114923 you asked for on #129485; @alexey-milovidov as its author. Could one of you add the can be tested and ci-force-all labels? A Revert PR runs only the style check otherwise, and this one is hand-resolved (later work in the same files is kept, see the description), so it needs the full CI.

@clickhouse-gh

clickhouse-gh Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [64d6b1b]

Summary: ✅

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Nov 10, 2026
@PedroTadim PedroTadim added can be tested Allows running workflows for external contributors v26.10-must-backport labels Nov 10, 2026
@PedroTadim PedroTadim self-assigned this Nov 10, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-database-engines Database engine implementations (e.g., Atomic/Replicated) and database-level behavior. label Nov 10, 2026
@PedroTadim
PedroTadim enabled auto-merge November 10, 2026 16:20
PedroTadim and others added 2 commits November 12, 2026 11:19
…itly

The case relied on `CREATE` adding the current database to the `joinGet` table name, which this revert
removes. The unqualified name was then resolved against the test database at `ATTACH`, so the case no
longer covered a dropped database and the server logged `Replacing outdated dependencies` to stderr.

Related: ClickHouse/clickhouse-private#86905

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@PedroTadim
PedroTadim added this pull request to the merge queue Nov 12, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 12, 2026
@PedroTadim
PedroTadim enabled auto-merge November 13, 2026 08:32
@PedroTadim
PedroTadim added this pull request to the merge queue Nov 13, 2026
@PedroTadim
PedroTadim removed this pull request from the merge queue due to a manual request Nov 13, 2026
The revert drops `#include <Databases/DatabaseOnDisk.h>` from TablesLoader.cpp,
but `removeUnresolvableDependencies` now does a `dynamic_cast` to
`DatabaseWithOwnTablesBase` (12cee6e, merged on 2026-11-09), which got its
declaration only through that include. The merge queue build of this PR failed
with `unknown type name 'DatabaseWithOwnTablesBase'`. Include the header that
declares it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

The merge queue could not build this PR (TablesLoader.cpp:208:68: error: unknown type name 'DatabaseWithOwnTablesBase'): the revert drops the DatabaseOnDisk.h include that the dynamic_cast added by #127377 relied on. This PR's own CI skips the build (a revert PR without ci-force-all), so only the queue saw it. Fixed in b51d955 (includes Databases/DatabasesCommon.h); the full build passes locally on that head, so it can go back into the queue.

@PedroTadim
PedroTadim enabled auto-merge November 13, 2026 13:28
@PedroTadim
PedroTadim added this pull request to the merge queue Nov 13, 2026
@PedroTadim

Copy link
Copy Markdown
Member

The CI failure is unrelated

Merged via the queue into ClickHouse:master with commit d5291e7 Nov 13, 2026
204 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 13, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 13, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 15, 2026
…lify-new-stored-definitions

Conflicts in AddDefaultDatabaseVisitor.h and InterpreterCreateQuery.cpp:
master removed the post-UDF qualification pass (ClickHouse#130531, the revert of
ClickHouse#114923), and this branch had added its assignCentroid literal branch
and a setIsNewDefinition call there. Resolved by taking master's removal:
like dictGet, a dictionary name brought in by a SQL UDF body is no longer
qualified at CREATE. The full traversal and the ALTER path keep this
branch's qualification unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 16, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 removed the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 16, 2026
PedroTadim added a commit that referenced this pull request Nov 16, 2026
Backport of the revert of #114923 (CONSTRAINT scalar-subquery loading
dependency) to 26.10. Conflict: 05397_implicit_minmax_index_alias_unresolvable_attach.sql
does not exist on 26.10 (it is a master-only test the revert only re-qualified),
so it is kept absent rather than introduced here.
robot-clickhouse added a commit that referenced this pull request Nov 16, 2026
…uery in a CONSTRAINT a loading dependency"
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 16, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 16, 2026
Backport #130531 to 26.10: Revert "Make a table read by a scalar subquery in a CONSTRAINT a loading dependency"
alexey-milovidov added a commit to zvonand/ClickHouse that referenced this pull request Nov 19, 2026
Master reverted ClickHouse#114923 (ClickHouse#130531), which removed
the `current_database` parameter of `getLoadingDependenciesFromCreateQuery` and the narrow
qualification pass (`visitTableExpressionsImpl`) of `AddDefaultDatabaseVisitor`.

Resolution:
- `AddDefaultDatabaseVisitor.h`: take master, dropping the narrow pass and the members only it used;
  keep the static alias helpers of this PR which `DDLDependencyVisitor` uses.
- `DDLLoadingDependencyVisitor`: keep the `current_database` and `engine_arguments_database`
  parameters of this PR (the constraint subquery part of ClickHouse#114923 stays removed). At startup,
  `TablesLoader` passes the default database of the server, which keeps the behaviour of master there.
- Call sites in `DatabaseMemory`, `DatabaseOrdinary`, `InterpreterCreateQuery`: keep this PR's version.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov added a commit to zvonand/ClickHouse that referenced this pull request Nov 19, 2026
…st the session database

Review threads:
ClickHouse#92472 (comment)
ClickHouse#92472 (comment)

The column expressions (`DEFAULT`, constraints, ...) and the table engine with all of its arguments
are evaluated in the context of a query, so an unqualified name in them is resolved against the
current database of the session, not against the database owning the table. Only the query of a
view is bound to the owning database. Rename `engine_arguments_database` to `execution_database`
and apply it to these subtrees:
- `DDLDependencyVisitor` visits the columns, the storage and the view targets with a nested visitor
  while `current_database` is overridden, and skips them in the outer traversal. Before, the
  `SCOPE_EXIT` in `visitTableEngine` restored the database before the depth-first traversal reached
  the arguments, so `dictGet` in the sharding key of `Distributed` was resolved against the owning
  database.
- `DDLLoadingDependencyVisitor` looks only at such expressions, so it resolves everything against
  `execution_database`.

After merging master, which reverted the load-time qualification of ClickHouse#114923
(ClickHouse#130531), `TablesLoader` resolves the query of a view
against the database owning it, as the `ALTER` path and the graph of plain views do, and everything
else against the default database of the server, as master does. Remove
`05444_plain_view_dependencies_rename_after_metadata_reload`: it asserted that loading the view
qualifies its unqualified source, which master reverted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 23, 2026
…rewrite

The revert of ClickHouse#114923 (ClickHouse#130531) removed `qualifyNamesFromLegacyMetadata`:
metadata load no longer qualifies the bare names that metadata written
before SQL UDF table names were qualified at CREATE time can contain. The
rewrite reads the definitions the same way load does, so it no longer
qualifies them either, and a rewritten view keeps the state a restart gives
it. The dependencies of a rewritten definition are still resolved against
the database of the view rather than the current database of the RENAME
query.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-database-engines Database engine implementations (e.g., Atomic/Replicated) and database-level behavior. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo v26.10-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

View that reads a session temporary table by bare name breaks after restart on 26.10

5 participants