Skip to content

Parse qualified COLUMNS matcher in INSERT column lists - #109176

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-insert-columns-matcher-roundtrip-109158
Jul 11, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-insert-columns-matcher-roundtrip-109158

Conversation

@groeneai

@groeneai groeneai commented Jul 2, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #109158

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):

Fixed a parser inconsistency where an INSERT column list accepted a qualified column matcher written as t.* LIKE '<pattern>' / t.* ILIKE '<pattern>' but rejected its canonical t.COLUMNS('<regexp>') form, breaking the query format round-trip (and aborting the server in debug/sanitizer builds).

Description

ParserInsertElement (the parser for one element of an INSERT column list) tried ParserColumnsMatcher, ParserQualifiedAsterisk, ParserAsterisk and ParserCompoundIdentifier, but not ParserQualifiedColumnsMatcher. So it accepted t.* [I]LIKE 'pattern' (via ParserQualifiedAsterisk), but on t.COLUMNS('regexp') the t.COLUMNS prefix was consumed by ParserCompoundIdentifier as a plain identifier, leaving (...) unparsed.

Formatting a parsed t.* [I]LIKE 'pattern' matcher always emits the canonical t.COLUMNS('regexp') form, which then failed to parse back. The AST format round-trip self-check in executeQueryImpl therefore raised an Inconsistent AST formatting LOGICAL_ERROR (exception in release builds, server abort in debug/sanitizer builds). The AST fuzzer reaches this through its * [I]LIKE matcher generation (STID 1941-26fa).

Fix: add ParserQualifiedColumnsMatcher to ParserInsertElement, before ParserCompoundIdentifier, mirroring the SELECT expression-element parser. The INSERT column-list parser now accepts the canonical serialization of every matcher node it can already produce.

Found by the AST fuzzer on Stress test (amd_debug): https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100930&sha=e17029031666298b6c9586e883f05f0016ba2977&name_0=PR&name_1=Stress%20test%20%28amd_debug%29

Reproducer (before this change, in a debug build):

