如果面对一个需要优化的SQL语句,没有很好的想法,可以先试试Oracle的SQL Tuning Advisor。

SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for 64-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
--创建测试表
SQL> create table test_sql_tuning(id_ number); Table created. SQL> declare
2 begin
3 for i in 1..100000 loop
4 insert into test_sql_tuning values(i)
5 end loop;
6 commit;
7 end;
8 / PL/SQL procedure successfully completed. SQL> set autotrace on exp
SQL> select * from test_sql_tuning t where t.id_=333; ID_
----------
333 Execution Plan
----------------------------------------------------------
Plan hash value: 3855182387 -------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 3 | 39 | 69 (2)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| TEST_SQL_TUNING | 3 | 39 | 69 (2)| 00:00:01 |
------------------------------------------------------------------------------------- Predicate Information (identified by operation id):
--------------------------------------------------- 1 - filter("T"."ID_"=333) Note
-----
- dynamic sampling used for this statement (level=2) SQL> declare
2 my_task_name varchar2(50);
3 begin
4 my_task_name := dbms_sqltune.create_tuning_task(
5 SQL_ID => 'g72kdvcacxvtf',
6 scope => 'COMPREHENSIVE',
7 task_name => 'ZEN_TEST_SQLTUNE');
8 DBMS_SQLTUNE.execute_tuning_task(my_task_name);
9 end;
10 / PL/SQL procedure successfully completed. SQL> select dbms_sqltune.report_tuning_task('ZEN_TEST_SQLTUNE') from dual; DBMS_SQLTUNE.REPORT_TUNING_TASK('ZEN_TEST_SQLTUNE')
--------------------------------------------------------------------------------
GENERAL INFORMATION SECTION
-------------------------------------------------------------------------------
Tuning Task Name : ZEN_TEST_SQLTUNE
Tuning Task Owner : HR
Workload Type : Single SQL Statement
Scope : COMPREHENSIVE
Time Limit(seconds): 1800
Completion Status : COMPLETED
Started at : 07/02/2017 16:31:20
Completed at : 07/02/2017 16:31:20 DBMS_SQLTUNE.REPORT_TUNING_TASK('ZEN_TEST_SQLTUNE')
--------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Schema Name: HR
SQL ID : cnvs1fb15pqb4
SQL Text : select * from test_sql_tuning t where t.id_=333 -------------------------------------------------------------------------------
FINDINGS SECTION (2 findings)
------------------------------------------------------------------------------- 1- Statistics Finding
--------------------- DBMS_SQLTUNE.REPORT_TUNING_TASK('ZEN_TEST_SQLTUNE')
--------------------------------------------------------------------------------
Table "HR"."TEST_SQL_TUNING" was not analyzed. Recommendation
--------------
- Consider collecting optimizer statistics for this table.
execute dbms_stats.gather_table_stats(ownname => 'HR', tabname =>
'TEST_SQL_TUNING', estimate_percent =>
DBMS_STATS.AUTO_SAMPLE_SIZE, method_opt => 'FOR ALL COLUMNS SIZE
AUTO'); Rationale DBMS_SQLTUNE.REPORT_TUNING_TASK('ZEN_TEST_SQLTUNE')
--------------------------------------------------------------------------------
---------
The optimizer requires up-to-date statistics for the table 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: 98.55%)
------------------------------------------ DBMS_SQLTUNE.REPORT_TUNING_TASK('ZEN_TEST_SQLTUNE')
--------------------------------------------------------------------------------
- Consider running the Access Advisor to improve the physical schema design
or creating the recommended index.
create index HR.IDX$$_06650001 on HR.TEST_SQL_TUNING("ID_"); 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. DBMS_SQLTUNE.REPORT_TUNING_TASK('ZEN_TEST_SQLTUNE')
-------------------------------------------------------------------------------- -------------------------------------------------------------------------------
EXPLAIN PLANS SECTION
------------------------------------------------------------------------------- 1- Original
-----------
Plan hash value: 3855182387 -------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | DBMS_SQLTUNE.REPORT_TUNING_TASK('ZEN_TEST_SQLTUNE')
--------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 3 | 39 | 69 (2)| 00:00:01 | |* 1 | TABLE ACCESS FULL| TEST_SQL_TUNING | 3 | 39 | 69 (2)| 00:00:01 |
------------------------------------------------------------------------------------- Predicate Information (identified by operation id):
--------------------------------------------------- 1 - filter("T"."ID_"=333) DBMS_SQLTUNE.REPORT_TUNING_TASK('ZEN_TEST_SQLTUNE')
--------------------------------------------------------------------------------
2- Using New Indices
--------------------
Plan hash value: 1603088386 -----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 1 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| IDX$$_06650001 | 1 | 13 | 1 (0)| 00:00:01
|
----------------------------------------------------------------------------------- DBMS_SQLTUNE.REPORT_TUNING_TASK('ZEN_TEST_SQLTUNE')
-------------------------------------------------------------------------------- Predicate Information (identified by operation id):
--------------------------------------------------- 1 - access("T"."ID_"=333) ------------------------------------------------------------------------------- 1 row selected. Execution Plan
----------------------------------------------------------
Plan hash value: 1388734953 -----------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-----------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 2 (0)| 00:00:01 |
| 1 | FAST DUAL | | 1 | 2 (0)| 00:00:01 |
----------------------------------------------------------------- SQL>

上面的report总共分为3个部分,
分别是SQL调优的基本信息、SQL调优的建议findings、以及SQL对应的执行计划部分
在基本信息部分包含了SQL调优的任务名称,状态,执行,完成时间,对应的SQL完整语句等
在finding部分则给出本次调优所得到的成果,如本次是提示缺少统计信息,可以及创建索引。
在执行计划部分则给出了当前SQL语句的执行计划以及谓词信息

