select count(*) from table,MyISAM只要简单的读出保存好的行数,注意的是,当count(*)语句包含 where条件时,两种表的操作是一样的
InnoDB 中不保存表的具体行数,也就是说,执行select count(*) from table时,InnoDB要扫描一遍整个表来计算有多少行
希望能够更深入的了解,请问MyISAM是如何保存这个行数的?保存在什么地方?存储方式?如何查询?希望知道的高手赐教!谢谢!

解决方案 »

  1.   

    select count(*) from table,MyISAM只要简单的读出保存好的行数这个观点你是从哪儿看到的?
      

  2.   

    一般要得到准确的行数 ,都要 COUNT一遍,MYSQL5以上,在系统表TABLES中有TABLE_ROWS,不过不准确
      

  3.   

    在MySQL官方站点翻到两段相关的描述。原文如下:    For explains on simple count queries (i.e. explain select count(*) from people) the extra section will read "Select tables optimized away." This is due to the fact that MySQL can read the result directly from the table internals and therefore does not need to perform the select.     …… ……    SELECT count(*) is so common so it is partly optimized away.
        If you are using MyISAM or HEAP tables it reads the information directly from the table information which is lightning fast and is actually the information that show table status displays.
        But for InnoDB tables it actually has to perform an index scan on the primary index which can take a while depending on size of table, innodb_buffer_size, hardware etc.
      

  4.   

    SELECT 从一个表中检索,而不检索其它的列,并且没有 WHERE子句时, COUNT(*)被优化到最快的返回速度。例如:mysql> SELECT COUNT(*) FROM student;这个优化仅适用于 MyISAM表, 原因是这些表类型会储存一个函数返回记录的精确数量,而且非常容易访问。
    Mysql参考手册都有这样的记录,难道是我看的有问题?
      

  5.   

    COUNT(*) on a single table without a WHERE is retrieved directly from the table information for MyISAM and MEMORY tables. This is also done for any NOT NULL expression when used with only one table. 对于MYISAM和MEMORY存储引擎来说,它本身提供了这个表中记录数的函数。所以MYSQL可以直接去访问表信息得到其中的记录总数。而INNODB存储引擎没有提供这个函数。
      

  6.   

    原来是预先存储好的,不错。相当于是每次CUD操作,都要锁一次系统表,更新一下那条记录。
      

  7.   

    MYISAM引擎记录了表的记录条数。如果不带条件的COUNT(*),就直接取出这个数,然后发送到结果集。
    《高性能MYSQL》里面的“MYISAM的COUNT(*)迷思”一节有详细论述。