Repository navigation
Conversation
`ParserStorage::parseImpl` appended children in the order (engine, partition_by, primary_key, order_by, sample_by, ttl_table, unique_key, settings), but `ASTStorage::normalizeChildrenOrder` and `ASTStorage::formatImpl` use the canonical order (engine, partition_by, primary_key, order_by, unique_key, sample_by, ttl_table, settings). When a `CREATE TABLE` carried both a `UNIQUE KEY` and a `TTL` clause and the original AST happened to be normalized (e.g., an inline column-level `PRIMARY KEY` triggered `normalizeChildrenOrder` in `ParserCreateTableQuery::parseImpl`), the formatter emitted the clauses in canonical order but the reparse path landed back in `ParserStorage::parseImpl` where the inline PK was already hoisted, so `normalizeChildrenOrder` was not invoked. The reparsed AST therefore had `unique_key` and `ttl_table` swapped relative to the original, and the round-trip check in `executeQueryImpl` aborted the debug server with `LOGICAL_ERROR: Inconsistent AST formatting`. Reorder the `set()` calls in `ParserStorage::parseImpl` to match the canonical order so re-parses produce identical child order, and add a regression test covering the three shapes that exercise the affected paths: inline `PRIMARY KEY` + `UNIQUE KEY` + `TTL`, storage-level `PRIMARY KEY` + `UNIQUE KEY` + `TTL`, and the full clause combination with `PARTITION BY`, `SAMPLE BY` added. Closes ClickHouse#104963 Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
cc @evillique @alexey-milovidov @PedroTadim — could you review this? It fixes the AST round-trip mismatch in #104963: |
|
Pre-PR validation gate (session cron:clickhouse-ci-task-worker:20260514-164500) (a) Deterministic repro: (b) Root cause: (c) Fix matches root cause: Reordered the (d) New regression test: (e) Both directions demonstrated: Without the fix, the server SIGABRTs while (f) Fix is general: The parser is the single source of children order during initial AST construction. No other code paths build |
|
Workflow [PR], commit [d1004ad] Summary: ❌
AI ReviewSummaryThis PR fixes an Final VerdictStatus: ✅ Approve |
The previous commit aligned `ParserStorage::parseImpl` with the canonical order used by `ASTStorage::formatImpl` and `normalizeChildrenOrder` (engine, partition_by, primary_key, order_by, unique_key, sample_by, ttl_table, settings). `ASTStorage::clone` was missed and still appended `sample_by`, `ttl_table`, `unique_key` in the old order. `IAST::updateTreeHash` iterates `children` in sequence, so a divergent clone order makes `getTreeHash` order-dependent under cloning: parse-then-hash and parse-then-clone-then-hash would produce different hashes for the same storage definition with all three clauses present. Subsystems that key caches or fingerprints on tree hashes (parameterized view cache, query plan cache, AST-based deduplication) would treat the original and the clone as two distinct keys. Reorder the `set()` calls in `ASTStorage::clone` to match the canonical order and add a comment documenting the invariant so future edits stay in sync with `formatImpl` and `normalizeChildrenOrder`. Reported by clickhouse-gh[bot] review on PR ClickHouse#104968. Co-Authored-By: Claude Opus 4.7 <[email protected]>
The regression test for issue ClickHouse#104963 exercises `CREATE TABLE ... UNIQUE KEY ... TTL ...`. `UNIQUE KEY` is an experimental MergeTree feature that the engine currently restricts to local-disk storage in an `Atomic` database — on s3/azure/cached_s3/shared-merge-tree/replicated-database variants it raises `SUPPORT_IS_DISABLED: UNIQUE KEY on non-local disks is not yet supported`. Without skip tags, the test failed on every object-storage CI variant (`amd_tsan, s3 storage`, `amd_debug, distributed plan, s3 storage`, `amd_llvm_coverage, ParallelReplicas/AsyncInsert/old analyzer, s3 storage`, `arm_asan_ubsan, azure`, and `Bugfix validation (functional tests)` which runs against MinIO/Azurite). Add the same tag set used by the canonical UNIQUE KEY test `04046_unique_key_ddl.sql`: `no-ordinary-database, no-replicated-database, no-shared-merge-tree, no-object-storage, no-s3-storage`. The original `LOGICAL_ERROR: Inconsistent AST formatting` reproduces on the default local-disk MergeTree variants (amd_debug parallel, amd_tsan parallel, amd_asan_ubsan parallel, etc.), so the regression coverage this PR adds is preserved on every variant where the feature is actually supported.
|
Fix-up for PR-caused regression on What broke: the latest commit ran on every s3 / azure / cached_s3 / Bugfix-validation variant (which runs against MinIO+Azurite). All of those raised Fix: added the same tag set the canonical Diff is a single 6-line block at the top of the |
The round-trip check in `executeQueryImpl` is gated by `#ifndef NDEBUG`, so the `LOGICAL_ERROR` from ClickHouse#104963 only fires in debug-build CI variants. The `Bugfix validation (functional tests)` runner downloads a master `RelWithDebInfo + NDEBUG` binary where the check is compiled out, so a `pr-bugfix`-labelled validation cannot reproduce the master-side failure that proves the fix. Recategorising as `CI Fix or Improvement` and expanding the regression test comment to document why. Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Following up on the Root reason The original out_ast = parseQuery(parser, ...);
#ifndef NDEBUG
try
{
/// Verify that AST formatting is consistent:
/// If you format AST, parse it back, you get the same AST, ...So the failure is debug-build-only. The The debug-only round-trip check is compiled out in this binary, so no Sibling AST-formatting fixes use the same lightweight category for the same reason:
The current PR remains a real correctness improvement:
What stays the same: regression test cc @evillique @alexey-milovidov @PedroTadim — the source-code fix and the test are unchanged from the previous CI-clean run on Session: |
|
@groeneai please simplify the pr description |
|
@murphy-4o done — PR description trimmed to ~200 words. Kept the root cause one-paragraph, the fix one-liner, the regression test reference, and the |
|
@groeneai can you check the CI failures? |
… WasmEdge MSan CI Algunenano's PR ClickHouse#104971 reverts the x86v3 default; that fixed the chronic DB::SystemLogQueue<DB::QueryLogElement>::waitFlush 180s timeout family on Stateless tests (amd_msan, WasmEdge, *) which was the only failing check on this PR's prior CI run (2026-05-15 02:15 UTC). Master WasmEdge MSan SystemLog flush timeouts dropped from 33/day (2026-05-13) to 0/day (2026-05-16+) after PR ClickHouse#104971 merged at 2026-05-15 08:57 UTC. Merging master to re-trigger CI on the post-revert build so PR ClickHouse#104968 can be evaluated cleanly.
|
@PedroTadim sure — here is what the CI looks like on the prior head Only one failing check across the entire matrix: Classification (CIDB, last 30 days,
This is the WasmEdge MSan The prior CI on this PR ran at 2026-05-15 02:15 UTC, six hours before the revert merged, so it was still on the affected build. I just merged master into the PR branch (commit The PR's source-code change is unchanged from |
|
Per review feedback on PR ClickHouse#104968: 1. Move the UNIQUE KEY + TTL regression cases from a separate 04240_104963_unique_key_ttl_ast_format.{sql,reference} pair into 04046_unique_key_ddl as a new section (case 22 with sub-cases a-d). Both tests share the same tag set and target the same experimental feature, so a single canonical UNIQUE KEY DDL test is preferable. 2. Trim the multi-line clone-order comment in ASTStorage::clone down to the two-line invariant. The root-cause story is already in the prior commit message and PR description. Source fix and child-order behaviour are unchanged from 6118cc8.
|
@murphy-4o thanks for the review. Both items addressed in
Source-level behaviour is unchanged from |
LLVM Coverage Report
Changed lines: 100.00% (26/26) · Uncovered code |
90e97b9
CREATE TABLE t0 (c0 Int PRIMARY KEY) ENGINE = MergeTree() UNIQUE KEY (c0) TTL 1aborted the debug server withLOGICAL_ERROR: Inconsistent AST formatting.Root cause:
ParserStorage::parseImplandASTStorage::cloneappended children (unique_key,sample_by,ttl_table) in a different order thanASTStorage::formatImplandASTStorage::normalizeChildrenOrderuse. WhennormalizeChildrenOrderwas not invoked on the reparse path (storage-levelPRIMARY KEY, orPRIMARY KEYalready hoisted out), the round-trip check inexecuteQueryImplfailed. The same mismatch also brokeIAST::getTreeHashstability acrossclone.Fix: reorder
set()calls inParserStorage::parseImplandASTStorage::cloneto match canonical order. Regression test04240_104963_unique_key_ttl_ast_format(local-disk-Atomic-only —UNIQUE KEYreturnsSUPPORT_IS_DISABLEDelsewhere).Categorised as
CI Fixbecause the user-visible abort only fires under#ifndef NDEBUG(debug builds), soBugfix validation (functional tests)(which downloads aRelWithDebInfo + NDEBUGmaster binary) cannot reproduce it. ThegetTreeHashstability part is release-visible. Sibling AST-formatting fixes #100136 / #96894 use the same category for the same reason.Closes #104963
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Not applicable (CI Fix).
Documentation entry for user-facing changes
Version info
26.6.1.1100