mysql max(自增主键)很快

来源:互联网 发布:晋中网络教研平台首页 编辑:程序博客网 时间:2024/05/22 05:30

“`

explain select max(id) from xx;
+——+————-+——-+——+—————+——+———+——+——+——————————+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+——+————-+——-+——+—————+——+———+——+——+——————————+
| 1 | SIMPLE | NULL | NULL | NULL | NULL | NULL | NULL | NULL | Select tables optimized away |
+——+————-+——-+——+—————+——+———+——+——+——————————+

在查看max的执行计划的时候,出现了select tables optimized away的这种方式,执行的速度奇快,下面是官网的描述,可以看到是直接在内部表读取的记录,不需要去扫描表。
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.
但是不知道内部是怎么存放的,难道每个表存放一个自增主键的计数器?

0 0
原创粉丝点击