使用SQL調整顧問得到SQL優化建議
SQL調整顧問可以通過SQL*PLUS或EM呼叫。
一般分為3個步驟:
1. 建立調整任務。
2. 執行調整任務。
3. 檢視結果。
建立調整任務:
執行調整任務
上個步驟可能會耗時很長。
檢視結果
觀察執行結果,調整顧問會給出該語句的調整建議(上例是建立索引),並給出當前和使用調整建議後不同的執行計劃。
一般分為3個步驟:
1. 建立調整任務。
2. 執行調整任務。
3. 檢視結果。
建立調整任務:
點選(此處)摺疊或開啟
-
DECLARE
-
tuning_task_name VARCHAR2(30);
-
tuning_sqltext CLOB;
-
BEGIN
-
tuning_sqltext := 'SELECT id FROM BOM WHERE MOD3=3';
-
tuning_task_name := DBMS_SQLTUNE.CREATE_TUNING_TASK(
-
sql_text => tuning_sqltext,
-
bind_list => NULL,
-
user_name => 'HK',
-
scope => 'COMPREHENSIVE',
-
time_limit => 60,
-
task_name => 'first_tuning_task50',
-
description => 'Tune T50 count');
-
END;
- /
點選(此處)摺疊或開啟
-
BEGIN
-
DBMS_SQLTUNE.EXECUTE_TUNING_TASK( task_name => 'first_tuning_task50' );
-
END;
- /
上個步驟可能會耗時很長。
檢視結果
點選(此處)摺疊或開啟
-
SET SERVEROUTPUT ON
- BEGIN
- DBMS_OUTPUT.PUT_LINE(dbms_sqltune.report_tuning_task('first_tuning_task60'));
- END;
- /
"DBMS_SQLTUNE.REPORT_TUNING_TAS"
"GENERAL INFORMATION SECTION
-------------------------------------------------------------------------------
Tuning Task Name : first_tuning_task50
Tuning Task Owner : HK
Scope : COMPREHENSIVE
Time Limit(seconds) : 60
Completion Status : COMPLETED
Started at : 09/26/2014 17:58:41
Completed at : 09/26/2014 17:59:14
Number of Statistic Findings : 1
Number of Index Findings : 1
-------------------------------------------------------------------------------
Schema Name: HK
SQL ID : bx8zw8mfvh7u1
SQL Text : SELECT id FROM BOM WHERE MOD3=3
-------------------------------------------------------------------------------
FINDINGS SECTION (2 findings)
-------------------------------------------------------------------------------
1- Statistics Finding
---------------------
Table ""HK"".""BOM"" and its indices were not analyzed.
Recommendation
--------------
- Consider collecting optimizer statistics for this table and its indices.
execute dbms_stats.gather_table_stats(ownname => 'HK', tabname => 'BOM',
estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE, method_opt =>
'FOR ALL COLUMNS SIZE AUTO', cascade => TRUE);
Rationale
---------
The optimizer requires up-to-date statistics for the table and its indices
in order to select a good execution plan.
2- Index Finding (see explain plans section below)
--------------------------------------------------
The execution plan of this statement can be improved by creating one or more
indices.
Recommendation (estimated benefit: 100%)
----------------------------------------
- Consider running the Access Advisor to improve the physical schema design
or creating the recommended index.
create index HK.IDX$$_00FE0001 on HK.BOM('MOD3');
Rationale
---------
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.
-------------------------------------------------------------------------------
EXPLAIN PLANS SECTION
-------------------------------------------------------------------------------
1- Original
-----------
Plan hash value: 258718033
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 6008K| 148M| 242K (1)| 00:48:31 |
|* 1 | TABLE ACCESS FULL| BOM | 6008K| 148M| 242K (1)| 00:48:31 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(""MOD3""=:SYS_B_0)
2- Using New Indices
--------------------
Plan hash value: 964494434
-------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 6008K| 148M| 30552 (2)| 00:06:07 |
|* 1 | VIEW | index$_join$_001 | 6008K| 148M| 30552 (2)| 00:06:07 |
|* 2 | HASH JOIN | | | | | |
|* 3 | INDEX RANGE SCAN | IDX$$_00FE0001 | 6008K| 148M| 2797 (1)| 00:00:34 |
| 4 | INDEX FAST FULL SCAN| BOM_PK_ID | 6008K| 148M| 20992 (2)| 00:04:12 |
-------------------------------------------------..."
"GENERAL INFORMATION SECTION
-------------------------------------------------------------------------------
Tuning Task Name : first_tuning_task50
Tuning Task Owner : HK
Scope : COMPREHENSIVE
Time Limit(seconds) : 60
Completion Status : COMPLETED
Started at : 09/26/2014 17:58:41
Completed at : 09/26/2014 17:59:14
Number of Statistic Findings : 1
Number of Index Findings : 1
-------------------------------------------------------------------------------
Schema Name: HK
SQL ID : bx8zw8mfvh7u1
SQL Text : SELECT id FROM BOM WHERE MOD3=3
-------------------------------------------------------------------------------
FINDINGS SECTION (2 findings)
-------------------------------------------------------------------------------
1- Statistics Finding
---------------------
Table ""HK"".""BOM"" and its indices were not analyzed.
Recommendation
--------------
- Consider collecting optimizer statistics for this table and its indices.
execute dbms_stats.gather_table_stats(ownname => 'HK', tabname => 'BOM',
estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE, method_opt =>
'FOR ALL COLUMNS SIZE AUTO', cascade => TRUE);
Rationale
---------
The optimizer requires up-to-date statistics for the table and its indices
in order to select a good execution plan.
2- Index Finding (see explain plans section below)
--------------------------------------------------
The execution plan of this statement can be improved by creating one or more
indices.
Recommendation (estimated benefit: 100%)
----------------------------------------
- Consider running the Access Advisor to improve the physical schema design
or creating the recommended index.
create index HK.IDX$$_00FE0001 on HK.BOM('MOD3');
Rationale
---------
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.
-------------------------------------------------------------------------------
EXPLAIN PLANS SECTION
-------------------------------------------------------------------------------
1- Original
-----------
Plan hash value: 258718033
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 6008K| 148M| 242K (1)| 00:48:31 |
|* 1 | TABLE ACCESS FULL| BOM | 6008K| 148M| 242K (1)| 00:48:31 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(""MOD3""=:SYS_B_0)
2- Using New Indices
--------------------
Plan hash value: 964494434
-------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 6008K| 148M| 30552 (2)| 00:06:07 |
|* 1 | VIEW | index$_join$_001 | 6008K| 148M| 30552 (2)| 00:06:07 |
|* 2 | HASH JOIN | | | | | |
|* 3 | INDEX RANGE SCAN | IDX$$_00FE0001 | 6008K| 148M| 2797 (1)| 00:00:34 |
| 4 | INDEX FAST FULL SCAN| BOM_PK_ID | 6008K| 148M| 20992 (2)| 00:04:12 |
-------------------------------------------------..."
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22621861/viewspace-1282023/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 使用SQL調整顧問進行語句優化SQL優化
- 在EM中使用SQL Access Advisor(SQL訪問建議)優化SQLSQL優化
- 在EM中使用SQL Tuning Advisor(SQL優化建議)優化SQLSQL優化
- 一條sql語句的建議調優分析SQL
- Oracle PL/SQL 優化與調整 -- Bulk 說明OracleSQL優化
- mysql優化 | 儲存引擎,建表,索引,sql的優化建議MySql優化儲存引擎索引
- Oracle PL/SQL 優化與調整 – PL/SQL Native Compilation 說明OracleSQL優化
- ORACLE SQL 效能優化的一些建議OracleSQL優化
- oracle優化sql語句的一些建議Oracle優化SQL
- 效能調優——SQL最佳化SQL
- SQL調優SQL
- SQL調整優化與10053跟蹤分析一例SQL優化
- 使用explain優化sqlAI優化SQL
- SQL調優13連問,收藏好!SQL
- 檢視自動sql調優作業,最佳化sql訪問路徑SQL
- MySQL 調優/優化的 100 個建議MySql優化
- Sql最佳化(十九) 調優工具(2)sql_traceSQL
- 分析SQL給出索引優化建議的工具(美團開源)SQL索引優化
- SQL語句優化的34條建議(轉-浪花七八朵 )SQL優化
- SQL Server 2008 實施查詢優化建議SQLServer優化
- 使用SQL Profile進行SQL優化案例SQL優化
- SQL調整優化與10053跟蹤分析一例(zt)SQL優化
- sql調優1SQL
- oracle sql調優OracleSQL
- laravel-soar(2.x) - 自動監控輸出 SQL 優化建議、輔助 laravel 應用 SQL 優化LaravelSQL優化
- 資料庫引擎調整顧問資料庫
- 使用hint來調優sql語句SQL
- 【SQL優化】SQL優化工具SQL優化
- 【SQL】關於Oracle12c SQL調整中一些變化SQLOracle
- 從一條問題SQL優化看SQL TransformationSQL優化ORM
- 調整sql臨時記錄SQL
- Oracle高效能SQL調整OracleSQL
- 針對SQL Server的最佳化建議SQLServer
- SQL Server優化之SQL語句優化SQLServer優化
- 使用dbms_sqltune獲得SQL調整建議SQL
- Teradata SQL調優SQL
- Oracle 高效能SQL引擎剖析--SQL優化與調優機制詳解OracleSQL優化
- SQL SERVER中SQL優化SQLServer優化