SQL Statement | Discussion |
---|---|
SET QRYPLAN=<on | off> | Instructs the database engine to create a query plan for use with Query Plan Viewer, or not. |
SET QRYPLANOUTPUT=<NULL | file_name> | Sets the location and name of the query plan file. NULL specifies not to create a query plan file. A single query plan file can contain plans resulting from multiple queries. For your reference, the query plan file contains the code page identifier of the encoding used for each query. Regardless which database encoding a query used, Query Plan Viewer correctly displays wide character data. By default, Query Plan Viewer looks for the file name extension .qpf. You may use whatever file name extension you want, or omit one. Example: You want to create a query plan named select_salary and store the query plan file in a directory named mydirectory on drive D off of the root: SET QRYPLANOUTPUT='d:\mydirectory\select_salary.qpf' The database engine creates the query plan output file, so the path must be a location on the machine where the database engine is running. The path should not reference client-side locations or client drive mappings. |
Node Symbol | Node Meaning |
---|---|
Represents data coming from a table in the database. The name displayed under the rectangle is the name of the table. If present, the name shown under the table indicates the index used to retrieve data from the table. An asterisk to the right of the index name indicates that the index contains unique values. | |
Represents a row selection operation. The word in parentheses can be either "Normal" or "Range:" • A Normal filter is applied after the row is returned from the downstream node. • A Range filter appears only directly above a base table. The Range filter causes a restricted record retrieval from the table based on an index value. | |
Performs a distinct operation. This node normally appears at the top or close to the top of the plan tree. Eliminates duplicates from the result set before returning rows from the query. | |
Detects group breaks based on a GROUP BY clause. | |
Works with Group Break node to assist in correctly accumulating aggregates for SELECT and HAVING clauses. | |
Performs a JOIN between two nodes. The value in parentheses indicates the type of JOIN performed: • "Outer" indicates left for right outer join without any indexes. • "OuterRange" indicates left or right outer join using an index. • "Normal" indicates a Cartesian join. • "Range" indicates an inner join using an index. | |
Performs aggregate value accumulation. This node is used for MIN, MAX, AVG, COUNT, SUM, and STDEV, and for these aggregates when the DISTINCT clause is used with them. The word inside the node indicates the type of aggregate being accumulated. When an aggregate is accumulated in conjunction with a GROUP BY clause, the aggregate nodes appear between the group break and group nodes. | |
Handles accumulating aggregates when no GROUP BY clause is present. | |
Handles data retrieval from a single subquery of the main query. This node never appears when you view the root query plan, only when you view a subquery. | |
Handles creation of temporary tables and data retrieval from temporary tables. References to the base table under this node are changed to reference columns of the temporary table. | |
Processes the UNION and UNION ALL operations. Cycles through the underlying query execution plans to retrieve data for the UNION result set. The Plan Viewer displays unions with the first query as the root query, the second query as Subquery 1, and so forth. |
Node Type | Detailed Information |
---|---|
Table | • Name of table • Total rows in table • Estimated number of rows to be read • Range information. Range information is used only when the base table is on the right side of a JOIN and the retrieval of data from the table can be optimized through the use of an index. Range information includes: • Column or columns retrieved • Value used to initiate range retrieval (the value normally comes from another table and column) and the value to terminate retrieval • Initial operations to perform, such as greater than (GT), greater than or equal to (GE), less than (LT), and so forth • Method of comparison to determine when to stop (GT, GE, and so forth) |
Filter (Normal) | Text representation of conditions used to evaluate row. If present, wide character data is displayed correctly. |
Filter (Range) | • Information about index used • How filter is reducing set of rows returned • Type of first read from table (GT, GE, and so forth) • Condition that must evaluate to TRUE to stop reading more records (GT, GE, and so forth) |
Subquery | Type of subquery and optimizations being performed for subquery |
Ordered temp table | • List of columns included in the temporary table • Column indication of whether column is used to order rows of the temporary table (a key) or is a value to pass up the tree |
Element and Attributes | Explanation | Parent Element | Child Elements |
---|---|---|---|
<QPF filename=filename> filename: path and name of QPF file | QPF file on which XML file is based, one per XML file | Header Information | <Query> |
<Query number=number> number: query number displayed in Query Plan Viewer. First is 1, second is 2, and so forth. | Query in the <QPF> file, at least one per XML file | <QPF> | <SQL> <TreeRoot> |
<SQL> | SQL statement used to generate plan. If your SQL scripts declare a Unicode character string literal prefixed with an uppercase N, the prefix appears in the <SQL> element. See also child <Properties> for <Filter>. | <Query> | |
<TreeRoot name=name> name: Root Query or Subquery X | Indicates root query or subquery | <Query> | All Node Elements: <Join> <Filter> <Base> <Distinct> <Set> <FCalc> <Group> <GroupBreak> <OrderedTempTable> <Union> <Subquery> |
Node Elements | Each is a node in the query plan tree (a part of the SQL statement) | <TreeRoot> or the <Child>, <LeftChild>, or <RightChild> of another node element | |
<Join> | <TreeRoot> | <Text> <Properties> <LeftChild> <RightChild> | |
<Filter> | If your SQL scripts declare a Unicode character string literal prefixed with an uppercase N, the prefix does not appear in the <Properties> child element. See also <SQL>. | <TreeRoot> | <Text> <Properties> <Child> |
<Base> | Represents a leaf in diagram tree | <TreeRoot> | <Text> <Properties> |
<Distinct> | <TreeRoot> | <Properties> <Child> | |
<Set> | <TreeRoot> | <Text> <Properties> <SetString> <Child> | |
<FCalc> | <TreeRoot> | <Properties> <LeftChild> <RightChild> | |
<Group> | <TreeRoot> | <Properties> <Child> | |
<GroupBreak> | <TreeRoot> | <Properties> <Child> | |
<OrderedTempTable> | <TreeRoot> | <Properties> <Child> | |
<Union> | <TreeRoot> | <Properties> <Child> | |
<Subquery> | <TreeRoot> | <Properties> <Child> | |
Node Element Children | Varies. Provide additional information about node or link to child of node tag. | Varies | |
<Text> | <Join> <Filter> <Set> Optionally, <Base> | ||
<Properties> | All node elements | ||
<SetString> | <Set> | ||
<Child> | <Filter> <Distinct> <Set> <Group> <GroupBreak> <OrderedTempTable> <Union> <Subquery> | ||
<LeftChild > | <Join> <FCalc> | ||
<RightChild> | <Join> optionally, <FCalc> |