最初由 bodyguard 发布
[B]a,b表同结构,数据量很大,则
1:select a.* from a, b where a.c = b.c + and b.c is null
要比
2:select * from a where a.c not in (select c from b )
快很多
1和2的结果集不一定等价.
如果b.c列全部not null,1会返回空. [/B]
如果b.c列全部not null,1会返回空?
不对!!!!!
看下面的测试:
SQL> create table t1 (id number);
表已创建。
SQL> create table t2 (id2 number);
表已创建。
SQL> insert into t1 values(1);
已创建 1 行。
SQL> insert into t1 values(2);
已创建 1 行。
SQL> insert into t2 values(10);
已创建 1 行。
SQL> insert into t2 values(20);
已创建 1 行。
SQL> commit;
提交完成。
SQL> select * from t1;
ID
----------
1
2
SQL> select * from t2;
ID2
----------
10
20
SQL> select t1.* from t1, t2 where t1.id=t2.id2(+) and t2.id2 is null;
ID
----------
1
2
--结果与下面的完全一样.
SQL> select * from t1 where t1.id not in (select * from t2);