Presentation is loading. Please wait.

Presentation is loading. Please wait.

SQLXPress Visual Query Tuner Copyright © 2014 Merlon Software Corporation.

Similar presentations


Presentation on theme: "SQLXPress Visual Query Tuner Copyright © 2014 Merlon Software Corporation."— Presentation transcript:

1 SQLXPress Visual Query Tuner Copyright © 2014 Merlon Software Corporation

2 Agenda Introduction to Visual Query Tuner (VQT) How to generate a plan How to read a plan Measuring query performance Influencing plans Comparing performance Auto-tuner

3 Introduction VQT is a Windows ® application Connects to SQLXPress server process running on a NonStop system Supports both MX and MP queries  MX version 2.3.4 or later  MP version 350 or later

4 Introduction VQT uses a NonStop SQL database to store query details  Each query has a name and plain language description Keeps a history of ”snapshots” for each query Each snapshot contains:  Query text  Plain language description of snapshot  Params, defines, and CONTROL statements  Execution plan  Execution statistics

5 Introduction Why use VQT?  Learn how query is executed  Get performance characteristics of query  Identify problems in a plan  Try remedial changes, for example: Update statistics Database changes (create index) Query changes (predicate re-write) Use of SQL CONTROL statements (CQD, CQS)  Compare performance after remediation

6 How to generate a plan Use the Query tab to enter query detail  Color-coded syntax  Auto-completion  Query text will most likely be pasted from clipboard Click Take Snapshot to save query, generate plan, and collect execution statistics

7 How to generate a plan The first Take Snapshot command prompts for a query name Subsequent Take Snapshot commands for the same query use the same name  Use Save Snapshot As to save under a new name  Use New command to start working on a new query Each snapshot is identified by the query name and the time the snapshot was taken

8 How to generate a plan Snapshot Management  Take snapshot command adds a new snapshot  Delete snapshot command deletes current snapshot Also has delete snapshots dialog to delete multiple snapshots with one command  Easy to navigate snapshots from toolbar  Snapshot retention – automatically delete oldest snapshot when retention limit exceeded  Use any snapshot as staring point for new query “experiment”

9 How to read a plan Plans are displayed in the Execution Plan tab Plans displayed in three different ways:  Summary – key attributes of each operator  Details – plan outline, plus complete details on each operator  Plan Diagram – a truly visual plan depiction

10 How to read a plan Plan Summary (MX) Lists each operator Key operator attributes Similar to HP’s VQP

11 How to read a plan Plan Summary (MP) Lists each operation Shows index and table selectivity

12 How to read a plan Plan Details (MX) Tree view on left provides plan outline Complete plan text on right shows operator details Click a node in the outline to show details for selected operator Similar to HP’s VQP, but viewing operator details is much easier

13 How to read a plan Plan Details (MP) Outline shows steps and operations Click on node in outline to show details of step / operation

14 How to read a plan Plan Diagram (MX) Plan displayed as a tree Much more intuitive layout than traditional tree view There is a lot of information in the diagram

15 How to read an MX plan diagram Plan fragments are color-coded Data flows between fragments shown as heavy dotted line Data flows within a fragment shown as lighter solid lines Full table / index scan operators have heavy red borders Operators that run in parallel are “stacked” Estimated row count displayed above each operator Operator details displayed in popup window

16 How to read a plan Operator details can be displayed in a popup window Move mouse over an operator to display details Move mouse away, popup is dismissed

17 How to read a plan Plan Diagram (MP) Plan displayed as a tree Both steps and operations are represented by nodes Similar to MX diagram

18 How to read a plan Various ways to mitigate problems displaying large plans  Scroll and zoom  Fit to page  Left to right – may be better than top to bottom on wide-screen monitors  Simplified MX plan diagrams

19 How to read a plan Simplified Plan Tree (MX) Suppress display of:  ESP Exchange  Split Top  Partition Access Fewer nodes to display Diagram visually indicates fragment boundaries and parallel operators

20 Measuring query performance Take Snapshot command automatically runs query to gather execution statistics  Can be turned off in Options Use Run Query command to explicitly run the query without creating a new snapshot  Use to collect multiple samples of execution statistics  Avoid cache bias by running query more than once Run Query does not display query results  Rows are discarded as soon as they are received by the server process Execution Statistics tab shows results from Run Query

21 Measuring query performance Execution Statistics Shows compile time and execution time Per-table statistics, like those shown by MXCI / SQLCI Shows min, max, avg values for multiple samples

