... |
h1. Getting a Query Plan |
You can get a query plan any time you execute a command. The SQL options available are as follows: |
|
*SHOWPLAN \[ON|DEBUG]*- Returns the plan or the plan and the full planner debug log. With the above options, the query plan is available from the Statement object by casting to the {{org.teiid.jdbc.TeiidStatement}} interface. |
You can get a query plan any time you execute a command. The SQL options available are as follows: |
|
*SHOWPLAN \[ON\|DEBUG\]*\- Returns the plan or the plan and the full planner debug log. With the above options, the query plan is available from the Statement object by casting to the {{org.teiid.jdbc.TeiidStatement}} interface. |
{code:SQL|title=Retrieving a Query Plan} statement.execute("set showplan on"); |
... |
Once a query plan has been obtained you will most commonly be looking for: |
* Source pushdown \-\- what parts of the query that got pushed to each source |
* Join ordering |
... |
The nodes for a relational query plan are: |
* Access - Access a source. A source query is sent to the connection factory associated with the source. \[For a dependent join, this node is called Dependent Select.\] |
|
* Project - Defines the columns returned from the node. This does not alter the number of records returned. \[When there is a subquery in the Select clause, this node is called Dependent Project.\] |
* Project Into - Like a normal project, but outputs rows into a target table. |
* Select - Select is a criteria evaluation filter node \(WHERE / HAVING). \[When there is a subquery in the criteria, this node is called Dependent Select.\] |
|
* Join - Defines the join type, join criteria, and join strategy \(merge or nested loop). |
|
* Union - There are no properties for this node, it just passes rows through from it's children |
* Sort - Defines the columns to sort on, the sort direction for each column, and whether to remove duplicates or not. |
... |
* Group - 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. |
* Limit - Returns a specified number of rows, then stops processing. Also processes an offset if present. |
|
... |
h1. Source Hints |
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\(:'arg') source\-name:'arg1' ... \*/ and is expected to appear after the query keyword, e.g. "SELECT /\*+ sh:'general hint' my\-oracle:'oracle hint' \*/. The sh arg is optional and is passed to all source queries via the {{ExecutionContext.getGeneralHint}} method. See the [Developer's Guide] for more on the additional args should have source\-name that matches the source name assigned to the translator in the VDB. If the source\-name matches the hint value will be supplied via the {{ExecutionContext.getSourceHint}} method. |
|
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: {code:sql}/*+ sh[[ KEEP ALIASES]:'arg'] source-name[ KEEP ALIASES]:'arg1' ... */{code} - The source hint is expected to appear after the query (SELECT, INSERT, UPDATE, DELETE) keyword. - The sh arg is optional and is passed to all source queries via the {{ExecutionContext.getGeneralHint}} method. The additional args should have a source-name that matches the source name assigned to the translator in the VDB. If the source-name matches, the hint value will be supplied via the {{ExecutionContext.getSourceHint}} method. See the [Developer's Guide] for more on using an ExecutionContext. |
See the [Developer's Guide] for more on using an ExecutionContext. - Each of the arg values has the form of a string literal - it must be surrounded in single quotes and a single quote can be escaped with another single quote. Only the Oracle translator does anything with source hints by default. The Oracle translator will use either the source hint or the general hint \(in that order) if available to form an Oracle hint enclosed in /\*+ /*\+ ... \*/. Source hints in views will not be passed to the source if the view is used as a pushdown subquery, is joined, or is in a set operation. |
- If the KEEP ALIASES option is used either for the general hint or on the applicable source specific hint, then the table/view aliases from the user query and any nested views will be preserved in the push-down query. This is useful in situations where the source hint may need to reference aliases and the user does not wish to rely on the generated aliases (which can be seen in the query plan in the relevant source queries - see above). However in some situations this may result in an invalid source query if the preserved alias names are not valid for the source or result in a name collision. If the usage of KEEP ALIASES results in an error, the query could be modified by preventing view removal with the NO_UNNEST hint, the aliases modified, or the KEEP ALIASES option could be removed and the query plan used to determine the generated alias names. {code:SQL|title=Sample Source Hint}SELECT /*+ sh:'general hint' my-oracle:'oracle hint' */ ... {code}. |
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.
You can get a query plan any time you execute a command. The SQL options available are as follows:
SHOWPLAN [ON|DEBUG]- Returns the plan or the plan and the full planner debug log.
With the above options, the query plan is available from the Statement object by casting to the org.teiid.jdbc.TeiidStatement interface.
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 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. 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.
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:
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 |
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' my-oracle:'oracle hint' */ ...