SYS@orcl1> create user test identified by 123456;
SYS@orcl1> grant connect to test;
SYS@orcl1> @?/rdbms/admin/utlxplan.sql
SYS@orcl1> @?/sqlplus/admin/plustrce.sql ---生成 plustrace角色
SYS@orcl1> grant plustrace to test; ---普通用户(非dba用户)需要有plustrace角色才能在sqlplus下使用autotrace。
SYS@orcl1> conn test/123456
test@orcl1>
SELECT a.id,
a.name,
a.sex,
a.region,
b.logtime,
b.cardid,
b.score,
c.tel,
c.joindate
FROM test_member a, test_sales b, test_m10 c
WHERE a.cardid = b.cardid
AND b.cardid=c.cardid
AND a.name in ('test1175189','test3077390','test7132935')
AND b.cardid like '10%'
AND c.joindate > to_date('2010-12-15', 'yyyy-mm-dd')
ORDER BY c.joindate;
test@orcl1> set line 400;
test@orcl1> set autotrace on;
test@orcl1>
SELECT a.id,
a.name,
a.sex,
a.region,
b.logtime,
b.cardid,
b.score,
c.tel,
c.joindate
FROM test_member a, test_sales b, test_m10 c
WHERE a.cardid = b.cardid
AND b.cardid=c.cardid
AND a.name in ('test1175189','test3077390','test7132935')
AND b.cardid like '10%'
AND c.joindate > to_date('2010-12-15', 'yyyy-mm-dd')
ORDER BY c.joindate;
Predicate Information (identified by operation id)为谓词信息部分:谓词信息部分列出了执行计划部分where过滤条件或者join连接条件的信息,其实也就是where过滤条件或者join连接条件都会在谓词信息中,where过滤条件或者join连接条件对于查询性能最重要,通过谓词信息部分考虑是否可以通过添加或修改索引来提高过滤操作的效率。
TEST@orcl1> create index idx_test_member_name on test_member(name);
4)再次执行SQL语句,并查看执行计划
sql复制代码
test@orcl1>
SELECT a.id,
a.name,
a.sex,
a.region,
b.logtime,
b.cardid,
b.score,
c.tel,
c.joindate
FROM test_member a, test_sales b, test_m10 c
WHERE a.cardid = b.cardid
AND b.cardid=c.cardid
AND a.name in ('test1175189','test3077390','test7132935')
AND b.cardid like '10%'
AND c.joindate > to_date('2010-12-15', 'yyyy-mm-dd')
ORDER BY c.joindate;
通过创建索引优化,查询时间降到了0.08秒
Execution Plan部分:test_member表不再进行全表扫描,而是使用到了IDX_TEST_MEMBER_NAME索引,进行了索引范围扫描(index range scan)****
Predicate Information (identified by operation id)部分:access表示的是使用索引作为过滤条件。索引范围扫描(index range scan)对应的就是内部标识符4的谓词信息,test_member的name使用了索引