oracle 如何使用索引,更快

来源:百度知道 编辑:UC知道 时间:2024/06/14 00:10:06
环境:test1(大表,字段a存在索引,字段a,b,c,d存在复合索引);test2(小表,存在与test1相同的字段a,d),先要根据a,d进行两表的匹配,如果设置索引,使得提取数据速度更快?
(1)create index ind_a on test2(a);
create table test3 as select * from test1 t where exists(select 1 from test2 where a=t.a);
(2)create index ind_a_d on test2(a,d);
create table test3 as select * from test1 t where exists(select 1 from test2 where a=t.a and d=t.d);
(3)上面两种都试过,速度都很慢以致没有得到结果,应该如何修改,或推荐更好的方法!

索引不是一句两句能讲清楚的
select * from test1 t where a in (select a from test2);
test1 大 ,test2 小,用in快

你用Pl/SQL DEVELOPER的 EXPLAIN PLAN(即按F5后)看下是否用到了索引.这种关联如果用上了索引应该不会很慢.