set serveroutput on> set long 99999;
select dbms_sqltune.report_tuning_task('manual_advisor') from dual;
建议结果如下:
SQL> select dbms_sqltune.report_tuning_task('manual_advisor') from dual;
DBMS_SQLTUNE.REPORT_TUNING_TASK('MANUAL_ADVISOR')
--------------------------------------------------------------------------------
GENERAL INFORMATION SECTION
-------------------------------------------------------------------------------
Tuning Task Name : manual_advisor
Tuning Task Owner : SYS
Workload Type : Single SQL Statement
Scope : COMPREHENSIVE
Time Limit(seconds): 30
Completion Status : COMPLETED
Started at : 07/02/2017 21:21:56
Completed at : 07/02/2017 21:21:59
DBMS_SQLTUNE.REPORT_TUNING_TASK('MANUAL_ADVISOR')
Schema Name: SCOTT
SQL>
SQL Text : select> FINDINGS SECTION (2 findings)
1- Index Finding (see explain plans section below)
DBMS_SQLTUNE.REPORT_TUNING_TASK('MANUAL_ADVISOR')
The execution plan of this statement can be improved by creating one or more
indices.
Recommendation (estimated benefit: 98.04%)
------------------------------------------
- Consider running the Access Advisor to improve the physical schema design
or creating the recommended index.
create index SCOTT.IDX$$_023A0001 on SCOTT.TEST_ADVISOR(TO_NUMBER("ID"));
Rationale
---------
DBMS_SQLTUNE.REPORT_TUNING_TASK('MANUAL_ADVISOR')
--------------------------------------------------------------------------------
Creating the recommended indices significantly improves the execution plan
of this statement. However, it might be preferable to run "Access Advisor"
using a representative SQL workload as opposed to a single statement. This
will allow to get comprehensive index recommendations which takes into
account index maintenance overhead and additional space consumption.
2- Restructure SQL finding (see plan 1 in explain plans section)
----------------------------------------------------------------
The predicate TO_NUMBER("TEST_ADVISOR"."ID")=1000 used at line> execution plan contains an implicit data type conversion on indexed column
"ID". This implicit data type conversion prevents the optimizer from
从上面可以看到有2条建议,说可以提高性能的98.4%(Recommendation (estimated benefit: 98.04%))分别如下:
create index SCOTT.IDX$$_023A0001 on SCOTT.TEST_ADVISOR(TO_NUMBER("ID"));
TO_NUMBER("TEST_ADVISOR"."ID")=1000
下面来看看第二条建议怎么样?
select> 结果还是全表扫描cost为103
在看看第一条建议
create index SCOTT.IDX$$_023A0001 on SCOTT.TEST_ADVISOR(TO_NUMBER("ID"));
在查询结果为走索引,代价为3,的确提高了98.4%性能!!!!!!!