Skip to content

Forbid Tuple element name null to prevent subcolumn ambiguity - #98377

Merged
alexey-milovidov merged 21 commits into
masterfrom
forbid-tuple-null-element-name
May 1, 2026
Merged

alexey-milovidov merged 21 commits into
masterfrom
forbid-tuple-null-element-name

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Mar 1, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Forbid the Tuple element name null in checkTupleNames (DataTypeTuple.cpp) because it conflicts with the subcolumn name used for Nullable null maps, causing an exception in SerializationNullable::enumerateStreams
  • Add test 04000_nullable_tuple_null_subcolumn_ambiguity validating the new restriction
  • Update existing test 01872_functions_to_subcolumns_analyzer to rename Tuple(null UInt32) → Tuple(n UInt32)

Closes #96681
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=98293&sha=f68ee0d3f6944d6418c2304965c72af57a2e9971&name_0=PR&name_1=AST%20fuzzer%20%28arm_asan%29
#98293

Changelog category (leave one):

  • Backward Incompatible Change

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Tuple element name null is now forbidden because it conflicts with the subcolumn name used for Nullable null maps, causing ambiguous subcolumn resolution.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

🤖 Generated with Claude Code

Version info

  • Merged into: 26.5.1.235

For `Nullable(Tuple(null UInt32))`, the subcolumn name `null` is
ambiguous — it matches both the Nullable's null-map and the Tuple
element named `null`. This causes an exception in
`SerializationNullable::enumerateStreams` because the type and
serialization resolve to different things via different code paths.

Rather than patching the resolution logic, forbid the ambiguous name
at type creation time in `checkTupleNames`.

Closes #96681
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=98293&sha=f68ee0d3f6944d6418c2304965c72af57a2e9971&name_0=PR&name_1=AST%20fuzzer%20%28arm_asan%29

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@alexey-milovidov
alexey-milovidov requested a review from nihalzp March 1, 2026 03:01
@clickhouse-gh

clickhouse-gh Bot commented Mar 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f903d4f]

Summary: ✅


AI Review

Summary

This PR forbids Tuple element name null and updates tests around nullable-subcolumn ambiguity. High-level verdict: request changes due to a backward-compatibility break for existing schemas/metadata that already contain Tuple(null ...).

Findings

❌ Blockers

  • [src/DataTypes/DataTypeTuple.cpp:63] The new unconditional rejection of element name null in checkTupleNames applies during type parsing/loading, not only for new DDL. Existing tables/metadata using Tuple(null ...) can fail on ATTACH/startup/type parsing after upgrade.
    Suggested fix: gate this validation behind a compatibility/setting switch (with legacy behavior preserved by default for old compatibility profiles), or scope enforcement to newly created objects only; add an upgrade/metadata-loading test for legacy Tuple(null ...).
Tests
  • ⚠️ Add an upgrade-compatibility test that loads metadata containing Tuple(null ...) from a previous version and verifies behavior under compatibility settings (legacy allowed vs new validation enabled).
ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ❌ New validation rejects previously valid tuple element names during metadata/type loading.
SettingsChangesHistory.cpp ⚠️ If compatibility behavior is introduced for rollout, it must be reflected there.
PR metadata quality ✅
Safe rollout ⚠️ Upgrade path for existing metadata with Tuple(null ...) is not safe yet.
Compilation time ✅
No large/binary files ✅
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions:
    1. Add a compatibility-preserving rollout path for existing Tuple(null ...) metadata (setting/compatibility-based or new-objects-only enforcement).
    2. Add a regression test for loading/attaching legacy metadata containing Tuple(null ...).

@clickhouse-gh clickhouse-gh Bot added the pr-backward-incompatible Pull request with backwards incompatible changes label Mar 1, 2026
…nto Nested types

When a query accesses `.null` subcolumns on `Array(Nullable(T))` columns
(e.g. `SELECT a3.null FROM t`), the subcolumn `a3.null` has type
`Array(UInt8)`. Both `StorageLog` and `IMergeTreeReader` call
`Nested::convertToSubcolumns`, which internally calls
`getSubcolumnsOfNested`. This function found `a3.null` (an Array with a
dotted name), split it into prefix `a3` / suffix `null`, and tried to
create `Array(Tuple(null UInt8))` — triggering the new check that
forbids `null` as a Tuple element name.

The fix: skip entries where `isSubcolumn()` is true, since these are
derived subcolumns (like `.null`, `.size0`), not real flat-nested columns
(like `n.a Array(T)`, `n.b Array(T)`).

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@nihalzp nihalzp self-assigned this Mar 1, 2026
if (name.empty())
return Exception(ErrorCodes::BAD_ARGUMENTS, "Names of tuple elements cannot be empty");

if (name == "null")

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 check is applied in DataTypeTuple construction globally, so it is also hit when loading existing metadata/types (not only on new CREATE/ALTER).

That makes this a hard backward-incompatible parse failure for already-existing schemas that contain Tuple(null ...) and can prevent table attach/startup paths. Per ClickHouse compatibility policy, please gate this with a compatibility/setting path (or apply only to newly created objects) so old metadata can still be loaded.

-- The column `t` is Nullable(Tuple(null UInt32)), so `t.null` could mean either
-- the null-map of the Nullable or the "null" element of the Tuple.
-- This should not cause an exception.
SELECT CAST((1), 'Tuple(null UInt32)'); -- { serverError BAD_ARGUMENTS }

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 test covers new rejection paths, but the compatibility risk is loading existing metadata that already contains Tuple(null ...) during ATTACH/startup.

Please add a test that verifies legacy metadata loading behavior (or compatibility-gated behavior), so this backward-incompatible path is explicitly covered.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix.

Comment thread src/DataTypes/DataTypeTuple.cpp Resolved
alexey-milovidov and others added 6 commits April 27, 2026 23:33
Reword the message so it makes sense for both `Nullable(Tuple(...))` and
plain `Tuple(...)` usages. The previous wording said the name conflicts
with the null-map subcolumn, but the check applies to all Tuples, not
only those inside `Nullable`. The new wording explains that `null` is
reserved because it would clash if such a tuple is later wrapped in
`Nullable`.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This covers the scenario fixed by the previous commit `Fix Nested::getSubcolumnsOfNested incorrectly grouping subcolumns into Nested types`. Without that fix, reading `a3.null` from a column of type `Array(Nullable(T))` triggered the new `checkTupleNames` exception via `Nested::convertToSubcolumns` because the derived subcolumn was incorrectly fed back into Nested grouping.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 91.10% 91.10% +0.00%
Branches 76.60% 76.60% +0.00%

Changed lines: 75.00% (6/8) · Uncovered code

Full report · Diff report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think this is reasonable...

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue May 1, 2026
Merged via the queue into master with commit 6d0cf96 May 1, 2026
165 checks passed
@alexey-milovidov
alexey-milovidov deleted the forbid-tuple-null-element-name branch May 1, 2026 09:22
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-synced-to-cloud The PR is synced to the cloud repo label May 1, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

Hi @alexey-milovidov — while reviewing this PR I found the following:

Could you review the test PR and add the can be tested label if it looks good?
Happy to discuss — close anything that's wrong or already addressed.

pull Bot pushed a commit to CrazyForks/ClickHouse that referenced this pull request May 2, 2026
pull Bot pushed a commit to AKJUS/ClickHouse that referenced this pull request May 4, 2026
PR ClickHouse#98377 (`Forbid Tuple element name `null` to prevent subcolumn
ambiguity`) makes the new server reject attaching any pre-existing
table whose schema contains `Tuple(null ...)`. The stress test
`01872_functions_to_subcolumns_analyzer.sql` historically created
such a table (`t_tuple_null` with `Tuple(null UInt32)`); after
upgrade, the new server logs a `BAD_ARGUMENTS` error from
`AsyncLoader::worker` while attempting to attach it. This is the
new validation working as intended, not a regression — the
table is left detached, but the error surfaces in the upgrade
check as `Error message in clickhouse-server.log (see upgrade_error_messages.txt)`.

Add the message to the upgrade-check error allowlist so that this
expected post-upgrade rejection does not fail the check.

Example failing run (as reproduced on PR ClickHouse#100300):
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100300&sha=a93523dfa84eebfb7bd5b2f25596f01e2e18ab2e&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
The upgrade test in CI installs a previous release binary, runs the test
suite, then upgrades to the new server build and restarts. Tables created
on the old binary with columns like `Nullable(Tuple(`null` UInt32))` fail
to attach on the new binary because PR ClickHouse#98377 forbade Tuple element name
`null` to avoid ambiguity with the Nullable null-map subcolumn name.

This is a known consequence of the backward-incompatible change, not a
regression introduced by any in-flight PR. Add the exact reserved-name
phrase to the upgrade-runner error filter so unrelated PRs no longer fail
the upgrade check on this message.

Observed on PR ClickHouse#100141: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100141&sha=ca91e01ef6f3c799bddb2176485608a8c9eaf151&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backward-incompatible Pull request with backwards incompatible changes 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: Bad cast from type A to B (STID: 3694-54f6)

4 participants