GROUP_CONCAT returns an empty string instead of NULL when all merged values are NULL

Author: thswlsqlsCreated Sep 17, 2026Updated Sep 17, 2026

GROUP_CONCAT returns an empty string instead of NULL when all merged values are NULL

Bug Report

Which version of ShardingSphere did you use?

master @ 101c3d56ccd

Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

Both

Expected behavior

GROUP_CONCAT over a group whose values are NULL on every shard returns NULL, as MySQL documents: "It returns NULL if there are no non-NULL values."

Actual behavior

On a multi-shard route the merged GROUP_CONCAT and GROUP_CONCAT(DISTINCT ...) value is "" with wasNull() == false; a single-shard route returns NULL.

Reason analyze (If you can)

GroupConcatAggregationUnit.getResult() and DistinctGroupConcatAggregationUnit.getResult() (features/sharding/core/.../merge/dql/groupby/aggregation/) always return String.join(separator, values); merge() skips NULL, so an all-NULL group yields "". The six sibling units return null when nothing was merged, and GroupByStreamMergedResult.getValue() already maps null to wasNull. Introduced with #33808.

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

  1. Shard t_user across two data sources.
  2. Insert rows for one user_id into both shards with nickname = NULL.
  3. SELECT user_id, GROUP_CONCAT(nickname) FROM t_user GROUP BY user_id returns "" instead of NULL.

Example codes for reproduce this issue (such as a github link).

N/A