首页 > 其他 > 详细

查询条件左边写入函数,导致无法命中索引

时间:2016-08-02 22:14:31      阅读:310      评论:0      收藏:0      [点我收藏+]

背景:

简单罗列下之前做过的优化,人懒。

所以没能把所有的整理统一放出来。

情况:

系统查询过慢,没能命中索引。

<!--对账单数量 -->
<select id="selectCount" resultType="java.lang.Integer" parameterType="map">
    select count(*) from monthly_statements where store_id = #{storeId}
    <if test="billNo != null">
        and bill_no = #{billNo}
    </if>
    <if test="beginTime != null and endTime != null">
        and date_format(created_at,"%Y-%m-%d") between #{beginTime,jdbcType=VARCHAR}
        and #{endTime,jdbcType=VARCHAR}
    </if>
    <if test="isDeadline == 0">   <!-- 未到账期时间 -->
        and expiration_time  &gt;  now()
    </if>
    <if test="isDeadline == 1">   <!-- 已到账期时间 -->
        and expiration_time  &lt;=  now()
    </if>
</select>

 

案例:

  • 优化前
select * from cc where date_format(dd,‘%Y-%m-%d‘)="2016-02-22";

技术分享

  • 优化后
select * from orders where `created_at` > ‘2016-02-22‘ and `created_at` < date_add(‘2016-02-22‘,interval 1 day);

技术分享

查询条件左边写入函数,导致无法命中索引

原文:http://www.cnblogs.com/snifferhu/p/5730933.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!