forked from docs/doc-exports
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com> Co-authored-by: luhuayi <luhuayi@huawei.com> Co-committed-by: luhuayi <luhuayi@huawei.com>
30 lines
6.6 KiB
HTML
30 lines
6.6 KiB
HTML
<a name="EN-US_TOPIC_0000002116194489"></a><a name="EN-US_TOPIC_0000002116194489"></a>
|
|
|
|
<h1 class="topictitle1">Join Operation Hints</h1>
|
|
<div id="body8662426"><div class="section" id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_section290819468377"><h4 class="sectiontitle">Function</h4><p id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_p0435135710376">Specifies the join method. It can be nested loop join, hash join, or merge join.</p>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_section3654114133815"><h4 class="sectiontitle">Syntax</h4><div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_screen633016295385"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="p">[</span><span class="k">no</span><span class="p">]</span><span class="w"> </span><span class="n">nestloop</span><span class="o">|</span><span class="n">hashjoin</span><span class="o">|</span><span class="n">mergejoin</span><span class="p">([</span><span class="o">@</span><span class="n">block_name</span><span class="p">]</span><span class="w"> </span><span class="n">table_list</span><span class="p">)</span>
|
|
</pre></div></td></tr></table></div>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_section35948678143011"><h4 class="sectiontitle">Parameter Description</h4><ul id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_ul99028441556"><li id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_li13902184410513"><strong id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_b1032416913113">no</strong> indicates that the specified hint will not be used for a join.</li><li id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_li16968121203013"><em id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_i172885331829">block_name</em> indicates the block name of the statement block. For details, see <a href="dws_04_0456.html#EN-US_TOPIC_0000002080515442__en-us_topic_0000001460722632_li99021444551">block_name</a>.</li><li id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_li425818267149"><em id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_i19593192312597">table_list</em> specifies the tables to be joined. The values are the same as those of <a href="dws_04_0456.html#EN-US_TOPIC_0000002080515442__en-us_topic_0000001460722632_section1280444714345">join_table_list</a> but contain no parentheses.</li></ul>
|
|
</div>
|
|
<p id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_p1210634411913">For example:</p>
|
|
<p id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_p4184823611913"><strong id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_b15134192142">no nestloop(t1 t2 t3)</strong>: <strong id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_b109721842171411">nestloop</strong> is not used for joining <strong id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_b546119133152">t1</strong>, <strong id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_b13373316191514">t2</strong>, and <strong id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_b13847218151518">t3</strong>. The three tables may be joined in either of the two ways: Join <strong id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_b1688215611915">t2</strong> and <strong id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_b849441062020">t3</strong>, and then <strong id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_b6640823112013">t1</strong>; join <strong id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_b3833175619204">t1</strong> and <strong id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_b15759105992017">t2</strong>, and then <strong id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_b1283615215219">t3</strong>. This hint takes effect only for the last join. If necessary, you can hint other joins. For example, you can add <strong id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_b11570138112712">no nestloop(t2 t3)</strong> to join <strong id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_b968274322819">t2</strong> and <strong id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_b3950154672816">t3</strong> first and to forbid the use of <strong id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_b4822154162810">nestloop</strong>.</p>
|
|
<div class="section" id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_section1127715590585"><h4 class="sectiontitle">Examples</h4><p id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_p1698632723710">Hint the query plan in <a href="dws_04_0455.html#EN-US_TOPIC_0000002053159594__en-us_topic_0000001658028034_section671421102912">Examples</a> as follows:</p>
|
|
</div>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_screen1097581733915"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
|
|
<span class="normal">2</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">explain</span>
|
|
<span class="k">select</span><span class="w"> </span><span class="cm">/*+ nestloop(store_sales store_returns item) */</span><span class="w"> </span><span class="n">i_product_name</span><span class="w"> </span><span class="n">product_name</span><span class="w"> </span><span class="p">...</span>
|
|
</pre></div></td></tr></table></div>
|
|
</div>
|
|
<p id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_p35873872152236"><strong id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_b597219072514">nestloop</strong> is used for the last join between <strong id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_b1851143142515">store_sales</strong>, <strong id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_b18644682513">store_returns</strong>, and <strong id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_b15759165342512">item</strong>. The optimized plan is as follows:</p>
|
|
<p id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_p1369718253710"><span><img id="EN-US_TOPIC_0000002116194489__en-us_topic_0000001510402197_image11697172173716" src="figure/en-us_image_0000001460723036.png"></span></p>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_04_0454.html">Hint-based Tuning</a></div>
|
|
</div>
|
|
</div>
|
|
|