InnoDB does not directly save the total number of data in the table. select count(*) from emp; requires scanning the index. Repeated searches will of course consume CPU. select count(*) from emp;要扫一遍索引,反复查当然要耗CPU。
我的测试表有两千万数据,没缓存时count(*)
My test table has 20 million data. Without cache, count(*) takes 15 seconds, and with cache, it takes 3 seconds.
You don’t access the index at all, you read the hard disk data directly
Send the sql statement.
InnoDB does not directly save the total number of data in the table.
select count(*) from emp;
requires scanning the index. Repeated searches will of course consume CPU.select count(*) from emp;
要扫一遍索引,反复查当然要耗CPU。我的测试表有两千万数据,没缓存时
My test table has 20 million data. Without cache,count(*)
count(*)
takes 15 seconds, and with cache, it takes 3 seconds.This can be done using delayed association query (index coverage query)