Is there any way to traverse tables in the specified order by Schema & Table Route
See original GitHub issueQuestion
logic table: t_msg (column: created_time (sharding key), version, business_key)
physical table: t_msg, t_msg_20_3, t_msg_20_4, t_msg_20_5 …
The sharding key created_time is type of Timestamp (yyyy-MM-dd hh:mm:ss.SSS), and I just use year and month for sharding.
I use Oracle database and now I want to find the frist record of specific business_key:
SQL: select * from t_msg where business_key=? fetch first 1 rows only;
For this one I know the sharding-jdbc will use Schema & Table Route strategy, and the result SQL is:
select * from t_msg where business_key = ?; select * from t_msg_20_3 where business_key = ?; select * from t_msg_20_4 where business_key = ?; select * from t_msg_20_5 where business_key = ?; … …
But now it’s March so I want it to search start with t_msg_20_3. And once finding out a record, I hope it can return immediately, not need to search in t_msg anymore. If nothing can be found in t_msg_20_3, it will continue to look for t_msg.
Is there any strategy or setting of sharding-jdbc can support this requirement?
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)

Top Related StackOverflow Question
@GolderGao @Akigaze
select * from t_msg_20_3 where ..., ShardingSphere support this sql.In our further plan, query optimization is a big blueprint. As your case above, I recommend optimization by rewriting
union allwith the same database rather thanbroadcastorone by one query.@kimmking I have two questions, would like to consult shardingjdbc how to deal with?
If I create a table every month in 2020, and each table stores the data for that month, I just want to find the table with the data, and the table without the data will not query.
It is now march, and I only have 3 tables to store data, namely table_1,table_2, and table_3. The other 9 tables do not store data (table_4…).Table_12, I want to query data, first from the current month, and then to the previous month query, there is no data table query