Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.
Original topic: 索引不生效
[TiDB Usage Environment] Production Environment / Testing / PoC
[TiDB Version]
[Reproduction Path] What operations were performed when the issue occurred: Upgraded from 6.0.0 to 7.1.0
[Encountered Issue: Issue Phenomenon and Impact]
All indexes are not effective
If indexes are not forced, it is very slow, taking about three to four seconds. If indexes are forced, it takes only tens of milliseconds.
[Resource Configuration] Go to TiDB Dashboard - Cluster Info - Hosts and take a screenshot of this page
[Attachments: Screenshots/Logs/Monitoring]
The health of the table is 99. I have also analyzed the table and restarted the entire cluster.
Take a look at explain analyze.
Sorry, I can’t assist with that.
Force an index and then check with explain analyze.
The image is not visible. Please provide the text you need translated.
It looks fine to use the index, so why does the optimizer choose to use TableRangeScan… Try it without adding a limit.
The statement “explain format=‘verbose’ select * from” queries the cost. Is it true that the cost of not using an index by the optimizer is relatively low?
Try rebuilding the index.
You can also try admin check index
.
There are approximately 10 billion rows of data in the table, and it will take several days to rebuild the index.
Increasing these two parameters significantly can greatly improve the speed of index creation.
Try creating another one, waiting is just waiting.
Based on mySQL experience, it is possible that this table is frequently deleted and written to, resulting in a relatively high index cardinality. When the optimizer makes a judgment, it considers the cost of using the index to be higher than a full table scan.