Repository navigation
Bind an unqualified dictGet name to the current database - #115541
Conversation
The dictionary name of `dictGet` and its variations is resolved against the
current database of the server that evaluates the function. A shard of a
`Distributed` table evaluates it in a session whose current database comes from
the cluster configuration - `default` unless `<default_database>` is set - and
not from the initiator, so a query written as
USE demo;
SELECT code, dictGet('dict_test', 'value', code) FROM demo.test;
fails on the shards with `Dictionary (dict_test) not found`, or - when a
dictionary of the same name also exists in the shard's own database - silently
returns the values of the wrong dictionary.
Bind the name in the analyzer, while the current database of the initiator is
still known, so the bound name travels to the shards inside the query tree. The
old analyzer already does the same in `AddDefaultDatabaseVisitor` for the query
it sends to the shards.
The binding happens after the projection names of the arguments have been
calculated, so the column name of the expression stays exactly as it was written
by the user. `qualifyDictionaryNameWithDatabase` leaves the name alone when it is
already qualified, when it belongs to an XML dictionary, and when no such
dictionary exists in the current database.
The `EXPLAIN SYNTAX run_query_tree_passes=1` references of the inverse dictionary
lookup tests now show the bound name; only the printed query changes there.
The old analyzer keeps failing with `NOT_FOUND_COLUMN_IN_BLOCK` because the
header it computes on the initiator keeps the unqualified column name, so the
new test is tagged `no-old-analyzer`.
Closes: #85181
Related: #44301
Related: #46424
Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [78e6ef0] Summary: ✅
AI ReviewSummaryThis PR fixes the main literal/identifier form of distributed Findings
Final VerdictStatus: Minimum required action: close the remaining initiator/shard divergence for const-string dictionary-name expressions (or explicitly narrow the implementation and regression coverage if that shape is intentionally out of scope). LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 11/11 (100.00%) · Uncovered code |
| auto & dict_get_arguments = function_node_ptr->getArguments().getNodes(); | ||
| if (!dict_get_arguments.empty()) | ||
| { | ||
| const auto * dictionary_name_node = dict_get_arguments[0]->as<ConstantNode>(); |
There was a problem hiding this comment.
dictGet still has one initiator/shard divergence here: this only binds carriers that have already become a ConstantNode. Supported const-string expressions like dictGet(currentDatabase() || '.dict', ...) (see tests/queries/0_stateless/01552_dict_fixedstring.sql) are still a live FunctionNode at this point because currentDatabase is explicitly non-deterministic (src/Functions/currentDatabase.cpp:43) and the later constant-folding step will not fold it into a literal on the initiator (resolveFunction.cpp:2468-2517). On a real remote connection the shard will re-evaluate that expression in its own session and still pick default.dict, so the bug remains for that name form. This needs an initiator-side substitution/binding for server-context const-string expressions, similar to AddDefaultDatabaseVisitor::substituteCurrentDatabase, before the query tree is serialized to shards.
There was a problem hiding this comment.
It is a secondary problem. If it is even slightly non-trivial to fix, let's pass.
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, 12 s compile time in total, 7 of them have a recent master baseline. |
alexey-milovidov
left a comment
There was a problem hiding this comment.
The fix is correct, the comment is a little bit redundant. LGTM.
Closes: #85181
Related: #44301
Related: #46424
The dictionary name of
dictGetand its variations is resolved against the current database of the server that evaluates the function. A shard of aDistributedtable evaluates it in a session whose current database comes from the cluster configuration —defaultunless<default_database>is set — and not from the initiator. So:fails on the shards with
and — worse — when a dictionary of the same name also exists in the shard's own database, no error is raised at all and the values of the wrong dictionary are returned silently.
This binds the name in the analyzer, while the current database of the initiator is still known, so the bound name travels to the shards inside the query tree. The old analyzer already does the same in
AddDefaultDatabaseVisitorfor the query it sends to the shards.The binding happens after the projection names of the arguments have been calculated, so the column name of the expression stays exactly as it was written by the user:
dictGet('dict_test', 'value', code), notdictGet('demo.dict_test', 'value', code).qualifyDictionaryNameWithDatabaseleaves the name alone when it is already qualified, when it belongs to an XML dictionary, and when no such dictionary exists in the current database — in the last case the name may still be meant for a dictionary that only exists on the shards.Notes:
EXPLAIN SYNTAX run_query_tree_passes=1references of the inverse dictionary lookup tests now show the bound name; only the printed query changes there, no result changes.04054_dictget_unqualified_name_distributeddeliberately runs in thedefaultdatabase so that the shard can resolve the unqualified name, which is why it never caught this. The new test runs in the test's own database withprefer_localhost_replica = 0, which is what makes the shard query travel over a real connection.NOT_FOUND_COLUMN_IN_BLOCK, because the header it computes on the initiator keeps the unqualified column name while the query it ships to the shards carries the qualified one. Fixing that needs a separate change, so the new test is taggedno-old-analyzer.joinGethas the same defect (Table default.jt does not exist. Maybe you meant demo.jt?); its first argument is a table name with temporary-table and access-control semantics of its own, so it is left for a separate change.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
dictGetand its variations in distributed queries: an unqualified dictionary name is now bound to the current database of the initiator, instead of being resolved against the current database of each shard, where it either was not found or resolved to a different dictionary of the same name.Documentation entry for user-facing changes
Workflow [PR]
Sync PR [sync-upstream/pr/115541]
Version info
26.8.1.1789(included in26.8and later)