strongduanmu opened a new issue #14341:
URL: https://github.com/apache/shardingsphere/issues/14341
## Bug Report
### Which version of ShardingSphere did you use?
3b8dc82bfb8691f52f221ae394587bcfc03bfa9b
### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
ShardingSphere-Proxy
### Expected behavior
Return correct result.
```sql
SELECT count( DISTINCT test_id ), sum(distinct test_id), user_id FROM
t_order group by user_id;
+--------------------------------+--------------------------------+---------+
| AGGREGATION_DISTINCT_DERIVED_0 | AGGREGATION_DISTINCT_DERIVED_1 | user_id |
+--------------------------------+--------------------------------+---------+
| 3 | 8 | 1 |
| 1 | 4 | 2 |
| 3 | 9 | 3 |
| 1 | 1 | 4 |
| 1 | 2 | 5 |
| 1 | 2 | 6 |
+--------------------------------+--------------------------------+---------+
```
### Actual behavior
But the result is wrong.
```sql
SELECT count( DISTINCT test_id ), sum(distinct test_id), user_id FROM
t_order group by user_id;
+--------------------------------+--------------------------------+---------+
| AGGREGATION_DISTINCT_DERIVED_0 | AGGREGATION_DISTINCT_DERIVED_1 | user_id |
+--------------------------------+--------------------------------+---------+
| 2 | 5 | 1 |
| 1 | 4 | 2 |
| 2 | 5 | 3 |
| 1 | 1 | 4 |
| 1 | 2 | 5 |
| 1 | 2 | 6 |
+--------------------------------+--------------------------------+---------+
```
### Reason analyze (If you can)
### Steps to reproduce the behavior, such as: SQL to execute, sharding rule
configuration, when exception occur etc.
```yaml
schemaName: sharding_db
dataSources:
ds_0:
url:
jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false
username: root
password: 123456
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
ds_1:
url:
jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false
username: root
password: 123456
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
rules:
- !SHARDING
tables:
t_order:
actualDataNodes: ds_${0..1}.t_order_${0..1}
tableStrategy:
standard:
shardingColumn: order_id
shardingAlgorithmName: t_order_inline
keyGenerateStrategy:
column: order_id
keyGeneratorName: snowflake
t_order_item:
actualDataNodes: ds_${0..1}.t_order_item_${0..1}
tableStrategy:
standard:
shardingColumn: order_id
shardingAlgorithmName: t_order_item_inline
keyGenerateStrategy:
column: order_item_id
keyGeneratorName: snowflake
bindingTables:
- t_order,t_order_item
defaultDatabaseStrategy:
standard:
shardingColumn: user_id
shardingAlgorithmName: database_inline
defaultTableStrategy:
none:
shardingAlgorithms:
database_inline:
type: INLINE
props:
algorithm-expression: ds_${user_id % 2}
t_order_inline:
type: INLINE
props:
algorithm-expression: t_order_${order_id % 2}
t_order_item_inline:
type: INLINE
props:
algorithm-expression: t_order_item_${order_id % 2}
keyGenerators:
snowflake:
type: SNOWFLAKE
props:
worker-id: 123
```
```sql
DROP TABLE IF EXISTS t_order;
CREATE TABLE t_order (
order_id INT NOT NULL,
user_id int NOT NULL,
test_id int NOT NULL,
content varchar(50) DEFAULT NULL,
PRIMARY KEY (order_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO t_order(order_id, user_id, test_id, content) VALUES(1, 1, 4,
'TEST1')
,(2, 1, 1, 'TEST1')
,(3, 3, 3, 'TEST1')
,(4, 2, 4, 'TEST1')
,(5, 4, 1, 'TEST1')
,(6, 1, 3, 'TEST1')
,(7, 3, 4, 'TEST1')
,(8, 6, 2, 'TEST1')
,(9, 5, 2, 'TEST1')
,(10, 3, 2, 'TEST1')
;
```
### Example codes for reproduce this issue (such as a github link).
--
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]