Remember a real MySQL million data optimization

证实下确实是150万+数据哈

insert image description here

Original SQL

insert image description here

Original SQL execution plan

insert image description here

The original SQL execution time is about 5 seconds

insert image description here

Raw SQL Analysis

Source of ideas
Looking at SQL as a whole, it seems that there is nothing to optimize. Then we could be very wrong.
Some people may say why table B is abnormal behind table A, because this is an inner join query, not a left and right join query. The order of A and B tables can be exchanged (the actual measurement has no effect).
First, we can see that the extra of the execution plan is User where;Using temporary;Using filesort
type ALL全表扫描, indicating that there is a problem with the SQL and needs to be optimized.

Guess you like

Origin blog.csdn.net/qq_40673786/article/details/131810627