sql语句中使用强制索引

后台管理进行分页查询时,发现其他人都是一个条件加一个索引,然后在sql语句里强制使用一个联合索引

索引

 

mybatis中的sql语句

    <select id="listRecommenderByCondition" parameterType="com.wscar.xny.recommender.domain.dto.DaoRecommenderQueryDTO"
            resultMap="BaseResultMap">
        SELECT
        *
        FROM
        recommender
        FORCE INDEX(`idx_phone`,`idx_name`,`idx_city`,`idx_orderCount`,`idx_gmtCreate`)
        <include refid="WhereColumn"/>
        ORDER BY
        ${sortColumn} ${sortType}
        LIMIT
        #{limit,jdbcType=BIGINT},#{rows,jdbcType=BIGINT}
    </select>
  <sql id="WhereColumn">
        <where>
            <if test="name != null and name != ''">
                AND
                name LIKE #{name,jdbcType=VARCHAR}
            </if>
            <if test="phone != null and phone != ''">
                AND
                phone LIKE #{phone,jdbcType=VARCHAR}
            </if>
            <if test="cityCode != null and cityCode > 0">
                AND
                cityCode = #{cityCode,jdbcType=INTEGER}
            </if>
            <if test="gmtCreateStart != null and gmtCreateStart > 0">
                AND
                gmtCreate &gt;= #{gmtCreateStart,jdbcType=BIGINT}
            </if>
            <if test="gmtCreateEnd != null and gmtCreateEnd > 0">
                AND
                gmtCreate &lt;= #{gmtCreateEnd,jdbcType=BIGINT}
            </if>
        </where>
    </sql>
 <resultMap id="BaseResultMap" type="com.wscar.xny.recommender.domain.entity.RecommenderDO">
        <!--
          WARNING - @mbg.generated
        -->
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="phone" jdbcType="VARCHAR" property="phone"/>
        <result column="name" jdbcType="VARCHAR" property="name"/>
        <result column="companyId" jdbcType="INTEGER" property="companyId"/>
        <result column="companyName" jdbcType="VARCHAR" property="companyName"/>
        <result column="serviceyStationName" jdbcType="VARCHAR" property="serviceyStationName"/>
        <result column="positionName" jdbcType="VARCHAR" property="positionName"/>
        <result column="cityCode" jdbcType="INTEGER" property="cityCode"/>
        <result column="orderCount" jdbcType="BIGINT" property="orderCount"/>
        <result column="status" jdbcType="TINYINT" property="status"/>
        <result column="gmtCreate" jdbcType="BIGINT" property="gmtCreate"/>
        <result column="gmtModified" jdbcType="BIGINT" property="gmtModified"/>
        <result column="creater" jdbcType="BIGINT" property="creater"/>
        <result column="updater" jdbcType="BIGINT" property="updater"/>
    </resultMap>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值