Manually Run SQL Advisor Archives
Manually Run SQL Advisor Archives
Index dropped.
Index created.
SQL>
SQL> DECLARE
n number;
BEGIN
for i in 1..1000 loop
select /*+ ORDERED USE_NL(c) FULL(c) FULL(s)*/ count(*) into
n
from sales s, customers c
where c.cust_id = s.cust_id and CUST_FIRST_NAME='Dina'
order by time_id;
DBMS_LOCK.SLEEP(1);
end loop;
END;
/ 2 3 4 5 6 7 8 9 10 11 12
SQL>
SET serveroutput ON
DECLARE
l_sql_tune_task_id VARCHAR2(100);
BEGIN
l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (
sql_id => '&&my_sql_id',
scope =>
DBMS_SQLTUNE.scope_comprehensive,
time_limit => 60,
task_name =>
'sql_tuning_task_&&my_sql_id',
description => 'Tuning task for
statement &&my_sql_id.');
DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' ||
l_sql_tune_task_id);
END;
/
output:
SQL> DECLARE
l_sql_tune_task_id VARCHAR2(100);
2 3 BEGIN
4 l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (
5 sql_id => '&&my_sql_id',
6 scope =>
DBMS_SQLTUNE.scope_comprehensive,
7 time_limit => 60,
8 task_name =>
'sql_tuning_task_&&my_sql_id',
9 description => 'Tuning task for
statement &&my_sql_id.');
10 DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' ||
l_sql_tune_task_id);
11 END;
/ 12
Enter value for my_sql_id: 5mxdwvuf9j3vp
old 5: sql_id =>
'&&my_sql_id',
new 5: sql_id =>
'5mxdwvuf9j3vp',
old 8: task_name =>
'sql_tuning_task_&&my_sql_id',
new 8: task_name =>
'sql_tuning_task_5mxdwvuf9j3vp',
old 9: description => 'Tuning task
for statement &&my_sql_id.');
new 9: description => 'Tuning task
for statement 5mxdwvuf9j3vp');
SQL>
output:
SQL>
output:
SQL>
output:
TASK_NAME STATUS
------------------------------ -----------
sql_tuning_task_5mxdwvuf9j3vp COMPLETED
SQL>
SELECT
DBMS_SQLTUNE.report_tuning_task('sql_tuning_task_&&my_sql_id')
AS recommendations FROM dual;
output:
SELECT
DBMS_SQLTUNE.report_tuning_task('sql_tuning_task_&&my_sql_id')
AS recommendations FROM dual;
SQL> SQL> SQL> SQL> SQL> old 1: SELECT
DBMS_SQLTUNE.report_tuning_task('sql_tuning_task_&&my_sql_id')
AS recommendations FROM dual
new 1: SELECT
DBMS_SQLTUNE.report_tuning_task('sql_tuning_task_5mxdwvuf9j3vp
') AS recommendations FROM dual
RECOMMENDATIONS
--------------------------------------------------------------
--------------------------------------------------------------
--------------------------
GENERAL INFORMATION SECTION
--------------------------------------------------------------
-----------------
Tuning Task Name : sql_tuning_task_5mxdwvuf9j3vp
Tuning Task Owner : SYS
Workload Type : Single SQL Statement
Scope : COMPREHENSIVE
Time Limit(seconds): 60
Completion Status : COMPLETED
Started at : 07/20/2016 22:05:52
Completed at : 07/20/2016 22:06:25
--------------------------------------------------------------
-----------------
Schema Name: SH
SQL ID : 5mxdwvuf9j3vp
SQL Text : SELECT /*+ ORDERED USE_NL(c) FULL(c) FULL(s)*/
COUNT(*) FROM
SALES S, CUSTOMERS C WHERE C.CUST_ID = S.CUST_ID
AND
CUST_FIRST_NAME='Dina' ORDER BY TIME_ID
--------------------------------------------------------------
-----------------
FINDINGS SECTION (1 finding)
--------------------------------------------------------------
-----------------
Validation results
------------------
The SQL profile was tested by executing both its plan and
the original plan
and measuring their respective execution statistics. A plan
may have been
only partially executed if the other could be run to
completion in less time.
Original Plan With SQL Profile %
Improved
------------- ----------------
----------
Completion Status: PARTIAL COMPLETE
Elapsed Time (s): 15.829308 .131064
99.17 %
CPU Time (s): 9.99348 .074863
99.25 %
User I/O Time (s): 0 .000694
Buffer Gets: 5320022 3093
99.94 %
Physical Read Requests: 0 10
Physical Write Requests: 0 0
Physical Read Bytes: 0 884736
Physical Write Bytes: 0 0
Rows Processed: 0 1
Fetches: 0 1
Executions: 0 1
Notes
-----
1. Statistics for the original plan were averaged over 0
executions.
2. Statistics for the SQL profile plan were averaged over 8
executions.
--------------------------------------------------------------
-----------------
EXPLAIN PLANS SECTION
--------------------------------------------------------------
-----------------
--------------------------------------------------------------
-------------------------------------
| Id | Operation | Name | Rows | Bytes |
Cost (%CPU)| Time | Pstart| Pstop |
--------------------------------------------------------------
-------------------------------------
| 0 | SELECT STATEMENT | | 1 | 25 |
370M (1)|999:59:59 | | |
| 1 | SORT AGGREGATE | | 1 | 25 |
| | | |
| 2 | NESTED LOOPS | | 982 | 24550 |
370M (1)|999:59:59 | | |
| 3 | PARTITION RANGE ALL| | 918K| 11M|
527 (2)| 00:00:07 | 1 | 28 |
| 4 | TABLE ACCESS FULL | SALES | 918K| 11M|
527 (2)| 00:00:07 | 1 | 28 |
|* 5 | TABLE ACCESS FULL | CUSTOMERS | 1 | 12 |
404 (1)| 00:00:05 | | |
--------------------------------------------------------------
-------------------------------------
5 - filter("CUST_FIRST_NAME"='Dina' AND
"C"."CUST_ID"="S"."CUST_ID")
--------------------------------------------------------------
-------------------------------------
| Id | Operation | Name | Rows | Bytes |
Cost (%CPU)| Time | Pstart| Pstop |
--------------------------------------------------------------
-------------------------------------
| 0 | SELECT STATEMENT | | 1 | 25 |
937 (2)| 00:00:12 | | |
| 1 | SORT AGGREGATE | | 1 | 25 |
| | | |
|* 2 | HASH JOIN | | 982 | 24550 |
937 (2)| 00:00:12 | | |
|* 3 | TABLE ACCESS FULL | CUSTOMERS | 43 | 516 |
405 (1)| 00:00:05 | | |
| 4 | PARTITION RANGE ALL| | 918K| 11M|
527 (2)| 00:00:07 | 1 | 28 |
| 5 | TABLE ACCESS FULL | SALES | 918K| 11M|
527 (2)| 00:00:07 | 1 | 28 |
--------------------------------------------------------------
-------------------------------------
2 - access("C"."CUST_ID"="S"."CUST_ID")
3 - filter("CUST_FIRST_NAME"='Dina')
--------------------------------------------------------------
-----------------
SQL>
output:
SQL>
Step 6: Drop_tuning_task
After review recommendations, we can remove the task by drop_tuning_task
BEGIN
DBMS_SQLTUNE.drop_tuning_task (task_name =>
'sql_tuning_task_&&my_sql_id');
END;
/
output:
SQL> BEGIN
DBMS_SQLTUNE.drop_tuning_task (task_name =>
'sql_tuning_task_&&my_sql_id');
END;
/ 2 3 4
old 2: DBMS_SQLTUNE.drop_tuning_task (task_name =>
'sql_tuning_task_&&my_sql_id');
new 2: DBMS_SQLTUNE.drop_tuning_task (task_name =>
'sql_tuning_task_5mxdwvuf9j3vp');
SQL>
Step 7: Verify
output:
no rows selected
SQL>
Reference:
http://kb.initso.at/2011/05/oracle-howto-run-the-sql-tuning-advisor-without-enterprise-manager-db-
console-or-grid-control/
OR ELSE YOU CAN TRY LIKE BELOW WAY
EXEC DBMS_SQLTUNE.EXECUTE_TUNING_TASK('sql_tuning_task1');
Caution: Your use of any information or materials on this website is entirely at your own risk. It
is provided for educational purposes only. It has been tested internally, however, we do not
guarantee that it will work for you. Ensure that you run it in your test environment before us-
ing.