- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
这个MySQL查询的复杂度是多少
SELECT COUNT(*) FROM MyTable;
表中的条目数是否存储在某处并在每次插入或删除行时更新?如果是这样,那么复杂度应该是 O(1)。
最佳答案
这取决于存储引擎。
SELECT COUNT(*) FROM yourtable
是一个 O(1) 操作。它只需要读取这个值。来自 manual :
InnoDB
does not keep an internal count of rows in a table. (In practice, this would be somewhat complicated due to multi-versioning.) To process aSELECT COUNT(*) FROM t
statement,InnoDB
must scan an index of the table, which takes some time if the index is not entirely in the buffer pool. If your table does not change often, using the MySQL query cache is a good solution. To get a fast count, you have to use a counter table you create yourself and let your application update it according to the inserts and deletes it does.SHOW TABLE STATUS
also can be used if an approximate row count is sufficient. See Section 13.2.13.1, "InnoDB
Performance Tuning Tips".
关于MySQL - 复杂度 : SELECT COUNT(*) FROM MyTable;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5257973/
我是一名优秀的程序员,十分优秀!