没有合适的资源?快使用搜索试试~ 我知道了~
首页SQL Tuning Advisor使用总结
资源详情
资源评论
资源推荐

SQL Tuning Advisor
1 input:
Automatic Database Diagnostic Monitor
High-load SQL statements --awr report hight-load sql
Cursor cache
SQL Tuning Set
2 Tuning Options
limited
statistics checks, access path analysis, and SQL structure analysis. SQL Profile recommendations
are not generated
comprehensive
comprehensive option you can also specify a time limit for the tuning task, which by default is 30
minutes.
3 output
After analyzing the SQL statements, the SQL Tuning Advisor provides advice on
optimizing the execution plan, the rationale for the proposed optimization, the
estimated performance benefit, and the command to implement the advice. You
simply have to choose whether or not to accept the recommendations to optimize the
SQL statements.

4 DBMS_SQLTUNE
Using SQL Tuning Advisor APIs
A SQL tuning task can be created for a single SQL statement. For tuning
multiple statements, a SQL Tuning Set (STS) has to be rst created. An STS
is a database object that stores SQL statements along with their execution
context.
4.1 创建优化任务
--创建优化任务 Creating a SQL Tuning Task
--create_tuning_task 可传递如下三个参数:
The text of a SQL statement
The reference (sql_id) to a SQL statement stored in the shared pool
The reference (sql_id) to a SQL statement stored in the Automatic Workload Repository
The name of a SQL tuning set
--创建优化任务的方法有几种,具体如下所示:
SET SERVEROUTPUT ON

4.1.1 从 awr 报告中获取 sql
-- Tuning task created for specific a statement from the AWR.
DECLARE
l_sql_tune_task_id VARCHAR2(100);
BEGIN
l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (
begin_snap => 87,
end_snap => 88,
sql_id => '7gtztzv329wg0',
scope => DBMS_SQLTUNE.scope_comprehensive,
time_limit => 60,
task_name => '17gtztzv329wg0_AWR_tuning_task',
description => 'Tuning task for statement 19v5guvsgcd1v in AWR.');
DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
END;
/
4.1.2 从 cursor 中获取 sql
-- Tuning task created for specific a statement from the cursor cache.
DECLARE
l_sql_tune_task_id VARCHAR2(100);
BEGIN
l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (
sql_id => '19v5guvsgcd1v',
scope => DBMS_SQLTUNE.scope_comprehensive,
time_limit => 60,
task_name => '19v5guvsgcd1v_tuning_task',
description => 'Tuning task for statement 19v5guvsgcd1v.');
DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
END;
/
4.1.3 从 sql set 中获取 sql 组
-- Tuning task created from an SQL tuning set.
DECLARE
l_sql_tune_task_id VARCHAR2(100);

BEGIN
l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (
sqlset_name => 'test_sql_tuning_set',
scope => DBMS_SQLTUNE.scope_comprehensive,
time_limit => 60,
task_name => 'sqlset_tuning_task',
description => 'Tuning task for an SQL tuning set.');
DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
END;
/
4.1.4 人为指定 sql
-- Tuning task created for a manually specified statement.
DECLARE
l_sql VARCHAR2(500);
l_sql_tune_task_id VARCHAR2(100);
BEGIN
l_sql := 'SELECT e.*, d.* ' ||
'FROM emp e JOIN dept d ON e.deptno = d.deptno ' ||
'WHERE NVL(empno, ''0'') = :empno';
l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (
sql_text => l_sql,
bind_list => sql_binds(anydata.ConvertNumber(100)),
user_name => 'scott',
scope => DBMS_SQLTUNE.scope_comprehensive,
time_limit => 60,
task_name => 'emp_dept_tuning_task',
description => 'Tuning task for an EMP to DEPT join query.');
DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
END;
/
DECLARE
my_task_name VARCHAR2 (30);
my_sqltext CLOB;
BEGIN
my_sqltext := 'select * from v$parameter';
my_task_name := dbms_sqltune.create_tuning_task (sql_text=> my_sqltext,
bind_list => null,
user_name => 'TEST',
剩余16页未读,继续阅读


















安全验证
文档复制为VIP权益,开通VIP直接复制

评论2