apache / shardingsphere

Distributed SQL transaction & query engine for data sharding, scaling, encryption, and more - on any database.
Apache License 2.0
19.82k stars 6.71k forks source link

Single table union all sharding table, sharding table routing problem #29539

Open chly1103 opened 9 months ago

chly1103 commented 9 months ago

version:

ShardingSphere Proxy 5.4.0

-- single table
CREATE TABLE `t_order` (  `id` int NOT NULL,  `name` varchar(45) DEFAULT NULL,create_time datetime,  PRIMARY KEY (`id`));

-- sharding table
CREATE TABLE `t_order_his` (  `id` int NOT NULL,  `name` varchar(45) DEFAULT NULL,create_time datetime,  PRIMARY KEY (`id`));

t_order_his_202308 t_order_his_202309 t_order_his_202310 t_order_his_202311 t_order_his_202312

Execute the following sql

select * from t_order where create_time BETWEEN '2023-12-06 00:00:00' AND '2023-12-06 23:59:59'
union all
select * from t_order_his where create_time BETWEEN '2023-12-06 00:00:00' AND '2023-12-06 23:59:59';

select * from t_order_his where create_time BETWEEN '2023-12-06 00:00:00' AND '2023-12-06 23:59:59'; OK
![image](https://github.com/apache/shardingsphere/assets/5884703/68eb1156-38d5-46c4-bfab-2a52824b2a64)

Expected behavior

[INFO ] 2023-12-25 17:48:58.576 [ShardingSphere-Command-0] ShardingSphere-SQL - Actual SQL: ds ::: select from t_order where create_time BETWEEN '2023-12-06 00:00:00' AND '2023-12-06 23:59:59' union all select from t_order_his_202312 where create_time BETWEEN '2023-12-06 00:00:00' AND '2023-12-06 23:59:59' UNION ALL select * from t_order where create_time BETWEEN '2023-12-06 00:00:00' AND '2023-12-06 23:59:59'

Actual behavior

image

insert into

harish-bendale commented 8 months ago

Please assign it to me..

strongduanmu commented 8 months ago

@harish-bendale Assigned.