需求:获取指定用户下某个邮箱最近一次发送时间
场景:
CREATE_TIME,
USER_ID
已经添加索引,
ADDRESS是text字段无法添加索引。
原语句:(max导致全表扫描!!!)
SELECT MAX(CREATE_TIME) AS MAX0 FROM t_mail_send_extend WHERE USER_ID = '03515d6956c0434c86175835b9fae0bf' AND LOCATE( 'sebastian.sandoli@ladespensa.es', ADDRESS ) AND STATUS = 1
改进:
SELECT CREATE_TIME FROM t_mail_send_extend WHERE USER_ID = '03515d6956c0434c86175835b9fae0bf' AND LOCATE( 'sebastian.sandoli@ladespensa.es', ADDRESS ) AND STATUS = 1 ORDER BY CREATE_TIME DESC LIMIT 1