Obtaining an Execution Plan

You can select a SQL statement from SQL Editor and use the context menu to visually display the execution plan of the statement. This feature allows developers or database administrators to optimize the database and SQL code. SQL developers or database administrators can tell from the query plan when to, for example, create table indexes, reorganize data tables, or change the way a query is written. This feature can be useful during troubleshooting and fine-tuning performance.

The query plan shows actual statistics when you show it during execution, and estimated statistics when you get an execution plan without executing the SQL.

In the Query Plan preferences page you can choose the plan orientation, whether to show the plan while execution is taking place, the style of plan displayed, and continuation behavior if an error occurs in producing the plan.

Before you can get a query plan from within a SQL file, the SQL file must be connected to an Adaptive Server Anywhere or Adaptive Server Enterprise connection profile.

To obtain an execution plan for a particular statement:

  1. In SQL Editor, open a SQL file or procedural object.

  2. Select the statement or statements for which you want to display an execution plan.

  3. Right-click in SQL Editor to display the context menu.

    If Get Execution Plan is grayed out, the SQL file is not connected to a connection profile. Choose Attach Connection Profile and complete the Select Profile for the Editor dialog to connect.

  4. Select Get Execution Plan from the SQL Editor context menu.

    The SQL Execution Plan view opens with:

    • A frame that displays a graphical or text representation of the SQL statements you have selected.

    • For graphics plans, a second frame that displays useful statistics such as rows returned, run time, CPU time, and disk read/write times; and various options used, such as case sensitivity, character set, date format, encryption, histograms, start time, and thread count.

  5. In a graphics plan, click a node in the graphic to see details for that node .

  6. Choose any of these actions to change the plans you can see in the SQL Execution Plan view:

    • To remove the current plan from the view, click the Remove Current Plan icon.

    • To remove all plans from the view, click the Remove All Plans icon.

    • To save the plan to a file, click in either frame of the SQL Execution Plan view and click the Save Plans to File icon.

    • To load a previously saved plan, click the Load Plans from a File icon and select a plan to load.

    • To show a different plan, click the Show Previous Plans icon and choose a plan from the Previous Plans dialog, or click Remove to remove the selected plan.

      You can also click the black Show Previous Plans drop-down to show a different plan or to remove all plans.

  7. (Optional) Click the drop-down menu button to change query plan preferences or to change the orientation.

See the documentation for your server to understand query optimization and query plans.

Setting Database Development Preferences

Setting Query Plan Preferences

Executing a SQL File

SQL User's Guide , Chapter 13, "Query Optimization and Execution" in the Adaptive Server Anywhere collection under Sybase WorkSpace Server Administration.

See Query Processor in the Adaptive Server Enterprise collection under Sybase WorkSpace Server Administration.

Send your feedback on this help topic to Sybase Tech Pubs: pubs@sybase.com