select * from ( select id from table1 union all select id from table2 union all select id from table3 union all select id from table4 union all select id from table5 union all select id from table6 union all select id from table7
) as temp WHERE xx= xx;
我这样查询是不是本身就是不正确的?
是有点问题,你这个union 7个表,尽量让每个子查询走索引,应该会快些,可以看看执行计划, 瓶颈应该在每个子查询上,union all 本身不耗什么时间的 [解决办法]
select * from ( select id from table1 union all select id from table2 union all select id from table3 union all select id from table4 union all select id from table5 union all select id from table6 union all select id from table7
) as temp WHERE xx= xx;
我这样查询是不是本身就是不正确的?
改为先筛选后联合应该会快点吧?另外过滤条件比较固定的话,在涉及到的列上加个索引应该也是个好方法。
select * from ( select id from table1 WHERE xx= xx; union all select id from table2 WHERE xx= xx; union all select id from table3 WHERE xx= xx; union all select id from table4 WHERE xx= xx; union all select id from table5 WHERE xx= xx; union all select id from table6 WHERE xx= xx; union all select id from table7 WHERE xx= xx; ) [解决办法] select 1 from bean [解决办法] select count(1) from bean