场景:mybatis中一段sql是分页查询,查询中有个查询条件是in一个传入的list,极端情况下这个list会变得很大,导致sql报错。应该怎么解决?
考虑过建临时表,但是还没查询到在select语句里面创建临时表的例子
mybatis动态创建临时表
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- engchina 2016-12-27 01:21关注
参考URL:http://blog.csdn.net/engchina/article/details/48250829
使用with,试试下面这个2个方法可不可以。(exists性能比in性能好,请根据需要选择)
1,用in的写法
with TEMP_TABLE_A as (
select
t1.c1
from
Table1 t1
)select
t2.c1
from
Table2 t2
where
t2.c1 in (
select
temp.c1
from
TEMP_TABLE_A temp)
2,用exists的写法
with TEMP_TABLE_A as ( select t1.c1 from Table1 t1
)
select
t2.c1
from
Table2 t2
where
exists (
select
1
from
TEMP_TABLE_A temp
where t2.c1 = temp.c1
)
==================================解决 无用评论 打赏 举报