Repository navigation
Fix logical error for Distributed table with empty remote database under distributed_product_mode=local - #110677
Conversation
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-6:20260716-111500 |
|
cc @evillique @azat — could you review this? It fixes an |
|
Workflow [PR], commit [d9d7947] Summary: ✅
AI ReviewSummaryThis PR narrows the old-analyzer Findings
Final VerdictChanges requested. The assertion is gone, but the old-analyzer LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 2/2 (100.00%) · Uncovered code |
…se and distributed_product_mode=local
Rewriting a Distributed table to its remote table under
distributed_product_mode=local builds an ASTTableIdentifier from the remote
(database, table) pair. When the remote database name is empty (a legal
Distributed definition meaning the current database on the remote), the
(String, String) constructor produced an identifier with an empty leading
name-part, which trips chassert(!part.empty()) in the ASTIdentifier
constructor and aborts the server in debug/sanitizer builds (a handled
exception in release). Found by the AST fuzzer (STID 2508-3750).
Mirror the existing ASTTableIdentifier(StorageID) constructor: when the
database is empty, build a single-part identifier. Only do this when there
are no name parameters: a parameterized identifier such as
{db:Identifier}.{tbl:Identifier} legitimately carries empty name-parts that
are filled by the corresponding name_params children, and collapsing them
would drop the placeholder and break identifier formatting/resolution.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
1685a48 to
b599aa5
Compare
|
The previous revision collapsed Refined the guard to Verified locally (debug):
|
…mpty-db-distributed-local
CI finish ledger — b599aa5CI finished on the prior head. The earlier broad Fast test regression (empty-table/UNKNOWN_TABLE identifier resolution) was fixed on this head by the
Session id: cron:our-pr-ci-monitor:20260718-173000 |
| ASTTableIdentifier::ASTTableIdentifier(const String & database_name, const String & table_name, ASTs && name_params) | ||
| : ASTIdentifier({database_name, table_name}, true, std::move(name_params)) | ||
| : ASTIdentifier( | ||
| (database_name.empty() && name_params.empty()) |
There was a problem hiding this comment.
Collapsing ("", table) to a short identifier fixes the ASTIdentifier invariant, but on the old-analyzer JOIN path it also changes the remote-dispatch behavior. InJoinSubqueriesPreprocessor::resetTable now leaves the rewritten table non-compound, and ClusterProxy::rewriteSelectQuery still runs the JOIN-only AddDefaultDatabaseVisitor (SelectStreamFactory.cpp:95-102 / AddDefaultDatabaseVisitor.h:176-191), which re-qualifies it with context->getCurrentDatabase(). On clusters that intentionally use an empty remote database so each shard falls back to its own default_database (for example test_cluster_two_shards_different_databases), the shard query becomes current_db.table instead of preserving the per-shard default. The new EXPLAIN AST test won't see this because it never goes through remote dispatch. I think this still needs either a marker that suppresses that JOIN requalification for empty-remote-db rewrites, or an old-analyzer execution test modeled on 04303_58766_distributed_product_mode_local_default_database.sql.
There was a problem hiding this comment.
Verified on a debug build (this branch) vs the same file reverted to master, same query and cluster config (test_cluster_two_shards_different_databases, per-shard default_database).
The mechanism is correct: the collapsed non-compound table gets re-qualified to current_db.table by AddDefaultDatabaseVisitor(only_replace_in_join). But that path did not preserve the per-shard default before the fix either. On master the identical old-analyzer JOIN aborts the server:
Logical error: '!part.empty()' at InJoinSubqueriesPreprocessor.cpp:96 -> resetTable -> ASTIdentifier ctor (signal 6)
Measured on this branch:
- old-analyzer JOIN,
distributed_product_mode=local, empty remote db:Code 60 UNKNOWN_TABLE default.smaller_table(was: server abort) - old-analyzer IN-subquery (the issue Systax error on query when using remote_server default_database with distributed_product_mode='local' #58766 query):
4 enable_analyzer=1IN and JOIN:4,4
For a non-empty remote db the constructor is byte-identical to master (the else branch), so only the empty-remote-db case, which crashed, is affected. The remaining UNKNOWN_TABLE is a pre-existing limitation of the old-analyzer JOIN rewrite (the release-build symptom is the empty-backtick SYNTAX_ERROR documented in 04303); enable_analyzer=1 resolves it. A JOIN execution test can't assert a passing result since that path never worked. I can add a marker suppressing the JOIN re-qualification for empty-remote-db rewrites if that resolution is preferred; leaving the disposition to the assignee.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 5/5 (100.00%) · Uncovered code |
CI finish ledger — f7229f3 (clean)CI fully finished on this head (a master merge that picked up the fix for the one real failure from the prior head). No failures remain.
Session id: cron:our-pr-ci-monitor:20260718-223000 |
CI finish ledger — f7229f3Every check has an owner; only
The earlier Fast-test regression (empty-table/UNKNOWN_TABLE) was on stale head 1685a48 and fixed by the Session id: cron:our-pr-ci-monitor:20260719-003000 |
azat
left a comment
There was a problem hiding this comment.
I don't like this, better to use auto identifier = make_intrusive<ASTTableIdentifier>(StorageID{database_name, table_name}); instead of auto identifier = make_intrusive<ASTTableIdentifier>(database_name, table_name); in the ASTTableIdentifier::resetTable
And keep only essentials in commits description, PR description and code comments
…se and distributed_product_mode=local Rewriting a Distributed table to its remote table under distributed_product_mode=local calls ASTTableIdentifier::resetTable with the remote (database, table) pair. An empty remote database is legal (it means the current database on the remote), but the (String, String) constructor built an identifier with an empty leading name-part, tripping chassert(!part.empty()) in the ASTIdentifier constructor. Build the identifier from a StorageID instead, which already collapses an empty database to a single-part name. Found by the AST fuzzer (STID 2508-3750). Co-Authored-By: Claude Opus 5 <[email protected]>
|
Done in d9d7947.
Verified on a debug build: the repro no longer aborts, and with only the constructor reverted (i.e. without the One behaviour difference worth flagging: |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units7 translation units recompiled, 7 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger - d9d7947CI fully finished on this head (the head that addresses @azat's change requests) and it is clean. Every failure line would have an owner; there are none.
Session id: cron:our-pr-ci-monitor:20260810-010000 |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a logical error (
!part.empty()) when aDistributedtable defined with an empty remote database name is used in a JOIN withdistributed_product_mode = 'local'.Description
ASTTableIdentifier::resetTable, called whendistributed_product_mode = 'local'rewrites aDistributedtable to its remote table, built the identifier via the(String, String)constructor. An empty remote database is legal (it means the current database on the remote), but that constructor produced an empty leading name-part, trippingchassert(!part.empty())in theASTIdentifierconstructor. It now builds from aStorageID, which already collapses an empty database to a single-part name.Found by the AST fuzzer (STID 2508-3750). Reproducer:
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110633&sha=ea2a114066175d6c883deeb89b0d32d84760e28c&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%29