Mybatis查询in的字段过多不走索引

mybatis查询in的字段有索引,比如说是主键查询, 但是in的字段过多导致索引失效,

这个时候可以考虑将in的数量变少, 200以内都可以, 在数据库方面采用 foreach unionall 的方式将数据集合查询出来

c 复制代码
Service层:
List<List<String>> zffsDdbhList = Lists.partition(ddbhList, MagicNumber.INT200);

Dao层:
List<HotelKhSjzfxx> getListByDdbhArray(@Param("ywdh") List<List<String>> ywdh);

sql.xml:
<select id="getListByDdbhArray" resultType="cn.vetech.center.hotel.entity.HotelKhSjzfxx">
  SELECT * from (
        <foreach collection="ywdh" item="ddbhArray" index="index" separator="union all">
                SELECT *  FROM hotel_kh_sjzfxx
                WHERE ywdh in
                <foreach collection="ddbhArray" item="ddbh" open="(" separator="," close=")">
                        #{ddbh}
                </foreach>
        </foreach>
  ) t
 </select>
相关推荐
记忆不曾留7 小时前
Mybatis 源码解读-SqlSession 会话源码和Executor SQL操作执行器源码
mybatis·二级缓存·sqlsession会话·executor执行器·一级缓存localcache
昵称为空C2 天前
SpringBoot 实现DataSource接口实现多租户数据源切换方案
后端·mybatis
isyangli_blog2 天前
(2-10-1)MyBatis的基础与基本使用
java·开发语言·mybatis
_码农121382 天前
Mybatis简单练习注解sql和配置文件sql+注解形式加载+配置文件加载
mybatis
期待のcode2 天前
Maven
java·spring·maven·mybatis
独泪了无痕2 天前
一文搞懂MyBatis中的TypeHandler
数据库·后端·mybatis
Easocen2 天前
Mybatis学习笔记(十)
mybatis
千睢3 天前
Mybatis实现页面增删改查
mybatis
Warren983 天前
Java后端面试题(含Dubbo、MQ、分布式、并发、算法)
java·开发语言·分布式·学习·算法·mybatis·dubbo
羊锦磊3 天前
[ Mybatis 多表关联查询 ] resultMap
java·开发语言·数据库·mysql·mybatis