question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there any way to traverse tables in the specified order by Schema & Table Route

See original GitHub issue

Question

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:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
kimmkingcommented, Mar 26, 2020

@GolderGao @Akigaze

  1. How to know which one with data, and which one without data? If you know the data with its month is 3, you can direct query with select * from t_msg_20_3 where ..., ShardingSphere support this sql.
  2. As a middleware for generic usage&scenario, each one of 12 sharding tables is the same to ShardingSphere engine, no one is specially prior of others. If in your business semantics, they have an order to process one by one, I suggestion in native sql way. And Actually broadcasting 12 sharding tables will be parallelly query and merged, it’s faster than one by one queries for several times.

In our further plan, query optimization is a big blueprint. As your case above, I recommend optimization by rewriting union all with the same database rather than broadcast or one by one query.

0reactions
GolderGaocommented, Mar 26, 2020

@kimmking I have two questions, would like to consult shardingjdbc how to deal with?

  1. 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.

  2. 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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there a way to loop through a table variable in TSQL without ...
First of all you should be absolutely sure you need to iterate through each row — set based operations will perform faster in...
Read more >
Creating multiple tables and table relationships - Launch School
Having all our data in one table can make for very difficult data management. We can split data in specialized tables that are...
Read more >
Documentation: 15: 5.9. Schemas - PostgreSQL
The system determines which table is meant by following a search path, which is a list of schemas to look in. The first...
Read more >
Specify nested and repeated columns in table schemas
Specifying the nested and repeated columns in the example · In the Google Cloud console, open the BigQuery page. Go to BigQuery ·...
Read more >
Query Processing Architecture Guide - SQL Server
When a query is executed and accesses data in row store tables, the execution tree operators and child operators read each required row,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found