1、取最大值
慢查:SELECT `id` FROM `table_name` WHERE ( `addtime` < 1498924800 ) AND ( `user_id` = 1111 ) ORDER BY id DESC LIMIT 1;
优化:SELECT MAX(`id`) FROM `table_name` WHERE ( `addtime` < 1498924800 ) AND ( `user_id` = 1111 );
2、in查询优化
慢查:SELECT `field1` FROM `table_name` WHERE `field2` IN ('JSA00113020171004108456','JSA00113020171005109122') AND `field3` IN(1,2) GROUP BY field2;
优化:
ALTER TABLE `table_name`
DROP INDEX `index_name` ,
ADD INDEX `new_index_name` (`field2`, `field3`) USING BTREE ;