Skip to content

Fix GROUP BY server constants over s3Cluster and object_storage_cluster - #2490

Merged
zvonand merged 4 commits into
antalya-26.6from
bugfix/antalya-26.6/2139-hostname-object-storage-cluster
Oct 14, 2026
Merged

zvonand merged 4 commits into
antalya-26.6from
bugfix/antalya-26.6/2139-hostname-object-storage-cluster

Conversation

@ianton-ru

@ianton-ru ianton-ru commented Oct 6, 2026 •

Copy link
Copy Markdown

Solved #2139

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fix GROUP BY server constants over s3Cluster and object_storage_cluster

Documentation entry for user-facing changes

...

CI/CD Options

Exclude tests:

  • Fast test
  • Integration Tests
  • Stateless tests
  • Stateful tests
  • Unit tests
  • Performance tests
  • Aarch64 tests
  • All with ASAN
  • All with TSAN
  • All with MSAN
  • All with UBSAN
  • All with Coverage
  • All Regression
  • Disable CI Cache

Regression jobs to run:

  • Fast suites (mostly <1h)
  • Aggregate Functions (2h)
  • Alter (1.5h)
  • Benchmark (30m)
  • CAS (content-addressed storage; Antalya only)
  • ClickHouse Keeper (1h)
  • Iceberg (2h)
  • LDAP (1h)
  • OAuth (5m)
  • Parquet (1.5h)
  • RBAC (1.5h)
  • SSL Server (1h)
  • S3 (2h)
  • S3 Export (2h)
  • Swarms (30m)
  • Tiered Storage (2h)

ianton-ru and others added 2 commits October 6, 2026 13:31
The old analyzer drops constant GROUP BY keys when distributed_depth is 0. Cluster table function reads never increased that depth, so workers folded hostName() and returned only the aggregate.

https: //github.com//issues/2139
Co-authored-by: Cursor <[email protected]>
Raising distributed_depth on cluster reads also changes parallel replicas, max_distributed_depth, and block marshalling. The old analyzer now keeps a key such as hostName() and still drops ordinary constants.

https: //github.com//issues/2139
Co-authored-by: Cursor <[email protected]>
@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Workflow [PR], commit [26d3a68]

@ianton-ru

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-09T16:06:38.582813Z 26d3a68 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ea70a1fdff

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/Interpreters/ExpressionAnalyzer.cpp Outdated
Comment on lines +174 to +175
if (current->function_base && current->function_base->isServerConstant())
return true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Exclude scalar-subquery accessors from server constants

When a scalar subquery is represented by __getScalar (notably for Array, Tuple, or aggregate-state results), its function base also reports isServerConstant, even though ExecuteScalarSubqueriesVisitor evaluates it on the initiator and ships the same scalar to every shard. This check therefore retains such constant GROUP BY keys instead of removing them as before; for example, with the old analyzer, grouping an aggregate query by a scalar subquery returning Tuple(Dynamic) now reaches group-key validation and throws ILLEGAL_COLUMN, whereas the constant key previously disappeared. Special-case shipped scalar accessors, or otherwise distinguish genuinely per-server functions from every function carrying this flag.

Useful? React with 👍 / 👎.

__getScalar is marked as a server constant, but the initiator evaluates it and sends the same value to every shard. Keeping it made GROUP BY of a scalar subquery with Dynamic throw ILLEGAL_COLUMN.

https: //github.com//pull/2490
Co-authored-by: Cursor <[email protected]>
@ianton-ru

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 12460edf61

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +179 to +180
for (const auto * child : current->children)
stack.push(child);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Deduplicate DAG nodes during traversal

Because an ActionsDAG can share child nodes, this traversal can revisit the same subtree exponentially many times. For example, a linear sequence of aliases such as plus(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 roughly 2^N paths 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 👍 / 👎.

Copy link
Copy Markdown
Author

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. containsServerConstant does not record visited nodes, and an ActionsDAG can store the same child twice, but this example never reaches that walk as a compact graph.

The old analyzer expands aliases in QueryNormalizer before aggregation analysis. The expanded tree is limited by max_expanded_ast_elements (default 500000). A chain 1 AS x0, x0 + x0 AS x1, … throws TOO_BIG_AST at depth 16. Depth 15 finishes in about 0.25s (enable_analyzer = 0). The same SELECT list with GROUP BY 1 takes about 0.15s, so the extra time is the expanded tree, not an unbounded walk of a shared DAG.

Measured on a local server:

Depth Result
8 0.009s
12 0.028s
14 0.120s
15 0.244s
16 TOO_BIG_AST

Comment thread src/Interpreters/ExpressionAnalyzer.cpp Outdated
/// Constant expressions have non-null column pointer at this stage.
if (node->column)
/// Server constants stay: they are different on each shard.
if (node->column && !containsServerConstant(node))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve server constants only when the query can fan out

For a local enable_analyzer=0 query, distributed_depth is also zero, so this predicate now retains server constants even though only one server can observe their value. For example, SELECT count() FROM numbers(3) GROUP BY [CAST(hostName(), 'Dynamic')] SETTINGS enable_analyzer = 0 previously removed the folded constant key, but now retains its Array(Dynamic) type and subsequently raises ILLEGAL_COLUMN under the default allow_suspicious_types_in_group_by = 0; the new analyzer still removes such keys when the context is not distributed. Limit this exception to queries that can actually dispatch work, including the affected cluster-backed table functions.

Useful? React with 👍 / 👎.

Comment thread src/Interpreters/ExpressionAnalyzer.cpp Outdated
return true;
}

/// A folded server constant (`hostName()`, `tcpPort()`, ...) must stay a GROUP BY key.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove call syntax from function-name examples

