... |
h2. Reading a Processor Plan |
h1. Other Plans XML document model queries and proecedure execution (including instead of triggers) use intermediate and final plan forms that include relational plans. Generally the structure of the xml/procedure plans will closely match their logical forms. It's the nested relational plans that will be of interest when analyzing performance issues. |
h1. Source Hints |
... |
** PRESERVE - if the preserve hint is preserving the join order * Project Properties |
** PROJECT_COLS, // List <SingleElementSymbol> ** INTO_GROUP, // GroupSymbol ** HAS_WINDOW_FUNCTIONS, // Boolean |
** PROJECT_COLS - the expressions projected ** INTO_GROUP - the group targeted if this is a select into or insert with a query expression ** HAS_WINDOW_FUNCTIONS - true if window functions are used |
** CONSTRAINT - the constraint that must be met if the values are being projected into a group |
* Select Properties |
** SELECT_CRITERIA, // Criteria IS_HAVING, // Boolean //phantom nodes represent the previous position of criteria that has been pushed across a source, group, or union node. //phantom nodes are used by RuleCopyCriteria and removed by RuleCleanCriteria. IS_PHANTOM, // Boolean IS_TEMPORARY, // Boolean IS_COPIED, // Boolean - used in CopyCriteria to mark which selects have already been copied IS_PUSHED, // true if this node has already been pushed IS_DEPENDENT_SET, // Boolean - only used with dependent joins |
** SELECT_CRITERIA - the filter ** IS_HAVING - if the filter is applied after grouping ** IS_PHANTOM - true if the node is marked for removal, but temporarily left in the plan. ** IS_TEMPORARY - inferred criteria that may not be used in the final plan ** IS_COPIED - if the criteria has already been processed by rule copy criteria ** IS_PUSHED - if the criteria is pushed as far as possible ** IS_DEPENDENT_SET - if the criteria is the filter of a dependent join |
* Sort Properties ** SORT_ORDER - the order by that defines the sort |
UNRELATED_SORT, // Boolean IS_DUP_REMOVAL, // Boolean |
** UNRELATED_SORT - if the ordering includes a value that is not being projected ** IS_DUP_REMOVAL - if the sort should also perform duplicate removal over the entire projection |
* Source Properties - many source properties also become present on associated access nodes |
SYMBOL_MAP, // SymbolMap PARTITION_INFO, // Map<ElementSymbol, List<Set<Constant>>> - it will only be consistent in the initial stages of planning VIRTUAL_COMMAND, // Command MAKE_DEP, // Option.Makedep PROCESSOR_PLAN, // ProcessorPlan for non-relational sub plan NESTED_COMMAND, // Command for nested processor plan TABLE_FUNCTION, // Table Function CORRELATED_REFERENCES, // SymbolMap MAKE_NOT_DEP, // Boolean |
** SYMBOL_MAP - the mapping from the columns above the source to the projected expressions. Also present on Group nodes ** PARTITION_INFO - the partitioning of the union branches ** VIRTUAL_COMMAND - if the source represents an view or inline view, the query that defined the view ** MAKE_DEP - hint information ** PROCESSOR_PLAN - the processor plan of a non-relational source (typically from the NESTED_COMMAND) ** NESTED_COMMAND - the non-relational command ** TABLE_FUNCTION - the table function (XMLTABLE, OBJECTTABLE, etc.) defining the source ** CORRELATED_REFERENCES - the correlated references for the nodes below the source ** MAKE_NOT_DEP - if make not dep is set |
INLINE_VIEW, // ** INLINE_VIEW - If the source node represents an inline view |
NO_UNNEST, MAKE_IND, |
** NO_UNNEST - if the no_unnest hint is set ** MAKE_IND - if the make ind hint is set ** SOURCE_HINT - the source hint. See Source Hints above. ** ACCESS_PATTERNS - access patterns yet to be satisfied ** ACCESS_PATTERN_USED - satisfied access patterns ** REQUIRED_ACCESS_PATTERN_GROUPS - groups needed to satisfy the access patterns. Used in join planning. |
* Group Properties |
GROUP_COLS, // List <Expression> ROLLUP, // Boolean |
** GROUP_COLS - the grouping columns ** ROLLUP - if the grouping includes a rollup |
* Tuple Limit Properties |
MAX_TUPLE_LIMIT, // Expression ** MAX_TUPLE_LIMIT - expression that evaluates to the max number of tuples generated |
OFFSET_TUPLE_COUNT, // ** OFFSET_TUPLE_COUNT - Expression that evaluates to the tuple offset of the starting tuple |
IS_IMPLICIT_LIMIT, // Boolean ** IS_IMPLICIT_LIMIT - if the limit is created by the rewriter as part of a subquery optimization |
IS_NON_STRICT, // Boolean ** IS_NON_STRICT - if the unordered limit should not be enforced strictly |
SOURCE_HINT, |
* General and Costing Properties |
OUTPUT_COLS, // List <SingleElementSymbol> |
** OUTPUT_COLS - the output columns for the node. Is typically set after rule assign output elements. |
EST_SET_SIZE, // Integer ** EST_SET_SIZE - represents the estimated set size this node would produce for a sibling node as the independent node in a dependent join scenario |
EST_DEP_CARDINALITY, // Float ** EST_DEP_CARDINALITY - value that represents the estimated cardinality (amount of rows) produced by this node as the dependent node in a dependent join scenario |
EST_DEP_JOIN_COST, // Float ** EST_DEP_JOIN_COST - value that represents the estimated cost of a dependent join (the join strategy for this could be Nested Loop or Merge) |
EST_JOIN_COST, // Float ** EST_JOIN_COST - value that represents the estimated cost of a merge join (the join strategy for this could be Nested Loop or Merge) |
EST_CARDINALITY, // Float ** EST_CARDINALITY - represents the estimated cardinality (amount of rows) produced by this node |
EST_COL_STATS, |
** EST_COL_STATS - column statistics including number of null values, distinct value count, etc. |
EST_SELECTIVITY, // Float that ** EST_SELECTIVITY - represents the selectivity of a criteria node |
ACCESS_PATTERNS, // Collection <List <Object element ID> > ACCESS_PATTERN_USED, // List <Object element ID> REQUIRED_ACCESS_PATTERN_GROUPS, |
|
h2. Rules |
Access Pattern Validation Apply Security Assign Output ElementSymbol Calculate Cost Choose Dependent Choose Join Stategy Clean Criteria Collapse Source Copy Criteria Decompose Join Implement Join Strategy Merge Criteria Merge Virtual Place Access Plan Joins Plan Procedures Plan Sorts Plan Unions Plan Aggregates Push Limit Push Non-Join Criteria Push Select Criteria Raise Access Raise Null Remove Optional Joins Substitute Expressions Validate Where All |
Plan rule manipulate the plan tree, fire other rules, and drive the optimization process. The structure of the query determines the initial set of rules. Each rule is designed to perform a narrow set of tasks. Some rules can be run multiple times. Some rules require a specific set of precursors to run properly. |
|
* Access Pattern Validation * Apply Security * Assign Output Symbol * Calculate Cost * Choose Dependent * Choose Join Strategy * Clean Criteria * Collapse Source * Copy Criteria * Decompose Join * Implement Join Strategy * Merge Criteria * Merge Virtual * Place Access * Plan Joins * Plan Procedures * Plan Sorts * Plan Unions * Plan Aggregates * Push Limit * Push Non-Join Criteria * Push Select Criteria * Raise Access * Raise Null * Remove Optional Joins * Substitute Expressions * Validate Where All |
h2. Reading a Debug Plan |
... |
When integrating information using a federated query planner it is useful to view the query plans to better understand how information is being accessed and processed, and to troubleshoot problems.
A query plan is a set of instructions created by a query engine for executing a command submitted by a user or application. The purpose of the query plan is to execute the user's query in as efficient a way as possible.
You can get a query plan any time you execute a command. The SQL options available are as follows:
SET SHOWPLAN [ON|DEBUG]- Returns the processing plan or the plan and the full planner debug log. See also the SET Statement.
With the above options, the query plan is available from the Statement object by casting to the org.teiid.jdbc.TeiidStatement interface or by using the "SHOW PLAN" statement.
statement.execute("set showplan on"); ResultSet rs = statement.executeQuery("select ..."); TeiidStatement tstatement = statement.unwrap(TeiidStatement.class); PlanNode queryPlan = tstatement.getPlanDescription(); System.out.println(queryPlan);
The query plan is made available automatically in several of Teiid's tools.
Once a query plan has been obtained you will most commonly be looking for:
All of the above information can be determined from the processing plan. You will typically be interested in analyzing the textual form of the final processing plan. To understand why particular decisions are made for debugging or support you will want to obtain the full debug log which will contain the intermediate planning steps as well as annotations as to why specific pushdown decisions are made.
A query plan consists of a set of nodes organized in a tree structure. If you are executing a procedure or generating an XML document from an XML Document Model, the overall query plan will contain additional information related the surrounding procedural execution.
In a procedural context the ordering of child nodes implies the order of execution. In most other situation, child nodes may be executed in any order even in parallel. Only in specific optimizations, such as dependent join, will the children of a join execute serially.
Relational plans represent the processing plan that is composed of nodes representing building blocks of logical relational operations. Relational processing plans differ from logical debug relational plans in that they will contain additional operations and execution specifics that were chosen by the optimizer.
The nodes for a relational query plan are:
Every node has a set of statistics that are output. These can be used to determine the amount of data flowing through the node.
Statistic | Description | Units |
---|---|---|
Node Output Rows | Number of records output from the node | count |
Node Process Time | Time processing in this node only | millisec |
Node Cumulative Process Time | Elapsed time from beginning of processing to end | millisec |
Node Cumulative Next Batch Process Time | Time processing in this node + child nodes | millisec |
Node Next Batch Calls | Number of times a node was called for processing | count |
Node Blocks | Number of times a blocked exception was thrown by this node or a child | count |
In addition to node statistics, some nodes display cost estimates computed at the node.
Cost Estimates | Description | Units |
---|---|---|
Estimated Node Cardinality | Estimated number of records that will be output from the node; -1 if unknown | count |
The root node will display additional information.
Top level Statistics | Description | Units |
---|---|---|
Data Bytes Sent | The size of the serialized data result (row and lob values) sent to the client | bytes |
XML document model queries and proecedure execution (including instead of triggers) use intermediate and final plan forms that include relational plans. Generally the structure of the xml/procedure plans will closely match their logical forms. It's the nested relational plans that will be of interest when analyzing performance issues.
Teiid user and transformation queries can contain a meta source hint that can provide additional information to source queries. The source hint has the form:
/*+ sh[[ KEEP ALIASES]:'arg'] source-name[ KEEP ALIASES]:'arg1' ... */
SELECT /*+ sh:'general hint' */ ... SELECT /*+ sh KEEP ALIASES:'general hint' my-oracle:'oracle hint' */ ...
A relational processing plan is created by the optimizer after the logical plan is manipulated by a series of rules. The application of rules is determined both by the query structure and by the rules themselves. The node structure of the debug plan resembles that of the processing plan, but the node types more logically represent SQL operations.
User SQL statements after rewrite are converted into a cannonical plan form. The connonical plan form most closely resembles the initial SQL structure. For example, a SQL statement such as SELECT max(pm1.g1.e1) FROM pm1.g1 WHERE e2 = 1 creates a logical plan:
Project(groups=[anon_grp0], props={PROJECT_COLS=[anon_grp0.agg0 AS expr1]}) Group(groups=[anon_grp0], props={SYMBOL_MAP={anon_grp0.agg0=MAX(pm1.g1.e1)}}) Select(groups=[pm1.g1], props={SELECT_CRITERIA=e2 = 1}) Source(groups=[pm1.g1])
Here the Source corresponds to the FROM clause, the Select correspondes to the WHERE clause, the Group corresponds to the implied grouping to create the max aggregate, and the Project corresponds to the SELECT clause.
Note that the affect of grouping generates what is effectively an inline view, anon_grp0, to handle the projection of values created by the gropuing.
Each node has a set of applicable properties that are typically shown on the node.
Plan rule manipulate the plan tree, fire other rules, and drive the optimization process. The structure of the query determines the initial set of rules. Each rule is designed to perform a narrow set of tasks. Some rules can be run multiple times. Some rules require a specific set of precursors to run properly.