Skip to content

Fix data-type names containing the substring INT being parsed as MySQL integers - #108354

Merged
cv4g merged 3 commits into
ClickHouse:masterfrom
groeneai:fix-data-type-name-int-substring
Jul 2, 2026
Merged

cv4g merged 3 commits into
ClickHouse:masterfrom
groeneai:fix-data-type-name-int-substring

Conversation

@groeneai

@groeneai groeneai commented Jun 24, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #107806

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 parsing of data-type names whose name contains the substring INT (for example a function-like name such as quantileInterpolatedWeighted used in a data-type position). Such names were mistaken for MySQL integer types and had their first (...) argument group silently consumed as a display-width modifier, which could break the query formatting round-trip.

Description

ParserDataType treated any data-type name whose uppercase contains the substring INT as a MySQL integer type that accepts a display-width modifier (e.g. INT(11)). The check used type_name_upper.contains("INT"), which also matched unrelated names such as quantileInterpolatedWeighted (contains INT inside INTERPOLATED), pointInPolygon, intDiv, and so on.

For such a name used in a data-type position the leading (N) group was consumed as a display width and silently dropped. A parametric form like quantileInterpolatedWeighted(0.8)(a, 1) lost its (0.8) on formatting and re-emitted as quantileInterpolatedWeighted(a, 1), so the formatted query no longer parsed back to the same AST. In debug and sanitizer builds the executeQuery round-trip check then aborted with the LOGICAL_ERROR "Inconsistent AST formatting".

This is the parametric-aggregate (shape-2) signature of the AST formatting finding STID 1941-26fa, produced by the AST and BuzzHouse fuzzers. The no-argument-window-function variant of the same STID was fixed separately in #107806.

CI report (Stress test, amd_debug) where the signature was observed: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106522&sha=095d6c6a9efbfb32fbb3233307115a6e42d16755&name_0=PR&name_1=Stress%20test%20%28amd_debug%29

The fix matches the integer type names and their MySQL aliases exactly instead of by substring. The MySQL display-width modifier and the SIGNED/UNSIGNED suffix keep working for the real integer types (TINYINT(8), INT(32), INT(11) UNSIGNED, ...), while unrelated names no longer have their first argument group eaten.

Version info

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

…L integers

ParserDataType treated any data-type name whose uppercase contained the
substring "INT" as a MySQL integer type that accepts a display-width
modifier (e.g. INT(11)). The check used type_name_upper.contains("INT"),
which also matched unrelated names such as quantileInterpolatedWeighted
(contains "INT" inside "INTERPOLATED"), pointInPolygon, intDiv, etc.

For such a name used in a data-type position, the leading (N) group was
consumed as a display width and silently dropped. A parametric form like
quantileInterpolatedWeighted(0.8)(a, 1) lost its (0.8) on formatting and
re-emitted as quantileInterpolatedWeighted(a, 1), so the formatted query
no longer parsed back to the same AST. In debug/sanitizer builds the
executeQuery round-trip check then aborted with the LOGICAL_ERROR
"Inconsistent AST formatting" (the shape-(2) signature of STID 1941-26fa,
seen by the AST/BuzzHouse fuzzers).

Match the integer type names and their MySQL aliases exactly instead of
by substring. The MySQL display-width modifier and SIGNED/UNSIGNED suffix
keep working for the real integer types (TINYINT(8), INT(32), INT(11)
UNSIGNED, ...), and unrelated names no longer have their first argument
group eaten.

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

groeneai commented Jun 24, 2026 •

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

