Skip to content

Fix assignCentroid with an unqualified dictionary name on remote shards and parallel replicas - #123711

Merged
fm4v merged 3 commits into
ClickHouse:masterfrom
groeneai:assign-centroid-bind-dictionary-database
Oct 9, 2026
Merged

fm4v merged 3 commits into
ClickHouse:masterfrom
groeneai:assign-centroid-bind-dictionary-database

Conversation

@groeneai

@groeneai groeneai commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #123993
Related: #115541
Related: #85181

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 assignCentroid(vec, 'dict') with an unqualified dictionary name over a Distributed table, cluster()/remote() or parallel replicas. Remote shards and replicas resolved the name in their own default database, so the query failed with Dictionary (dict) not found or silently used a dictionary with the same name from default. The name is now resolved in the current database of the initiator, as for dictGet.

Description

On 26.9 (checked on v26.9.1.1629-stable), SELECT assignCentroid(v, 'centroids_dict') FROM <Distributed table> fails with Dictionary (centroids_dict) not found on the remote shards, and if default has 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%29

A 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 in resolveFunction, but only the first argument of dictGet and its variations. assignCentroid takes 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, because assignCentroid also accepts a Nullable or LowCardinality name and its result type follows it.

Test 05320_assign_centroid_distributed_current_database covers Distributed, cluster() and parallel replicas without the local plan, with a Nullable name. It fails on master with the CI error and passes with the fix. 02354_vector_search_assign_centroid with parallel_replicas_local_plan = 0 fails 5/5 before and passes 5/5 after.

Not changed: a view that stores an unqualified assignCentroid name still resolves it in the reader's current database (a dictGet name is qualified when the view is created).

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/123711]

Version info

  • Merged into: 26.10.1.1883-master (included in 26.10 and later)

