Repository navigation
Fix grouping function on Distributed table with single shard - #101030
Conversation
The `grouping` function (used with `GROUPING SETS`, `ROLLUP`, `CUBE`) failed with "Method executeImpl is not supported for 'grouping' function" when querying a Distributed table backed by a single shard. Root cause: `buildQueryTreeForShard` called `removeGroupingFunctionSpecializations` which replaced specialized functions (e.g. `groupingForGroupingSets`) with the generic `FunctionGrouping` that throws on execute. The same query tree was then reused for `getSampleBlock` / plan building, which executes functions with 0 rows for header computation, triggering the exception. Fix: move `removeGroupingFunctionSpecializations` out of `buildQueryTreeForShard` and apply it only on clones of the query tree right before AST conversion for shard execution. This keeps the original tree with specialized (executable) functions intact for plan building, while the AST sent to shards still contains the generic `grouping` name that the shard's analyzer can re-resolve. Closes #71270 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Workflow [PR], commit [302671e] Summary: ✅ AI ReviewSummaryThis PR fixes ClickHouse Rules
Final VerdictStatus: ✅ Approve |
Address review feedback: the original test only used `remote()` table function, which does not exercise the `StorageDistributed::read` code path. Add test cases that create a real `Distributed` table over a local `MergeTree` table and run `GROUPING SETS`, `ROLLUP`, and `CUBE` queries with the `grouping` function, including with `prefer_localhost_replica = 0`. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The `serialize_query_plan` setting causes the specialized grouping functions (`groupingForGroupingSets`, etc.) to be serialized in the query plan via `ActionsDAG::serialize`. On the shard side, `ActionsDAG::deserialize` looks up the function by name in the `FunctionFactory`, but these internal functions are not registered there, causing `UNKNOWN_FUNCTION` errors. This is a pre-existing limitation unrelated to the fix in this PR. Disable `serialize_query_plan` in the test to work around it. Also add a parallel replicas test case (Part 3) to exercise the `executeQueryWithParallelReplicas` and `findParallelReplicasQuery` code paths, as requested in review. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…buted-single-shard
This file was accidentally included in commit b884ff7 and is unrelated to the PR. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Parallel replicas require the analyzer by default (`parallel_replicas_only_with_analyzer = true`), so the test was silently falling back to a non-parallel path in the old-analyzer CI run, producing no output and causing a reference mismatch. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…buted-single-shard
…buted-single-shard
…lan = 1` The `buildQueryPlanForParallelReplicas` code path is only reached when `serialize_query_plan` is enabled (or in follower mode). The previous parallel replicas test ran with `serialize_query_plan = 0`, so it only exercised the `executeQueryWithParallelReplicas` path. Add a Part 4 that explicitly sets `serialize_query_plan = 1` to cover the `findParallelReplicasQuery` fix as well. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix. |
…buted-single-shard
…buted-single-shard
…buted-single-shard
…buted-single-shard
…buted-single-shard
…buted-single-shard
LLVM Coverage Report
Changed lines: 100.00% (33/33) · Uncovered code |
|
Hi — this PR may need backporting to Affected code: Why: Fix for If this should be backported, consider adding |
…ldren A Merge of a local table and a Distributed table is read at WithMergeableState, so ReadFromMerge::createPlanForTable plans each local child by printing the already-analyzed query tree and re-analyzing it. GroupingFunctionsResolvePass has replaced every grouping(...) in that tree with an analyzer-built specialization such as __groupingForGroupingSets(__grouping_set, <keys>, <state constants>), and __grouping_set is a column produced by aggregation, so the printed query fails in the child with UNKNOWN_IDENTIFIER `__grouping_set`. The same happens for ROLLUP and CUBE and for a nested Merge child. Every place that prints an analyzed tree for a remote analyzer (StorageDistributed::read, SelectStreamFactory, ClusterProxy, parallel replicas, IStorageCluster) already calls removeGroupingFunctionSpecializations on a clone first; this local re-analysis site was missing from that list. Do the same here. The clone keeps the original tree intact, because the de-specialized nodes would throw if executed. The child runs the resolve passes, which include GroupingFunctionsResolvePass, so it rebuilds the specializations from its own GROUP BY. Related: ClickHouse#124125 (comment) Related: ClickHouse#101030 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The
groupingfunction (used withGROUPING SETS,ROLLUP,CUBE) failed with "Method executeImpl is not supported for 'grouping' function" when querying a Distributed table backed by a single shard.Root cause:
buildQueryTreeForShardcalledremoveGroupingFunctionSpecializationswhich replaced specialized functions (e.g.groupingForGroupingSets) with the genericFunctionGroupingthat throws on execute. The same query tree was then reused forgetSampleBlock/ plan building, which executes functions with 0 rows for header computation, triggering the exception.Fix: move
removeGroupingFunctionSpecializationsout ofbuildQueryTreeForShardand apply it only on clones of the query tree right before AST conversion for shard execution. This keeps the original tree with specialized (executable) functions intact for plan building, while the AST sent to shards still contains the genericgroupingname that the shard's analyzer can re-resolve.Closes #71270
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
grouping/GROUPING SETSqueries on Distributed tables with a single shard that failed with "Method executeImpl is not supported for 'grouping' function".Documentation entry for user-facing changes
Version info
26.5.1.68