[TiDB Usage Environment] Production Environment
[TiDB Version] v6.5.1
[Reproduction Path] Operations performed that led to the issue
[Encountered Issue: Phenomenon and Impact] TiFlash is not used in complex queries
[Resource Configuration] 1 TiFlash, 3 PD, 5 TiKV
[Attachments: Screenshots/Logs/Monitoring]
Coincidentally, I am also comparing the performance of TiKV and TiFlash. I found that letting the optimizer choose by itself yields the highest performance. For some small range data scans, TiKV is more efficient than TiFlash. I think this might be because TiKV can use indexes to quickly retrieve this part of the data, while TiFlash requires a full table scan.
It’s better to let the TiDB optimizer choose autonomously for this kind of situation. It depends on the usage scenario, and it’s not necessarily true that TiFlash is always faster than TiKV.
It might be related to the number of fields in the query. TiFlash uses columnar storage, which is actually suitable for aggregating a small number of columns. Each additional column read increases the cost of using TiFlash. In other words, the more fields in the query, the more likely the optimizer will prefer TiKV. I previously encountered a SQL query that couldn’t use TiFlash no matter what. After asking the business to reduce the number of query fields, it worked.