Oracle SQL Tuning Advisor 测试的更多相关文章

  1. 使用ORACLE SQL Tuning advisor快速优化低效的SQL语句

    ORACLE10G以后版本的SQL Tuning advisor可以从以下四个方面给出优化方案 (1)为统计信息丢失或失效的对象收集统计信息   (2)考虑优化器的任何数据偏差.复杂谓词或失效的统计信 ...

  2. ORACLE SQL TUNING ADVISOR 使用方法

    sql tunning advisor 使用的主要步骤: 1 建立tunning task 2 执行task 3 显示tunning 结果 4 根据建议来运行相应的调优方法  下面来按照这个顺序来实施 ...

  3. Oracle 10G强大的SQL优化工具:SQL Tuning Advisor

    p { margin-bottom: 0.25cm; direction: ltr; color: rgb(0, 0, 0); line-height: 120%; orphans: 2; widow ...

  4. Oracle调整顾问(SQL Tuning Advisor 与 SQL Access Advisor

    在Oracle数据库出现性能问题时,使用Oracle本身的工具包,给出合理的调优建议是比较省力的做法. tuning advisor 是对输入的sql set的执行计划进行优化accsee advis ...

  5. 怎样使用oracle 的DBMS_SQLTUNE package 来执行 Sql Tuning Advisor 进行sql 自己主动调优

     怎样使用oracle 的DBMS_SQLTUNE package 来执行 Sql Tuning Advisor 进行sql 自己主动调优 1>.这里简单举个样例来说明DBMS_SQLTUN ...

  6. [terry笔记]Oracle SQL 优化之sql tuning advisor (STA)

    前言:经常可以碰到优化sql的需求,开发人员直接扔过来一个SQL让DBA优化,然后怎么办? 当然,经验丰富的DBA可以从各种方向下手,有时通过建立正确索引即可获得很好的优化效果,但是那些复杂SQL错综 ...

  7. Oracle自带工具sql优化集-SQL Tuning Advisor (使用心得体会)

    如何有效的诊断和监控高负载的SQL对于DBA来说并非是件容易的事情,对SQL语句手工调优需要很多的经验和技巧, 结合个人经验常见如下问题:          . 对SQL语句本身进行优化以便获得更优的 ...

  8. Oracle 11g 禁用 SQL Tuning Advisor 与 auto space advisor

    生产上有一套11g数据库alert.log报错ORA-16957: SQL Analyze time limit interrupt.  查询MOS相关文档Troubleshooting: ORA-1 ...

  9. 【转】使用SQL Tuning Advisor STA优化SQL

    SQL优化器(SQL Tuning Advisor STA)是Oracle10g中推出的帮助DBA优化工具,它的特点是简单.智能,DBA值需要调用函数就可以给出一个性能很差的语句的优化结果.下面介绍一 ...

随机推荐

  1. 关于集合的小demo

    /*1.分析以下需求,并用代码实现: (1)有如下代码: (2)定义方法统计集合中指定元素出现的次数,如"e" 3,"f" 2,"g" 4* ...

  2. STL--C++中 destory() 和deallocate()以及delete函数的相关性和区别性,destorydeallocate

    这里非常的绕口  需要仔细的来看看: destory(): 显示调用一个对象的析构函数 相当于释放一个对象需要释放的一些动态内存 为下次真正释放对象做准备 deallocate():真正的释放一个内存 ...

  3. 2015年第六届蓝桥杯省赛试题(JavaA组)

    1.结果填空 (满分3分)2.结果填空 (满分5分)3.结果填空 (满分9分)4.代码填空 (满分11分)5.代码填空 (满分13分)6.结果填空 (满分17分)7.结果填空 (满分21分)8.程序设 ...

  4. Linux下管理员强行踢出用户的命令使用方法

    Linux强制踢出用户命令: 一.输入w命令查看已登录用户信息 [root@KW_S01_192.168.1.106_A ~]# w 19:22:31 up  2:11,  3 users,  loa ...

  5. IIS如何避免子web应用程序中继承根目录web.config配置

    1.一种方式,需要改动根目录的web.config(不是很推荐) <?xml version="1.0"?> <configuration> <loc ...

  6. UIPasteboard

    1.UIPasteboard 简介 顾名思义,UIPasteboard 是剪切板功能,因为 iOS 的原生控件 UITextField.UITextView.UIWebView, 我们在使用时如果长按 ...

  7. webpack4 入门(一)

    一.简介 WebPack可以看做是模块打包机:它做的事情是,分析你的项目结构,找到JavaScript模块以及其它的一些浏览器不能直接运行的拓展语言(Scss,less, TypeScript等),并 ...

  8. springboot mybatis自定义枚举enum转换

    原文链接:https://blog.csdn.net/u014527058/article/details/62883573 一.概述 在利用Spring进行Web后台开发时,经常会遇到枚举类型的绑定 ...

  9. luogu1210 回文检测

    Manacher 正确读法:抹内A撤(马拉车) (跟着假硕学英语) 我们把原来的字符串,通过玄学处理,变成只留下字母,且每两个字母之间有一个奇怪的字符的那种Manacher专用字符串. 建立双射关系f ...

  10. Qt 学习之路 2(12):菜单栏、工具栏和状态栏

    Home / Qt 学习之路 2 / Qt 学习之路 2(12):菜单栏.工具栏和状态栏 Qt 学习之路 2(12):菜单栏.工具栏和状态栏  豆子  2012年9月10日  Qt 学习之路 2  2 ...