Repository navigation
Fix a crash in INSERT ... RETURNING whose query reads the inserted table through merge - #127919
Conversation
…ble through merge The RETURNING query is analyzed with the inserted block (a StorageValues without keys) as the view source. Resolving the inserted table kept the catalog storage but took its storage snapshot with the view source's metadata, and with enable_shared_storage_snapshot_in_query that snapshot is cached per storage for the whole query. A merge() or Merge read of the same table in a RETURNING subquery then got the key-less snapshot, and KeyCondition dereferenced a null primary key expression (STID 2830-4b5d, found by the AST fuzzer in Stress tests). Take the snapshot with the table's own metadata, which is the one the shared cache may hand to every read of the table, and give only the resolved table node a copy with the view source's metadata and the same data. getStorageSnapshotWithoutData would also keep the cache clean, but leaves the node without parts, so a materialized view that reads its source table through merge with a Distributed sibling (the node is then read without the view source swap) would read no rows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding) plus my own review (2 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261027-072300 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261027-064600 |
|
cc @KochetovNicolai @vdimir, could you review this and add the |
|
Workflow [PR], commit [2ac7d6d] Summary: ✅
AI ReviewSummaryThe PR fixes a segmentation fault in Final VerdictStatus: ✅ Approve |
CI finish ledger - 4c055b0Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The first runs of this head stopped at Session id: cron:our-pr-ci-monitor:20261027-213006 |
|
🕵️ @groeneai The same crash (STID A shorter version, with CREATE TABLE t (x UInt64) ENGINE = MergeTree ORDER BY x;
INSERT INTO t VALUES (1);
INSERT INTO t RETURNING ((SELECT * FROM remote('127.0.0.1', currentDatabase(), 't')) EXCEPT (SELECT * FROM t)) SELECT 4;On the CI release binaries:
Since the fix already covers it, could you add this query to |
The same crash happens when the RETURNING query reads the inserted table through remote() on the local shard while the bare table name in the same query resolves to the inserted block (found by the AST fuzzer in Stateless tests (amd_tsan, s3 storage, targeted) on ClickHouse#128707). prefer_localhost_replica is pinned to 1: with 0, remote() sends a separate query over TCP and the read does not share the snapshot, so the case would not reach the defect. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Added in On master |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 12 s compile time in total, 7 of them have a recent master baseline. |
Related: #76867 (comment)
Related: #126476
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a crash in
INSERT ... RETURNINGwhen theRETURNINGquery reads the inserted table through themergetable function, aMergetable orremote.Description
Segmentation fault (STID: 2830-4b5d)inKeyConditionunder the AST fuzzer: #76867 Stress test (arm_tsan), #127090 Stress test (amd_tsan), and throughremotein #128707 Stateless tests (amd_tsan, s3 storage, targeted). Deterministic on master:The
RETURNINGquery is analyzed with the inserted block (aStorageValueswithout keys) as the view source. Resolvingtkeeps the catalog storage but took its storage snapshot with the view source's metadata, and withenable_shared_storage_snapshot_in_querythat snapshot is cached per storage for the whole query. Amergeor localremoteread oftthen got the key-less snapshot andKeyConditiondereferenced a null primary key expression.The snapshot is now taken with the table's own metadata, and only the resolved table node gets a copy with the view source's metadata (same parts). Using
getStorageSnapshotWithoutDatathere, as in #126589, also stops the crash, but leaves that node without parts: a materialized view whose query reads its source table throughmergewith aDistributedsibling then reads 0 rows instead of 12 (measured).INSERT ... RETURNINGis only on master (#126476), so no changelog entry; a materialized view with the samemergescalar does not crash.Validation: each of the test's four cases crashes master with the cache on and passes with the fix; 80/80 runs (random and fixed settings) and the
insert_returning, shared-snapshot and MV-source tests pass.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/127919]
Version info
26.11.1.1367-master(included in26.11and later)