<html>
<head>
    <base href="https://docs.jboss.org/author">
            <link rel="stylesheet" href="/author/s/en/2172/19/5/_/styles/combined.css?spaceKey=TEIID&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://docs.jboss.org/author/display/TEIID/Federated+Optimizations">Federated Optimizations</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://docs.jboss.org/author/display/~shawkins">Steven Hawkins</a>
    </h4>
        <br/>
                         <h4>Changes (1)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >The engine will for IN clauses to filter the values coming from the dependent side. If the number of values from the independent side exceeds the translators MaxInCriteriaSize, the values will be split into multiple IN predicates up to MaxDependentPredicates. When the number of independent values exceeds MaxInCriteriaSize\*MaxDependentPredicates, then multiple dependent queries will be issued in parallel. <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{tip:title=Tip} While these hints can be applied to views, the optimizer will by default remove views when possible.  This can result in the hit placement being significantly different than the original intention.  You should consider using the NO_UNNEST hint to prevent the optimizer from removing the view in these cases. <br>{tip} <br></td></tr>
            <tr><td class="diff-unchanged" > <br>h1. Copy Criteria <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h1><a name="FederatedOptimizations-AccessPatterns"></a>Access Patterns</h1>
<p>Access patterns are used on both physical tables and views to specify the need for criteria against a set of columns. Failure to supply the criteria will result in a planning error, rather than a run&#45;away source query. Access patterns can be applied in a set such that only one of the access patterns is required to be satisfied.</p>

<p>Currently any form of criteria referencing an affected column may satisfy an access pattern.</p>


<h1><a name="FederatedOptimizations-Pushdown"></a>Pushdown</h1>
<p>In federated database systems pushdown refers to decomposing the user level query into source queries that perform as much work as possible on their respective source system. Pushdown analysis requires knowledge of source system capabilities, which is provided to Teiid though the Connector API. Any work not performed at the source is then processed in Federate's relational engine.</p>

<p>Based upon capabilities, Teiid will manipulate the query plan to ensure that each source performs as much joining, filtering, grouping, etc. as possible. In may cases, such as with join ordering, planning is a combination of <a href="#FederatedOptimizations-StandardRelationalTechniques">Standard Relational Techniques</a> and, cost based and heuristics for pushdown optimization.</p>

<p>Criteria and join push down are typically the most important aspects of the query to push down when performance is a concern. See <a href="/author/display/TEIID/Query+Plans" title="Query Plans">Query Plans</a> on how to read a plan to ensure that source queries are as efficient as possible.</p>


<h1><a name="FederatedOptimizations-DependentJoins"></a>Dependent Joins</h1>
<p>A special optimization called a dependent join is used to reduce the rows returned from one of the two relations involved in a multi&#45;source join. In a dependent join, queries are issued to each source sequentially rather than in parallel, with the results obtained from the first source used to restrict the records returned from the second. Dependent joins can perform some joins much faster by drastically reducing the amount of data retrieved from the second source and the number of join comparisons that must be performed.</p>

<p> The conditions when a dependent join is used are determined by the query planner based on <a href="#FederatedOptimizations-AccessPatterns">Access Patterns</a>, hints, and costing information.</p>

<p>Teiid supports hints to control dependent join behavior: </p>

<ul>
        <li>MAKEIND - indicates that the clause should be the independent side of a dependent join.</li>
</ul>


<ul>
        <li>MAKEDEP - indicates that the clause should be the dependent side of a join.</li>
</ul>


<ul>
        <li>MAKENOTDEP - prevents the clause from being the dependent side of a join.</li>
</ul>