groeneai and others added 2 commits October 3, 2026 15:26
`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]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Oct 3, 2026
@groeneai

groeneai commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator Author
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).

# Sev Finding Verdict Evidence / action
1 💡 A view, materialized view or column DEFAULT stores an unqualified assignCentroid dictionary name, so it resolves in the reader's current database (AddDefaultDatabaseVisitor qualifies only the first argument of dictGet) AGREE, not changed here Pre-existing on a path this PR does not touch; changing stored definitions needs its own upgrade story. Stated in the description.

Severity: ❌ blocker / ⚠️ major / 💡 nit.

Session id: cron:clickhouse-review-slot-8:20261003-153400

@groeneai

groeneai commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The new test fails on every run on master (Received from 127.0.0.2 ... Dictionary (centroids_dict) not found), and 02354_vector_search_assign_centroid with parallel_replicas_local_plan = 0 fails 5/5. Also reproduced on the official v26.9.1.1629-stable image.
b Root cause explained? Remote shards and replicas run in the default database. The analyzer binds the dictionary name to the initiator's database only for the first argument of dictGet and its variations; assignCentroid takes it as the second, so it was shipped unqualified.
c Fix matches root cause? Yes. The same binding in resolveFunction now covers assignCentroid's second argument. No test-side tag or guard.
d Test intent preserved / new tests added? 02354 is unchanged. New 05320 covers Distributed, cluster(), parallel replicas, WHERE, GROUP BY, a lambda, a Nullable name and the column name.
e Both directions demonstrated? Master: 5/5 FAIL. Fix: 50/50 OK with random settings. Reverting the binding reddens the test; dropping the type preservation reddens the Nullable line.
f Fix is general across code paths? All function-level dictionary-name consumers are now bound. Checked: Distributed, cluster(), parallel replicas with local plan 0 and 1, serialize_query_plan = 1. Not changed: names stored in view definitions (disclosed in the description).
g Fix generalizes across inputs (params/datatypes/wrappers)? Checked String, Nullable, LowCardinality, LowCardinality(Nullable), a scalar subquery, an already qualified name, NULL, a name absent locally, an inline centroid array. The result type is unchanged in every case.
h Backward compatible? (maintainer-approved exception only) Yes. No setting or format change. An old shard resolves the qualified name; an old initiator behaves as before.
i Invariants and contracts preserved? qualifyDictionaryNameWithDatabase still leaves qualified, XML and absent names alone. The new constant keeps the argument's type, so the result type, header and column name do not change. The dictGet path is unchanged.

Session id: cron:clickhouse-impl-slot-5:20261003-144600

@clickhouse-gh

clickhouse-gh Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [dee5b32]

Summary: ✅


AI Review

Summary

This PR fixes the direct-query analyzer path for assignCentroid(..., 'dict') on Distributed, cluster() and parallel-replica reads by qualifying the dictionary name in resolveFunction. That part looks correct, but the change stops short of the persisted-definition paths, so stored view / materialized view / column DEFAULT expressions still keep the old broken behavior. Because of that remaining user-visible gap, I would not approve this as a complete fix yet.

Findings

⚠️ Majors

  • [src/Analyzer/Resolve/resolveFunction.cpp:2339] The fix only covers ad-hoc query-tree resolution. Stored definitions still persist a bare assignCentroid dictionary name because the metadata visitors used by CREATE VIEW / column defaults and metadata reload still special-case only dictGet (src/Interpreters/AddDefaultDatabaseVisitor.h:258, src/Interpreters/AddDefaultDatabaseVisitor.h:664, src/Interpreters/InterpreterCreateQuery.cpp:2067, src/Databases/DatabaseOnDisk.cpp:105). A view like CREATE VIEW v AS SELECT assignCentroid(vec, 'dict') ... will therefore still reload unqualified and remote reads will keep resolving the dictionary in the reader's current database. Suggested fix: wire the same second-argument qualification through those visitors, and update the dependency / rename visitors that still only recognize dictGet.
Final Verdict

Status: ⚠️ Request changes

Minimum required action: extend the stored-definition path for assignCentroid's second argument as well, so view / materialized view / column DEFAULT metadata is qualified consistently with direct queries, and keep the dictionary dependency / rename handling aligned with that change.

LLVM Coverage Report

Measured on commit dee5b32.

Metric Baseline Current Δ
Lines 88.30% 88.30% +0.00%
Functions 92.10% 92.10% +0.00%
Branches 79.70% 79.70% +0.00%

Changed lines: Changed C/C++ lines covered: 26/26 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default comp-query-analyzer Semantic analysis + logical/physical planning + rewrites (Analyzer and Planner modules). labels Oct 3, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit dee5b32eb1f9e9974d110e3e669e70f9ca7a7157 was not compared: the CI logs cluster did not answer (every POST attempt failed with an exception).

See the job log for details.

@groeneai

groeneai commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 6e5434c

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
AST fuzzer (amd_debug, targeted, old_compatibility) / Received signal 6 (STID: 3843-4f98) not from this PR: a pre-existing abort in ExpressionActions::linearizeActions on a remote read of a lambda the shard cannot fold with LIMIT AFTER; the fuzzed query aborts the same way on the PR base without this diff, and with no dictionary at all, and no longer aborts with #122045's patch #122045 (mine, open)
Build (amd_fuzzers) / Build ClickHouse not from this PR: the same job is red on master and on 116 PRs in 24h; the clickhouse_fuzzer link outgrows the 2 GiB reach of the small code model #122521 (mine, open)
Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel) / 04653_bloom_filter_fixed_string_constant_scalar not from this PR: a replica receives the Dynamic constant without its active member type, so the FixedString value no longer equals the String one and that replica's rows drop out (1 instead of 3); 14 PRs today #118988 (mine, open)
Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel) / 05257_sql_security_view_sealed not from this PR: a replica cannot run the SQL SECURITY DEFINER view's read as the definer, so the row policy check fails with ACCESS_DENIED; 58 PRs in 48h #123729 (mine, open)
Stateless tests (arm_binary, s3 storage, DBReplicated, parallel, 1/2) / 05237_with_expression_alias_scope_descendant deterministic under a Replicated database: the replicated CREATE VIEW qualifies a nested WITH alias with the database, so the view reads the same-named table; 124 PRs in 48h a fix task is created (fix in progress, fixing-PR link to follow here)
Mergeable Check, PR rollups, red only because of the rows above #122045, #122521, #118988, #123729 and the fix task above

05320_assign_centroid_distributed_current_database passed. All 157 checks completed; CIDB has no other FAIL or ERROR on this head.

Session id: cron:our-pr-ci-monitor:20261003-200032

@groeneai

groeneai commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator Author

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();

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 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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@fm4v
fm4v added this pull request to the merge queue Oct 8, 2026
Merged via the queue into ClickHouse:master with commit c0fecec Oct 9, 2026
152 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 9, 2026
kute1654 pushed a commit to kute1654/ClickHouse that referenced this pull request Oct 10, 2026
ClickHouse#123711 fixed ClickHouse#123993, which ClickHouse#123790 tagged the test `no-parallel-replicas` for.

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

Labels

can be tested Allows running workflows for external contributors comp-query-analyzer Semantic analysis + logical/physical planning + rewrites (Analyzer and Planner modules). groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding 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.

assignCentroid with an unqualified dictionary name fails on remote shards and parallel replicas

3 participants