Skip to content

Hide a Backup locator named like a COLUMNS matcher in EXPLAIN AST instead of throwing - #122870

Merged
harikrishnan94 merged 2 commits into
ClickHouse:masterfrom
groeneai:explain-ast-backup-locator-columns-name
Sep 30, 2026
Merged

harikrishnan94 merged 2 commits into
ClickHouse:masterfrom
groeneai:explain-ast-backup-locator-columns-name

Conversation

@groeneai

@groeneai groeneai commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #122810
Related: #120313

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

With secrets hidden (the default), EXPLAIN AST CREATE DATABASE d ENGINE = Backup('db', `t.COLUMNS`('x')) throws Can't set alias '' of t.COLUMNS('[HIDDEN]') (LOGICAL_ERROR), which aborts debug and sanitizer builds. Found by the automated review of #120313 (#122810).

EXPLAIN AST replaces a secret argument with the masked SQL the secret finder builds for the formatter, parsed back, and sets the argument's alias on it. The Backup rule wrote the locator name unquoted, so the masked text parses back as a qualified COLUMNS matcher, which cannot carry an alias.

The change:

  • the finder prints the locator name with backQuoteIfNeed, as ASTFunction prints a function name, so the masked text reads back as the same function (the dump keeps the locator's structure, and query_log keeps the quotes);
  • replaceWithMaskedText hides the argument whole when the parsed text cannot carry an alias, as it already did for text that does not parse. This covers a bare COLUMNS locator, which stays unquoted, and the S3(...) reconstruction, which writes a named-collection identifier as is (Mask the S3 locator of a Backup database with the same rule as BACKUP ... TO #122776 quotes it).

Validation: the new test fails on master with the LOGICAL_ERROR and passes with the fix (50/50 randomized runs); reverting either half alone reddens it. Using each of the 421 single-word keywords as the locator name, with two argument shapes, gives no Can't set alias with the fix. In debug builds, `COLUMNS`('x') still fails earlier in the AST formatting check; that is the formatter issue #121162 addresses.

Not for changelog: #120313 is in no release yet. Its cherry-picks to 26.3, 26.7, 26.8 and 26.9 (#122800 to #122803) are open, so this needs pr-must-backport as well.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.10.1.1058-master (included in 26.10 and later)
  • Backported to: 26.9.9.25, 26.8.16.35, 26.7.20.26, 26.3.40.17

…T` instead of throwing

With secrets hidden, `EXPLAIN AST` replaces a secret argument with the
masked SQL the secret finder produces for the formatter, parsed back, and
sets the argument's alias on the result. The `Backup` database rule wrote
the locator function name unquoted, so `` `t.COLUMNS`('x') `` was masked as
`t.COLUMNS('[HIDDEN]')`, which parses back as a qualified `COLUMNS`
matcher. A matcher cannot carry an alias, so `EXPLAIN AST` threw
`Can't set alias ... (LOGICAL_ERROR)`.

Print the locator name with `backQuoteIfNeed`, as `ASTFunction` prints a
function name, so the masked text reads back as the same function and
keeps its structure in the dump. In `replaceWithMaskedText`, hide the
argument whole when the parsed text cannot carry an alias, as it already
did for text that does not parse: a bare `COLUMNS` name stays unquoted in
both the formatter and the finder, and the reconstructed `S3(...)` locator
writes a named-collection identifier as written, so its text can also end
in a matcher.

Closes ClickHouse#122810

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Sep 29, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings), after my own cold review of the same head (3 nits, none blocking).

# Sev Finding Verdict Evidence / action
1 💡 Test header: "a bare COLUMNS locator" describes how the finder prints the name; the query back-quotes it AGREE, noted-not-blocking wording only
2 💡 The extra_credentials(...) keys of the reconstructed S3(...) locator are also written as is AGREE, noted-not-blocking they can only reach the new fail-closed branch; #122776 quotes them
3 💡 After #121162, ASTFunction back-quotes a function named COLUMNS, the finder does not AGREE, noted-not-blocking such a locator stays hidden whole in EXPLAIN AST (stricter); the test output does not change

Severity: ❌ blocker / ⚠️ major / 💡 nit.

Session id: cron:clickhouse-review-slot-9:20260929-113800

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. EXPLAIN AST CREATE DATABASE d ENGINE = Backup('db', `t.COLUMNS`('SEKRIT')) and the same with `COLUMNS`(1) throw Can't set alias on every run of master (debug build aborts).
b Root cause explained? EXPLAIN AST parses back the masked text the secret finder builds and sets the argument's alias on it. The Backup rule wrote the locator name unquoted, so `t.COLUMNS`(...) parses back as a COLUMNS matcher, which has no alias (IAST::setAlias throws).
c Fix matches root cause? Yes. The finder quotes the name as ASTFunction does; the consumer hides the argument whole when the parsed text is not an ASTWithAlias (the only class whose setAlias does not throw), as it already did for text that does not parse.
d Test intent preserved / new tests added? New test 05295_explain_ast_backup_locator_columns_name; reverting either half alone makes it fail.
e Both directions demonstrated? Yes. Master: the server aborts with the LOGICAL_ERROR; fix: passes, 50/50 randomized runs.
f Fix is general across code paths? Only replaceWithMaskedText parses finder text back (both call sites go through it); the formatter prints it verbatim. The two producers that can yield a matcher (non-S3 locator name, S3(...) reconstruction) are both covered.
g Fix generalizes across inputs (params/datatypes/wrappers)? Checked qualified, doubly qualified and bare COLUMNS, string and numeric arguments, an aliased locator, the S3(...) destination, and all 421 single-word keywords as the name with two argument shapes: no Can't set alias.
h Backward compatible? (maintainer-approved exception only) Yes. No setting or stored format; the masked text changes only for names that need quoting (AzureBlobStorage unchanged).
i Invariants and contracts preserved? The masked argument is always replaced by a node carrying its alias (the parsed function or a hidden literal); the original node never stays in the tree.

Session id: cron:clickhouse-impl-slot-4:20260929-105300

@clickhouse-gh

clickhouse-gh Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f49a2e4]