Click to expand
# Question Answer
a Deterministic repro? Yes. clickhouse format on quantileInterpolatedWeighted(0.8)(a, 1) in a data-type position drops the (0.8) (emits quantileInterpolatedWeighted(a, 1)); CREATE TABLE t (a quantileInterpolatedWeighted(0.8)(a, 1)) ENGINE = Memory aborts a debug server (SIGABRT) with Inconsistent AST formatting.
b Root cause explained? ParserDataType used type_name_upper.contains("INT") to detect MySQL integer types accepting a display-width modifier. quantileInterpolatedWeighted contains INT (inside INTERPOLATED), so it entered the integer branch, consumed the leading (0.8) as a display width and dropped it. The reformatted query no longer parses back to the same AST, so the executeQuery round-trip check (debug/sanitizer) raises the Inconsistent AST formatting LOGICAL_ERROR. This is the parametric-aggregate (shape-2) signature of STID 1941-26fa.
c Fix matches root cause? Yes. Replaces the loose substring test with an exact match against the integer type names and their MySQL aliases (isIntegerTypeName). The (N) display-width path is now reached only by real integer types.
d Test intent preserved / new tests added? New test 04365_data_type_name_containing_int_substring: asserts the previously-aborting forms now produce clean parse/type errors, and asserts the MySQL display-width compat (TINYINT(8), INT(32), INT(), INT(11) UNSIGNED, ...) still works. Existing compat tests 01268_data_numeric_parameters and 02271_int_sql_compatibility still pass.
e Both directions demonstrated? Yes. Without the fix the test crashes the debug server with Fatal: Logical error: 'Inconsistent AST formatting: ... CREATE TABLE t_04365 (a quantileInterpolatedWeighted(a, 1)) ...' (signal 6). With the fix the test is [ OK ] (and stable over 30 randomized runs).
f Fix is general across code paths? Root cause is a single site. Grep confirms contains("INT") had no sibling occurrences in the parsers. The same class of names (pointInPolygon, intDiv, printf, interval, ...) is fixed by the same change, not just quantileInterpolatedWeighted.
g Fix generalizes across inputs (params/datatypes/wrappers)? Verified the bug reproduces and is fixed regardless of the surrounding wrapper (Nullable(...), Array(...), Tuple(...), nested modulo(...)/divide(...)), matching the fuzzer queries from PR #107830 and #104691. Verified all real integer names/aliases still accept and ignore the display width: native Int8(5)..Int256/UInt256(1), TINYINT(8), INT1(2), INTEGER(4), INT(). Non-integer INT-substring types (Point, IntervalDay) round-trip correctly.
h Backward compatible? (maintainer-approved exception only) Yes. No format/setting/metadata change. MySQL display-width and SIGNED/UNSIGNED behavior on integer types is unchanged. The only behavior change is that a name like quantileInterpolatedWeighted is no longer silently treated as an integer (it was already meaningless as a data type).
i Invariants and contracts preserved? Yes. The AST formatting round-trip invariant format -> parse -> format is now upheld for these names. isIntegerTypeName is a pure predicate over the uppercased name; the display-width consumption logic and the ASTDataType construction are unchanged.

Session id: cron:clickhouse-worker-slot-0:20260624-064600

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @evillique @george-larionov — could you review this? It's a small ParserDataType fix: data-type names whose uppercase contains the substring INT (e.g. quantileInterpolatedWeighted) were treated as MySQL integer types and had their first (...) group eaten as a display-width modifier, breaking the AST formatting round-trip (shape-2 of STID 1941-26fa). It now matches integer type names exactly; MySQL INT(11) etc. still work.

@pufit pufit added the can be tested Allows running workflows for external contributors label Jun 24, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b898e89]

Summary: ❌

job_name test_name status info comment
Integration tests (amd_tsan, 6/6) FAIL
test_ttl_replicated/test.py::test_ttl_drop_parts_limit FAIL cidb IGNORED
Stress test (amd_tsan) FAIL
Hung check failed, possible deadlock found FAIL cidb, issue ISSUE EXISTS
Stress test (arm_tsan) FAIL
Hung check failed, possible deadlock found FAIL cidb, issue ISSUE EXISTS

AI Review

Summary

This PR narrows ParserDataType's MySQL integer display-width handling from a substring match on INT to an exact match on the integer type names and aliases that should reach that branch. The change is scoped to the parser, keeps the existing compatibility path for real integer aliases, and the consolidated stateless tests cover both the formatter regression and the MySQL alias/display-width behavior. I did not find any review findings.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 24, 2026
…reserved

With the loose contains("INT") substring match, toUInt128 was mistaken for a
MySQL integer type and its (12) group was consumed as a display-width modifier
and silently dropped. The exact-match isIntegerTypeName() predicate no longer
matches toUInt128, so the (12) argument is preserved on round-trip.

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

