Cross-shard pagination queries
Last updated
Was this helpful?
Last updated
Was this helpful?
In sharding cases, how will the following pagination query be executed
"LIMIT x OFFSET y" gets transformed to "LIMIT x+y OFFSET 0".
Suppose that there are N tables hit. After getting results from N tables, it could be merged together using "merge sort".
For a query "LIMIT 10 OFFSET 1000"
In cross-shard query scenarios, it will be tranformed to "LIMIT 1010 OFFSET 1000".
If there are N table hit, in total N * 1010 rows need to be transmitted.
Since query results for N tables need to sit inside memory and then merged, the memory footprint will be high.
Divide the LIMIT and OFFSET by 2
It will get an approximate answer in most cases.
The improved version could be an weighted average pagination.
Cross shard queries are forbidden.
Assume that one page data is only in one shard. Then the query could be simplified.
Use an additional table for sorting purpose.
Assume that we use update time for ranking purpose
During search, we could first look up inside intermediate table.
Then goes to the target DB, and looks for the message.