mysql max() 函数的需扫描where条件过滤后的所有行:
在测试环境中重现:
测试版本:Server version: 5.1.58-log MySQL Community Server (GPL)
testtable表中的索引
mysql> show index from testtable;
+-----------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+-----------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| testtable | 0 | PRIMARY | 1 | id | A | 2 | NULL | NULL | | BTREE | |
| testtable |