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>
相关推荐
sensenlin9121 小时前
Mybatis中SQL全大写或全小写影响执行性能吗
数据库·sql·mybatis
BXCQ_xuan1 天前
软件工程实践四:MyBatis-Plus 教程(连接、分页、查询)
spring boot·mysql·json·mybatis
wuyunhang1234561 天前
Redis----缓存策略和注意事项
redis·缓存·mybatis
lunz_fly19921 天前
【源码解读之 Mybatis】【基础篇】-- 第2篇:配置系统深度解析
mybatis
森林-1 天前
MyBatis 从入门到精通(第一篇)—— 框架基础与环境搭建
java·tomcat·mybatis
森林-1 天前
MyBatis 从入门到精通(第三篇)—— 动态 SQL、关联查询与查询缓存
sql·缓存·mybatis
java干货1 天前
MyBatis 的“魔法”:Mapper 接口是如何找到并执行 SQL 的?
数据库·sql·mybatis
嬉牛1 天前
项目日志输出配置总结(多数据源MyBatis+Logback)
mybatis·logback
哈喽姥爷3 天前
Spring Boot--yml配置信息书写和获取
java·数据库·spring boot·mybatis
奔跑你个Run4 天前
mybatis plus 使用wrapper输出SQL
mybatis