Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.
Original topic: 自定义排序问题
For a data table with approximately 1 billion rows, where fl
is an indexed field and you need to perform an IN
query with 10,000 entries, and sort according to the input order of the field
field, what optimization solutions are available?
SELECT fl, name FROM t WHERE fl in (1, 2, 3) ORDER BY FIELD(fl, 1, 2, 3)
In 10,000 queries, change to temporary tables for Join.
For sorting, it’s best to use other methods instead (sorting will aggregate data to TiDB, which can easily cause OOM).
Try to partition the range as much as possible.
I don’t understand this SQL… What does the part after “order by” mean?
When sorting, consider pushing operators down to the storage layer or using operators that consume less memory.
Custom sorting, sort according to the values inside “in”.
Isn’t it better for the program to fetch and display each item in a loop directly?
For sorting, isn’t it that each TiKV node performs the sorting first and then aggregates it to TiDB for sorting?
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.