doc-exports/docs/dws/dev/dws_04_0457.html
Lu, Huayi e6fa411af0 DWS DEV 830.201 version
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com>
Co-authored-by: Lu, Huayi <luhuayi@huawei.com>
Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
2024-05-16 07:24:04 +00:00

33 lines
5.3 KiB
HTML

<a name="EN-US_TOPIC_0000001233563309"></a><a name="EN-US_TOPIC_0000001233563309"></a>
<h1 class="topictitle1">Join Operation Hints</h1>
<div id="body1534471018690"><div class="section" id="EN-US_TOPIC_0000001233563309__section290819468377"><h4 class="sectiontitle">Function</h4><p id="EN-US_TOPIC_0000001233563309__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_0000001233563309__section3654114133815"><h4 class="sectiontitle">Syntax</h4><div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001233563309__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="n">table_list</span><span class="p">)</span>
</pre></div></td></tr></table></div>
</div>
</div>
<div class="section" id="EN-US_TOPIC_0000001233563309__section35948678143011"><a name="EN-US_TOPIC_0000001233563309__section35948678143011"></a><a name="section35948678143011"></a><h4 class="sectiontitle">Parameter Description</h4><ul id="EN-US_TOPIC_0000001233563309__ul99028441556"><li id="EN-US_TOPIC_0000001233563309__li13902184410513"><strong id="EN-US_TOPIC_0000001233563309__b1032416913113">no</strong> indicates that the specified hint will not be used for a join.</li></ul>
</div>
<ul id="EN-US_TOPIC_0000001233563309__ul139031441510"><li id="EN-US_TOPIC_0000001233563309__li1090312446510"><a name="EN-US_TOPIC_0000001233563309__li1090312446510"></a><a name="li1090312446510"></a><em id="EN-US_TOPIC_0000001233563309__i1582382232010">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_0000001188163600__section1280444714345">join_table_list</a> but contain no parentheses.</li></ul>
<p id="EN-US_TOPIC_0000001233563309__p1210634411913">For example:</p>
<p id="EN-US_TOPIC_0000001233563309__p4184823611913"><strong id="EN-US_TOPIC_0000001233563309__b15134192142">no nestloop(t1 t2 t3)</strong>: <strong id="EN-US_TOPIC_0000001233563309__b109721842171411">nestloop</strong> is not used for joining <strong id="EN-US_TOPIC_0000001233563309__b546119133152">t1</strong>, <strong id="EN-US_TOPIC_0000001233563309__b13373316191514">t2</strong>, and <strong id="EN-US_TOPIC_0000001233563309__b13847218151518">t3</strong>. The three tables may be joined in either of the two ways: Join <strong id="EN-US_TOPIC_0000001233563309__b1688215611915">t2</strong> and <strong id="EN-US_TOPIC_0000001233563309__b849441062020">t3</strong>, and then <strong id="EN-US_TOPIC_0000001233563309__b6640823112013">t1</strong>; join <strong id="EN-US_TOPIC_0000001233563309__b3833175619204">t1</strong> and <strong id="EN-US_TOPIC_0000001233563309__b15759105992017">t2</strong>, and then <strong id="EN-US_TOPIC_0000001233563309__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_0000001233563309__b11570138112712">no nestloop(t2 t3)</strong> to join <strong id="EN-US_TOPIC_0000001233563309__b968274322819">t2</strong> and <strong id="EN-US_TOPIC_0000001233563309__b3950154672816">t3</strong> first and to forbid the use of <strong id="EN-US_TOPIC_0000001233563309__b4822154162810">nestloop</strong>.</p>
<div class="section" id="EN-US_TOPIC_0000001233563309__section1127715590585"><h4 class="sectiontitle">Examples</h4><p id="EN-US_TOPIC_0000001233563309__p1698632723710">Hint the query plan in <a href="dws_04_0455.html#EN-US_TOPIC_0000001188642062__section671421102912">Examples</a> as follows:</p>
</div>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001233563309__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_0000001233563309__p35873872152236"><strong id="EN-US_TOPIC_0000001233563309__b597219072514">nestloop</strong> is used for the last join between <strong id="EN-US_TOPIC_0000001233563309__b1851143142515">store_sales</strong>, <strong id="EN-US_TOPIC_0000001233563309__b18644682513">store_returns</strong>, and <strong id="EN-US_TOPIC_0000001233563309__b15759165342512">item</strong>. The optimized plan is as follows:</p>
<p id="EN-US_TOPIC_0000001233563309__p1369718253710"><span><img id="EN-US_TOPIC_0000001233563309__image11697172173716" src="figure/en-us_image_0000001188323794.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>