Overview

    Purpose

    This tutorial shows you how to use the sql Tuning Advisor feature in Oracle sql Developer 3.2.

    Time to Complete

    Approximately 40 minutes

    Introduction

    The sql Tuning Advisor analyzes high-volume sql statements and offers tuning recommendations. It takes one or more sql statements as an input and invokes the Automatic Tuning Optimizer to perform sql tuning on the statements. It can run against any given sql statement. The sql Tuning Advisor provides advice in the form of precise sql actions for tuning the sql statements along with their expected performance benefits. The recommendation or advice provided relates to the collection of statistics on objects,creation of new indexes,restructuring of the sql statement,or creation of a sql profile. You can choose to accept the recommendation to complete the tuning of the sql statements.

    Oracle Database can automatically tune sql statements by identifying problematic sql statements and implementing tuning recommendations using the sql Tuning Advisor. You can also run the sql Tuning Advisor selectively on a single or a set of sql statements that have been identified as problematic.

    In this tutorial,you learn how to run and review the recommendations of the sql Tuning Advisor.

    Note: Tuning Advisor is part of the Tuning Pack,one of the Oracle management packs and is available for purchase with Enterprise Edition. For more information see The Oracle Technology Network or theonline documentation.

    Hardware and Software Requirements

    The following is a list of hardware and software requirements:

  • Oracle Database 11g Enterprise Edition with access to the Tuning and Diagnostic management packs and with the sample schema installed.
  • Oracle sql Developer 3.2.

Prerequisites

  • Download Oracle sql Developer 3.2 here.

Note: For best results,use Firefox or Chrome browsers to view this tutorial.

Creating a Database Connection

    The first step to managing database objects using Oracle sql Developer 3.2 is to create a database connection.

    Perform the following steps to create a database connection:

    Note: If you already have database connections for HR and SYstem,you do not need to perform the following steps. You can move toProviding Privileges to the Hr Usertopic.

    If you have installed the sql Developer icon on your desktop,click the icon to start your sql Developer and move to Step 4. If you do not have the icon located on your desktop,perform the following steps to create a shortcut to launch sql Developer 3.2 from your desktop.

    Open the directory where the sql Developer 3.2 is located,right-click sqldeveloper.exe (on Windows) or sqldeveloper.sh (on Linux) and select Send to > Desktop (create shortcut).

    On the desktop,you will find an icon named Shortcut to sqldeveloper.exe. Double-click the icon to open sql Developer 3.2.

    Note: To rename it,select the icon and then press F2 and enter a new name.


    Your Oracle sql Developer opens up.

    In the Connections navigator,right-click Connections and select New Connection.

    The New / Select Database Connection dialog opens. Enter the connection details as follows and clickTest.

    Connection Name: system

    Username: system

    Password: <your_password > (Select Save Password)

    Hostname: localhost

    SID: <your_own_SID>


    Check for the status of the connection on the left-bottom side(above the Help button). It should readSuccess. ClickSave and then click Connect.

    In the Connections navigator,to create a new connection to the hr schema,right-clickConnections and selectNew Connection.

    The New / Select Database Connection dialog opens. Enter the connection details as follows and clickTest.

    Connection Name: hr

    Username: hr

    Password: <your_password > (Select Save Password)

    Hostname: localhost

    SID: <your_own_SID>

    Check for the status of the connection on the left-bottom side(above the Help button). It should readSuccess. ClickSave and then click Connect.

Providing Privileges and Removing the Existing Statistics on the HR User

    A user requires certain privileges to run the sql Tuning Advisor. Also,in order to collect and manage statistics on the HR schema,the existing statistics need to be cleared. Below are the steps to grant sql Tuning Advisor privileges and to remove the existing statistics on the hr user.

    Click sql Worksheet and select system user.


    To grant privileges to the hr user to run the sql Tuning Advisor,enter the following lines of code. Click Run Script.
    grant advisor to hr;
    grant administer sql tuning set to hr;


    The output for the statements is displayed.


    The Oracle database allows you to collect statistics of many different kinds in order to improve performance. To illustrate some of the features the sql Tuning Advisor offers,clear the existing statistics from the HR schema.

    To delete the schema statistics,enter the following line of code.

    exec DBMS_STATS.DELETE_SCHEMA_STATS ('hr');

    Select the statement and click Run Statement

    With the DBMS_STATS package you can view and modify optimizer statistics gathered for database objects.TheDELETE_SCHEMA_STATS procedure deletes statistics for an entire schema.


    The outputs for the statements are displayed.