Copy link
Copy Markdown
Collaborator Author

Pushed 7bc9b32 to fix the Fast test failure on 03210_inconsistent_formatting_of_data_types.

That test round-trips ... toLowCardinality(toUInt128(12)) ... through clickhouse format. With the old loose contains("INT") match, toUInt128 was treated as a MySQL integer type and its (12) group was consumed as a display-width modifier and silently dropped, so the reference encoded the lossy toUInt128. With the exact-match isIntegerTypeName() predicate toUInt128 is parsed as a regular function and the (12) is preserved, which is the correct round-trip. Updated the .reference accordingly (toUInt128 -> toUInt128(12)).

Verified locally on a debug build (Build ID 18df1742): 03210, the new 04365, and the MySQL display-width compat tests 01268_data_numeric_parameters / 02271_int_sql_compatibility all pass 20/20 with randomized settings.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 7bc9b32

Every failure below has an owner: a fixing PR (ours 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
Fast test / 03210_inconsistent_formatting_of_data_types PR-caused (our parser narrowing made the round-trip non-lossy) PR-caused -> fixed in this PR @ 7bc9b32 (updated .reference: toUInt128 -> toUInt128(12)), passes on this SHA
Stress test (amd_asan_ubsan) / Logical error: Bad cast from DB::ColumnNullable to DB::ColumnVector<unsigned long> (STID 1499-22cb) crash (chronic, NOT PR-caused: #91119 ColumnNullable->ColumnVector aggregate-argument family, ~25 unrelated PRs + 4 master in 30d) fix task #2026-06-20-ci-p1-stid-1499-1a38 (investigating at full effort -- fix PR link to follow on this PR)
Stateless tests (amd_tsan, parallel, 2/2) / test_storage_iceberg_with_spark/test_writes.py::test_writes_parquet_field_ids_update[local] flaky timeout (3+ unrelated PRs in 30d: #107566, #107442, #106794; 0 master; "Failed 0 out of 3 reruns") fix task #2026-06-24-ci-flaky-testwritesparquetfieldids (investigating at full effort -- fix PR link to follow on this PR)
CH Inc sync -- CH Inc sync (private, not actionable by us)

The Bad-cast (STID 1499-22cb) and the iceberg write-test timeout are both unrelated to this PR -- it only changes src/Parsers/ParserDataType.cpp (narrowing the loose contains("INT") match) plus its stateless data-type test. Neither failure touches aggregate type resolution or iceberg/spark writes. Each is owned and investigated at full effort under its fix task; the fixing-PR link will be posted here when it opens.

Session id: cron:our-pr-ci-monitor:20260624-203000

@groeneai

Copy link
Copy Markdown
Collaborator Author

Correction to the CI finish ledger above (SHA 7bc9b32): the Stateless tests (amd_tsan, parallel, 2/2) row was a CIDB misattribution. Integration tests (test_storage_iceberg_with_spark/...) do not run in Stateless jobs; that job's actual failure is 04033_tpc_ds_q10 (TPC-DS query timeout, test_duration_ms=600060, "Failed 0 out of 3 reruns") — as the CI summary above also lists. It is a known runtime regression from #107461, fixed by #107968 (open, approved — raises TPC-H/DS spill thresholds 300 MiB -> 2 GiB).

So the amd_tsan ledger line resolves to fixing PR #107968 (ours, open), not a flaky iceberg test. No iceberg fix is pending.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108354&sha=7bc9b32dd2ede958b27c4ccc85bec41f6b151042&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%2C%202%2F2%29

Session id: cron:clickhouse-worker-slot-0:20260624-205800

@cv4g

cv4g commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

@groeneai I think long term it would be better to not add this new stateless test that only focusses on this now fixed bug but instead expand test coverage of existing tests that focus on these issues. Please consider to

  • put the bad quantileInterpolatedWeighted(0.8)(a, 1) data-type-position case into 03210_inconsistent_formatting_of_data_types.sh, which already covers parser/formatter round-trip regressions and invalid data-type syntax as far as I can see.
  • put extra integer alias/display-width coverage into 01268_data_numeric_parameters.sql or 02271_int_sql_compatibility.sql. We should add coverage for all type aliases in the whitelist.
    Do you see better alternatives?

Following review feedback on ClickHouse#108354: instead of a dedicated bug-specific
test, fold the coverage into the existing tests that already focus on these
areas.

- 03210_inconsistent_formatting_of_data_types.sh: add the type-position
  quantileInterpolatedWeighted(0.8)(a, 1) case. This is the parser/formatter
  round-trip regression home; the case must produce a Syntax error rather than
  having its leading (N) eaten as a MySQL display width. Verified this case
  fails on the pre-fix parser and passes with the fix.
- 01268_data_numeric_parameters.sql: extend the integer block to every alias
  that accepts the (N) display-width modifier, bare and with (N):
  TINYINT, SMALLINT, MEDIUMINT, INT, INTEGER, BIGINT, INT1.
- 02271_int_sql_compatibility.sql: extend the SIGNED/UNSIGNED suffix coverage
  from INT to every whitelist alias (TINYINT/SMALLINT/MEDIUMINT/INTEGER/BIGINT).
- Drop the dedicated 04365 test.

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

Copy link
Copy Markdown
Collaborator Author

Agreed, consolidated into the existing tests and dropped the dedicated one (b898e89):

  • 03210_inconsistent_formatting_of_data_types.sh: added the type-position quantileInterpolatedWeighted(0.8)(a, 1) case. This is the parser/formatter round-trip home, and it is the part that actually catches the regression: I checked out the pre-fix contains("INT") parser, rebuilt, and confirmed this case fails (the (0.8) is eaten as a display width) and passes with the fix.
  • 01268_data_numeric_parameters.sql: extended the integer block to every alias that takes the (N) display-width modifier, bare and with (N): TINYINT, SMALLINT, MEDIUMINT, INT, INTEGER, BIGINT, INT1.
  • 02271_int_sql_compatibility.sql: extended the SIGNED/UNSIGNED suffix coverage from INT only to every whitelist alias.

One note on scope: the whitelist also lists the native forms INT8/INT16/.../UINT256, but those are not writable data-type families (a INT8 gives Unknown data type family: INT8, you write Int8). They only ever appear uppercased after parsing, so a user cannot reach them with a (N) modifier and there is nothing extra to assert for them.

All three pass 20/20 with randomized settings, and are parallel-safe (TEMPORARY/per-test table names, clickhouse format).

@clickhouse-gh

clickhouse-gh Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.40% 85.40% +0.00%
Functions 92.70% 92.70% +0.00%
Branches 77.60% 77.70% +0.10%

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

Full report · Diff report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — b898e89

CI fully finished (Finish Workflow: success). This PR changes only src/Parsers/ParserDataType.cpp + 4 stateless data-type tests (per @ cv4g's test-consolidation request). Every failure has an owner; none is PR-caused.

Check / test Reason Owner
Stress test (amd_tsan) + (arm_tsan) / "Hung check failed, possible deadlock found" deadlock (chronic hung-check family, 600+ distinct PRs / 30d) #108212 (ours, merged 2026-06-28) / #105905 (ours, open)
Integration tests (amd_tsan, 6/6) / test_ttl_replicated::test_ttl_drop_parts_limit flaky (9+ unrelated PRs + 1 master / 30d; #107928 sped it up but did not eliminate the flake) a fix task is created (investigating at full effort; fixing-PR link to follow here)
Bugfix validation (functional tests, aarch64 + amd64) / 01268_data_numeric_parameters, 02271_int_sql_compatibility NOT a real failure: the per-test FAIL rows are the EXPECTED Bugfix-validation INVERTER output for pass-on-master coverage-broadening tests; the bug-catcher 03210 fails-on-master so the JOB-LEVEL check_status = success on both Bugfix jobs N/A (job-level success; no owner needed)
CH Inc sync — CH Inc sync (private, not actionable by us)

Session id: cron:our-pr-ci-monitor:20260630-163000

@groeneai

Copy link
Copy Markdown
Collaborator Author

Ledger correction (SHA b898e89eb9d) — test_ttl_replicated::test_ttl_drop_parts_limit line now resolves to a fixing PR

Full-effort investigation done. The line is now owned by an existing fixing PR:

Check / test Reason Owner / fixing PR
Integration tests (amd_tsan, 6/6) / test_ttl_replicated::test_ttl_drop_parts_limit Keeper TSAN data race surfaced at module teardown (not a test-body flake) #107083 (external, open)

The test itself passed. It is recorded as ERROR at teardown of test_ttl_drop_parts_limit: pytest logged PASSED then ERROR, because the module fixture's cluster.shutdown() scans every container's log for the sanitizer banner (helpers/cluster.py:4254, SANITIZER_SIGN) and raises Sanitizer assert found for instance zoo3-1. The assert is attributed to whichever test ran last in the module, not to a defect in the test.

Root cause (from this run's docker.log, container zoo3-1): WARNING: ThreadSanitizer: data race on a Keeper queue slot, both accesses through KeeperRequestForSession::operator=(&&) (KeeperCommon.h:60):

  • Write (TCP handler thread): NonblockingBoundedQueue::tryPush (NonblockingBoundedQueue.h:107) <- KeeperRequestDispatcher::putRequest (KeeperRequestDispatcher.cpp:309)
  • Read (dispatch thread): NonblockingBoundedQueue::tryPop (NonblockingBoundedQueue.h:138) <- KeeperRequestDispatcher::tryPopRequest (KeeperRequestDispatcher.cpp:348) <- dispatchThread()

This is in core Keeper (the NonblockingBoundedQueue Vyukov queue + KeeperRequestDispatcher), not in test_ttl_replicated. The same Sanitizer assert found for instance zoo* signature hits 18 unrelated integration tests across the amd_tsan shards in 30d (e.g. test_storage_s3_queue, test_refreshable_mv, test_drop_replica, test_backup_restore_on_cluster, ...) plus 3 master runs - confirming it is queue-wide, not test-specific.

Fixing PR #107083 ("Suppress TSAN error in NonblockingBoundedQueue", open since 2026-06-10) targets exactly this: it adds NO_SANITIZE_THREAD to tryPush/tryPop, with a comment describing the same slot.value write/read race and concluding it is a TSAN false positive (the acquire/release on slot.pos establishes happens-before; isomorphic to Vyukov's original). It is unmerged, so the failing build (b898e89, no NO_SANITIZE_THREAD) predates it. This PR cannot affect a Keeper TSAN race - it touches only src/Parsers/ParserDataType.cpp + 4 stateless data-type tests.

#107928 (merged 2026-06-19) did speed up the test body; all 6 of the historical 900s query-timeouts on this test predate that merge.

Session id: cron:clickhouse-worker-slot-8:20260630-171500

@cv4g
cv4g added this pull request to the merge queue Jul 2, 2026
Merged via the queue into ClickHouse:master with commit 0bb6576 Jul 2, 2026
170 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 2, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Following review feedback on ClickHouse#108354: instead of a dedicated bug-specific
test, fold the coverage into the existing tests that already focus on these
areas.

- 03210_inconsistent_formatting_of_data_types.sh: add the type-position
  quantileInterpolatedWeighted(0.8)(a, 1) case. This is the parser/formatter
  round-trip regression home; the case must produce a Syntax error rather than
  having its leading (N) eaten as a MySQL display width. Verified this case
  fails on the pre-fix parser and passes with the fix.
- 01268_data_numeric_parameters.sql: extend the integer block to every alias
  that accepts the (N) display-width modifier, bare and with (N):
  TINYINT, SMALLINT, MEDIUMINT, INT, INTEGER, BIGINT, INT1.
- 02271_int_sql_compatibility.sql: extend the SIGNED/UNSIGNED suffix coverage
  from INT to every whitelist alias (TINYINT/SMALLINT/MEDIUMINT/INTEGER/BIGINT).
- Drop the dedicated 04365 test.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…-int-substring

Fix data-type names containing the substring INT being parsed as MySQL integers
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.

4 participants