Why the rows returns by “explain” is not equal to count()?

前端 未结 3 1878
迷失自我
迷失自我 2020-11-28 13:45
    mysql> select count(*) from table where relation_title=\'xxxxxxxxx\';
+----------+
| count(*) |
+----------+
|  1291958 |
+----------+

mysql> explain sele         


        
3条回答
  •  难免孤独
    2020-11-28 14:21

    It is showing how many rows it ran through to get your result.

    The reason for the wrong data is that EXPLAIN is not accurate, it makes guesses about your data based on information stored about your table.

    This is very useful information, for example when doing JOINS on many tables and you want to be sure that you aren't running through the entire joined table for one row of information for each row you have.

    Here's a test on a 608 row table.

    SELECT COUNT(id) FROM table WHERE user_id = 1
    

    Result:

    COUNT(id)
    512
    

    And here's the explain

    EXPLAIN SELECT COUNT(id) FROM table WHERE user_id = 1
    

    Result:

    id  rows
    1   608
    

提交回复
热议问题