测试环境:
测试Sql:
select max(sscode) from sm_sku_show where del_flag = "0";
select sscode from sm_sku_show where del_flag = "0" order by sscode desc limit 1; 测试耗时:
[SQL]
select max(sscode) from sm_sku_show where del_flag = "0";
受影响的行: 0
时间: 19.503s
[SQL]
select sscode from sm_sku_show where del_flag = "0" order by sscode desc limit 1;
受影响的行: 0
时间: 0.001s 测试结果:
+---------------------+
| max(sscode) |
+---------------------+
| SS20180120101925999 |
+---------------------+
1 row in set
+---------------------+
| sscode |
+---------------------+
| SS20180120101925999 |
+---------------------+
1 row in set

本文探讨了MySQL中max函数的性能问题,指出在有where条件的查询中,max函数可能需要扫描所有行。建议避免频繁使用,并提出将max()转换为`order by id desc limit 1`的方式作为优化策略。
最低0.47元/天 解锁文章
2057

被折叠的 条评论
为什么被折叠?



