When integrating information using a federated query planner, it is useful to be able to view the query plans that are created, 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. |
h1. Getting a Query Plan 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. |
|
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|Show Statement]. |
{code:SQL|title=Retrieving a Query Plan} statement.execute("set showplan on"); |
... |
The query plan is made available automatically in several of Teiid's tools. |
h1. Analyzing a Query Plan |
... |
* Source pushdown \-\- what parts of the query that got pushed to each source |
** Ensure that any predicates especially against indexes are pushed |
|
* Join ordering |
* Joins - as federated joins can be quite expensive ** Join ordering - typically influenced by costing ** Join criteria type mismatches. ** Join algorithm used - merge, enhanced merge, nested loop, etc. |
|
* Join algorithm used - merge or nested loop. |
* Presence of federated optimizations, such as dependent joins. |
* Join criteria type mismatches. |
* Ensure hints have the desired affects - see [Hints and Options], hints in the [From Clause], [Subquery Optimization], and source hints below. |
|
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. |
|
All of these issues presented above will be present subsections of the plan that are specific to relational queries. If you are executing a procedure or generating an XML document, the overall query plan will contain additional information related the surrounding procedural execution. |
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. |
|
A query plan consists of a set of nodes organized in a tree structure. As with the above example, you will typically be interested in analyzing the textual form of the plan. |
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. |
h1. Relational Execution Plans |
|
h1. Relational Plans |
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. |
|
Relational plans represent the actually processing plan that is composed of nodes that are the basic building blocks of logical relational operations. Physical relational plans differ from logical 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: |
... |
* Join - Defines the join type, join criteria, and join strategy (merge or nested loop). |
* Union All - There are no properties for this node, it just passes rows through from it's children. Depending upon other factors, such as if there is a transaction or the source query concurrency allowed, not all of the union children will execute in parallel. |
* Sort - Defines the columns to sort on, the sort direction for each column, and whether to remove duplicates or not. |
* Dup Remove - Removes duplicate rows. The processing uses a tree structure to detect duplicates so that results will effectively stream at the cost of IO operations. |
* Grouping - Groups sets of rows into groups and evaluates aggregate functions. |
... |
* Null - A node that produces no rows. Usually replaces a Select node where the criteria is always false (and whatever tree is underneath). There are no properties for this node. |
* Plan Execution - Executes another sub plan. Typically the sub plan will be a non-relational plan. |
* Dependent Procedure Execution - Executes a sub plan using multiple sets of input values. |
... |
* Limit - Returns a specified number of rows, then stops processing. Also processes an offset if present. |
* XML Table - Evaluates XMLTABLE |
* XML Table - Evaluates XMLTABLE. The debug plan will contain more information about the XQuery/XPath with regards to their optimization - see the XQuery section below or [XQuery Optimization]. |
* Text Table - Evaluates TEXTTABLE |
... |
| Data Bytes Sent | The size of the serialized data result (row and lob values) sent to the client | bytes | |
h2. Reading a Processor Plan |
h1. Source Hints |
... |
SELECT /*+ sh KEEP ALIASES:'general hint' my-oracle:'oracle hint' */ ... {code} |
h1. Debug Plans h2. All Node Properties h2. Reading a Debug Plan h2. XQuery |
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 |
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' */ ...