By examining the query plan, you can see exactly how the database executes your SQL statement, helping you judge whether the SQL statement is the most efficient or any changes to the table structure are needed such as adding a new index.
To view the query plan of the original SQL statement in the SQL Optimizer window
Click .
If parameters exist in the original SQL statement, you are required to define the parameters and data types of the parameters before the query plan is retrieved. Or, alternatively use the SQL | Show Default Plan to retrieve the query plan without the need to enter parameter details. Show Default Plan allows you to quickly view the query plan without the need to enter the data type variables.
For more specific information about each step of the query plan, click any text in the step and the Plan Detail window displays.
When the original SQL statement has parameters, you need to determine the data type of the parameters when executing the Show Plan, Optimize, Run Result, Run for all Records, or Run for First Record functions.
If you would like to view the query plan without needing to enter all the data types and values for the parameters, use the SQL | Show Default Plan to retrieve the query plan. In this case, all the parameters are assumed to have a BINARY data type when executing the Show Plan function. This is useful when you want to quickly investigate the query plan of the original SQL statement.
If sending a SQL statement from the SQL Scanner, SQL Worksheet, Database Explorer, or SQL Formatter to the SQL Optimizer (Edit | Send to SQL Optimizer), these statements are automatically optimized.
To optimize a SQL statement
In the SQL Optimizer window, enter the SQL statement in the SQL Editor pane of the SQL Optimizer.
Click .
The time it takes to optimize is dependent on the complexity of the original SQL statement and the quota values set in the Preferences window.
During optimization, the unique optimization engine uses multiple SQL syntax transformation rules to produce a list of semantically equivalent SQL statements. Selected optimization forces from the Preferences window are also applied to produce the list of optimized SQL statements.
To stop the optimization process
Click .
It may take a few seconds to terminate all processes.
Note:When setting the searching quota values that, the higher the quota, the longer it may take to optimize a complicated SQL statement.
Adaptive Server uses a different query plan for a SQL statement that is embedded in a cursor declaration from the query plan when the SQL statement is not embedded in a cursor. This needs to be taken into account when retrieving the query plan or run time and also when generating SQL alternatives.
Therefore, if the original SQL statement comes from or will be embedded in a cursor declaration then you need to select SQL for Cursor in the SQL Editor pane of SQL Optimizer window. This enables cursor simulation when retrieving the query plan and run time information.
This checkbox is automatically selected in the SQL Editor pane when you use the Send to SQL Optimizer function from the SQL Scanner if the SQL was extracted from within a cursor declaration.
In Adaptive Server 15 or later, the Declare Cursor Setting window is also available to select specific cursor settings.
The cursor arguments should match the settings used for the SQL statement in your application code.
Cursor Type | Description |
SEMI-SENSITIVE |
Specify that the worktable which holds the result set is populated only as the rows are fetched. Therefore changes to the data that occur while the cursor is opened may be visible in the result set. |
INSENSITIVE |
Specify that the data is copied to a worktable when the cursor is open which makes the data insensitive to changes in the data that may occur while the cursor is opened. |
SCROLL |
Specify that the cursor is scrollable meaning that you can position the cursor anywhere in the cursor result set for as long as the cursor is open. All scrollable cursors are read only. |
NO SCROLL |
Specify that the rows are retrieved one row at a time. All update cursors are non-scrollable. |
© 2024 Quest Software Inc. ALL RIGHTS RESERVED. 使用条款 隐私 Cookie Preference Center