<p>Theses can be placed in either the <a href="/author/display/TEIID/OPTION+Clause" title="OPTION Clause">OPTION Clause</a> or directly in the <a href="/author/display/TEIID/FROM+Clause" title="FROM Clause">FROM Clause</a>. As long as all <a href="#FederatedOptimizations-AccessPatterns">Access Patterns</a> can be met, the MAKEIND, MAKEDEP, and MAKENOTDEP hints override any use of costing information.  MAKENOTDEP supersedes the other hints.</p>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Tip</b><br />The MAKEDEP/MAKEIND hint should only be used if the proper query plan is not chosen by default. You should ensure that your costing information is representative of the actual source cardinality. An inappropriate MAKEDEP/MAKEIND hint can force an inefficient join structure and may result in many source queries.</td></tr></table></div>

<p>The engine will for IN clauses to filter the values coming from the dependent side. If the number of values from the independent side exceeds the translators MaxInCriteriaSize, the values will be split into multiple IN predicates up to MaxDependentPredicates. When the number of independent values exceeds MaxInCriteriaSize&#42;MaxDependentPredicates, then multiple dependent queries will be issued in parallel.</p>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Tip</b><br />While these hints can be applied to views, the optimizer will by default remove views when possible.  This can result in the hit placement being significantly different than the original intention.  You should consider using the NO_UNNEST hint to prevent the optimizer from removing the view in these cases.</td></tr></table></div>

<h1><a name="FederatedOptimizations-CopyCriteria"></a>Copy Criteria</h1>
<p>Copy criteria is an optimization that creates additional predicates based upon combining join and where clause criteria. For example, equi&#45;join predicates &#40;source1.table.column = source2.table.column) are used to create new predicates by substituting source1.table.column for source2.table.column and vice versa. In a cross source scenario, this allows for where criteria applied to a single side of the join to be applied to both source queries</p>


<h1><a name="FederatedOptimizations-ProjectionMinimization"></a>Projection Minimization</h1>
<p>Teiid ensures that each pushdown query only projects the symbols required for processing the user query. This is especially helpful when querying through large intermediate view layers.</p>


<h1><a name="FederatedOptimizations-PartialAggregatePushdown"></a>Partial Aggregate Pushdown</h1>
<p>Partial aggregate pushdown allows for grouping operations above multi&#45;source joins and unions to be decomposed so that some of the grouping and aggregate functions may be pushed down to the sources.</p>


<h1><a name="FederatedOptimizations-OptionalJoin"></a>Optional Join</h1>
<p>The optional join hint indicates to the optimizer that a joined table should be omitted if none of its columns are used by the output of the user query or in a meaningful way to construct the results of the user query. This hint is typically only used in view layers containing multi&#45;source joins.</p>

<p>The optional join hint is applied as a comment on a join clause.  It can be applied in both ANSI and non&#45;ANSI joins.  With non&#45;ANSI joins an entire joined table may be marked as optional. </p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Example Optional Join Hint</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
select a.column1, b.column2 from a, /*+ optional */ b WHERE a.key = b.key
</pre>
</div></div>

<p>Suppose this example defines a view layer X. If X is queried in such a way as to not need b.column2, then the optional join hint will cause b to be omitted from the query plan. The result would be the same as if X were defined as:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Example Optional Join Hint</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
select a.column1 from a
</pre>
</div></div>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Example ANSI Optional Join Hint</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
select a.column1, b.column2, c.column3 from /*+ optional */ (a inner join b ON a.key = b.key) INNER JOIN c ON a.key = c.key
</pre>
</div></div>

<p>In this example the ANSI join syntax allows for the join of a and b to be marked as optional.  Suppose this example defines a view layer X.  Only if both column a.column1 and b.column2 are not needed, e.g. "SELECT column3 FROM X" will the join be removed.</p>


<p>The optional join hint will not remove a bridging table that is still required.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Example Bridging Table</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
select a.column1, b.column2, c.column3 from /*+ optional */ a, b, c WHERE ON a.key = b.key AND a.key = c.key
</pre>
</div></div>

<p>Suppose this example defines a view layer X.  If b.column2 or c.column3 are solely required by a query to X, then the join on a be removed. However if a.column1 or both b.column2 and c.column3 are needed, then the optional join hint will not take effect.</p>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Tip</b><br />When a join clause is omitted via the optional join hint, the relevant criteria is not applied. Thus it is possible that the query results may not have the same cardinality or even the same row values as when the join is fully applied.

