标签:
在10g中,Oracle推出了自己的SQL优化辅助工具: SQL优化器(SQL Tuning Advisor :STA),它是新的DBMS_SQLTUNE包。
使用STA一定要保证优化器是CBO模式下。可是我觉得使用这样的工具,仅适合全然不懂SQL的调优的人群,不要觉得工具能解决好问题。
SQL说究竟是表达的是一个业务,工具怎么可能理解业务。SQL调优还是要用autotrace,10046,10053,display_cursor这些优秀的工具做诊断。然后依据业务和所具备的oracle基础的知识进行调优,这是最好的方法。今天在这里玩这个工具仅仅是玩票。
1.创建数据。有益不建索引,然后做查询
SQL> create table test1 as select * from dba_objects;可是, 使用典型的
可能比单个语句更可取。通过这样的方法能够获得全面的索引建
-------------------------------------------------------------------------------
EXPLAIN PLANS SECTION
-------------------------------------------------------------------------------
1- Original
-----------
Plan hash value: 2544416891
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 10 | 298 (1)| 00:00:04 |
| 1 | SORT AGGREGATE | | 1 | 10 | | |
|* 2 | HASH JOIN | | 50981 | 497K| 298 (1)| 00:00:04 |
| 3 | TABLE ACCESS FULL| TEST1 | 50982 | 248K| 149 (1)| 00:00:02 |
| 4 | TABLE ACCESS FULL| TEST2 | 50983 | 248K| 149 (1)| 00:00:02 |
-----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("T1"."OBJECT_ID"="T2"."OBJECT_ID")
2- Using New Indices
--------------------
Plan hash value: 3060659111
-----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 10 | 53 (2)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 10 | | |
|* 2 | HASH JOIN | | 50981 | 497K| 53 (2)| 00:00:01 |
| 3 | INDEX FAST FULL SCAN| IDX$$_0C890001 | 50982 | 248K| 26 (0)| 00:00:01 |
| 4 | INDEX FAST FULL SCAN| IDX$$_0C890002 | 50983 | 248K| 26 (0)| 00:00:01 |
-----------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("T1"."OBJECT_ID"="T2"."OBJECT_ID")
-------------------------------------------------------------------------------
5.验证一下
依据advisor的建议进行调优,1410降到204,是乎有点效果。
SQL>create index ind_t1_object_id on test1(object_id);
SQL> create index ind_t2_object_id on test2(object_id);
SQL> set autotrace traceonly
SQL> select count(*) from test1 t1, test2 t2 where t1.object_id = t2.object_id;
已用时间: 00: 00: 00.06
运行计划
----------------------------------------------------------
Plan hash value: 1069114244
-------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 10 | 51 (2)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 10 | | |
|* 2 | HASH JOIN | | 50981 | 497K| 51 (2)| 00:00:01 |
| 3 | INDEX FAST FULL SCAN| IND_T1_OBJECT_ID | 50982 | 248K| 25 (0)| 00:00:01 |
| 4 | INDEX FAST FULL SCAN| IND_T2_OBJECT_ID | 50983 | 248K| 25 (0)| 00:00:01 |
-------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("T1"."OBJECT_ID"="T2"."OBJECT_ID")
统计信息
----------------------------------------------------------
1 recursive calls
0 db block gets
240 consistent gets
226 physical reads
0 redo size
410 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
初次使用SQL调优建议工具--SQL Tuning Advisor
标签:
原文地址:http://www.cnblogs.com/lcchuguo/p/5383623.html