注意:limit条件不会影响MySQL Explain Plan中的rows结果

limit条件不会影响MySQL Explain Plan中的rows结果。比如,

explain select * from t limit 10

输出的rows值可能是1百万(如果t中有1百万数据)。 但实际上,MySQL不会为这十行数据扫描整张表的。

Peter Zaitsev说:

LIMIT is not taken into account while estimating number of rows Even if you have LIMIT which restricts how many rows will be examined MySQL will still print full number

如果不知道这个潜规则,会被explain plan迷惑死。这是典型的MySQL制造者的懒惰给使用者造成的麻烦。

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.