doc-exports/docs/dws/dev/dws_04_0460.html
Lu, Huayi ef0ada5a59 DWS DEV 20240716 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-11-02 09:07:47 +00:00

46 lines
8.4 KiB
HTML

<a name="EN-US_TOPIC_0000001510522553"></a><a name="EN-US_TOPIC_0000001510522553"></a>
<h1 class="topictitle1">Scan Operation Hints</h1>
<div id="body1534471018690"><div class="section" id="EN-US_TOPIC_0000001510522553__section290819468377"><h4 class="sectiontitle">Function</h4><p id="EN-US_TOPIC_0000001510522553__p18841126184211">These hints specify a scan operation, which can be <strong id="EN-US_TOPIC_0000001510522553__b4971143352713">tablescan</strong>, <strong id="EN-US_TOPIC_0000001510522553__b1436844115184">indexscan</strong>, or <strong id="EN-US_TOPIC_0000001510522553__b1767375122620">indexonlyscan</strong>.</p>
</div>
<div class="section" id="EN-US_TOPIC_0000001510522553__section17380317104213"><h4 class="sectiontitle">Syntax</h4><div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001510522553__screen0396113074210"><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">tablescan</span><span class="o">|</span><span class="n">indexscan</span><span class="o">|</span><span class="n">indexonlyscan</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="k">table</span><span class="w"> </span><span class="p">[</span><span class="k">index</span><span class="p">])</span>
</pre></div></td></tr></table></div>
</div>
</div>
<div class="section" id="EN-US_TOPIC_0000001510522553__section35087980143822"><h4 class="sectiontitle">Parameter Description</h4><ul id="EN-US_TOPIC_0000001510522553__ul12666121741113"><li id="EN-US_TOPIC_0000001510522553__li76667177115"><strong id="EN-US_TOPIC_0000001510522553__b1032416913113">no</strong> indicates that the specified hint will not be used for a join.</li><li id="EN-US_TOPIC_0000001510522553__li310512296202"><em id="EN-US_TOPIC_0000001510522553__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_0000001460722632__li99021444551">block_name</a>.</li><li id="EN-US_TOPIC_0000001510522553__li1329712269348"><em id="EN-US_TOPIC_0000001510522553__i188894474198">table</em> specifies the table to be scanned. You can specify only one table. Use a table alias (if any) instead of a table name.<div class="note" id="EN-US_TOPIC_0000001510522553__note1427713062915"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="EN-US_TOPIC_0000001510522553__en-us_topic_0000001460722632_ul114831571316"><li id="EN-US_TOPIC_0000001510522553__en-us_topic_0000001460722632_li134831971819">The syntax format of the table is as follows:<p id="EN-US_TOPIC_0000001510522553__en-us_topic_0000001460722632_p6483117519"><a name="EN-US_TOPIC_0000001510522553__en-us_topic_0000001460722632_li134831971819"></a><a name="en-us_topic_0000001460722632_li134831971819"></a>[schema.]table[@block_name]</p>
<p id="EN-US_TOPIC_0000001510522553__en-us_topic_0000001460722632_p204832718119">The table name can contain the schema name or block name before the subquery statement block is promoted. If the subquery statement block is optimized and rewritten by the optimizer, the value of <strong id="EN-US_TOPIC_0000001510522553__en-us_topic_0000001460722632_b1442317392810">block_name</strong> is different from that of <strong id="EN-US_TOPIC_0000001510522553__en-us_topic_0000001460722632_b152968102815">block_name</strong> in leading.</p>
</li><li id="EN-US_TOPIC_0000001510522553__en-us_topic_0000001460722632_li3483157118">If a table has an alias, the alias is preferentially used to represent the table.</li></ul>
</div></div>
</li><li id="EN-US_TOPIC_0000001510522553__li11674239153516"><em id="EN-US_TOPIC_0000001510522553__i8856173202115">index</em> indicates the index for <strong id="EN-US_TOPIC_0000001510522553__b570142117227">indexscan</strong> or <strong id="EN-US_TOPIC_0000001510522553__b245052811221">indexonlyscan</strong>. You can specify only one index.<div class="note" id="EN-US_TOPIC_0000001510522553__note04961250103515"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001510522553__p049618501350"><strong id="EN-US_TOPIC_0000001510522553__b9215191663615">indexscan</strong> and <strong id="EN-US_TOPIC_0000001510522553__b655183115360">indexonlyscan</strong> hints can be used only when the specified index belongs to the table.</p>
<p id="EN-US_TOPIC_0000001510522553__p14967504359">Scan operation hints can be used for row-store tables, column-store tables, HDFS tables, HDFS foreign tables, OBS tables, and subquery tables. HDFS tables include primary tables and delta tables. The delta tables are invisible to users. Therefore, scan operation hints are used only for primary tables.</p>
<p id="EN-US_TOPIC_0000001510522553__p549617504358">If <strong id="EN-US_TOPIC_0000001510522553__b185001352115611">indexscan</strong> is specified, <strong id="EN-US_TOPIC_0000001510522553__b534016558561">indexscan</strong> or <strong id="EN-US_TOPIC_0000001510522553__b257015115720">indexonlyscan</strong> takes effect. <strong id="EN-US_TOPIC_0000001510522553__b113171620572">indexscan</strong> and <strong id="EN-US_TOPIC_0000001510522553__b1852411015720">indexonlyscan</strong> can also take effect at the same time. When <strong id="EN-US_TOPIC_0000001510522553__b17859327165717">indexscan</strong> and <strong id="EN-US_TOPIC_0000001510522553__b4680123305716">indexonlyscan hints</strong> appear at the same time, <strong id="EN-US_TOPIC_0000001510522553__b8963193916573">indexonlyscan</strong> takes effect first.</p>
</div></div>
</li></ul>
</div>
<div class="section" id="EN-US_TOPIC_0000001510522553__section1127715590585"><h4 class="sectiontitle">Example</h4><p id="EN-US_TOPIC_0000001510522553__p50606497145546">To specify an index-based hint for a scan, create an index named <strong id="EN-US_TOPIC_0000001510522553__b9707114412139">i</strong> on the<strong id="EN-US_TOPIC_0000001510522553__b16707194421316"> i_item_sk</strong> column of the <strong id="EN-US_TOPIC_0000001510522553__b1170894411134">item</strong> table.</p>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001510522553__screen27545314435"><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="k">create</span><span class="w"> </span><span class="k">index</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="k">on</span><span class="w"> </span><span class="n">item</span><span class="p">(</span><span class="n">i_item_sk</span><span class="p">);</span>
</pre></div></td></tr></table></div>
</div>
</div>
<p id="EN-US_TOPIC_0000001510522553__p1698632723710">Hint the query plan in <a href="dws_04_0455.html#EN-US_TOPIC_0000001460562888__section671421102912">Examples</a> as follows:</p>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001510522553__screen194951433184320"><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">/*+ indexscan(item i) */</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_0000001510522553__p35873872152236"><strong id="EN-US_TOPIC_0000001510522553__b11234148172410">item</strong> is scanned based on an index. The optimized plan is as follows:</p>
<p id="EN-US_TOPIC_0000001510522553__p2249174015383"><span><img id="EN-US_TOPIC_0000001510522553__image3249174043812" src="figure/en-us_image_0000001460723188.png" height="213.465" width="523.6875" title="Click to enlarge" class="imgResize"></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>
<script language="JavaScript">
<!--
image_size('.imgResize');
var msg_imageMax = "view original image";
var msg_imageClose = "close";
//--></script>