Running the sql Tuning Advisor on a sql statement

    In this topic,you run the sql Tuning Advisor on a sql statement. Four types of analysis are performed by the sql Tuning Advisor on the sql statement.
    All the recommendations are displayed in the Overview. You can also view each recommendation individually.

    Open the sql Worksheet for the hr user by clicking sql Worksheet.


    Enter the following sql statement in the worksheet.
    select sum(e.salary),avg(e.salary),count(1),e.department_id from departments d,employees e group by e.department_id order by e.department_id;

    Select the sql statement and click sql Tuning Advisor .


    The sql Tuning Advisor output appears.


    In the left navigator,click Statistics. In this analysis,objects with stale or missing statistics are identified and appropriate recommendations are made to remedy the problem.


    In the left navigator,click sql Profile. Here,the sql Tuning Advisor recommends to improve the execution plan by the generation of a sql Profile.


    Click the Detail tabbed page to view the sql Profile Finding.


    In the left navigator,click Indexes. This recommends whether the sql statement might benefit from an index. If necessary,new indexes that can significantly enhance query performances are identified and recommended.


    Click the Overview tabbed page. In this case,there are no index recommendations.


    In the left navigator,click Restructure sql. In this analysis,relevant suggestions are made the restructure selected sql statements for improved performance.



Implementing sql Tuning Advisor Recommendations

    You can implement the sql Tuning Advisor recommendation feature. This will enable you to update the statistics in hr schema. Perform the following steps to implement the sql Tuning Advisor recommendations:

    In the Connections navigator,right-click hr and select Gather Schema Statistics....


    In Gather Schema Statistics,select Estimate Percent as100 from the drop-down list so that all rows in each table are read. This ensures that the statistics are as accurate as possible.


    Click Apply.


    A confirmation message appears. Click OK.


    To run the sql Tuning Advisor on the sql statement again,select the sql statement and click sql Tuning Advisor.


    The sql Tuning Advisor output appears. By gathering statistics,the Statistics and sql Profile advice is Now removed.


    In the left navigator,click each of the sql Tuning Advisor Implement Type to check if all the recommendations have been implemented.


    Note the issues reported to you:

    Note the issues reported to you:

    Note that the Restructure sql recommendation to remove an unused table remains.

    Remove the "departments" table in the sql statement and click sql Advisor.

    select sum(e.salary),e.department_id from employees e
    group by e.department_id order by e.department_id;


    The output appears. All of the advice recommendations have been removed.



Summary


    In this tutorial,you have learned how to:

  • Create a Database Connection
  • Provide Privileges to the HR User
  • Run the sql Tuning Advisor on a sql statement
  • Implement sql Tuning Advisor Recommendations

Credits

  • Lead Curriculum Developer: Dimpi Sarmah,Sharon Stephen
  • Other Contributors: Ashley Chen,Swarnapriya Shridhar,Nancy Greenberg