Summary: ✅


AI Review

Summary

This PR fixes the EXPLAIN AST failure for masked Backup locators by quoting reconstructed locator names before reparsing them and by failing closed when the masked text reparses into a node that cannot carry an alias. The added stateless test covers both the original `t.COLUMNS` reproducer and the stricter whole-node fallback, and I did not find a remaining correctness, safety, or coverage issue in the current head.

Final Verdict

✅ No findings. I did not post any inline review comments.

LLVM Coverage Report

Measured on commit f49a2e4.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 79.60% 79.60% +0.00%

Changed lines: Changed C/C++ lines covered: 11/11 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Sep 29, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. label Sep 29, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing f49a2e437 with master 6d87edd44 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 189abf6d0; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

8 translation units recompiled, 14 s compile time in total, 8 of them have a recent master baseline.

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - e585aa1

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Integration tests (amd_llvm_coverage, 1/8) / test_storage_iceberg_no_spark/test_iceberg_inverted_manifest_bounds.py::test_iceberg_narrow_manifest_bounds fails on every master run since this test file was restored on 2026-09-29: master now decodes manifest bounds only for the columns a filter uses, so the log line that the assertion at line 337 waits for is no longer written. This PR changes only EXPLAIN AST secret masking #122895 (mine, open)
Mergeable Check, PR rollups, red only because of the row above #122895 (mine, open)

146 of 146 check runs completed (104 passed, 41 not selected, 1 red: the job above), Finish Workflow is green and CH Inc sync passed. CIDB has no other FAIL or ERROR test row on this head.

Session id: cron:our-pr-ci-monitor:20260929-163137

@harikrishnan94 harikrishnan94 self-assigned this Sep 30, 2026
@harikrishnan94

Copy link
Copy Markdown
Contributor

@groeneai Make the PR merge ready

@harikrishnan94 harikrishnan94 added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Sep 30, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

