如何解决Oracle / SQL 调优顾问
STA 能否处理甚至未在数据库中运行一次的查询?我的意思是,如果缓存中没有它,SQL 调优顾问可以为我们得到一些结果吗?
解决方法
SQL Tuning Advisor 可以处理以前从未运行过的查询。我不确定您使用的是什么接口,但 DBMS_SQLTUNE package 可以轻松传递 SQL 文本。
例如,让我们创建一个没有索引的简单表:
--Create a simple table with no indexes.
create table table_missing_index(a number);
insert into table_missing_index
select level from dual connect by level <= 100000;
begin
dbms_stats.gather_table_stats(user,'TABLE_MISSING_INDEX');
end;
/
然后传入一个显然可以从索引中受益的查询:
--Create,execute,and display the tuning task.
declare
v_task varchar2(64);
begin
v_task := dbms_sqltune.create_tuning_task
(
sql_text => 'select a from table_missing_index where a = 1'
);
dbms_sqltune.execute_tuning_task(task_name => v_task);
dbms_output.put_line('Task name: '||v_task);
end;
/
从输出中获取任务名称,并将其插入此查询以查看结果:
select dbms_sqltune.report_tuning_task('TASK_362') from dual;
输出应该是这样的:
GENERAL INFORMATION SECTION
-------------------------------------------------------------------------------
Tuning Task Name : TASK_362
Tuning Task Owner : JHELLER
Workload Type : Single SQL Statement
Scope : COMPREHENSIVE
Time Limit(seconds): 1800
Completion Status : COMPLETED
Started at : 04/04/2021 14:26:15
Completed at : 04/04/2021 14:26:15
-------------------------------------------------------------------------------
Schema Name : JHELLER
Container Name: ORCLPDB
SQL ID : 0g6v1x1c7kcjt
SQL Text : select a from table_missing_index where a = 1
-------------------------------------------------------------------------------
FINDINGS SECTION (1 finding)
-------------------------------------------------------------------------------
1- 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: 98.56%)
------------------------------------------
- Consider running the Access Advisor to improve the physical schema design
or creating the recommended index.
create index JHELLER.IDX$$_016A0001 on JHELLER.TABLE_MISSING_INDEX("A");
... [removed rest of the large report] ...
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。