场景:mybatis中一段sql是分页查询,查询中有个查询条件是in一个传入的list,极端情况下这个list会变得很大,导致sql报错。应该怎么解决?
考虑过建临时表,但是还没查询到在select语句里面创建临时表的例子
参考URL:http://blog.csdn.net/engchina/article/details/48250829
使用with,试试下面这个2个方法可不可以。(exists性能比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
)
==================================