ORACLE SQL DEVELOPER 优化SQL语句的更多相关文章

  1. ORACLE SQL DEVELOPER 优化SQL语句

    OverviewPurposeThistutorialshowsyouhowtousethesqlTuningAdvisorfeatureinOraclesqlDeveloper3.2.TimetoCompleteApproximately40minutesIntroductionThesqlTuningAdvisoranalyzeshigh-volumesqlstatementsandoffer

  2. php – 使用MySQL的通配符IP禁止

    我正在尝试使用MySQL在我的网络应用程序中实现IP禁止系统,我知道我可以使用.htaccess来实现它,但这对我来说不是很好.基本上我目前的表是:在PHP中我查找数据库中的客户端IP以查看它是否被阻止:现在..这工作正常,但我希望能够在数据库中输入通配符IP范围,如:怎么做?

  3. php – 如何优化这个MySQL表?

    第一个.期.实际上你会失去更多.存储在int列中的时间戳将仅占用4个字节的空间.虽然以字符串格式存储的相同时间戳将占用10个字节.

  4. php – 每页最大SQL查询

    我应该停止开发一段时间并重构代码,删除不使用的SQL查询,并投入时间来提高这方面的性能?这可能听起来有点混乱,所以恢复:每个页面上运行的查询数量是不是一个事实上的最大数量,不会影响服务器?谢谢.与数据库匹配的总数也与页面浏览量成正比.因此,如果每页的页面浏览量*查询数量超过数据库的容量,那么您有问题.显然,流量从站点到网站的流量变化很大,数据库容量也是如此,所以真的不能有一个目标.

  5. php – MySQL索引 – 根据此表和查询的最佳做法是什么?

    我有这个表我正在考虑在x和y之间发布每个查询在同一时间,我想添加与publishedon在where子句发布,cat_id,source_id这样的事情那个查询是确定的,直到现在没有索引,但是当尝试使用orderon,它变得太慢,所以我使用这个索引它的工作和发布的顺序变得很快,现在我想通过这样的意见订购这是解释这个查询太慢了,因为ORDERBY的意见是DESC那么我试图删除旧的索引并添加它它也太慢了如果我在发行版上只使用单个索引呢?

  6. CentOS7.4上2分钟快速安装MySQL5.6

    所以直接yum-yinstallnumactl就可以解决这个问题了.再次初始化MysqL,此时初始化成功三、准备启动脚本并开启MysqL服务登录MysqL给MysqL初步优化:给MysqL服务设置登录密码:到此处安装完成四、CentOS7.4上MysqL5.6.39快速安装步骤:介绍完毕,希望可以帮助初级技术人员

  7. php – 操作连接到Mysql数据库的成本有多高?

    在代码的某些功能中,PHP将使用循环在相同的表上执行数百次或在某些情况下数千次查询.目前,它为每个查询创建一个新的数据库连接.这次手术有多贵?通过重复使用相同的连接,我会看到显着的速度增加吗?可能需要进行相当多的重构才能更改此行为并使用相同的数据库.PHP使用mysql_connect连接数据库.根据我在这里所说的,你会推荐其他明显的优化(我已经读过关于锁定表的例子……

  8. php – 对于简单的操作,Cassandra比Mysql慢得多?

    我看到很多声明如下:“Cassandra写入速度非常快”,“Cassandra的读取速度比写入慢,但比MysqL快得多”在我的windows7系统上:我安装了默认配置的MysqL.我安装了PHP5的默认配置.我安装了默认配置的Casssandra.在MysqL上进行简单的写测试:“INSERTINTOwp_testVALUES”给我结果:0.0002适用于1000个刀片:0.1106在Cassandra上进行简单相同的写测试:$column_faily->insert给出结果:0.005适用于1000个插

  9. php – 使用$_SESSION来缓冲/缓存MySQL查询

    几百个并发SQL查询对于共享服务器来说是一个问题,并且使用$_SESSION作为缓冲区来减轻其中的一部分.Isthereawaytoexecuteafunctionwhenthesessionsisdestroyedbytimeoutorclosingofthebrowser?Areacoupleofhundredconcurrentsqlqueriesgoingtobeaproblemforasharedserverandistheideaofusing$_SESSIONasabuffergoingto

  10. php – MySQL没有正确选择行(有时)

    更新:@miken32在下面的评论中建议我尝试一下EXPLAINSELECT…

随机推荐

  1. ORACLE SQL DEVELOPER 优化SQL语句

    OverviewPurposeThistutorialshowsyouhowtousethesqlTuningAdvisorfeatureinOraclesqlDeveloper3.2.TimetoCompleteApproximately40minutesIntroductionThesqlTuningAdvisoranalyzeshigh-volumesqlstatementsandoffer

返回
顶部