$ clickhouse format --oneline --query "INSERT INTO t (a.* ILIKE '%a%') SELECT 1" | clickhouse format --oneline
Code: 62. DB::Exception: Syntax error (query): failed at position 25 (()... (SYNTAX_ERROR)

Regression test: tests/queries/0_stateless/04493_insert_columns_matcher_format_roundtrip.sh (format round-trip of qualified/unqualified COLUMNS matchers and regular column lists in INSERT).

Version info

  • Merged into: 26.7.1.804 (included in 26.7 and later)

An INSERT column list accepted a qualified matcher written as
`q.* [I]LIKE 'pattern'` (parsed by ParserQualifiedAsterisk) but not its
canonical serialization `q.COLUMNS('regexp')`. ParserInsertElement did not
try ParserQualifiedColumnsMatcher, so ParserCompoundIdentifier consumed the
`q.COLUMNS` prefix as a plain identifier and left the trailing `(...)`
unparsed.

Formatting a parsed `q.* [I]LIKE 'pattern'` matcher always yields the
`q.COLUMNS('regexp')` form, which then failed to parse back, so the AST
format round-trip check in executeQueryImpl raised an Inconsistent AST
formatting LOGICAL_ERROR (server abort in debug/sanitizer builds). The AST
fuzzer reaches this via its `* [I]LIKE` matcher generation (STID 1941-26fa).

Add ParserQualifiedColumnsMatcher to ParserInsertElement, before
ParserCompoundIdentifier, mirroring the SELECT expression-element parser so
the INSERT column-list parser accepts the canonical serialization of every
matcher node it can already produce.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

groeneai commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. clickhouse format --oneline --query "INSERT INTO t (a.* ILIKE '%a%') SELECT 1" | clickhouse format --oneline → Syntax error ... failed at position 25 (\(`): ('(?i)a')` (SYNTAX_ERROR) on baseline.
b Root cause explained? Yes. ParserInsertElement lacked ParserQualifiedColumnsMatcher, so q.* [I]LIKE 'p' parsed (via ParserQualifiedAsterisk) into an ASTQualifiedColumnsRegexpMatcher but its canonical serialization q.COLUMNS('re') did not re-parse — ParserCompoundIdentifier ate q.COLUMNS as an identifier and left (...). Formatting the matcher always emits the COLUMNS form, so the executeQueryImpl round-trip re-parse failed → Inconsistent AST formatting LOGICAL_ERROR (server abort in debug/sanitizer builds).
c Fix matches root cause? Yes. Adds ParserQualifiedColumnsMatcher to ParserInsertElement (before ParserCompoundIdentifier), so the INSERT column-list parser accepts the exact canonical form its own formatter produces. No symptom guard, no assertion widening.
d Test intent preserved / new tests added? New regression test 04493_insert_columns_matcher_format_roundtrip.sh — format round-trip of qualified/unqualified COLUMNS matchers (with APPLY/EXCEPT/REPLACE transformers) AND regular column lists / a.b / a.* in INSERT.
e Both directions demonstrated? Yes. Baseline binary (Build ID 767ff8d4): test FAILS with SYNTAX_ERROR. Fixed binary (c450fbab): test PASSES, output byte-identical to reference. Rebuilt from the same tree; Build IDs verified distinct.
f Fix is general across code paths? Yes. The SELECT expression-element parser already had all three matcher parsers; this brings the INSERT column-list parser to parity. Verified q.COLUMNS('re'), q.COLUMNS(list), transformers, unqualified COLUMNS(...), q.*, a.b, and plain identifiers all round-trip; normal INSERTs unaffected.
g Fix generalizes across inputs? Yes. Verified across LIKE/ILIKE, case-insensitive (?i) regex, backquoted qualifiers (incl. `numbers(4)` and subquery-text names), transformer chains, and list vs regexp matchers.
h Backward compatible? (maintainer-approved exception only) Yes, fully backward compatible. Pure parser widening: previously-rejected q.COLUMNS('re') in an INSERT column list now parses; no setting/format/behavior change, nothing that used to parse changes meaning.
i Invariants and contracts preserved? Yes. ParserQualifiedColumnsMatcher returns false unless the identifier ends in .COLUMNS, so plain identifiers still fall through to ParserCompoundIdentifier (verified). AST is identical to the equivalent q.* [I]LIKE form. Column-list parse / rewind logic untouched.

Session id: cron:clickhouse-worker-slot-3:20260702-112700

@groeneai

groeneai commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

cc @evillique @george-larionov — could you review this? An INSERT column list accepted a qualified matcher as t.* [I]LIKE 'pat' but not its canonical t.COLUMNS('regexp') serialization (ParserInsertElement was missing ParserQualifiedColumnsMatcher), so the format round-trip failed with a LOGICAL_ERROR (STID 1941-26fa). The fix adds that parser to the INSERT element chain, mirroring the SELECT expression parser.

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Jul 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e727a800]

Summary: ✅


AI Review

Summary

This PR fixes ParserInsertElement so INSERT column lists accept the canonical qualified matcher form q.COLUMNS(...) that the formatter already emits for qualified * [I]LIKE matchers. The parser ordering change is correct, it backtracks safely on plain identifiers such as a.COLUMNS, and the added round-trip regression test covers the reported failure plus nearby supported column-list forms. I did not find any correctness, compatibility, or test-coverage issues in the current diff.

Final Verdict

✅ No findings.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.50% 85.50% +0.00%
Functions 92.70% 92.60% -0.10%
Branches 77.70% 77.70% +0.00%

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

Full report · Diff report

@groeneai

groeneai commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — e727a80

All checks green: Finish Workflow and Mergeable Check both pass, 0 failed tests and 0 failed jobs in CIDB. Only the private ClickHouse Inc sync check remains, which is exempt.

Check / test Reason Owner / fixing PR
(no failed checks) all green none needed
CH Inc sync private mirror check CH Inc sync (private, not actionable)

Session id: cron:our-pr-ci-monitor:20260702-173000

@Fgrtue Fgrtue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems to be the right approach -- to fix the parser in the insert query. LGTM.

@Fgrtue
Fgrtue enabled auto-merge July 10, 2026 11:43
@clickhouse-gh

clickhouse-gh Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 37 queries analysed

This PR is a parser-only fix: it adds a qualified COLUMNS matcher to the INSERT column-list parser (plus one round-trip test) and does not touch the SELECT execution path that ClickBench exercises. On that basis the flagged -22.6% improvement on Q15 is downgraded to variance rather than a real effect, and the +20.6%/+17.5% results on the intrinsically noisy Q30 and Q31 remain not_sure. The suppressed -21.5% on Q4 stays within the master variance band, consistent with no real perf change from this change.

clickbench

⚠️ 3 inconclusive

Flagged queries (3 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 15 not_sure 243 188 -22.6% <0.0001 The change is off-path: this PR only touches INSERT column-list parsing, so the -22.6% on a ClickBench SELECT is run-to-run variance, not a real PR effect.
⚠️ 30 not_sure 267 322 +20.6% <0.0001 Q30 is intrinsically noisy and the PR touches only INSERT parsing, so the +20.6% is off-path variance; not_sure stands.
⚠️ 31 not_sure 343 403 +17.5% <0.0001 Q31 is intrinsically noisy and this parser-only PR cannot affect a SELECT, so the +17.5% is off-path variance; not_sure stands.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 26c219df-4fa4-495d-99ef-b2f65114aab6
  • MIRAI run: 44148d2a-0a71-48bd-ab05-4b8343bc89d9
  • PR check IDs:
    • clickbench_225714_1783732603
    • clickbench_225728_1783732603
    • clickbench_225734_1783732603
    • tpch_adapted_1_official_225740_1783732603
    • tpch_adapted_1_official_225746_1783732603
    • tpch_adapted_1_official_225754_1783732603

@alexey-milovidov
alexey-milovidov merged commit ec06468 into ClickHouse:master Jul 11, 2026
173 of 174 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 11, 2026
alexey-milovidov added a commit that referenced this pull request Jul 12, 2026
Bring the branch up to date with master. This pulls in #109176
(`Parse qualified COLUMNS matcher in INSERT column lists`), the
root-cause fix for the `Stress test (amd_debug)` AST-fuzzer failure
(`Inconsistent AST formatting`, issue #109158), so that red clears on
the next CI run.
alexey-milovidov added a commit that referenced this pull request Jul 12, 2026
Refresh the branch onto the current master. This picks up the merged
fix #109176 ("Parse qualified COLUMNS matcher in INSERT column lists"),
which resolves the "Inconsistent AST formatting" logical error
(issue #109158, STID 1941-26fa) that the branch's `Stress test (arm_debug)`
job was hitting only because the branch predated the fix. Merging pulls
the fix in and clears that unrelated red on the next CI run.

The merge is clean: master's `play.html` changes since the branch point
(the colorize-toggle family) do not conflict with the syntax-error-highlight
changes in this PR.
@Fgrtue Fgrtue mentioned this pull request Jul 13, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…t-columns-matcher-roundtrip-109158

Parse qualified COLUMNS matcher in INSERT column lists
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Refresh the branch onto the current master. This picks up the merged
fix ClickHouse#109176 ("Parse qualified COLUMNS matcher in INSERT column lists"),
which resolves the "Inconsistent AST formatting" logical error
(issue ClickHouse#109158, STID 1941-26fa) that the branch's `Stress test (arm_debug)`
job was hitting only because the branch predated the fix. Merging pulls
the fix in and clears that unrelated red on the next CI run.

The merge is clean: master's `play.html` changes since the branch point
(the colorize-toggle family) do not conflict with the syntax-error-highlight
changes in this PR.
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Bring the branch up to date with master. This pulls in ClickHouse#109176
(`Parse qualified COLUMNS matcher in INSERT column lists`), the
root-cause fix for the `Stress test (amd_debug)` AST-fuzzer failure
(`Inconsistent AST formatting`, issue ClickHouse#109158), so that red clears on
the next CI run.
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 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.

Logical error: 'Inconsistent AST formatting: the query: (STID: 1941-26fa)

5 participants