forked from docs/doc-exports
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>
22 lines
4.7 KiB
HTML
22 lines
4.7 KiB
HTML
<a name="EN-US_TOPIC_0000001510162537"></a><a name="EN-US_TOPIC_0000001510162537"></a>
|
|
|
|
<h1 class="topictitle1">GaussDB(DWS) Constraint Design Rules</h1>
|
|
<div id="body1528162486098"><div class="section" id="EN-US_TOPIC_0000001510162537__section555838816718"><h4 class="sectiontitle">DEFAULT and NULL Constraints</h4><ul id="EN-US_TOPIC_0000001510162537__ul1188131610581"><li id="EN-US_TOPIC_0000001510162537__li1188616165818">[Proposal] If all the column values can be obtained from services, you are not advised to use the <strong id="EN-US_TOPIC_0000001510162537__b469211910561">DEFAULT</strong> constraint, because doing so will generate unexpected results during data loading.</li><li id="EN-US_TOPIC_0000001510162537__li124803200584">[Proposal] Add <strong id="EN-US_TOPIC_0000001510162537__b842352706163730">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_0000001510162537__li11798102210586">[Proposal] Explicitly name all constraints excluding <strong id="EN-US_TOPIC_0000001510162537__b842352706163934">NOT NULL</strong> and <strong id="EN-US_TOPIC_0000001510162537__b842352706163937">DEFAULT</strong>.</li></ul>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001510162537__section2578598416718"><h4 class="sectiontitle">Partial Cluster Key</h4><p id="EN-US_TOPIC_0000001510162537__p46071979">A partial cluster key (PCK) is a local clustering technology used for column-store tables. After creating a PCK, you can quickly filter and scan fact tables using min or max sparse indexes in <span id="EN-US_TOPIC_0000001510162537__text1158130347">GaussDB(DWS)</span>. Comply with the following rules to create a PCK:</p>
|
|
<ul id="EN-US_TOPIC_0000001510162537__ul8800142614588"><li id="EN-US_TOPIC_0000001510162537__li480092635814">[Notice] Only one PCK can be created in a table. A PCK can contain multiple columns, preferably no more than two columns.</li><li id="EN-US_TOPIC_0000001510162537__li1378132910586">[Proposal] Create a PCK on simple expression filter conditions in a query. Such filter conditions are usually in the form of <strong id="EN-US_TOPIC_0000001510162537__b84235270617039">col op const</strong>, where <strong id="EN-US_TOPIC_0000001510162537__b84235270617137">col</strong> specifies a column name, <strong id="EN-US_TOPIC_0000001510162537__b84235270617143">op</strong> specifies an operator (such as =, >, >=, <=, and <), and <strong id="EN-US_TOPIC_0000001510162537__b8423527061721">const</strong> specifies a constant.</li><li id="EN-US_TOPIC_0000001510162537__li1131316325583">[Proposal] If the preceding conditions are met, create a PCK on the column having the least distinct values.</li></ul>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001510162537__section958094516718"><h4 class="sectiontitle">Unique Constraint</h4><ul id="EN-US_TOPIC_0000001510162537__ul184984019587"><li id="EN-US_TOPIC_0000001510162537__li17849940165819">[Notice] Both row-store and column-store tables support unique constraints.</li><li id="EN-US_TOPIC_0000001510162537__li15802104395817">[Proposal] The constraint name should indicate that it is a unique constraint, for example, <strong id="EN-US_TOPIC_0000001510162537__b84235270617735">UNI</strong><em id="EN-US_TOPIC_0000001510162537__i84235269717747">Included columns</em>.</li></ul>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001510162537__section3696271616719"><h4 class="sectiontitle">Primary Key Constraint</h4><ul id="EN-US_TOPIC_0000001510162537__ul139403464585"><li id="EN-US_TOPIC_0000001510162537__li2940646185816">[Notice] Both row-store and column-store tables support the primary key constraint.</li><li id="EN-US_TOPIC_0000001510162537__li3376144911587">[Proposal] The constraint name should indicate that it is a primary key constraint, for example, <strong id="EN-US_TOPIC_0000001510162537__b982443271171149">PK</strong><em id="EN-US_TOPIC_0000001510162537__i2143730926171149">Included columns</em>.</li></ul>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001510162537__section45602286161148"><h4 class="sectiontitle">Check Constraint</h4><ul id="EN-US_TOPIC_0000001510162537__ul9583552165819"><li id="EN-US_TOPIC_0000001510162537__li135837525587">[Notice] Check constraints can be used in row-store tables but not in column-store tables.</li><li id="EN-US_TOPIC_0000001510162537__li3792165419589">[Proposal] The constraint name should indicate that it is a check constraint, for example, <strong id="EN-US_TOPIC_0000001510162537__b277246241">CK</strong><em id="EN-US_TOPIC_0000001510162537__i983161284">Included columns</em>.</li></ul>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_04_0077.html">GaussDB(DWS) Database Object Design</a></div>
|
|
</div>
|
|
</div>
|
|
|