Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Sql tuning

Introduce SQL Tuning technology and the SQL Tuning tool -- SQLBooster

  • Login to see the comments

  • Be the first to like this

Sql tuning

  1. 1. SQL Tuning Introduce the SQL tuning tool, SQLBooster, and SQL tuning technology
  2. 2. Why choose SQLBooster  No deep DBA knowledge required  Developer can do most tuning jobs without DBA assistant  Visualized performance data  Quick identify performance bottleneck  Break complex queries to simple ones to be tuned  Analysing result can be exported for DBA to do further review
  3. 3. Preparation
  4. 4. Download  Download the latest version SQLBooster from  Download Oracle Instant Client from html
  5. 5. Install & configure Oracle Instant Client  Set environment parameter ORACLE_HOME as Oracle Instant Client folder e.g. ORACLE_HOME=C:oracleinstantclient_12_x64  Create tnsfile NetworkAdmintnsnames.ora under ORACLE_HOME Tips: please send a request to dba team to get the latest tnsnames file.
  6. 6. Install SQLBooster  Run setup.exe to install the software  Get a trial license when first run it (We will get the full license later) Click “Get Trial Lic” Save a private key file Submit registration info & get license key in your email box Note: Ensure you ticked “Trial Key” to get a free key Check your spam folder if you did not see the key Input the license key to register the software
  7. 7. Configure SQLBooster  “File”=>”Preference”  Recommended Settings  Exceed Analysing Time 60 seconds (Ticked)  Exceptions: ORA-00600,ORA-07445,ORA-01003  Retries After Aborted: 0  Untick “Quick Analyze”  OCI Lib Path: <Your Oracle Instant Client Path>  Session Pre-Execute SQL: Recommended for VPD only  Associated Extensions: tick *.stw, *.anz
  8. 8. VPD Setting  Create a SQL file, input the portal context command Example: Begin vpd.set_context(portal_id => 123); end; /  Go to File => Preference, set this file in “Session Pre-Execute SQL” Tips: Your can create multiple files for different portals, change the file path before you login the target portal
  9. 9. Authorization  The software requires two user accounts when login  App user: For running the SQL to be tuned. You can also use to do the necessary queries  DBA User: For running the background command. You cannot use it directly.  Authorization Control: Sent below form to DBA team to get the authorization Product Name: e.g. Payroll Environment: e.g. Integration QA App User Name: e.g. payrollappuser Attach the existing authorization file: C:Users<UserName>AppDataLocalSQLBoosterSQLBoosterA.dat You will receive a same name file from DBA team to replace your existing file
  10. 10. Login  Click “New” button, or Click “File” => “New”  Choose the connection from the list  Do not change anything  Make sure PVD script is selected correctly if you login a PVD environment
  11. 11. SQL Tuning
  12. 12. Run Your SQL  Input your SQL in the SQL Editor, Click “Run” button (or F3)  A popup window for inputting default value for the missed bind variables  Input a default value for all bind variables, or  Click “Cancel”, input different values for the variables
  13. 13. Review the Performance Data  Performance Statistics Data of last SQL running will be shown at the bottom
  14. 14. Review Execution Plan  Execution plan will be shown on the right side after SQL finished  The high-cost operations will be highlighted  For large plan, you can click “Spot” button the locate the high-cost operations quickly
  15. 15. Tuning Tips  At this stage, you will able to do initial tuning based on these informations  Check your SQL part that is related to the high-cost operations For example, if the high-cost operation is a Full Table Scan, and there is a Filter Predicate on it, you may consider to create an index on these filter columns. Tips: Move the mouse to the operation, it will show the predicates if there is a * or/and # shown in this operation. This will help your to locate your code  The performance statistics data is important metric to determine if your changes helped to improve the performance. Tips: Some important statistics data: consistent gets, physical reads, sorts (memory)
  16. 16. Further Analyse Your SQL  Analysing SQL will analyse the SQL structure first, then generate a SQL tree  It will analyse the SQL from the bottom to the top, analyse each subquery in your SQL  For those complex SQLs, further analysing will help you to identify the bottleneck quickly  You don’t have to tune a large complex SQL, you only need to tune the spotted small subquery instead
  17. 17. Parse the SQL Structure  Click “SQL Tree”. Your SQL will be parsed as a SQL tree  You can view the subqueries by clicking any subquery/sub_query node in the tree. The constructed subquery will be shown in the SQL editor on the right side
  18. 18. Analyse SQL  Click “Analyse” button to analyse the pared SQL  Every subquery will be analyzed  Single subquery analysing process will be aborted once analysing time more than 60 seconds (set in the “Preference”)  Analyse result will be show on the bottom  Subqueries with poor performance are highlighted  Review & Tune the highlighted subqueries from top to bottom
  19. 19. Review & Tune the poor performance subquery  Click the highlighted analysed result to show the SQL text in the SQL Editor  Double click the highlighted result to show the plan and performance data
  20. 20. Tuning with SQL Profile  Tune SQL quickly, do not require to bounce applications  Fit for the SQLs not easy to be restructured. E.g. the dynamic SQL constructed in the Java Applications; the BI SQL constructed by OBIEE.  Easy and quick to rollback the change(s)
  21. 21. Apply SQL profile generated by a hinted SQL  Add SQL hints in the original SQL to tune it. E.g. index, leading, use_nl. Run it  Click “Plan Outline” tab under the plan tree  Click “Edit” to pop up the outline data  Select the SQL ID of the original SQL from the dropdown list  Click “Apply”
  22. 22. Advanced Usage
  23. 23. Identify a long-running SQL  Click “Sess” button or F5  Tick “Running SQL Only”  Click the column “SQL Running Time” to sort the result by running time  Select a (your) long running SQL  Click “Drill in SQL” to review the performance and tune it
  24. 24. Identify a top SQL  Click “Top SQL” button or F6  Choose a top type (Waits, CPU, IO, PGA or Temp Space)  Select a (your) top SQL to check the SQL text  Click “Drill in SQL” to review the performance and tune it
  25. 25. Identify the blocking&blocked sessions  Click “Block Tree” button, or F7  Review the session information  Click “Refresh” to check if the lock still exists  Select a session, click “Session History” to review the session activities  Do not click “Kill Session”, though the privilege has been revoked from the dba account
  26. 26. SQL Advisor (Not recommend to use)  Click “Advisor” button  Input the SQL text to be advised in the editor  Click “Advise” button to run an advisor task  Select a task to review the report
  27. 27. Seeking Assistant from DBA Team  Click “Export” to export your analyse result, or  Click “File”=>”Save Work” to save everything in a file  Send the exported or saved file to DBA team, including below information Product Name: e.g. Payroll Environment: e.g. Integration QA App User Name: e.g. payrollappuser VPD Portal ID (If applicable): e.g. 123456
  28. 28. Customized Reports  DBA Team has prepared some customized reports. Copy them to CustomReprots folder under the installation locationg  Click “…” button  Choose a report name from the dropdown list For example, if you want to check the index and indexed columns of a table, choose “TableIndex” report, input the table name as the value of the variable, all indexes and their columns will be listed
  29. 29. Q & A