Skip to content

Fix logical error when table is dropped before distributed plan task deserialization - #106944

Merged
davenger merged 1 commit into
masterfrom
fix-distributed-plan-unknown-table
Jun 10, 2026
Merged

davenger merged 1 commit into
masterfrom
fix-distributed-plan-unknown-table

Conversation

@davenger

@davenger davenger commented Jun 10, 2026 •

Copy link
Copy Markdown
Member

Closes: #106906
Related: #106020

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

...

With make_distributed_plan = 1, a table can be dropped concurrently between the coordinator serializing the query plan and a worker deserializing it. This is a reachable runtime condition, not an invariant violation, but the worker threw LOGICAL_ERROR, aborting the server in debug and sanitizer builds and bringing down stress tests since #106020.

Now such a query fails with a regular UNKNOWN_TABLE error — the same behavior as parallel replicas with ReplicatedMergeTree, where a replica that receives a query for a concurrently dropped table returns UNKNOWN_TABLE to the initiator.

🤖 Generated with Claude Code

Version info

  • Merged into: 26.6.1.602

…deserialization

A table can be dropped concurrently between the coordinator serializing
a distributed query plan and a worker task deserializing it, so a failed
catalog lookup in ReadFromMergeTree::deserialize is a reachable runtime
condition, not an invariant violation. Throw UNKNOWN_TABLE (as the
parallel replicas path does in the same scenario) instead of
LOGICAL_ERROR, which aborts the server in debug and sanitizer builds.
Also turn the unchecked MergeTreeData reference cast into a checked one:
the same race can resolve the name to a non-MergeTree table recreated
under the same name, which would crash with std::bad_cast.

Fixes #106906

Co-Authored-By: Claude Fable 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d260520]

Summary: ✅


AI Review

Summary

This PR changes ReadFromMergeTree::deserialize so a table dropped before distributed-plan task deserialization becomes a normal catalog error instead of a LOGICAL_ERROR. The missing-table case is improved, but the deserializer still resolves the serialized read by database.table only, so the same drop/recreate race can bind the task to a different MergeTree table and return data from the replacement. Request changes until table identity is preserved across serialization/deserialization.

Findings

⚠️ Majors

  • [src/Processors/QueryPlan/ReadFromMergeTree.cpp:4905] The serialized ReadFromMergeTree read is resolved by name only. If the coordinator serializes db.t for a MergeTree with UUID U1, then db.t is dropped and recreated as another MergeTree with the same schema and UUID U2, the worker deserializes a UUID-less StorageID, getTable returns U2, the dynamic_cast passes, and the header compatibility check passes. The query can then read the replacement table. The bucketed-read part-name check does not prove identity either, because part names like all_1_1_0 can be reused by a recreated table.
    Suggested fix: serialize the original StorageID UUID when present and resolve/check by UUID during deserialization, failing with a normal UNKNOWN_TABLE or TABLE_UUID_MISMATCH style exception if the original table is gone or the name now belongs to another table.
Tests
  • ⚠️ Add a focused regression for the drop/recreate case: serialize a distributed ReadFromMergeTree plan, drop and recreate the same database.table as another MergeTree with a compatible schema, and verify deserialization/execution fails instead of reading the replacement table. Include the bucketed case if part names are used as a guard.
Final Verdict

Status: ⚠️ Request changes

Minimum required action: preserve table identity across distributed-plan serialization/deserialization, and add regression coverage for the replacement-table race.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jun 10, 2026
auto storage_ptr = DatabaseCatalog::instance().tryGetTable(table_id, ctx.context);
if (!storage_ptr)
throw Exception(ErrorCodes::LOGICAL_ERROR, "Table {}.{} not found in catalog", database_name, table_name);
auto storage_ptr = DatabaseCatalog::instance().getTable(table_id, ctx.context);

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 still resolves the serialized ReadFromMergeTree by database.table only, so the same race can silently bind the task to a replacement table instead of failing. A concrete sequence is: the coordinator serializes db.t for a MergeTree with UUID U1; db.t is dropped and recreated as another MergeTree with the same schema and UUID U2; the worker deserializes StorageID(database_name, table_name) with no UUID, getTable returns U2, the dynamic_cast passes, and the header compatibility check also passes. The query can then read data from the new table. The part-name check is not enough for bucketed reads either, because part names such as all_1_1_0 can be reused by the replacement table.

Please serialize the original StorageID UUID when it is present and resolve/check by UUID during deserialization, failing with a normal UNKNOWN_TABLE/TABLE_UUID_MISMATCH style exception if the original table is gone or the name now belongs to a different table.

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.

@clickhouse-gh ReplicatedMergeTree replicas have different UUIDs on different nodes.

@vdimir vdimir self-assigned this Jun 10, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.70% 84.60% -0.10%
Functions 92.30% 92.30% +0.00%
Branches 77.30% 77.20% -0.10%

Changed lines: Changed C/C++ lines covered by tests: 7/9 (77.78%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@davenger
davenger added this pull request to the merge queue Jun 10, 2026
Merged via the queue into master with commit cdf12ed Jun 10, 2026
166 checks passed
@davenger
davenger deleted the fix-distributed-plan-unknown-table branch June 10, 2026 14:56
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 10, 2026
ianton-ru pushed a commit to Altinity/ClickHouse that referenced this pull request Jul 13, 2026
…plan-unknown-table

Fix logical error when table is dropped before distributed plan task deserialization
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog 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: Table A.B not found in catalog (STID: 3215-370f)

3 participants