Skip to content

Fix inconsistent AST formatting: reset parent_has_trailing_settings inside subqueries - #99938

Merged
nikitamikhaylov merged 2 commits into
masterfrom
fix-ast-formatting-trailing-settings
Mar 19, 2026
Merged

nikitamikhaylov merged 2 commits into
masterfrom
fix-ast-formatting-trailing-settings

Conversation

@nikitamikhaylov

@nikitamikhaylov nikitamikhaylov commented Mar 18, 2026 •

Copy link
Copy Markdown
Member

The parent_has_trailing_settings flag in the formatting frame was propagating from parent queries (e.g. ALTER TABLE with SETTINGS) into nested subqueries, causing ASTSelectWithUnionQuery to wrap inner SELECT nodes in extra parentheses at every nesting level. This produced syntactically invalid output like ((SELECT ... SETTINGS ...)) that failed to re-parse, triggering 'Inconsistent AST formatting' exceptions.

The fix resets parent_has_trailing_settings in
ASTSubquery::formatImplWithoutAlias, since subquery parentheses provide a clear syntactic boundary — any SETTINGS appended by a parent ASTQueryWithOutput will come after the closing ) and cannot be confused with a SELECT's own SETTINGS clause. This is consistent with the approach already used in ASTCreateQuery.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=96563&sha=bc8e58f5947d1691a0291771b96b05462e9ecd4a&name_0=PR&name_1=BuzzHouse+%28amd_debug%29
#96563

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 into CHANGELOG.md):

Fix "Inconsistent AST formatting" exception for ALTER TABLE ... MODIFY QUERY with nested subqueries containing SETTINGS when the ALTER itself also has SETTINGS.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.3.1.880

…nside subqueries

The `parent_has_trailing_settings` flag in the formatting frame was
propagating from parent queries (e.g. ALTER TABLE with SETTINGS) into
nested subqueries, causing `ASTSelectWithUnionQuery` to wrap inner
SELECT nodes in extra parentheses at every nesting level. This produced
syntactically invalid output like `((SELECT ... SETTINGS ...))` that
failed to re-parse, triggering 'Inconsistent AST formatting' exceptions.

The fix resets `parent_has_trailing_settings` in
`ASTSubquery::formatImplWithoutAlias`, since subquery parentheses
provide a clear syntactic boundary — any SETTINGS appended by a parent
`ASTQueryWithOutput` will come after the closing `)` and cannot be
confused with a SELECT's own SETTINGS clause. This is consistent with
the approach already used in `ASTCreateQuery`.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=96563&sha=bc8e58f5947d1691a0291771b96b05462e9ecd4a&name_0=PR&name_1=BuzzHouse+%28amd_debug%29
@clickhouse-gh

clickhouse-gh Bot commented Mar 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c4c96f1]

Summary: ✅

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Mar 18, 2026
@Avogar Avogar self-assigned this Mar 18, 2026
@clickhouse-gh

clickhouse-gh Bot commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 78.00% 83.80% +5.80%
Functions 22.80% 23.90% +1.10%
Branches 70.40% 76.30% +5.90%

PR changed lines: PR changed-lines coverage: 100.00% (7/7, 0 noise lines excluded)
Diff coverage report
Uncovered code

@nikitamikhaylov
nikitamikhaylov added this pull request to the merge queue Mar 19, 2026
Merged via the queue into master with commit 68c98b6 Mar 19, 2026
159 checks passed
@nikitamikhaylov
nikitamikhaylov deleted the fix-ast-formatting-trailing-settings branch March 19, 2026 15:56
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants