------解决方案--------------------
id是primary key的吧? innodb引擎的话order by limit 1效率会高些。 myisam下单纯select max(id)是很快的,最大id相当于存在一个缓存里,因为我explian语句发现Extra列显示的是Select tables optimized away,是和select count(id)一样的处理。 不过如果你除了max(id)还要select对应的其它字段,一条语句的效率可能就不如order by limit 1了, 当然你的语句可以变化为 select * from table where id = (select max(id) as id from table) 应该会非常快,是我基于explian的分析,你可以拿去测试下 自己多查看explian分析吧。
------解决方案-------------------- 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.