Obtaining an Execution Plan

View a statement execution (query) plan, which enables you to optimize the database and SQL code.

Prerequisites 

Before you can get an execution plan from within a SQL file, the SQL file must be connected to a data server connection profile.

The execution plan indicates when to create table indexes, reorganize data tables, or change the way a query is written. It displays actual statistics when you view it during execution and estimated statistics when you view it without executing the SQL code. Viewing an execution plan is useful during troubleshooting and performance tuning.

  1. Indicate the execution plan type you want to create by selecting it in the Execution Plan View Options preferences page .

    You can also indicate whether to view the plan during execution.

    1. From the WorkSpace main menu, choose Window > Preferences.
    2. In the Preferences dialog, expand the tree view for Sybase, Inc and Database Development, and click Execution Plan View Options.
    3. In the tab for the database server, select Graphic Plan or Text Plan, and indicate any other options.
    4. Click OK.
  2. In the Databases folder in Enterprise Explorer, under the database connection profile, expand the navigation tree for the appropriate database and schema owner.
    Database Steps
    From an ASE connection profile
    1. Expand the Databases folder.
    2. Expand the tree for a database and then the tree for the appropriate schema owner.
    From a SQL Anywhere or Sybase IQ connection profile
    1. Expand the tree for a database.
    2. Expand the Schemas folder and then the tree for the appropriate schema owner.
  3. Find an existing procedural object.
    Procedural object Description
    Stored procedures Expand the Stored Procedures folder.
    SQL Anywhere or Sybase IQ User-defined functions Expand the User Defined Functions folder.
    Triggers Expand the Tables folder, select the table in which the trigger resides, and then expand the Triggers folder.
    SQL Anywhere or Sybase IQ events Expand the Events folder.
  4. Double-click the object to open it in its corresponding editor.
  5. In the Source page, select the statement or statements for which you want to display an execution plan.

    To obtain the execution plan for the entire SQL file or procedural object, skip this step.

  6. Right-click and select Get Execution Plan.
    The 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. In a graphics plan, click a node in the graphic to see details for that node.

  7. (Optional) Choose any of these actions to change the plans you can see in the Execution Plan view:
    To Do this
    Remove the current plan from the view Click Remove Current Plan 
      Remove.
    Remove all plans from the view ClickRemove All Plans 
      Remove All.
    Save the plan to a file Click in either frame of the Execution Plan view, and click Save Plans to File 
      Save Plans to File.
    Load a previously saved plan ClickLoad Plans from a File 
      Load Plans from File, and select a plan to load.
    Show a different plan Click Show Previous Plans 
      Show Previous Plans, and choose a plan from the Previous Plans dialog, or click Remove to remove the selected plan.
  8. (Optional) Click the drop-down menu button to change execution plan preferences or to change the orientation.
Related concepts
Execution Plans
Execution Plan View
Related tasks
Creating a Graphic Execution Plan
Creating a Text Execution Plan
Related reference
Execution Plan View Options
ASE Execution Plan View Options
ASA Execution Plan View Options
Sybase IQ Execution Plan View Options

For product-related issues, contact Sybase Technical Support at 1-800-8SYBASE. Send your feedback on this help topic directly to Sybase Technical Publications: pubs@sybase.com