最近在搞巡检,就是线上问题巡查。其中慢sql比较常见,也最容易优化提升性能。
主要是数据量确认太多,二是索引没有或者失效。
1 先来看个不太严重的,57秒
select ..., order_type, print_order, replace(REPLACE(comment_info,char(10),''),char(13),''), from orders where length(create_time)=19 and create_time>= CONCAT(DATE_FORMAT('20180520','%Y-%m-%d'), ' 00:00:00') AND create_time<= CONCAT(DATE_FORMAT('20180619','%Y-%m-%d'), ' 23:59:59')
union all select order_id,.., print_order, REPLACE(REPLACE(comment_info,CHAR(10),''),CHAR(13),'') as comment_info, review_flag, ... from orders where create_time is null and order_time>= CONCAT(DATE_FORMAT('20180520','%Y-%m-%d'), ' 00:00:00') AND order_time<= CONCAT(DATE_FORMAT('20180619','%Y-%m-%d'), ' 23:59:59')
2 再来看个215秒的~~~~
select order_id,.. from orders where length(create_time)=19 and create_time>= CONCAT(DATE_FORMAT('20180516','%Y-%m-%d'), ' 00:00:00') AND create_time<= CONCAT(DATE_FORMAT('20180615','%Y-%m-%d'), ' 23:59:59') union all select order_id, from orders where create_time is null and order_time>= CONCAT(DATE_FORMAT('20180516','%Y-%m-%d'), ' 00:00:00') AND order_time<= CONCAT(DATE_FORMAT('20180615','%Y-%m-%d'), ' 23:59:59')
看语句是查询一天的数据,数据量应该不会很多。
真佩服他们~~~ 超出我的想象了。
is null 和 is not null 都不能利用 索引 ?? https://blog.csdn.net/cxzhq2002/article/details/43449197