forked from docs/doc-exports
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com> Co-authored-by: Lu, Huayi <luhuayi@huawei.com> Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
28 lines
4.3 KiB
HTML
28 lines
4.3 KiB
HTML
<a name="EN-US_TOPIC_0000001098974950"></a><a name="EN-US_TOPIC_0000001098974950"></a>
|
|
|
|
<h1 class="topictitle1">Selecting a Distribution Column</h1>
|
|
<div id="body8662426"><p id="EN-US_TOPIC_0000001098974950__a8bc4b1964cee4988bba61310304ea8b8">The distribution column in a hash table must meet the following requirements, which are ranked by priority in descending order:</p>
|
|
<ol id="EN-US_TOPIC_0000001098974950__ol29343014911"><li id="EN-US_TOPIC_0000001098974950__li993416017495"><strong id="EN-US_TOPIC_0000001098974950__b842352706105350">The value of the distribution column should be discrete so that data can be evenly distributed on each DN.</strong> For example, you are advised to select the primary key of a table as the distribution column, and the ID card number as the distribution column in a personnel information table.</li><li id="EN-US_TOPIC_0000001098974950__li993480194918"><strong id="EN-US_TOPIC_0000001098974950__b84235270611839">Do not select the column where a constant filter exists.</strong> For example, if a constant constraint (for example, zqdh= '000001') exists on the <strong id="EN-US_TOPIC_0000001098974950__b842352706164727">zqdh</strong> column in some queries on the <strong id="EN-US_TOPIC_0000001098974950__b84235270612518">dwcjk</strong> table, you are not advised to use <strong id="EN-US_TOPIC_0000001098974950__b84235270616480">zqdh</strong> as the distribution column.</li><li id="EN-US_TOPIC_0000001098974950__li4935110124917"><strong id="EN-US_TOPIC_0000001098974950__b516064154416">Select the join condition as the distribution column</strong>, so that join tasks can be pushed down to DNs to execute, reducing the amount of data transferred between the DNs.<p id="EN-US_TOPIC_0000001098974950__a4af0ed216612409ea73522d1b1f5ae64">For a hash table, an improper distribution key may cause data skew or poor I/O performance on certain DNs. Therefore, you need to check the table to ensure that data is evenly distributed on each DN. You can run the following SQL statements to check data skew:</p>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001098974950__s9b81a8050014459d962cffd10a0611b5"><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>
|
|
<span class="normal">5</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">select</span><span class="w"> </span>
|
|
<span class="n">xc_node_id</span><span class="p">,</span><span class="w"> </span><span class="k">count</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="w"> </span>
|
|
<span class="k">from</span><span class="w"> </span><span class="n">tablename</span><span class="w"> </span>
|
|
<span class="k">group</span><span class="w"> </span><span class="k">by</span><span class="w"> </span><span class="n">xc_node_id</span><span class="w"> </span>
|
|
<span class="k">order</span><span class="w"> </span><span class="k">by</span><span class="w"> </span><span class="n">xc_node_id</span><span class="w"> </span><span class="k">desc</span><span class="p">;</span><span class="w"></span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
<p id="EN-US_TOPIC_0000001098974950__p173751945154918"><strong id="EN-US_TOPIC_0000001098974950__b842352706125856">xc_node_id</strong> corresponds to a DN. Generally, <strong id="EN-US_TOPIC_0000001098974950__b84235270617258">over 5% difference between the amount of data on different DNs is regarded as data skew. If the difference is over 10%, choose another distribution column.</strong></p>
|
|
</li><li id="EN-US_TOPIC_0000001098974950__li796918294492">You are not advised to add a column as a distribution column, especially add a new column and use the SEQUENCE value to fill the column. This is because SEQUENCE may cause performance bottlenecks and unnecessary maintenance costs.</li></ol>
|
|
<p id="EN-US_TOPIC_0000001098974950__aca377a4227184714b95dba9b277485b6">Multiple distribution columns can be selected in <span id="EN-US_TOPIC_0000001098974950__text1523288790">GaussDB(DWS)</span> to evenly distribute data.</p>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_04_0437.html">Reviewing and Modifying a Table Definition</a></div>
|
|
</div>
|
|
</div>
|
|
|