<p>Left/right outer joins where the inner side values are not used and whose rows under go a distinct operation will automatically be treated as an optional join and do not require a hint. </p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Example Unnecessary Optional Join Hint</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
    select a.column1, b.column2 from a LEFT OUTER JOIN /*+optional*/ b ON a.key = b.key
</pre>
</div></div></td></tr></table></div>

<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/forbidden.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>A simple "SELECT COUNT&#40;*) FROM VIEW" against a view where all join tables are marked as optional will not return a meaningful result.</td></tr></table></div>

<h1><a name="FederatedOptimizations-PartitionedUnion"></a>Partitioned Union</h1>
<p>Union partitioning is inferred from the transformation/inline view. If one &#40;or more) of the UNION columns is defined by constants and/or has WHERE clause IN predicates containing only constants that make each branch mutually exclusive, then the UNION is considered partitioned. UNION ALL must be used and the UNION cannot have a LIMIT, WITH, or ORDER BY clause &#40;although individual branches may use LIMIT, WITH, or ORDER BY). Partitioning values should not be null. For example the view definition "select 1 as x, y from foo union all select z, a from foo1 where z in &#40;2, 3)" would be considered partitioned on column x, since the first branch can only be the value 1 and the second branch can only be the values 2 or 3. Note that more advanced or explicit partition could be considered in the future. The concept of a partitioned union is used for performing partition&#45;wise joins, in <a href="/author/display/TEIID/Updatable+Views" title="Updatable Views">Updatable Views</a>, and <a href="#FederatedOptimizations-PartialAggregatePushdown">Partial Aggregate Pushdown</a>.</p>


<h1><a name="FederatedOptimizations-StandardRelationalTechniques"></a>Standard Relational Techniques</h1>

<p>Teiid also incorporates many standard relational techniques to ensure efficient query plans. </p>

<ul>
        <li>Rewrite analysis for function simplification and evaluation.</li>
</ul>


<ul>
        <li>Boolean optimizations for basic criteria simplification.</li>
</ul>


<ul>
        <li>Removal of unnecessary view layers.</li>
</ul>


<ul>
        <li>Removal of unnecessary sort operations.</li>
</ul>


<ul>
        <li>Advanced search techniques through the left&#45;linear space of join trees.</li>
</ul>


<ul>
        <li>Parallelizing of source access during execution.</li>
</ul>


<ul>
        <li><a href="/author/display/TEIID/Subquery+Optimization" title="Subquery Optimization">Subquery Optimization</a></li>
</ul>


<h1><a name="FederatedOptimizations-JoinCompensation"></a>Join Compensation</h1>

<p>Some source systems only allow "relationship" queries logically producing left outer join results even when queried with an inner join Teiid will attempt to form an appropriate left outer join.  These sources are restricted to only supporting key joins.  In some circumstances foreign key relationships on the same source should not be traversed at all or with the referenced table on the outer side of join.  The extension property teiid_rel:allow-join can be used on the foreign key to further restrict the pushdown behavior.  With a value of "false" no join pushdown will be allowed, and with a value of "inner" the referenced table must be on the inner side of the join.  If the join pushdown is prevented, the join will be processed as a federated join.</p>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;" class="grey">
                        <a href="https://docs.jboss.org/author/users/removespacenotification.action?spaceKey=TEIID">Stop watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://docs.jboss.org/author/users/editmyemailsettings.action">Change email notification preferences</a>
</div>
        <a href="https://docs.jboss.org/author/display/TEIID/Federated+Optimizations">View Online</a>
        |
        <a href="https://docs.jboss.org/author/pages/diffpagesbyversion.action?pageId=18646293&revisedVersion=7&originalVersion=6">View Changes</a>
                |
        <a href="https://docs.jboss.org/author/display/TEIID/Federated+Optimizations?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>