22 Influencing plans There are various techniques to try and make query run faster  Update Statistics  Adjust access paths For example, add or modify an index  Use SQL Control statements For example, force join order, join method, parallelism  Adjust the query text Rewrite the query while still returning the same set of rows

23 Influencing plans - Update Statistics Use View Table Statistics command Current statistics are displayed for tables in the query From here you can update statistics

24 Influencing plans – Access Paths Use View Access Paths command Access paths for tables in query are displayed From here you can create or drop indexes Click Object Properties to view properties (including DDL)

25 Influencing plans – SQL Control Statements For MX:  CONTROL QUERY DEFAULT  CONTROL QUERY SHAPE  CONTROL TABLE For MP:  CONTROL QUERY  CONTROL EXECUTOR  CONTROL TABLE Specify CONTROL statements on Query tab Stored in database as part of query snapshot

26 Influencing plans example - MX CQD Example of CQD Click Edit to set CQD values

27 Influencing plans example - MX CQD Edit CQD dialog Click on link to get popup help on a CQD attribute Many attributes have pick-list of valid values Values that are Not Specified will take default value

28 Influencing plans example - MX CQS CQS tab Enter CQS statement Click Show to issue SHOWSHAPE to get current shape which you can then edit  Drag divider up to make more room when editing shape

29 Influencing plans example – MP Control Executor / Query tab  Parallel Plans  MDAM  Interactive Access Join Control tab  Specifies join sequence and join method Control Table tab  Additional control table statements

30 Influencing plans – adjust query text Change the query text in a way that helps the optimizer produce a better plan, but returns the same rows as before Avoid using columns as function parameters (including CAST) to allow use of an index Add additional redundant predicates to avoid full table scans Don’t aggregate data in the application, use the SQL aggregate functions Only select the columns you actually need

31 Influencing plans – example use of functions Suppose ORDERPLACED is a TIMESTAMP column To query yesterday’s orders:  Instead of: CAST (O.ORDERPLACED AS DATE) = CURRENT_DATE - INTERVAL '1' DAY  Use: O. ORDERPLACED >= CAST(CURRENT_DATE - INTERVAL '1' DAY AS TIMESTAMP) AND O. ORDERPLACED < CAST(CURRENT_DATE AS TIMESTAMP) If there is an index on ORDERPLACED this will avoid a full table scan

32 Influencing plans – example redundant predicates Instead of: select * from dept d where d.deptnum in (1000, 3000, 4000) Use: select * from dept d where d.deptnum in (1000, 3000, 4000) and d. deptnum >= 1000 and d. deptnum <= 4000 This will avoid a full table scan There are more examples of query rewrite in the VQT User Guide

33 Comparing performance After you make adjustments to a query, you should determine if the performance has improved  Take a new snapshot  Compare the performance with previous snapshots Use the View Performance Charts command to compare execution statistics

34 Comparing performance Chart shows stats for all snapshots Various Data Values:  Response Times  Records Read / Used  Number of Messages  Message Bytes Show sample:  Minimum  Maximum  Average

35 Comparing performance This is example uses line chart Shows records read and records used

36 The Auto-tuner Try other remediation techniques first Auto-tuner only works on SELECT statements May not work on some queries  Publish / subscribe  Queries using complex views Multi-step wizard Allows user to take snapshot based on recommended query and SQL control statements

37 The Auto-tuner Goals  Get a robust execution plan  Get good (but not necessarily the best) performance How it works  Analyzes query text  Determines available access paths  Collects metrics on joins and predicates Can use queries against tables, or ask the user  Generates recommendations: May include create / modify index recommendations Re-written query text SQL CONTROL statements

38 The Auto-tuner For robustness:  Use nested joins Scale well with increased table sizes Lower memory requirements compared to hash and merge joins Don’t require temporary disk space for hash or sort For performance  Determine best join order Drive query from table with best filter For the rest of the join order –Prefer joins to master tables over detail tables –Prefer joins to well filtered tables –Prefer joins with lower join ratios

39 The Auto-tuner For performance:  Support driver table filter with an index  Support joins to detail tables with index on foreign key  Prohibition on hash joins may be relaxed in some circumstances

40 The Auto-tuner Recommendations report Includes query re-write and SQL CONTROL statements

41 The Auto-tuner Post analysis actions Select a recommendation and click Go to implement

42


Download ppt "SQLXPress Visual Query Tuner Copyright © 2014 Merlon Software Corporation."

Similar presentations


Ads by Google