This comment refers to the functions themselves rather than describing particular applications, so the repository convention requires the names to be written as hostName and tcpPort, without parentheses.

AGENTS.md reference: AGENTS.md:L11-L11

Useful? React with 👍 / 👎.

@ianton-ru ianton-ru added antalya port-antalya PRs to be ported to all new Antalya releases antalya-26.6 labels Oct 8, 2026
A local query has one server, so a folded server constant is an ordinary constant. Keeping it made GROUP BY of `hostName` cast to `Dynamic` throw `ILLEGAL_COLUMN`. Secondary queries still keep the key, because cluster table function workers also have `distributed_depth` 0.

https: //github.com//pull/2490
Co-authored-by: Cursor <[email protected]>
@ianton-ru

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 26d3a68f3e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ianton-ru
ianton-ru marked this pull request as ready for review October 9, 2026 17:34
@DimensionWieldr

Copy link
Copy Markdown
Collaborator

CI Failures Analysis

Run 37955291070 at 26d3a68f. Three failed jobs, none caused by this change.

Infrastructure (unrelated)

  • GrypeScanKeeper and GrypeScanServer (-alpine) — High Alpine CVEs (keeper: CVE-2026-84782, CVE-2026-84784, CVE-2026-85091, CVE-2026-72897; Alpine server: CVE-2026-85091). The non-Alpine server scan passed. MasterCI on 8 and 9 October failed the same two jobs (4 and 1 high/critical). #2529 merged at 16:43 UTC on 9 October, after this run started, and the 10 October MasterCI reports 0 high/critical. Rebase onto antalya-26.6 and rerun.

  • 04293_cas_lightweight_delete in Stateless tests (amd_asan_ubsan, cas s3 storage, parallel, 2/2) — client stderr logged AWSClient: Response status: 404, Not Found. Every assertion matched. The in-job rerun was 2/2 passed. The same job passed on the previous commit of this PR (12460edf) and on MasterCI the next day (0 failed, 5591 passed). The 9 October branch run failed that job once (1 failed, 5588 passed); the report does not name the test.

Related to this PR

None. Regression suites this PR ran (Iceberg, OAuth, Parquet, S3 export, Swarms) succeeded.

@DimensionWieldr

Copy link
Copy Markdown
Collaborator

No AI audit defects.

Bugfix passes previously xfailed regression test in: clickhouse-regression/iceberg/tests/iceberg_engine/swarm_examples.py.

LGTM

@DimensionWieldr DimensionWieldr added the verified Approved for release label Oct 13, 2026
@mkmkme

mkmkme commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

@blau-ai

@blau-ai

blau-ai commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

CI triage

Verdict: 0 PR-caused failures. Everything red is either a flaky unrelated test or the Grype CVE scans (base-image vulnerabilities). All functional/integration/regression suites that exercise this change are green, and the three new tests added by the PR passed everywhere.

Failing check Classification
Stateless tests (amd_asan_ubsan, cas s3 storage, parallel, 2/2) Flaky, unrelated
GrypeScanKeeper / Grype Scan (4 high/critical) Infra / pre-existing (image CVEs)
GrypeScanServer (-alpine) / Grype Scan (1 high/critical) Infra / pre-existing (image CVEs)
PR (aggregate gate) Rolls up the above — not a separate failure

1. Stateless tests (cas s3 storage, 2/2) — flaky, not PR-related

Only one test failed: 04293_cas_lightweight_delete (Failed: 1, Passed: 5589). praktika's own diagnosis:

Step 1: Re-running with the same randomized settings… Runs: 2, Failed: 0, Passed: 2. All reruns passed. The failure is not reproducible (likely a transient issue).

Reason: having stderror: AWSClient: Response status: 404, Not Found
stdout: final_rows_match 1, final_data_match 1 — i.e. the test's actual assertions all passed.

The node carries the flaky label ("Failure is reproducible in less than 100% of reruns"). The failure is a transient S3 404 from the object-storage/CAS backend, while the test's data checks matched.

This test exercises CAS-metadata lightweight deletes over object storage. This PR touches only ExpressionAnalyzer::analyzeAggregation (old-analyzer GROUP BY server-constant key handling) — there is no code path connecting it to 04293. Not caused by this PR → safe to re-run.

2 & 3. Grype Scan (keeper / server-alpine) — infra / pre-existing

These scan the built Docker images for OS/library CVEs (4 high/critical in keeper, 1 in server-alpine). They reflect vulnerabilities in base images and bundled dependencies, not in any source this PR changes — the diff is a pure C++ query-analysis change plus .sql/.reference test files. A GROUP BY fix cannot introduce container CVEs, so these are pre-existing/infra and track the base branch, not this PR. (The non-alpine GrypeScanServer passed with 0 high/critical.)


Health check

The PR is in good shape. Builds (debug/asan+ubsan/binary/release, amd+arm) all passed; Fast test, both AST fuzzers, BuzzHouse, SQLLogic, SQLStorm, all Integration shards (old analyzer), and every Regression suite are green. Crucially, the suites most relevant to this change passed cleanly, and the three tests the PR adds —
05296_s3_cluster_hostname_group_by, 05297_scalar_subquery_group_by_old_analyzer, 05298_local_server_constant_group_by_old_analyzer — show no failures in any suite. No code change is needed to turn CI green; a re-run of the cas s3 storage 2/2 job should clear the only functional red, and the Grype results are the usual image-CVE noise for a maintainer to judge separately.

@zvonand
zvonand merged commit 264203c into antalya-26.6 Oct 14, 2026
309 of 316 checks passed
@ianton-ru ianton-ru removed the port-antalya PRs to be ported to all new Antalya releases label Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants