Skip to content

Fix exception when finding common supertype for tuples of different arities - #100699

Merged
antonio2368 merged 1 commit into
masterfrom
fix-tuple-empty-supertype
Mar 26, 2026
Merged

antonio2368 merged 1 commit into
masterfrom
fix-tuple-empty-supertype

Conversation

@antonio2368

@antonio2368 antonio2368 commented Mar 25, 2026 •

Copy link
Copy Markdown
Member

When use_variant_as_common_type is enabled, getLeastSuperTypeForTuple treats an empty tuple the same as "not yet initialized" because it checks element_types.empty() to detect the first tuple. An empty tuple legitimately has zero elements, so initialization is skipped and the next (non-empty) tuple silently overwrites the state.

This introduces an explicit initialized flag so that an empty tuple is correctly recorded.

In FunctionIf::executeTuple, the result type may now be Variant (wrapping tuples of different arities). The per-element loop must not run in that case because the branches have different numbers of elements. A guard is added that returns nullptr (falling back to the generic Variant path) when element counts disagree.

Closes #100691

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

Fix exception when computing common supertype for empty and non-empty tuples with use_variant_as_common_type enabled.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.4.1.280

…rities

When `use_variant_as_common_type` is enabled, `getLeastSuperTypeForTuple`
would treat an empty tuple the same as "not yet initialized", because
it checked `element_types.empty()` to detect the first tuple. An empty
tuple legitimately has zero elements, so the initialization was skipped
and the next (non-empty) tuple silently overwrote the state, losing the
empty-tuple branch entirely.

Introduce an explicit `initialized` flag so that an empty tuple is
correctly recorded as the first tuple seen.

In `FunctionIf::executeTuple`, the result type may now be `Variant`
(wrapping tuples of different arities) rather than a plain `Tuple`.
When the result is a `Variant`, the per-element loop must not run
because the branches have different numbers of elements. Add a guard
that returns `nullptr` (falling back to the generic `Variant` path)
when the element counts of either input tuple or column disagree with
the result tuple size.

Closes #100691

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

clickhouse-gh Bot commented Mar 25, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d3364a8]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_tsan, parallel, 1/2) failure
03312_line_numbers FAIL cidb

AI Review

Summary

This PR fixes handling of tuple least-supertype inference when empty tuples are involved under use_variant_as_common_type, and adds a guard in if tuple specialization to fall back safely when arities diverge. The change is focused, includes a dedicated stateless regression test, and I did not find correctness, safety, or performance issues that require changes.

Missing context
  • ⚠️ No CI logs/results were provided in this review context, so CI validation could not be independently verified here.
ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
Final Verdict
  • Status: ✅ Approve

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

clickhouse-gh Bot commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 24.40% 24.30% -0.10%
Branches 76.70% 76.60% -0.10%

PR changed lines: PR changed-lines coverage: 96.43% (27/28, 0 noise lines excluded)
Diff coverage report
Uncovered code

antonio2368 pushed a commit that referenced this pull request Mar 25, 2026
The two `SELECT 'Ok' FROM system.text_log` assertions were flaky
because text log writes are asynchronous and `SYSTEM FLUSH LOGS`
does not guarantee all async text-log entries are fully materialized.
CI logs from a failing run (PR #100699, amd_tsan) show ~430K messages
dropped from `AsyncLogMessageQueue` due to queue overflow during the
test's execution window, confirming the messages were permanently lost.

The remaining `query_log` assertions are deterministic (synchronous
flush) and fully cover the feature under test: correct
`script_query_number` and `script_line_number` propagation.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100699&sha=d3364a856816a3c582441841e5a85806271c9a6f&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%2C%201%2F2%29

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@antonio2368

Copy link
Copy Markdown
Member Author

03312_line_numbers - #100715

@antonio2368
antonio2368 added this pull request to the merge queue Mar 26, 2026
Merged via the queue into master with commit 36f55f4 Mar 26, 2026
148 of 149 checks passed
@antonio2368
antonio2368 deleted the fix-tuple-empty-supertype branch March 26, 2026 08:28
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 26, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
The two `SELECT 'Ok' FROM system.text_log` assertions were flaky
because text log writes are asynchronous and `SYSTEM FLUSH LOGS`
does not guarantee all async text-log entries are fully materialized.
CI logs from a failing run (PR ClickHouse#100699, amd_tsan) show ~430K messages
dropped from `AsyncLogMessageQueue` due to queue overflow during the
test's execution window, confirming the messages were permanently lost.

The remaining `query_log` assertions are deterministic (synchronous
flush) and fully cover the feature under test: correct
`script_query_number` and `script_line_number` propagation.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100699&sha=d3364a856816a3c582441841e5a85806271c9a6f&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%2C%201%2F2%29

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

Labels

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 "Block structure mismatch in IntersectOrExceptStep" with empty tuple and Variant type (STID: 0993-2cc2)

3 participants