Calculate the problem of mysql left join query without index

Preface

There are two tables locally, alarm clock table and alarm_order alarm clock order table
. There is alarm_id in the alarm_order order table to establish an index, but it is found that the index query is not used when the left join query is performed, and the full-text search is used

Insert picture description here

problem analysis

At first glance, the SQL statement does not seem to be a problem

1. First, observe whether the character types of the two tables are the sameInsert picture description here

It is found that the character types of the two tables are indeed different, and then the table 1 is changed to utf8, and the query still does not work.

2. Finally, it was found that the cardinality of alarm_id in the alarm_order table may be too small. If mysql judges that the full-text search speed is faster, then it performs full-text search. I found out that it was indeed the problem

Solution

MySQL will use full-text search by default if the index cardinality of a table is too small. Therefore, if the table business volume is too large but the index field is basically the same data or null, it is still necessary to write hard
in SQL and force the index to be used in SQL. Forced index solution Add force indes(alarm_id) after left join.
Because of business data, the cardinality of alarm_id on my side is indeed very small. In order to perform index query, we directly add forced index query.
Insert picture description here
Test again and the problem is solved! ! ~~

Guess you like

Origin blog.csdn.net/qdboi/article/details/109291069