Lesson 2: Accessing a query plan

Sybase WorkSpace allows you to select a SQL statement in the SQL editor and use the context menu to visually display the execution plan of the statement. This allows developers or database administrators to optimize the database and SQL code. SQL developers or database administrators can tell from the query plan when, for example, to create table indexes, reorganize data tables, or change the way a query is written.

In this lesson, you will learn how to:

NoteThis lesson does not teach you how to use a query plan, only how to access a query plan in Sybase WorkSpace. For specific information on how to use a query plan, see the Adaptive Server Anywhere SQL User’s Guide.

  1. Verify that the SybStoreDB.sql script still has a connection to the database by looking at the Sybase WorkSpace main window status bar. The status should include the information “...database: MySybStore, connected”.

    If the script no longer has an active connection, repeat “Lesson 1: Opening and executing a SQL script”.

  2. In SQL editor, highlight lines 13 through 16 in the script SybStoreDB.sql:

    select 1 from sys.sysindex i, sys.systable t
    where i.table_id=t.table_id 
    and i.index_name='WAREHOUSE_INVENTORY_PK'
    and t.table_name='WAREHOUSE_INVENTORY'
    
  3. Right-click in the editor and select Get Execution Plan on the context menu.

  4. When the SQL Execution Plan view displays, click the Maximize icon.

    The execution plan expands in the Sybase WorkSpace window.

    When you select different nodes in the left pane, the associated information for the selected node displays in the right pane.

    Now you will modify some preferences to change the behavior of the execution plan.

  5. Click the Menu icon (small white down arrow) on the SQL Execution Plan toolbar and select Preferences from the menu.

    For this lesson, you will change the plan’s executed orientation view to vertical, and the plan options to a graphics plan with statistics.

  6. When the Preferences dialog box opens, select Query Plan in the left pane, then change these options:

    Click OK.

  7. Close the SQL Execution Plan window by clicking the “X” icon on the title tab.

  8. Right-click in the SQL editor window and select Get Execution Plan from the context menu to regenerate the query plan.

    NoteAfter you make preference changes, reselect Get Execution Plan to see the results of those changes.

  9. Maximize the SQL Execution Plan window to see your preference changes displayed.

  10. Optionally, change other preferences and reselect Get Execution Plan to view how other preferences can be modified.

    To save the plan for later viewing, select the SQL Execution Plan tab and click the Save Plans to a File icon on the window’s toolbar. A dialog box displays where you specify the location and filename for the plan you want to save.

    To reload a plan, click the Load Plans from a File icon. A dialog box opens where you specify the path to the file from which to load a plan.

  11. To remove (delete) the current plan, click the single “X” icon on the toolbar. To delete all plans, click the double “XX” icon.

  12. Close the SQL Execution Plan window by clicking the “X” icon on the title tab, then select File|Close from the Sybase WorkSpace main menu to close the SQL editor. You have completed this tutorial and now know how to view and manage SQL query plans with Sybase WorkSpace.