doc-exports/docs/dws/dev/dws_04_0481.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

48 lines
5.9 KiB
HTML

<a name="EN-US_TOPIC_0000001188482144"></a><a name="EN-US_TOPIC_0000001188482144"></a>
<h1 class="topictitle1">Case: Adjusting the Partial Clustering Key</h1>
<div id="body8662426"><p id="EN-US_TOPIC_0000001188482144__p38951258115">Partial Cluster Key (PCK) is an index technology that uses min/max indexes to quickly scan base tables in column storage. Partial cluster key can specify multiple columns, but you are advised to specify no more than two columns. It can be used to accelerated queries on large column-store tables.</p>
<div class="section" id="EN-US_TOPIC_0000001188482144__sfaa9f7d929b74548870686b901e49068"><h4 class="sectiontitle">Before Optimization</h4><p id="EN-US_TOPIC_0000001188482144__p522395932114">Create a column-store table <strong id="EN-US_TOPIC_0000001188482144__b14627105015533">orders_no_pck</strong> without partial clustering (PCK). The table is defined as follows:</p>
<p id="EN-US_TOPIC_0000001188482144__p145612012242"><span><img id="EN-US_TOPIC_0000001188482144__image1487518487263" src="figure/en-us_image_0000001598442429.png"></span></p>
<p id="EN-US_TOPIC_0000001188482144__p205765200811">Run the following SQL statement to query the execution plan of a point query:</p>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001188482144__screen109551840886"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
<span class="normal">2</span>
<span class="normal">3</span>
<span class="normal">4</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">EXPLAIN</span><span class="w"> </span><span class="n">PERFORMANCE</span>
<span class="k">SELECT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">orders_no_pck</span>
<span class="k">WHERE</span><span class="w"> </span><span class="n">o_orderkey</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'13095143'</span>
<span class="k">ORDER</span><span class="w"> </span><span class="k">BY</span><span class="w"> </span><span class="n">o_orderdate</span><span class="p">;</span>
</pre></div></td></tr></table></div>
</div>
<p id="EN-US_TOPIC_0000001188482144__p3590651181">As shown in the following figure, the execution time is 48 ms. Check <strong id="EN-US_TOPIC_0000001188482144__b20636819185413">Datanode Information</strong>. It is found that the filter time is 19 ms and the CUNone ratio is 0.</p>
<p id="EN-US_TOPIC_0000001188482144__p198391149192111"><span><img id="EN-US_TOPIC_0000001188482144__image17843112013212" src="figure/en-us_image_0000001547757780.png"></span></p>
<p id="EN-US_TOPIC_0000001188482144__p16575653152018"><span><img id="EN-US_TOPIC_0000001188482144__image9931103032120" src="figure/en-us_image_0000001598557569.png"></span></p>
</div>
<div class="section" id="EN-US_TOPIC_0000001188482144__s71ffd8e8cc0542d180e9be037cf86e23"><h4 class="sectiontitle">After Optimization</h4><p id="EN-US_TOPIC_0000001188482144__p176281242152911">The created column-store table <strong id="EN-US_TOPIC_0000001188482144__b295121213510">orders_pck</strong> is defined as follows:</p>
<p id="EN-US_TOPIC_0000001188482144__p118551312114011"><span><img id="EN-US_TOPIC_0000001188482144__image175931647135111" src="figure/en-us_image_0000001598641405.png"></span></p>
<p id="EN-US_TOPIC_0000001188482144__p1186111450329">Use <strong id="EN-US_TOPIC_0000001188482144__b828314361327">ALTER TABLE</strong> to set the <strong id="EN-US_TOPIC_0000001188482144__b103159400219">o_orderkey</strong> field to <strong id="EN-US_TOPIC_0000001188482144__b15866184319211">PCK</strong>:</p>
<p id="EN-US_TOPIC_0000001188482144__p1939012225315"><span><img id="EN-US_TOPIC_0000001188482144__image3791142265314" src="figure/en-us_image_0000001547777474.png"></span></p>
<p id="EN-US_TOPIC_0000001188482144__a492b4be4f7674246b35ba05392ad0400">Run the following SQL statement to query the execution plan of the same point query SQL statement again:</p>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001188482144__screen15335125151517"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
<span class="normal">2</span>
<span class="normal">3</span>
<span class="normal">4</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">EXPLAIN</span><span class="w"> </span><span class="n">PERFORMANCE</span>
<span class="k">SELECT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">orders_pck</span>
<span class="k">WHERE</span><span class="w"> </span><span class="n">o_orderkey</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'13095143'</span>
<span class="k">ORDER</span><span class="w"> </span><span class="k">BY</span><span class="w"> </span><span class="n">o_orderdate</span><span class="p">;</span>
</pre></div></td></tr></table></div>
</div>
<p id="EN-US_TOPIC_0000001188482144__p10468020151714">As shown in the following figure, the execution time is 5 ms. Check <strong id="EN-US_TOPIC_0000001188482144__b11963624115512">Datanode Information</strong>. It is found that the filter time is 0.5 ms and the CUNone ratio is 82. The higher the CUNone ratio, the higher performance that the PCK will bring.</p>
<p id="EN-US_TOPIC_0000001188482144__p285811272203"><span><img id="EN-US_TOPIC_0000001188482144__image731219386195" src="figure/en-us_image_0000001598622253.png"></span></p>
<p id="EN-US_TOPIC_0000001188482144__p964012583177"><span><img id="EN-US_TOPIC_0000001188482144__image358444132017" src="figure/en-us_image_0000001547437736.png"></span></p>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_04_0474.html">Optimization Cases</a></div>
</div>
</div>