oracle sql 替换 in ,dual性能优化

create table bakInfo(
 id int,
 pname varchar2(10),
 remark varchar2(10),
 impdate varchar2(10),
 upstate varchar(10));
 
 create table Info(
    id int,
    pname varchar2(10),
    remark varchar2(10),
    impdate varchar2(10),
    upstate varchar(10));
    
insert into Info values(1,'1111','1111','1111','1111'); 
insert into Info values(2,'2222','2222','2222','2222'); 
insert into Info values(3,'3333','3333','3333','3333'); 
insert into Info values(4,'1111','1111','1111','1111'); 
insert into Info values(5,'2222','2222','2222','2222'); 
insert into Info values(6,'3333','3333','3333','3333'); 
    
insert into bakInfo values(1,'1111','1111','1111','1111'); 
insert into bakInfo values(2,'2222','2222','2222','2222'); 
insert into bakInfo values(3,'3333','3333','3333','3333'); 
insert into bakInfo values(4,'4444','4444','4444','4444'); 
insert into bakInfo values(5,'1111','1111','1111','1111'); 
insert into bakInfo values(6,'2222','2222','2222','2222'); 
insert into bakInfo values(7,'3333','3333','3333','3333'); 
insert into bakInfo values(8,'4444','4444','4444','4444'); 

select * from bakInfo;
select * from info;  
  
select * from bakInfo where id in (select id from info);
select b.* from bakinfo b  INNER join info i on b.id = i.id;

select b.* 
  from bakInfo b
  left join Info i
  on b.id=i.id
 where b.id in (3,4,1,2);

select b.* 
  from bakInfo b
  left join Info i
  on b.id=i.id
 where    exists(   select 1   from  (select 3 n from dual
                                       union all select 4 n from dual
                                        union all select 1 n from dual
                                         union all select 2 n from dual) t   
                    where    b.id=t.n
                )

posted @ 2015-09-26 12:48  172257861  阅读(726)  评论(0编辑  收藏  举报