forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 18
Antalya-26.3: Resolve currentDatabase() in Hybrid segment metadata #1995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mkmkme
wants to merge
4
commits into
antalya-26.3
Choose a base branch
from
mkmkme/antalya-26.3/hybrid-restart
base: antalya-26.3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7ba1a9d
Resolve currentDatabase() in Hybrid segment metadata
mkmkme 081738e
reduce code duplication, fix the original call instead
mkmkme 03fb9e9
replace integration test with a stateless one
mkmkme 1037c7d
fix 03645_hybrid_watermarks after the changes
mkmkme File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
tests/queries/0_stateless/03645_hybrid_watermarks.reference
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
tests/queries/0_stateless/04302_hybrid_current_database_reattach.reference
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| 4 | ||
| 4 |
38 changes: 38 additions & 0 deletions
38
tests/queries/0_stateless/04302_hybrid_current_database_reattach.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| -- Reproduce the Hybrid currentDatabase() metadata bug without a server restart. | ||
| -- Detaching the table and re-attaching it while a different database is current | ||
| -- mimics the missing session-database context that startup ATTACH has. Before the | ||
| -- fix the stored metadata keeps currentDatabase(), which then resolves to the wrong | ||
| -- database and the segment fails to attach with UNKNOWN_TABLE. | ||
|
|
||
| SET allow_experimental_hybrid_table = 1; | ||
|
|
||
| CREATE TABLE {CLICKHOUSE_DATABASE:Identifier}.local_hot (ts DateTime, value UInt64) ENGINE = MergeTree ORDER BY ts; | ||
| CREATE TABLE {CLICKHOUSE_DATABASE:Identifier}.local_cold (ts DateTime, value UInt64) ENGINE = MergeTree ORDER BY ts; | ||
| INSERT INTO {CLICKHOUSE_DATABASE:Identifier}.local_hot VALUES ('2025-10-15', 1), ('2025-11-01', 2); | ||
| INSERT INTO {CLICKHOUSE_DATABASE:Identifier}.local_cold VALUES ('2025-08-01', 3), ('2025-06-15', 4); | ||
|
|
||
| -- Create with the test database as current so currentDatabase() resolves to it. | ||
| USE {CLICKHOUSE_DATABASE:Identifier}; | ||
| CREATE TABLE {CLICKHOUSE_DATABASE:Identifier}.hybrid_t (ts DateTime, value UInt64) | ||
| ENGINE = Hybrid( | ||
| remote('localhost:9000', {CLICKHOUSE_DATABASE:String}, 'local_hot'), | ||
| ts > hybridParam('hybrid_watermark_hot', 'DateTime'), | ||
| remote('localhost:9000', currentDatabase(), 'local_cold'), | ||
| ts <= hybridParam('hybrid_watermark_hot', 'DateTime') | ||
| ) | ||
| SETTINGS hybrid_watermark_hot = '2025-09-01'; | ||
|
|
||
| SELECT count() FROM {CLICKHOUSE_DATABASE:Identifier}.hybrid_t; | ||
|
|
||
| -- Detach, switch the current database, then re-attach. currentDatabase() in the | ||
| -- stored metadata now resolves against the other database, whose local_cold does | ||
| -- not exist. With the fix the metadata holds the resolved name, so this succeeds. | ||
| DETACH TABLE {CLICKHOUSE_DATABASE:Identifier}.hybrid_t; | ||
| CREATE DATABASE IF NOT EXISTS {CLICKHOUSE_DATABASE_1:Identifier}; | ||
| USE {CLICKHOUSE_DATABASE_1:Identifier}; | ||
| ATTACH TABLE {CLICKHOUSE_DATABASE:Identifier}.hybrid_t; | ||
|
|
||
| SELECT count() FROM {CLICKHOUSE_DATABASE:Identifier}.hybrid_t; | ||
|
|
||
| USE {CLICKHOUSE_DATABASE:Identifier}; | ||
| DROP DATABASE {CLICKHOUSE_DATABASE_1:Identifier}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new metadata rewrite only catches AST functions named exactly
currentDatabase, but the same function is exposed through accepted aliases such asDATABASE,SCHEMA, andcurrent_database. For an additional segment likeremote('localhost:9000', DATABASE(), 'local_cold'),TableFunctionRemote::parseArgumentsstill normalizes the clone used in memory, while the originalengine_args[i]keeps the unresolved alias in the stored definition, so reattach/startup from a different current database can still point the segment at the wrong database and raise the sameUNKNOWN_TABLEexception this patch is fixing. Please normalize the actual remote/cluster database argument with the existing database-name constant evaluator instead of relying on this exact-name tree walk.Useful? React with 👍 / 👎.