Thanks. The only red job was Integration tests (amd_llvm_coverage, 1/8) (test_iceberg_narrow_manifest_bounds), fixed on master by #122895 after this PR's CI had run. I merged master into the branch (f49a2e4) to pick it up. The merge is clean and leaves this PR's diff unchanged, and 05295_explain_ast_backup_locator_columns_name passes on the merged build. CI is running on the new head; auto-merge is still enabled after my push.

robot-clickhouse-ci-2 added a commit that referenced this pull request Oct 2, 2026
Cherry pick #122870 to 26.7: Hide a `Backup` locator named like a `COLUMNS` matcher in `EXPLAIN AST` instead of throwing
robot-clickhouse added a commit that referenced this pull request Oct 2, 2026
…NS` matcher in `EXPLAIN AST` instead of throwing
robot-ch-test-poll3 added a commit that referenced this pull request Oct 2, 2026
Cherry pick #122870 to 26.8: Hide a `Backup` locator named like a `COLUMNS` matcher in `EXPLAIN AST` instead of throwing
robot-clickhouse added a commit that referenced this pull request Oct 2, 2026
…NS` matcher in `EXPLAIN AST` instead of throwing
robot-clickhouse added a commit that referenced this pull request Oct 2, 2026
robot-clickhouse added a commit that referenced this pull request Oct 2, 2026
robot-ch-test-poll added a commit that referenced this pull request Oct 2, 2026
Cherry pick #122870 to 26.9: Hide a `Backup` locator named like a `COLUMNS` matcher in `EXPLAIN AST` instead of throwing
robot-clickhouse added a commit that referenced this pull request Oct 2, 2026
robot-clickhouse added a commit that referenced this pull request Oct 2, 2026
…NS` matcher in `EXPLAIN AST` instead of throwing
robot-clickhouse added a commit that referenced this pull request Oct 2, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 2, 2026
Backport #122870 to 26.7: Hide a `Backup` locator named like a `COLUMNS` matcher in `EXPLAIN AST` instead of throwing
clickhouse-gh Bot added a commit that referenced this pull request Oct 2, 2026
Backport #122870 to 26.8: Hide a `Backup` locator named like a `COLUMNS` matcher in `EXPLAIN AST` instead of throwing
clickhouse-gh Bot added a commit that referenced this pull request Oct 2, 2026
Backport #122870 to 26.9: Hide a `Backup` locator named like a `COLUMNS` matcher in `EXPLAIN AST` instead of throwing
robot-clickhouse-ci-2 added a commit that referenced this pull request Oct 3, 2026
Cherry pick #122870 to 26.3: Hide a `Backup` locator named like a `COLUMNS` matcher in `EXPLAIN AST` instead of throwing
robot-clickhouse added a commit that referenced this pull request Oct 3, 2026
…NS` matcher in `EXPLAIN AST` instead of throwing
PedroTadim added a commit that referenced this pull request Oct 3, 2026
The prerequisite #120313 (`EXPLAIN AST` secret hiding) reached 26.3 through
#123453 after this cherry-pick was created, so merge 26.3 first. The only
remaining conflict is the include list: keep 26.3's includes and add
`Parsers/ASTWithAlias.h`, which the fix needs. `ASTSubquery.h` and
`ASTTablesInSelectQuery.h` are master-only context and are not needed here.

Backport of #122870

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 3, 2026
PedroTadim added a commit that referenced this pull request Oct 3, 2026
Backport #122870 to 26.3: Hide a `Backup` locator named like a `COLUMNS` matcher in `EXPLAIN AST` instead of throwing
@clickhouse-gh clickhouse-gh Bot added comp-explain EXPLAIN and query profiling output: EXPLAIN PLAN / PIPELINE / AST / SYNTAX / ESTIMATE, pretty EXP... and removed comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. labels Nov 22, 2026
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-explain EXPLAIN and query profiling output: EXPLAIN PLAN / PIPELINE / AST / SYNTAX / ESTIMATE, pretty EXP... groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport Pull request should be backported intentionally. Use this label with great care! 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EXPLAIN AST throws LOGICAL_ERROR on Backup locator named COLUMNS

4 participants