Index Failure Issues

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 索引失效问题

| username: 大飞飞呀

[TiDB Usage Environment] Production Environment
[TiDB Version]
[Reproduction Path] What operations were performed when the issue occurred
[Encountered Issue: Issue Phenomenon and Impact]
Left side is extremely fast, right side is particularly slow

Table a joins table b, table b joins table c, all join conditions have indexes, where condition queries based on table a, the query is particularly slow
Table a joins table b, table b joins table b, all join conditions have indexes, where condition queries based on table a, the query is particularly fast
[Resource Configuration]
[Attachments: Screenshots/Logs/Monitoring]

| username: xfworld | Original post link

Check the execution plan and compare the differences.

| username: tidb菜鸟一只 | Original post link

Post the execution plan and take a look. I think the issue is that neither of the two tables, a and b, are using the index on the join fields. So when doing a left outer join with table a, the i_status filter on a might be more selective, hence the speed is acceptable. However, when doing a left outer join with table b, the b_is_test filter on b is less selective, resulting in slower performance. You can test the speed by doing a left outer join between table d and table b separately.

| username: 大飞飞呀 | Original post link

Execution plan with slow speed

| username: 大飞飞呀 | Original post link

A plan with fast execution speed

| username: tidb菜鸟一只 | Original post link

How is the filtering of b_is_test in table b? I see that it has reached the index on this field. Is the actual statistical information accurate?

| username: 大飞飞呀 | Original post link

How to determine if the statistics are accurate?

| username: 大飞飞呀 | Original post link

Health score 99

| username: db_user | Original post link

Have you tried forcing an index join? I’ve encountered a similar situation where the optimizer chooses a hash join, which results in very slow performance.

| username: 大飞飞呀 | Original post link

I recently discovered that an incorrect index was used.



How can I make it use the index of the associated key?

| username: waeng | Original post link

Try using a force index.

| username: xingzhenxiang | Original post link

Try using the index

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.