Contents Index Text plans Accessing the plan

ASA SQL User's Guide
  Query Optimization and Execution
    Reading access plans

Graphical plans


There are two types of graphical plan: the graphical plan, and the graphical plan with statistics. To choose a plan type in Interactive SQL, open the Options dialog from the Tools menu, and click the Plan tab. To access the plan with SQL functions, see Accessing the Plan with SQL functions.

Once the graphical plan is displayed, you can configure the way it is displayed by right-clicking the left pane and choosing Customize.

You can print the graphical plan for later reference. To print the plan, right-click a node and choose Print.

To obtain context-sensitive help for each node in the graphical plan, select the node, right-click it and choose Help. For example, right-click Nested Loops Join and choose Help for information about the resources used by that part of the execution. There is also pop-up information that is available by hovering your cursor over each element in the graphical plan.

Graphical plan 

The graphical plan provides a great deal more information than the short or long plans. You can choose to see either the graphical plan, or the graphical plan with statistics. Both allow you to quickly view which parts of the plan have been estimated as the most expensive. The graphical plan with statistics, though more expensive to view, also provides the actual query execution statistics as monitored by the server when the query is executed, and permits direct comparison between the estimates used by the query optimizer in constructing the access plan with the actual statistics monitored during execution. Note, however, that the optimizer is often unable to precisely estimate a query's cost, so expect there to be differences. The graphical plan is the default format for access plans.

The graphical plan is designed to provide some key information visually:

Each of these display features is customizable.

Following is the same query that was used to describe the short and long text plans, presented with the graphical plan. The diagram is in the form of a tree, indicating that each node requests rows from the nodes beneath it. The Lock node indicates that the result set is materialized, or that a row is returned to an application. In this case, the sort requires that results are materialized. At level 0, rows aren't really locked: Adaptive Server Anywhere just ensures that the row has not been deleted since it was read from the base tables. At level 1, a row is locked only until the next row is accessed. At levels 2 and 3, read locks are applied and held until COMMIT.

You can obtain detailed information about the nodes in the plan by clicking the node in the graphical diagram. In this example, the nested loops join node is selected. The information in the right pane pertains only to that node.

The Plan tab in Interactive SQL, showing the graphical plan for a query.

For more information about abbreviations used in the plan, see Abbreviations used in the plan.

Graphical plan with statistics 

The graphical plan with statistics shows you all the estimates that are provided with the graphical plan, but also shows actual runtime costs of executing the statement. To do this, the statement must actually be executed. This means that there may be a delay in accessing the plan for expensive queries. It also means that any parts of your query such as deletes or updates are actually executed, although you can perform a rollback to undo these changes.

Use the graphical plan with statistics when you are having performance problems, and the estimated row count or run time differs from your expectations. The graphical plan with statistics provides estimates and actual statistics for you to compare. A large difference between actual and estimate is a warning sign that the optimizer might not have sufficient information to prepare correct estimates.

The database options and other global settings that affect query execution are displayed for the root operator only.

Following are some of the key statistics you can check in the graphical plan with statistics, and some possible remedies:

Following is an example of the graphical plan with statistics. Again, the nested loops join node is selected. The statistics in the right pane indicate the resources used by that part of the query.

The Plan tab in Interactive SQL, showing the graphical plan with statistics for a query.

For more information about code words used in the plan, see Abbreviations used in the plan.

Selectivity in the plan 

Following is an example of the Predicate showing selectivity of a search condition. In this example, the Filter node is selected, and the statistics pane shows the Predicate as the search condition and selectivity statistics.

Graphical plan with statistics showing the predicate.

This predicate is

department.dept_name = 'Sales' : 20% COLUMN

This can be read as follows:

Note: If you select the graphical plan, but not the graphical plan with statistics, the final two statistics are not displayed.


Contents Index Text plans Accessing the plan