表做了分析和优化:
ANALYZE TABLE Currsession_table;
OPTIMIZE TABLE Currsession_table;
两种写法严重的性能差异:
原因rcdate字段类型为datetime
下面的写法多了.0000毫秒信息,导致类型不同比较没有走索引。
select貌似走了索引,但rows显示还是全表的数据180多万,明显不正常。
delete完全没有走索引。
更换写法后可以看到,如果正常走索引应该就1条记录。
root@192.168.1.51 [jyc] >explain select count(*) FROM Currsession_table FORCE INDEX(idx_recdate) WHERE recdate explain select count(*) FROM Currsession_table use INDEX(idx_recdate) WHERE recdate explain delete FROM Currsession_table use INDEX(idx_recdate) WHERE recdate < DATE_ADD(SYSDATE(), INTERVAL - (1500/86400) * 86400 SECOND);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'use INDEX(idx_recdate) WHERE recdate explain delete FROM Currsession_table WHERE recdate select count(*) FROM Currsession_table use INDEX(idx_recdate) WHERE recdate select count(*) FROM Currsession_table WHERE recdate explain select count(*) FROM Currsession_table use INDEX(idx_recdate) WHERE recdate explain delete FROM Currsession_table WHERE recdate explain select count(*) FROM Currsession_table WHERE recdate