Explain MySQL explain execution plan maths, difference between two plans

前端 未结 2 1838
-上瘾入骨i
-上瘾入骨i 2021-02-14 11:49

I\'ve got a basic MySQL performance question related to explain. I have two queries that return the same result and I am trying to understand how to make sense of the EXPL

相关标签:
2条回答
  • 2021-02-14 12:04

    In fact when you see you should not to multiply, but sum this numbers. In you case compare (49520 x 413 x 4) and (50000 + 49520).

    Gereral rule is simple: summarize all segments (DERIVED, PRIMARY) and multiply rows within each segment.

    id select_type  ... rows
    1  PRIMARY           1
    1  PRIMARY           2
    2  DERIVED           3
    2  DERIVED           4
    3  DERIVED           5
    3  DERIVED           6
    

    Complexity is: 1*2 + 3*4 + 5*6

    0 讨论(0)
  • 2021-02-14 12:07

    Don't put too much trust in the "rows" Statement of EXPLAIN. As in the mysql docs: "Estimate of rows to be examined" (http://dev.mysql.com/doc/refman/5.1/en/explain-output.html).

    Perhaps updating your index statistics will give you a better estimate (OPTIMIZE TABLE, http://dev.mysql.com/doc/refman/5.0/en/optimize-table.html)

    0 讨论(0)
提交回复
热议问题