Oracle的SQL Tuning Advisor(STA) 到底做了什么?

php中文网
发布: 2016-06-07 17:29:47
原创
977人浏览过

SQL Tuing Advisor(STA) 是Automatic Tuning Optimizer(自动优化调整器)的一部分。在前面的文章使用SQL tuning advisor(STA)自动

sql tuing advisor(sta) 是automatic tuning optimizer(自动优化调整器)的一部分。在前面的文章使用sql tuning advisor(sta)自动优化sql中描述了sql tuing advisor(sta)的相关背景并给出示例。本文主要是描述sta底层到底为我们作了什么使得sql语句得以优化,同时演示绑定变量的情形下接受sql profile后,后续sql是否采纳对应的sql profile的执行计划的情形。最后给出了awr中的sql通过sta tuning的脚本。

1、使用STA优化library cache中的SQL

--演示环境
hr@CNMMBO> select * from v$version where rownum

BANNER
----------------------------------------------------------------
Oracle Database 10g Release 10.2.0.3.0 - 64bit Production

--下面直接根据sql_id优化library cache中的SQL语句
hr@CNMMBO> @tune_cache_sql
Enter value for input_sql_id: 8rnmr2dpnjvk8
Enter value for input_task_name: hr_query

RECS
---------------------------------------------------------------------------------------
GENERAL INFORMATION SECTION
-------------------------------------------------------------------------------
Tuning Task Name                  : hr_query
Tuning Task Owner                : HR
Scope                            : COMPREHENSIVE
Time Limit(seconds)              : 1800
Completion Status                : COMPLETED
Started at                        : 06/07/2013 11:40:27
Completed at                      : 06/07/2013 11:40:28
Number of SQL Profile Findings    : 1
Number of SQL Restructure Findings: 1

-------------------------------------------------------------------------------
Schema Name: HR
SQL ID    : 8rnmr2dpnjvk8
SQL Text  : SELECT      /*+ ORDERED */
                  *
              FROM employees e, locations l, departments d
              WHERE e.department_id = d.department_id AND l.location_id =
            d.location_id AND e.employee_id

-------------------------------------------------------------------------------
FINDINGS SECTION (2 findings)
-------------------------------------------------------------------------------

1- SQL Profile Finding (see explain plans section below)
--------------------------------------------------------
  A potentially better execution plan was found for this statement.

  Recommendation (estimated benefit: 90.74%)
  ------------------------------------------
  - Consider accepting the recommended SQL profile.
    execute dbms_sqltune.accept_sql_profile(task_name => 'hr_query', replace
            => TRUE);

2- Restructure SQL finding (see plan 1 in explain plans section)
----------------------------------------------------------------
  An expensive cartesian product operation was found at line ID 3 of the
  execution plan.

  Recommendation
  --------------
  - Consider removing the "ORDERED" hint.

  Rationale
  ---------
    The "ORDERED" hint might force the optimizer to generate a cartesian
    product. A cartesian product should be avoided whenever possible because
    it is an expensive operation and might produce a large amount of data.

-------------------------------------------------------------------------------
EXPLAIN PLANS SECTION
-------------------------------------------------------------------------------

1- Original With Adjusted Cost
------------------------------
Plan hash value: 3871948714

-----------------------------------------------------------------------------------------------
| Id  | Operation                    | Name          | Rows  | Bytes | Cost (%CPU)| Time    |
-----------------------------------------------------------------------------------------------
|  0 | SELECT STATEMENT              |              |    85 | 11645 |  103  (1)| 00:00:02 |
|*  1 |  HASH JOIN                    |              |    85 | 11645 |  103  (1)| 00:00:02 |
|  2 |  TABLE ACCESS FULL          | DEPARTMENTS  |    27 |  540 |    3  (0)| 00:00:01 |
|  3 |  MERGE JOIN CARTESIAN        |              |  1973 |  225K|    99  (0)| 00:00:02 |
|  4 |    TABLE ACCESS BY INDEX ROWID| EMPLOYEES    |    86 |  5848 |    3  (0)| 00:00:01 |
|*  5 |    INDEX RANGE SCAN          | EMP_EMP_ID_PK |    86 |      |    1  (0)| 00:00:01 |
|  6 |    BUFFER SORT                |              |    23 |  1127 |    96  (0)| 00:00:02 |
|  7 |    TABLE ACCESS FULL        | LOCATIONS    |    23 |  1127 |    1  (0)| 00:00:01 |
-----------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号