Repository navigation
Fix assignCentroid with an unqualified dictionary name on remote shards and parallel replicas - #123711
Conversation
`assignCentroid(vec, 'dict')` resolves an unqualified dictionary name against the current database of the server that evaluates it. A shard of a `Distributed` table, `cluster()`/`remote()`, or a parallel replica runs the query in a session whose current database comes from the cluster configuration (`default` unless `<default_database>` is set), so the remote side either throws `Dictionary (`dict`) not found` or silently uses a same-named dictionary from `default`. The analyzer already binds the name of `dictGet` and its variations to the initiator's current database in `resolveFunction`, but only for the first argument of `functionIsDictGet` functions. `assignCentroid` takes the name as its second argument, so it was shipped unqualified. Extend the same binding to it. The replacement constant keeps the argument's type: `assignCentroid` accepts a `Nullable(String)` or `LowCardinality(String)` name (a scalar subquery gives `Nullable(String)`) and its result type follows it, so a plain `String` would change the result type depending on whether the dictionary exists locally. The `dictGet` path is unchanged. Seen in CI as a flaky `02354_vector_search_assign_centroid` in the ParallelReplicas lane: it fails exactly when the reading coordinator hands rows to a remote replica. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the comment restating the dictionary-name argument position, which the code below already shows. 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; 0 findings) plus my own review (1 nit).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261003-153400 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261003-144600 |
|
Workflow [PR], commit [dee5b32] Summary: ✅
AI ReviewSummaryThis PR fixes the direct-query analyzer path for Findings
Final VerdictStatus: Minimum required action: extend the stored-definition path for LLVM Coverage ReportMeasured on commit dee5b32.
Changed lines: Changed C/C++ lines covered: 26/26 (100.00%) · Uncovered code |
Build profile diff (arm_release)Commit See the job log for details. |
CI finish ledger - 6e5434cEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261003-200032 |
|
Fixing PR for 05237_with_expression_alias_scope_descendant (DBReplicated): #123774 |
| { | ||
| const auto & dictionary_name = dictionary_name_node->getValue().safeGet<String>(); | ||
| auto qualified_dictionary_name = scope.context->getExternalDictionariesLoader() | ||
| .qualifyDictionaryNameWithDatabase(dictionary_name, scope.context).getFullName(); |
There was a problem hiding this comment.
This only fixes ad-hoc query-tree resolution. View / materialized view / column DEFAULT definitions are still stored bare because the metadata visitors used at CREATE time and on reload only special-case functionIsDictGet (src/Interpreters/AddDefaultDatabaseVisitor.h:258 and src/Interpreters/AddDefaultDatabaseVisitor.h:664, wired from src/Interpreters/InterpreterCreateQuery.cpp:2067 and src/Databases/DatabaseOnDisk.cpp:105).
So CREATE VIEW ... SELECT assignCentroid(v, 'dict') ... continues to persist and reload an unqualified dictionary name, and remote reads will still resolve it against the reader's current database. Please thread the same second-argument qualification through those visitors too, and keep the dependency / rename visitors in sync.
There was a problem hiding this comment.
Addressed in #124989: a new CREATE or ALTER now stores the assignCentroid dictionary name qualified with the database, like dictGet. Definitions replayed from stored metadata (short ATTACH, startup, RESTORE, Replicated replay) keep their stored text, because without a loading dependency the dictionary may not be loaded yet there; the PR description explains why I did not add that dependency.
ClickHouse#123711 fixed ClickHouse#123993, which ClickHouse#123790 tagged the test `no-parallel-replicas` for. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #123993
Related: #115541
Related: #85181
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
assignCentroid(vec, 'dict')with an unqualified dictionary name over aDistributedtable,cluster()/remote()or parallel replicas. Remote shards and replicas resolved the name in their owndefaultdatabase, so the query failed withDictionary (dict) not foundor silently used a dictionary with the same name fromdefault. The name is now resolved in the current database of the initiator, as fordictGet.Description
On 26.9 (checked on
v26.9.1.1629-stable),SELECT assignCentroid(v, 'centroids_dict') FROM <Distributed table>fails withDictionary (centroids_dict) not foundon the remote shards, and ifdefaulthas a dictionary with the same name it returns that dictionary's centroid ids.Seen in CI as a flaky
02354_vector_search_assign_centroid: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=101783&sha=4c6504bf145f6165e1a6b6795ab23ca486fe7330&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29A shard or a parallel replica evaluates the query in a session whose current database is
default(unless the cluster sets<default_database>). #115541 binds an unqualified dictionary name to the initiator's database inresolveFunction, but only the first argument ofdictGetand its variations.assignCentroidtakes the name as its second argument, so it was shipped bare.The change extends that binding to the second argument of
assignCentroid. The new constant keeps the argument's type, becauseassignCentroidalso accepts aNullableorLowCardinalityname and its result type follows it.Test
05320_assign_centroid_distributed_current_databasecoversDistributed,cluster()and parallel replicas without the local plan, with aNullablename. It fails on master with the CI error and passes with the fix.02354_vector_search_assign_centroidwithparallel_replicas_local_plan = 0fails 5/5 before and passes 5/5 after.Not changed: a view that stores an unqualified
assignCentroidname still resolves it in the reader's current database (adictGetname is qualified when the view is created).🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/123711]
Version info
26.10.1.1883-master(included in26.10and later)