You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/10/13 03:11:05 UTC
[GitHub] [shardingsphere] azexcy opened a new issue, #21540: The result of `select * fromt table ` is different is not the same as the return value of a direct database connection
azexcy opened a new issue, #21540:
URL: https://github.com/apache/shardingsphere/issues/21540
## Bug Report
create table sql:
```
CREATE TABLE `t_order` (
`id` bigint NOT NULL COMMENT 'pk id',
`order_id` bigint NOT NULL,
`user_id` int NOT NULL,
`status` varchar(255) DEFAULT NULL,
`t_unsigned_mediumint` mediumint unsigned DEFAULT NULL,
`username` varchar(255) DEFAULT NULL,
`pwd` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `unique_key_order_id` (`order_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
```
resource:
```
ADD RESOURCE ds_0 (
URL="jdbc:mysql://127.0.0.1:3306/target_ds_0?serverTimezone=UTC&useSSL=false",
USER="root",
PASSWORD="root",
PROPERTIES("maxPoolSize"="50","idleTimeout"="60000")
);
ADD RESOURCE ds_1 (
URL="jdbc:mysql://127.0.0.1:3306/target_ds_1?serverTimezone=UTC&useSSL=false",
USER="root",
PASSWORD="root",
PROPERTIES("maxPoolSize"="50","idleTimeout"="60000")
);
```
sharding rule
```
CREATE SHARDING TABLE RULE t_order(
RESOURCES(ds_0,ds_1),
SHARDING_COLUMN=order_id,
TYPE(NAME="hash_mod",PROPERTIES("sharding-count"="6")),
KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME="snowflake"))
);
```
The result between `select * from t_order where id > 0 limit 1;` and `select * from t_order where id > 0 order by id limit 1;` are different.
```
mysql> select * from t_order where id > 0 order by id limit 1;
+----+----------+---------+--------+----------------------+----------+------+
| id | order_id | user_id | status | t_unsigned_mediumint | username | pwd |
+----+----------+---------+--------+----------------------+----------+------+
| 1 | 1 | 1 | newnew | 123 | 1 | 1 |
+----+----------+---------+--------+----------------------+----------+------+
1 row in set (0.04 sec)
mysql> select * from t_order where id > 0 limit 1;
+----+----------+---------+--------+----------------------+----------+------+
| id | order_id | user_id | status | t_unsigned_mediumint | username | pwd |
+----+----------+---------+--------+----------------------+----------+------+
| 66 | 66 | 66 | fff | 16777215 | 6 | 6 |
+----+----------+---------+--------+----------------------+----------+------+
1 row in set (0.02 sec)
```
the proxy log
```
[INFO ] 2022-10-13 10:54:56.722 [Connection-1-ThreadExecutor] ShardingSphere-SQL - Actual SQL: ds_0 ::: select * from t_order_0 where id > 0 order by id limit 1
[INFO ] 2022-10-13 10:54:56.722 [Connection-1-ThreadExecutor] ShardingSphere-SQL - Actual SQL: ds_0 ::: select * from t_order_2 where id > 0 order by id limit 1
[INFO ] 2022-10-13 10:54:56.722 [Connection-1-ThreadExecutor] ShardingSphere-SQL - Actual SQL: ds_0 ::: select * from t_order_4 where id > 0 order by id limit 1
[INFO ] 2022-10-13 10:54:56.722 [Connection-1-ThreadExecutor] ShardingSphere-SQL - Actual SQL: ds_1 ::: select * from t_order_1 where id > 0 order by id limit 1
[INFO ] 2022-10-13 10:54:56.722 [Connection-1-ThreadExecutor] ShardingSphere-SQL - Actual SQL: ds_1 ::: select * from t_order_3 where id > 0 order by id limit 1
[INFO ] 2022-10-13 10:54:56.722 [Connection-1-ThreadExecutor] ShardingSphere-SQL - Actual SQL: ds_1 ::: select * from t_order_5 where id > 0 order by id limit 1
[INFO ] 2022-10-13 10:55:38.229 [Connection-1-ThreadExecutor] ShardingSphere-SQL - Logic SQL: select * from t_order where id > 0 limit 1
[INFO ] 2022-10-13 10:55:38.230 [Connection-1-ThreadExecutor] ShardingSphere-SQL - Actual SQL: ds_0 ::: select * from t_order_0 where id > 0 limit 1
[INFO ] 2022-10-13 10:55:38.230 [Connection-1-ThreadExecutor] ShardingSphere-SQL - Actual SQL: ds_0 ::: select * from t_order_2 where id > 0 limit 1
[INFO ] 2022-10-13 10:55:38.230 [Connection-1-ThreadExecutor] ShardingSphere-SQL - Actual SQL: ds_0 ::: select * from t_order_4 where id > 0 limit 1
[INFO ] 2022-10-13 10:55:38.230 [Connection-1-ThreadExecutor] ShardingSphere-SQL - Actual SQL: ds_1 ::: select * from t_order_1 where id > 0 limit 1
[INFO ] 2022-10-13 10:55:38.230 [Connection-1-ThreadExecutor] ShardingSphere-SQL - Actual SQL: ds_1 ::: select * from t_order_3 where id > 0 limit 1
[INFO ] 2022-10-13 10:55:38.230 [Connection-1-ThreadExecutor] ShardingSphere-SQL - Actual SQL: ds_1 ::: select * from t_order_5 where id > 0 limit 1
[INFO ] 2022-10-13 10:57:48.391 [Connection-1-ThreadExecutor] ShardingSphere-SQL - Logic SQL: SELECT MAX(t.id) as maxid, COUNT(1) AS cnt FROM (SELECT * FROM t_order WHERE id>0 ORDER BY id ASC LIMIT 1) t
[INFO ] 2022-10-13 10:57:48.396 [Connection-1-ThreadExecutor] ShardingSphere-SQL - Actual SQL: ds_0 ::: SELECT MAX(t.id) as maxid, COUNT(1) AS cnt FROM (SELECT * FROM t_order_0 WHERE id>0 ORDER BY id ASC LIMIT 1) t
[INFO ] 2022-10-13 10:57:48.396 [Connection-1-ThreadExecutor] ShardingSphere-SQL - Actual SQL: ds_0 ::: SELECT MAX(t.id) as maxid, COUNT(1) AS cnt FROM (SELECT * FROM t_order_2 WHERE id>0 ORDER BY id ASC LIMIT 1) t
[INFO ] 2022-10-13 10:57:48.396 [Connection-1-ThreadExecutor] ShardingSphere-SQL - Actual SQL: ds_0 ::: SELECT MAX(t.id) as maxid, COUNT(1) AS cnt FROM (SELECT * FROM t_order_4 WHERE id>0 ORDER BY id ASC LIMIT 1) t
[INFO ] 2022-10-13 10:57:48.396 [Connection-1-ThreadExecutor] ShardingSphere-SQL - Actual SQL: ds_1 ::: SELECT MAX(t.id) as maxid, COUNT(1) AS cnt FROM (SELECT * FROM t_order_1 WHERE id>0 ORDER BY id ASC LIMIT 1) t
[INFO ] 2022-10-13 10:57:48.396 [Connection-1-ThreadExecutor] ShardingSphere-SQL - Actual SQL: ds_1 ::: SELECT MAX(t.id) as maxid, COUNT(1) AS cnt FROM (SELECT * FROM t_order_3 WHERE id>0 ORDER BY id ASC LIMIT 1) t
[INFO ] 2022-10-13 10:57:48.396 [Connection-1-ThreadExecutor] ShardingSphere-SQL - Actual SQL: ds_1 ::: SELECT MAX(t.id) as maxid, COUNT(1) AS cnt FROM (SELECT * FROM t_order_5 WHERE id>0 ORDER BY id ASC LIMIT 1) t
```
and at sub query, the Proxy result
```
mysql> SELECT MAX(t.id) as maxid, COUNT(1) AS cnt FROM (SELECT * FROM t_order WHERE id>0 ORDER BY id ASC LIMIT 1) t;
+-------+-----+
| maxid | cnt |
+-------+-----+
| 66 | 6 |
+-------+-----+
1 row in set (0.26 sec)
```
but not use Proxy, just query MySQL
<img width="819" alt="image" src="https://user-images.githubusercontent.com/101622833/195488914-d072f0bc-05c2-4da4-b330-b961a33fc240.png">
### Which version of ShardingSphere did you use?
master
### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
ShardingSphere-Proxy
### Expected behavior
The result is the same as that returned by a direct connection to the database
### Actual behavior
The result is different
### Reason analyze (If you can)
### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
mysql table data
<img width="873" alt="image" src="https://user-images.githubusercontent.com/101622833/195489531-f2d8a374-6adc-46f4-9113-48cd3a9607de.png">
```
INSERT INTO `source_ds`.`t_order` (`id`, `order_id`, `user_id`, `status`, `t_unsigned_mediumint`, `username`, `pwd`) VALUES (1, 1, 1, 'newnew', 123, '1', '1');
INSERT INTO `source_ds`.`t_order` (`id`, `order_id`, `user_id`, `status`, `t_unsigned_mediumint`, `username`, `pwd`) VALUES (2, 2, 2, 'OK', 0, '2', '2');
INSERT INTO `source_ds`.`t_order` (`id`, `order_id`, `user_id`, `status`, `t_unsigned_mediumint`, `username`, `pwd`) VALUES (3, 3, 3, 'NO', 34, '3', '3');
INSERT INTO `source_ds`.`t_order` (`id`, `order_id`, `user_id`, `status`, `t_unsigned_mediumint`, `username`, `pwd`) VALUES (4, 4, 4, 'OK', 25, '4', '4');
INSERT INTO `source_ds`.`t_order` (`id`, `order_id`, `user_id`, `status`, `t_unsigned_mediumint`, `username`, `pwd`) VALUES (5, 5, 5, 'OK', 89, '5', '5');
INSERT INTO `source_ds`.`t_order` (`id`, `order_id`, `user_id`, `status`, `t_unsigned_mediumint`, `username`, `pwd`) VALUES (66, 66, 66, 'fff', 16777215, '6', '6');
INSERT INTO `source_ds`.`t_order` (`id`, `order_id`, `user_id`, `status`, `t_unsigned_mediumint`, `username`, `pwd`) VALUES (100, 100, 100, 'udpate', 111, '7', '7');
INSERT INTO `source_ds`.`t_order` (`id`, `order_id`, `user_id`, `status`, `t_unsigned_mediumint`, `username`, `pwd`) VALUES (101, 101, 101, 'update', 99, '8', '8');
```
### 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: notifications-unsubscribe@shardingsphere.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] azexcy commented on issue #21540: The result of `select * fromt table ` is different is not the same as the return value of a direct database connection
Posted by "azexcy (via GitHub)" <gi...@apache.org>.
azexcy commented on issue #21540:
URL: https://github.com/apache/shardingsphere/issues/21540#issuecomment-1407546355
change the `sql-federation-type: NONE` to `sql-federation-type: ADVANCED` will fix the problem.
--
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: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] azexcy closed issue #21540: The result of `select * fromt table ` is different is not the same as the return value of a direct database connection
Posted by "azexcy (via GitHub)" <gi...@apache.org>.
azexcy closed issue #21540: The result of `select * fromt table ` is different is not the same as the return value of a direct database connection
URL: https://github.com/apache/shardingsphere/issues/21540
--
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: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org