terrymanu commented on issue #28914:
URL:
https://github.com/apache/shardingsphere/issues/28914#issuecomment-3621628763
Root Cause: In the default sharding execution path, the inner GROUP BY
distinct information is not preserved for merging. The outer COUNT (with no
GROUP BY) sums per-shard counts directly, so duplicate name values across
shards are double-counted.
Problem Analysis:
- Routing sees a subquery, so aggregate rewrite is not enabled; each shard
executes a local count.
- Merge phase uses accumulation for COUNT without global distinct tracking
because only local counts are returned, not grouped rows.
- Cross-shard duplicates therefore inflate the result to 3 instead of 2.
Conclusion:
- This is a known limitation of the default execution path.
- Recommended usage: enable SQL Federation (e.g., set the sql-federation
rule to FORCE/ALL) so GROUP BY de-duplication happens globally before counting;
or change to select name ... group by name and count in the application after
ShardingSphere performs global
grouping.
- If you need further confirmation, please share your rule configuration
(whether SQL Federation is enabled), data distribution, and execution logs to
verify whether the query took the sharding merge path instead of the federation
path.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]