Files
doc-exports/docs/dws/dev/dws_04_0112.html
luhuayi 177cd61a57 DWS DEVG 910.211 version
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com>
Co-authored-by: luhuayi <luhuayi@huawei.com>
Co-committed-by: luhuayi <luhuayi@huawei.com>
2025-05-05 07:44:03 +00:00

139 lines
27 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<a name="EN-US_TOPIC_0000002100746050"></a><a name="EN-US_TOPIC_0000002100746050"></a>
<h1 class="topictitle1">TABLE Object Design (Prioritized)</h1>
<div id="body8662426"><div class="section" id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_section015412016423"><h4 class="sectiontitle">Rule 2.9: Selecting the Optimal Distribution Method and Columns During Table Creation</h4><div class="note" id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_note820812172539"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p42334441334"><strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b33635405810736">Impact of rule violation:</strong></p>
<ul id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_ul823384423314"><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li2074645931"><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p167410459318"><a name="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li2074645931"></a><a name="en-us_topic_0000002135726597_li2074645931"></a>Incorrect distribution method and column selection can cause storage skew, deteriorate access performance, and even overload storage and computing resources.</p>
</li></ul>
<p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p1323344463316"><strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b414968340112625">Solution:</strong></p>
<ul id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_ul92191316161014"><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li221981611010">When creating a table, it is important to use the <strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b3130182815719">DISTRIBUTE BY</strong> clause to explicitly specify the distribution method and distribution columns. The table below provides principles for selecting the distribution columns.</li></ul>
</div></div>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_table1278902025420" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Distribution column selection</caption><thead align="left"><tr id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_row681662025419"><th align="left" class="cellrowborder" valign="top" width="14.288571142885711%" id="mcps1.3.1.3.2.4.1.1"><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p181632013547"><strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b1980614814612">Distribution Method</strong></p>
</th>
<th align="left" class="cellrowborder" valign="top" width="43.87561243875613%" id="mcps1.3.1.3.2.4.1.2"><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p11816020155413"><strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b681642014546">Description</strong></p>
</th>
<th align="left" class="cellrowborder" valign="top" width="41.835816418358164%" id="mcps1.3.1.3.2.4.1.3"><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p181611207545"><strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b439151613464">Scenario</strong></p>
</th>
</tr>
</thead>
<tbody><tr id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_row881652017546"><td class="cellrowborder" valign="top" width="14.288571142885711%" headers="mcps1.3.1.3.2.4.1.1 "><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p2081692085418">Hash</p>
</td>
<td class="cellrowborder" valign="top" width="43.87561243875613%" headers="mcps1.3.1.3.2.4.1.2 "><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p188161820155420">Table data is distributed to each DN based on the mapping between hash values generated by distribution columns and DNs.</p>
<ul id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_ul530617366178"><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li10306103651712"><strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b48161520125411">Advantage</strong>: Each DN contains only part of data, which is space-saving.</li><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li930633621716"><strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b138163201547">Disadvantage</strong>: The even distribution of data depends heavily on the selection of distribution columns. If the join condition does not include the distribution columns of each node, data communication between nodes will be required.</li></ul>
</td>
<td class="cellrowborder" valign="top" width="41.835816418358164%" headers="mcps1.3.1.3.2.4.1.3 "><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p8816182055410">Large tables and fact tables</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_row19816162055418"><td class="cellrowborder" valign="top" width="14.288571142885711%" headers="mcps1.3.1.3.2.4.1.1 "><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p11816122019547">RoundRobin</p>
</td>
<td class="cellrowborder" valign="top" width="43.87561243875613%" headers="mcps1.3.1.3.2.4.1.2 "><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p208165203548">Table data is distributed to DNs in polling mode.</p>
<ul id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_ul967523931719"><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li1267553913178"><strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b13816142012546">Advantage</strong>: Each DN only contains a portion of the data, taking up a small amount of space. Data is evenly distributed in polling mode and does not rely on distribution columns, eliminating data skews.</li><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li1567553919173"><strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b18171020135419">Disadvantage</strong>: Using distribution column conditions cannot eliminate or reduce inter-node communication. In this scenario, the performance is inferior to that of <strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b023383223710">HASH</strong>.</li></ul>
</td>
<td class="cellrowborder" valign="top" width="41.835816418358164%" headers="mcps1.3.1.3.2.4.1.3 "><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p208171720195412">Large tables, fact tables, and tables without proper distribution columns</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_row8817152035416"><td class="cellrowborder" valign="top" width="14.288571142885711%" headers="mcps1.3.1.3.2.4.1.1 "><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p1081742055416">Replication</p>
</td>
<td class="cellrowborder" valign="top" width="43.87561243875613%" headers="mcps1.3.1.3.2.4.1.2 "><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p118174209547">Full data in a table is copied to each DN in the cluster.</p>
<ul id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_ul6930175111719"><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li5930195113170"><strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b68171420135420">Advantage</strong>: Each DN holds the complete data of the table. The <strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b219025414374">JOIN</strong> operation avoids data communication between nodes, reducing network overhead and the overhead of starting and stopping the <strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b179183853810">STREAM</strong> thread.</li><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li19930751131711"><strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b1681732020542">Disadvantage</strong>: Each DN retains complete table data, which is redundant and occupies more storage space.</li></ul>
</td>
<td class="cellrowborder" valign="top" width="41.835816418358164%" headers="mcps1.3.1.3.2.4.1.3 "><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p208174209544">Small tables and dimension tables</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_section16391112254212"><h4 class="sectiontitle">Rule 2.10 Selecting an Optimal Storage Type During Table Creation</h4><div class="note" id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_note72185115162"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p4799193031410"><strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b207770544810736">Impact of rule violation:</strong></p>
<ul id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_ul1279993001410"><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li10799930161419"><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p379963011410"><a name="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li10799930161419"></a><a name="en-us_topic_0000002135726597_li10799930161419"></a>Row-store tables are not properly used. As a result, the query performance is poor and resources are overloaded.</p>
</li><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li1598893921617">Improper use of column-store tables causes CU expansion, poor performance, and resource overload.</li></ul>
<p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p1979911303141"><strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b99023674112625">Solution:</strong></p>
<ul id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_ul1079933031411"><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li7799630101420">When creating a table, use the <strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b1852011197385">orientation</strong> parameter to explicitly specify the storage type. The following table describes the rules for selecting a storage type.</li></ul>
</div></div>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_table15691442115518" frame="border" border="1" rules="all"><caption><b>Table 2 </b>Storage type selection</caption><thead align="left"><tr id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_row1459834219552"><th align="left" class="cellrowborder" valign="top" width="12.031203120312032%" id="mcps1.3.2.3.2.4.1.1"><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p259874225514"><strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b2059834295519">Storage Type</strong></p>
</th>
<th align="left" class="cellrowborder" valign="top" width="45.54455445544555%" id="mcps1.3.2.3.2.4.1.2"><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p12598242145518"><strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b653254144814">Applicable Scenario</strong></p>
</th>
<th align="left" class="cellrowborder" valign="top" width="42.42424242424242%" id="mcps1.3.2.3.2.4.1.3"><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p55986426552"><strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b15661148114815">Inapplicable Scenario</strong></p>
</th>
</tr>
</thead>
<tbody><tr id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_row135988422555"><td class="cellrowborder" valign="top" width="12.031203120312032%" headers="mcps1.3.2.3.2.4.1.1 "><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p12598642115514">Row storage</p>
</td>
<td class="cellrowborder" valign="top" width="45.54455445544555%" headers="mcps1.3.2.3.2.4.1.2 "><ul id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_ul321474220187"><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li17214114261816">DML addition, deletion, and modification: scenarios with many <strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b468916461033">UPDATE</strong> and <strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b1477754914318">DELETE</strong> operations</li><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li22141542141812">DML query: point query (simple indexbased query that returns only a few records)</li></ul>
</td>
<td class="cellrowborder" valign="top" width="42.42424242424242%" headers="mcps1.3.2.3.2.4.1.3 "><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p159884210555">DML query: statistical analysis query (with mass data involved in <strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b45451395415">GROUP</strong> and <strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b1819964710420">JOIN</strong> processes)</p>
<div class="caution" id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_note11914185912180"><span class="cautiontitle"> CAUTION: </span><div class="cautionbody"><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p149344497236">When creating a row-store table (<strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b18790195012385">orientation</strong> is set to <strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b2251195312387">row</strong>), do not specify the <strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b173622913396">compress</strong> attribute or use a row-store compressed table.</p>
</div></div>
</td>
</tr>
<tr id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_row7598114216555"><td class="cellrowborder" valign="top" width="12.031203120312032%" headers="mcps1.3.2.3.2.4.1.1 "><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p1959834245515">Column storage</p>
</td>
<td class="cellrowborder" valign="top" width="45.54455445544555%" headers="mcps1.3.2.3.2.4.1.2 "><ul id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_ul811234521818"><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li16112945151818">DML addition, deletion, and modification: <strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b12501219153">INSERT</strong> batch import scenario (The number of data records imported to a single partition at a time is approximately 60,000 times the number of DNs or greater.)</li><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li3112134571818">DML query: statistical analysis query (with mass data involved in <strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b8569468559">GROUP</strong> and <strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b20571746125519">JOIN</strong> processes)</li></ul>
</td>
<td class="cellrowborder" valign="top" width="42.42424242424242%" headers="mcps1.3.2.3.2.4.1.3 "><ul id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_ul4361216101919"><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li53661681917">DML addition, deletion, and modification: scenarios with many <strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b1056312531368">UPDATE</strong>/<strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b1083085617617">DELETE</strong> operations or a small number of <strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b11621143720">INSERT</strong> operations</li><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li1361316161911">DML query: high-concurrency point query</li></ul>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_section392619458421"><h4 class="sectiontitle">Rule 2.11 Selecting an Optimal Partitioning Policy During Table Creation</h4><div class="note" id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_note13964114617545"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p125061225260"><strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b96794404110736">Impact of rule violation:</strong></p>
<p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p1098755910329">Without partitioning, query performance and data governance efficiency will deteriorate. The larger the data volume, the greater the deterioration. The advantages of partitioning include:</p>
<ul id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_ul11987115933216"><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li4987115993217">High query performance: The system queries only the relevant partitions rather than the whole table, improving the query efficiency.</li><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li1698705920325">Improved data governance efficiency: In the data lifecycle management scenario, performing <strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b0605142944117">TRUNCATE</strong> or <strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b7240103244111">DROP PARTITION</strong> on historical partitions is much more efficient and effective than using <strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b583014244115">DELETE</strong>.</li></ul>
<p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p5506225268"><strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b358174993112625">Solution:</strong></p>
<ul id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_ul44448349289"><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li174443344289">Design partitions for tables that contain fields of the time type.</li></ul>
</div></div>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_table11185114820544" frame="border" border="1" rules="all"><caption><b>Table 3 </b>Partitioning policy selection</caption><thead align="left"><tr id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_row15203174895413"><th align="left" class="cellrowborder" valign="top" width="19.19191919191919%" id="mcps1.3.3.3.2.4.1.1"><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p920334865416"><strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b186831554185112">Partitioning Policy</strong></p>
</th>
<th align="left" class="cellrowborder" valign="top" width="38.38383838383838%" id="mcps1.3.3.3.2.4.1.2"><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p1120312489546"><strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b301991419104512">Description</strong></p>
</th>
<th align="left" class="cellrowborder" valign="top" width="42.42424242424242%" id="mcps1.3.3.3.2.4.1.3"><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p8203124805412"><strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b13251905525">Scenario</strong></p>
</th>
</tr>
</thead>
<tbody><tr id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_row1220316489545"><td class="cellrowborder" valign="top" width="19.19191919191919%" headers="mcps1.3.3.3.2.4.1.1 "><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p8203848185413">Range partitioning</p>
</td>
<td class="cellrowborder" valign="top" width="38.38383838383838%" headers="mcps1.3.3.3.2.4.1.2 "><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p8203154810548">Data is stored in different partitions based on the range of partition key values. The partition key ranges are consecutive but not overlapped.</p>
</td>
<td class="cellrowborder" valign="top" width="42.42424242424242%" headers="mcps1.3.3.3.2.4.1.3 "><ol id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_ol04406921513"><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li1444015981512">The date or time field is used as the partition key.</li><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li14404911158">Most queries contain partition keys as filter criteria.</li><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li2440189131517">Periodically delete data based on the partition key.</li></ol>
</td>
</tr>
<tr id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_row920314815417"><td class="cellrowborder" valign="top" width="19.19191919191919%" headers="mcps1.3.3.3.2.4.1.1 "><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p142036489546">List partitioning</p>
</td>
<td class="cellrowborder" valign="top" width="38.38383838383838%" headers="mcps1.3.3.3.2.4.1.2 "><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p420314817545">Partitioning is performed based on a unique list of partition key values.</p>
</td>
<td class="cellrowborder" valign="top" width="42.42424242424242%" headers="mcps1.3.3.3.2.4.1.3 "><ol id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_ol4256201819153"><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li5256218101513">A specific number of enumerated values are used as partition key values.</li><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li62561218171514">Most queries contain partition keys as filter criteria.</li></ol>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_section140547134319"><h4 class="sectiontitle">Suggestion 2.12: Designing Table Columns for Fast and Accurate Queries</h4><div class="note" id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_note1879565824217"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p83309242313"><strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b207490739610736">Impact of rule violation:</strong></p>
<ul id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_ul23094256234"><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li1026014535302">The system may have limited storage space and low query efficiency.</li></ul>
<p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p156727318239"><strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b381599277112625">Solution:</strong></p>
<ol id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_ol471172192914"><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li15317152182919">Design the table columns well for fast queries.<ul id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_ul1787563122918"><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li28751131172911">If you can select an integer, do not select the floating point or character type.</li><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li5875173118296">When using variable-length character type, specify the maximum length based on data features.</li></ul>
</li><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li157119220294">Design the table columns well for accurate queries.<ul id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_ul87156509280"><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li18715450172814">Use the time type instead of the character type to store time data.</li><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li1871565011287">Use the minimum numeric type that meets the requirements. Avoid using bigint if int or smallint is sufficient to save space.</li></ul>
</li><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li983612529334"><strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b115284557201">Correctly use the constraints.</strong><ul id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_ul10610111347"><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li665114343">Add <strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b14340628301">NOT NULL</strong> constraints to columns that never have NULL values. The optimizer automatically optimizes the columns in certain scenarios.</li><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li1361014342">Do not use the <strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b1168819478013">DEFAULT</strong> constraint for fields that can be supplemented at the service layer. Otherwise, unexpected results may be generated during data loading.</li></ul>
</li><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li64921019163813"><strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b1861925719207">Avoid unnecessary data type conversion.</strong><ul id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_ul2092612519385"><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li79262251389">In tables that are logically related, columns having the same meaning should use the same data type.</li><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li79261725143818">Different types of comparison operations cause data type conversion, which may cause index and partition pruning failures and affect query performance.</li></ul>
</li></ol>
</div></div>
</div>
<div class="section" id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_section20860162415439"><h4 class="sectiontitle">Suggestion 2.13: Avoiding the Usage of Auto-increment Columns or Data Types</h4><div class="note" id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_note16759754195512"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p1692225813502"><strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b175857472910736">Impact of rule violation:</strong></p>
<ul id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_ul492255815014"><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li10922158145018"><p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p192255885012"><a name="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li10922158145018"></a><a name="en-us_topic_0000002135726597_li10922158145018"></a>When auto-increment sequences or data types are heavily used, the GTM may become overloaded and slow down sequence generation.</p>
</li></ul>
<p id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_p12922115810502"><strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b1037959141112625">Solution:</strong></p>
<ul id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_ul6922858145014"><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li75495491510">Set a UUID to obtain a unique ID.</li><li id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_li17321154105112">If the auto-increment sequence must be used and there is no strict requirement for increasing order, you can set the cache, for example, <strong id="EN-US_TOPIC_0000002100746050__en-us_topic_0000002135726597_b8125191819512">1000</strong>, to reduce the pressure on GTM.</li></ul>
</div></div>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_04_0104.html">GaussDB(DWS) Object Design Specifications</a></div>
</div>
</div>