Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.Original topic: 执行计划问题-Index Lookup Join效率低下
To improve efficiency, please provide the following information. Clear problem descriptions can be resolved faster:
【TiDB Usage Environment】Research
【TiDB Version】6.2
【Encountered Problem】Low efficiency when performing Index Lookup Join on primary key
【Problem Phenomenon and Impact】
Execution Plan Issue.txt (13.1 KB)
When simulating Index Lookup Join to observe execution efficiency, I found that the efficiency is particularly low when reading inner table data (intentionally turned off the TiDB cache, and repeated executions took about 2 seconds each time).
As shown in Execution Plan 1 in the attachment, the inner table is associated using the primary key C_CUSTKEY. In the operator TableReader_56 (Probe), the maximum cop_task task takes 363.3ms, max_proc_keys: 636 (through total_process_keys: 6196, total_keys: 6200, it can be inferred that max_keys will not exceed 640), which means scanning 636 keys, and all are memory reads (block: {cache_hit_count: 24023}, it can be confirmed that no physical reads occurred). Why does it take so much time?
For comparison simulation, directly query the primary key C_CUSTKEY of the customer table, simulate full memory read, scan more than 640 records (set to 1000 here), and repeatedly test to find the longest time taken. As shown in Execution Plan 2 in the attachment, it can be seen that scanning total_process_keys: 999 in tikv takes almost no time.
So, I would like to ask, in the case of a small number of records associated with the primary key index, why is it still so slow?
Supplementary trace execution situation:
trace execution time.txt (25.0 KB)
Even the query filtered by index on the outer table is slow: select count(O_CUSTKEY) from orders b where b.O_ORDERDATE =‘1996-12-14’ The actual result is only more than 6k, but it takes more than 1 second.
Specific data can be found in the attachment: orders step-by-step single table slow data.txt (16.0 KB)
Looking at the execution plan, the phenomenon of inefficient SQL is: cache_hit_count is much greater than total_keys. That is, I don’t know why there are so many cache_hit_count. Does this cache_hit_count refer to the number of times rocksdb’s block is read?