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

52 lines
7.5 KiB
HTML

<a name="EN-US_TOPIC_0000001628950669"></a><a name="EN-US_TOPIC_0000001628950669"></a>
<h1 class="topictitle1">Case: Adjusting the Partial Clustering Key</h1>
<div id="body32001227"><p id="EN-US_TOPIC_0000001628950669__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_0000001628950669__en-us_topic_0000001188482144_sfaa9f7d929b74548870686b901e49068"><h4 class="sectiontitle">Before Optimization</h4><p id="EN-US_TOPIC_0000001628950669__en-us_topic_0000001188482144_p522395932114">Create a column-store table <strong id="EN-US_TOPIC_0000001628950669__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_0000001628950669__en-us_topic_0000001188482144_p145612012242"><span><img id="EN-US_TOPIC_0000001628950669__en-us_topic_0000001188482144_image1487518487263" src="figure/en-us_image_0000001598442429.png" width="518.7" height="216.77670000000003" title="Click to enlarge" class="imgResize"></span></p>
<p id="EN-US_TOPIC_0000001628950669__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_0000001628950669__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_0000001628950669__en-us_topic_0000001188482144_p3590651181">As shown in the following figure, the execution time is 48 ms. Check <strong id="EN-US_TOPIC_0000001628950669__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_0000001628950669__en-us_topic_0000001188482144_p198391149192111"><span><img id="EN-US_TOPIC_0000001628950669__en-us_topic_0000001188482144_image17843112013212" src="figure/en-us_image_0000001547757780.png" width="518.7" height="88.3652" title="Click to enlarge" class="imgResize"></span></p>
<p id="EN-US_TOPIC_0000001628950669__en-us_topic_0000001188482144_p16575653152018"><span><img id="EN-US_TOPIC_0000001628950669__en-us_topic_0000001188482144_image9931103032120" src="figure/en-us_image_0000001598557569.png" width="518.7" height="234.2662" title="Click to enlarge" class="imgResize"></span></p>
</div>
<div class="section" id="EN-US_TOPIC_0000001628950669__en-us_topic_0000001188482144_s71ffd8e8cc0542d180e9be037cf86e23"><h4 class="sectiontitle">After Optimization</h4><p id="EN-US_TOPIC_0000001628950669__en-us_topic_0000001188482144_p176281242152911">The created column-store table <strong id="EN-US_TOPIC_0000001628950669__en-us_topic_0000001188482144_b295121213510">orders_pck</strong> is defined as follows:</p>
<p id="EN-US_TOPIC_0000001628950669__en-us_topic_0000001188482144_p118551312114011"><span><img id="EN-US_TOPIC_0000001628950669__en-us_topic_0000001188482144_image175931647135111" src="figure/en-us_image_0000001598641405.png" width="518.7" height="213.67780000000002" title="Click to enlarge" class="imgResize"></span></p>
<p id="EN-US_TOPIC_0000001628950669__en-us_topic_0000001188482144_p1186111450329">Use <strong id="EN-US_TOPIC_0000001628950669__en-us_topic_0000001188482144_b828314361327">ALTER TABLE</strong> to set the <strong id="EN-US_TOPIC_0000001628950669__en-us_topic_0000001188482144_b103159400219">o_orderkey</strong> field to <strong id="EN-US_TOPIC_0000001628950669__en-us_topic_0000001188482144_b15866184319211">PCK</strong>:</p>
<p id="EN-US_TOPIC_0000001628950669__en-us_topic_0000001188482144_p1939012225315"><span><img id="EN-US_TOPIC_0000001628950669__en-us_topic_0000001188482144_image3791142265314" src="figure/en-us_image_0000001547777474.png" width="518.7" height="31.5742" title="Click to enlarge" class="imgResize"></span></p>
<p id="EN-US_TOPIC_0000001628950669__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_0000001628950669__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_0000001628950669__en-us_topic_0000001188482144_p10468020151714">As shown in the following figure, the execution time is 5 ms. Check <strong id="EN-US_TOPIC_0000001628950669__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_0000001628950669__en-us_topic_0000001188482144_p285811272203"><span><img id="EN-US_TOPIC_0000001628950669__en-us_topic_0000001188482144_image731219386195" src="figure/en-us_image_0000001598622253.png" width="518.7" height="93.3128" title="Click to enlarge" class="imgResize"></span></p>
<p id="EN-US_TOPIC_0000001628950669__en-us_topic_0000001188482144_p964012583177"><span><img id="EN-US_TOPIC_0000001628950669__en-us_topic_0000001188482144_image358444132017" src="figure/en-us_image_0000001547437736.png" width="518.7" height="231.9786" title="Click to enlarge" class="imgResize"></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>
<script language="JavaScript">
<!--
image_size('.imgResize');
var msg_imageMax = "view original image";
var msg_imageClose = "close";
//--></script>