Repository navigation
Fix GROUP BY server constants over s3Cluster and object_storage_cluster #2490
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
ianton-ru
wants to merge
4
commits into
antalya-26.6
Choose a base branch
from
bugfix/antalya-26.6/2139-hostname-object-storage-cluster
base: antalya-26.6
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
804c619
Fix GROUP BY hostName() over s3Cluster and object_storage_cluster
ianton-ru ea70a1f
Keep server-constant GROUP BY keys without raising distributed_depth
ianton-ru 12460ed
Drop __getScalar GROUP BY keys in the old analyzer
ianton-ru 26d3a68
Drop local server-constant GROUP BY keys in the old analyzer
ianton-ru 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
3 changes: 3 additions & 0 deletions
3
tests/queries/0_stateless/05296_s3_cluster_hostname_group_by.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,3 @@ | ||
| 1 10 | ||
| 1 10 | ||
| 1 10 |
32 changes: 32 additions & 0 deletions
32
tests/queries/0_stateless/05296_s3_cluster_hostname_group_by.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,32 @@ | ||
| -- Tags: no-fasttest | ||
| -- Tag no-fasttest: Depends on Minio | ||
| -- https://github.com/Altinity/ClickHouse/issues/2139 | ||
|
|
||
| INSERT INTO FUNCTION s3('http://localhost:11111/test/05296_s3_cluster_hostname_group_by.tsv', 'TSV', 'x UInt32') | ||
| SELECT number FROM numbers(10) | ||
| SETTINGS s3_truncate_on_insert = 1; | ||
|
|
||
| SELECT host != '', c FROM | ||
| ( | ||
| SELECT hostName() AS host, count() AS c | ||
| FROM s3Cluster('test_cluster_two_shards_localhost', 'http://localhost:11111/test/05296_s3_cluster_hostname_group_by.tsv', 'TSV', 'x UInt32') | ||
| GROUP BY host | ||
| ) | ||
| SETTINGS enable_analyzer = 0; | ||
|
|
||
| SELECT host != '', c FROM | ||
| ( | ||
| SELECT hostName() AS host, count() AS c | ||
| FROM s3('http://localhost:11111/test/05296_s3_cluster_hostname_group_by.tsv', 'TSV', 'x UInt32') | ||
| GROUP BY host | ||
| SETTINGS object_storage_cluster = 'test_cluster_two_shards_localhost' | ||
| ) | ||
| SETTINGS enable_analyzer = 0; | ||
|
|
||
| SELECT host != '', c FROM | ||
| ( | ||
| SELECT hostName() AS host, count() AS c | ||
| FROM s3Cluster('test_cluster_two_shards_localhost', 'http://localhost:11111/test/05296_s3_cluster_hostname_group_by.tsv', 'TSV', 'x UInt32') | ||
| GROUP BY host | ||
| ) | ||
| SETTINGS enable_analyzer = 1; |
2 changes: 2 additions & 0 deletions
2
tests/queries/0_stateless/05297_scalar_subquery_group_by_old_analyzer.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 @@ | ||
| 3 | ||
| 3 |
7 changes: 7 additions & 0 deletions
7
tests/queries/0_stateless/05297_scalar_subquery_group_by_old_analyzer.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,7 @@ | ||
| -- A scalar subquery is evaluated once and sent to every shard as `__getScalar`. | ||
| -- It must not stay a GROUP BY key just because that function is marked as a server constant. | ||
| -- https://github.com/Altinity/ClickHouse/pull/2490 | ||
|
|
||
| SELECT count() FROM numbers(3) GROUP BY (SELECT [1, 2]) SETTINGS enable_analyzer = 0; | ||
|
|
||
| SELECT count() FROM numbers(3) GROUP BY (SELECT [CAST(1, 'Dynamic')]) SETTINGS enable_analyzer = 0; |
3 changes: 3 additions & 0 deletions
3
tests/queries/0_stateless/05298_local_server_constant_group_by_old_analyzer.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,3 @@ | ||
| 3 | ||
| 3 | ||
| 3 |
9 changes: 9 additions & 0 deletions
9
tests/queries/0_stateless/05298_local_server_constant_group_by_old_analyzer.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,9 @@ | ||
| -- A local query has one server, so a folded server constant is an ordinary GROUP BY constant. | ||
| -- Keeping it makes `Dynamic` fail group-key validation. | ||
| -- https://github.com/Altinity/ClickHouse/pull/2490 | ||
|
|
||
| SELECT count() FROM numbers(3) GROUP BY hostName() SETTINGS enable_analyzer = 0; | ||
|
|
||
| SELECT count() FROM numbers(3) GROUP BY CAST(hostName(), 'Dynamic') SETTINGS enable_analyzer = 0; | ||
|
|
||
| SELECT count() FROM numbers(3) GROUP BY [CAST(hostName(), 'Dynamic')] SETTINGS enable_analyzer = 0; |
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.
Because an
ActionsDAGcan share child nodes, this traversal can revisit the same subtree exponentially many times. For example, a linear sequence of aliases such asplus(x0, x0) AS x1,plus(x1, x1) AS x2, and so on produces a constant DAG where each level references the same child twice; checking the final alias explores roughly2^Npaths when no server constant exists, allowing a compact old-analyzer query to consume an analysis thread indefinitely. Track visited node pointers before pushing children.Useful? React with 👍 / 👎.
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.
The alias chain in this comment does not keep an analysis thread busy.
containsServerConstantdoes not record visited nodes, and anActionsDAGcan store the same child twice, but this example never reaches that walk as a compact graph.The old analyzer expands aliases in
QueryNormalizerbefore aggregation analysis. The expanded tree is limited bymax_expanded_ast_elements(default 500000). A chain1 AS x0,x0 + x0 AS x1, … throwsTOO_BIG_ASTat depth 16. Depth 15 finishes in about 0.25s (enable_analyzer = 0). The sameSELECTlist withGROUP BY 1takes about 0.15s, so the extra time is the expanded tree, not an unbounded walk of a shared DAG.Measured on a local server:
TOO_BIG_AST