解读Oracle执行计划(二)
一些典型的执行计划:AND-EQUAL(Index merge)
AND-EQUAL
这种方式需要查询条件里面包括所有索引列,然后取得每个索引中得到的rowid列表,然后对这些列表做merge join,过滤出相同的rowid后再去表中获取数据或者直接从索引中获得数据。and-equal有一些限制,比如它只对单列索引有效,只对非唯一索引有效,使用到的索引不能超过5个,查询条件只能是”=”。
在10g中,and_equal已经被废弃了,只能通过hint才能生效!
Can operate on 2 to 5 non-unique, single-column indexes with an equality condition on the indexed values. For colX = const each index produces a list of rowids which are guaranteed to be in rowid order, hence pre-sorted and ready for a merge join. rowids that survive the join are used to access the table.
and-equal支持操作2-5个非唯一单列索引,这些索引都有一个基于索引值的等值查询条件。 对于colX = “常量”, 每个索引都生成一个排好了顺序的rowid列表,可以直接进行合并连接。符合连接条件的rowid用来访问表取得结果数据。
示例:
SQL> create table emp_copy
2 as
3 select * from emp;
表已创建。
SQL> create table dept_copy
2 as
3 select * from dept;
表已创建。
SQL> create index idx_mgr on emp_copy(mgr);
索引已创建。
SQL> create index idx_deptno on emp_copy(deptno);
索引已创建。
执行如下SQL查询:
SQL> set timing on;
SQL> set autotrace on;
SQL> select /*+ and_equal(emp_copy idx_mgr idx_deptno) */ empno,job
2 from emp_copy
3 where mgr=7902 and deptno=20;
EMPNO JOB
---------- ------------------
7369 CLE