--Connected to Oracle9i Enterprise Edition Release 9.2.0.5.0 --test_tbl1 记录数500000 --test_tbl2 记录数200 --test_tbl1 的ID字段没有使用到索引 --test_tbl2 的ID字段有索引 select count(*) from test_tbl1 where id in ( select id from test_tbl2--执行时间2.473s select count(*) from test_tbl1 a where exists(select * from test_tbl2 b where b.id =a.id )--执行时间1.522s 如果数据量更大的话时间差别就越大,可见oracle9i的in和exists还是有差别的。
--Connected to Oracle9i Enterprise Edition Release 9.2.0.5.0 --test_tbl3 记录数1400000 --test_tbl2 记录数200 --test_tbl3 的ID字段没有使用到索引 --test_tbl2 的ID字段有索引 select count(*) from test_tbl3 where id in ( select id from test_tbl2--执行时间4.887s select count(*) from test_tbl3 a where exists(select * from test_tbl2 b where b.id =a.id )--执行时间2.323s
--test_tbl1 记录数500000
--test_tbl2 记录数200
--test_tbl1 的ID字段没有使用到索引
--test_tbl2 的ID字段有索引
select count(*) from test_tbl1 where id in (
select id from test_tbl2--执行时间2.473s select count(*) from test_tbl1 a where exists(select * from test_tbl2 b
where b.id =a.id )--执行时间1.522s
如果数据量更大的话时间差别就越大,可见oracle9i的in和exists还是有差别的。
--test_tbl3 记录数1400000
--test_tbl2 记录数200
--test_tbl3 的ID字段没有使用到索引
--test_tbl2 的ID字段有索引
select count(*) from test_tbl3 where id in (
select id from test_tbl2--执行时间4.887s select count(*) from test_tbl3 a where exists(select * from test_tbl2 b
where b.id =a.id )--执行时间2.323s