您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關STA的使用分析,文章內容質量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。
利用Oracle 10g提供的SQL Tuning Advisor,DBA可以很容易的來根據STA給出的意見和建議來進行SQL的優化,一切終于變的如此的簡單了。
SQL> set timing on
SQL> set autot on
SQL> select count(*) from bigtab a,smalltab b
2 where a.object_name=b.table_name;
COUNT(*)
----------
191597
已用時間: 00: 00: 27.53
執行計劃
----------------------------------------------------------
Plan hash value: 3089226980
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 83 | 16418 (3)| 00:03:18 |
| 1 | SORT AGGREGATE | | 1 | 83 | | |
|* 2 | HASH JOIN | | 1928K| 152M| 16418 (3)| 00:03:18 |
| 3 | TABLE ACCESS FULL| SMALLTAB | 1594 | 27098 | 12 (0)| 00:00:01 |
| 4 | TABLE ACCESS FULL| BIGTAB | 5465K| 343M| 16311 (2)| 00:03:16 |
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("A"."OBJECT_NAME"="B"."TABLE_NAME")
Note
-----
- dynamic sampling used for this statement
統計信息
----------------------------------------------------------
446 recursive calls
0 db block gets
73581 consistent gets
73386 physical reads
0 redo size
414 bytes sent via SQL*Net to client
400 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
6 sorts (memory)
0 sorts (disk)
1 rows processed
現在我們可以創建并執行我們的SQL tuning task
DECLARE
my_task_name VARCHAR2(30);
my_sqltext CLOB;
BEGIN
my_sqltext := 'select count(*) from bigtab a, smalltab b where a.object_name=b.table_name';
my_task_name := DBMS_SQLTUNE.CREATE_TUNING_TASK(
sql_text => my_sqltext,
user_name => 'SYS',
scope => 'COMPREHENSIVE',
time_limit => 60,
task_name => 'oracle_ace_task',
description => 'Task to tune a query on a specified table');
DBMS_SQLTUNE.EXECUTE_TUNING_TASK( task_name => 'oracle_ace_task');
END;
或者我們可以利用一個procedure來生成
create or replace procedure sql_tuning(my_sqltext in clob,schema_name in varchar2)
is
my_task_name varchar2(30);
begin
my_task_name := DBMS_SQLTUNE.CREATE_TUNING_TASK(
sql_text => my_sqltext,
user_name => schema_name,
scope => 'COMPREHENSIVE',
time_limit => 60,
task_name => 'oracle_ace_task',
description => 'Task to tune a query on a specified table');
DBMS_SQLTUNE.EXECUTE_TUNING_TASK( task_name => 'oracle_ace_task');
end;
exec sql_tuning('select count(*) from bigtab a, smalltab b where a.object_name=b.table_name','SYS');
在函數CREATE_TUNING_TASK,sql_text是需要優化的語句,user_name是該語句通過哪個用戶執行,scope是優化范圍(limited或comprehensive),time_limit優化過程的時間限制,task_name優化任務名稱,description優化任務描述。
可以通過視圖USER_ADVISOR_LOG和USER_ADVISOR_LOG來查看創建過的優化任務。
SQL> select task_name, status from USER_ADVISOR_LOG where task_name='oracle_ace_task';
TASK_NAME STATUS
------------------------------ -----------
oracle_ace_task COMPLETED
最后我們來生成tuning的報告.
SQL> set long 10000
SQL> set longchunksize 1000
SQL> set linesize 100
SQL> SELECT DBMS_SQLTUNE.REPORT_TUNING_TASK( 'tuning_sql_test') from DUAL;
/
PL/SQL procedure successfully completed.
關于STA的使用分析就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。