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

428 lines
102 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_0000001188429064"></a><a name="EN-US_TOPIC_0000001188429064"></a>
<h1 class="topictitle1">CREATE TABLE</h1>
<div id="body8662426"><div class="section" id="EN-US_TOPIC_0000001188429064__sf337ecb5bde84580afed94be7bbf5fb9"><h4 class="sectiontitle">Function</h4><p id="EN-US_TOPIC_0000001188429064__p1821535819539">Creates a new empty table in the current database.</p>
<p id="EN-US_TOPIC_0000001188429064__p1479251195413">This table is owned by the user who executes the command. However, if the system administrator creates a table in the schema with the same name as a common user, the owner of the table is the user (not the system administrator).</p>
</div>
<div class="section" id="EN-US_TOPIC_0000001188429064__s0c57396ef17642e9a39a88ab766472e1"><h4 class="sectiontitle">Precautions</h4><ul id="EN-US_TOPIC_0000001188429064__u833942a091c642dba1f12f016ec573a6"><li id="EN-US_TOPIC_0000001188429064__le903af21ab1644e0b51a936ddbd4c996">For details about the data types supported by column-store tables, see <a href="dws_06_0024.html">Data Types Supported by Column-Store Tables</a>.</li><li id="EN-US_TOPIC_0000001188429064__l504f7aa1a84c4020b9b51a8bff923e10">It is recommended that the number of column-store and HDFS partitioned tables do not exceed 1000.</li><li id="EN-US_TOPIC_0000001188429064__lce538d16b2d64c65ae8ca8377cec854e">The primary key constraint and unique constraint in the table must contain a distribution column.</li><li id="EN-US_TOPIC_0000001188429064__ld83425fa453940b8b1a64221980594cd">If an error occurs during table creation, after it is fixed, the system may fail to delete the empty disk files created before the last automatic clearance. This problem seldom occurs.</li><li id="EN-US_TOPIC_0000001188429064__le8ecab52de30457fbd82700c5935cf14">Column-store tables support the <strong id="EN-US_TOPIC_0000001188429064__b13213192281711">PARTIAL CLUSTER KEY</strong> and table-level primary key and unique constraints, but do not support table-level foreign key constraints.</li><li id="EN-US_TOPIC_0000001188429064__l76076d8dd65d4bee88728948873de834">Only the NULL, NOT NULL, and DEFAULT constant values can be used as column-store table column constraints.</li><li id="EN-US_TOPIC_0000001188429064__li1650612339613">Whether column-store tables support a delta table is specified by the <strong id="EN-US_TOPIC_0000001188429064__b16709154122318">enable_delta</strong> parameter. The threshold for storing data into a delta table is specified by the <strong id="EN-US_TOPIC_0000001188429064__b147101754132315">deltarow_threshold</strong> parameter.</li><li id="EN-US_TOPIC_0000001188429064__li62418531059">Multi-temperature tables support only partitioned column-store tables and depend on available OBS tablespaces.</li><li id="EN-US_TOPIC_0000001188429064__li926141319599">Multi-temperature tables support only the default tablespace <strong id="EN-US_TOPIC_0000001188429064__b1378181413559">default_obs_tbs</strong>. If you need to add an OBS tablespace, contact technical support.</li></ul>
</div>
<div class="section" id="EN-US_TOPIC_0000001188429064__s24f4eafc7fd349969c837eaaf863b260"><h4 class="sectiontitle">Syntax</h4><div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001188429064__s8ca28ce519cb41439fb1df4c043e6e8b"><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>
<span class="normal"> 6</span>
<span class="normal"> 7</span>
<span class="normal"> 8</span>
<span class="normal"> 9</span>
<span class="normal">10</span>
<span class="normal">11</span>
<span class="normal">12</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">CREATE</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">GLOBAL</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">LOCAL</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="err">{</span><span class="w"> </span><span class="k">TEMPORARY</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">TEMP</span><span class="w"> </span><span class="err">}</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">UNLOGGED</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">IF</span><span class="w"> </span><span class="k">NOT</span><span class="w"> </span><span class="k">EXISTS</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="k">table_name</span><span class="w"> </span>
<span class="w"> </span><span class="err">{</span><span class="w"> </span><span class="p">(</span><span class="err">{</span><span class="w"> </span><span class="k">column_name</span><span class="w"> </span><span class="n">data_type</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="n">compress_mode</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">COLLATE</span><span class="w"> </span><span class="k">collation</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="n">column_constraint</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="p">]</span>
<span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">table_constraint</span>
<span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">LIKE</span><span class="w"> </span><span class="n">source_table</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="n">like_option</span><span class="w"> </span><span class="p">[...]</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="err">}</span>
<span class="w"> </span><span class="p">[,</span><span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="p">])</span><span class="o">|</span>
<span class="w"> </span><span class="k">LIKE</span><span class="w"> </span><span class="n">source_table</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="n">like_option</span><span class="w"> </span><span class="p">[...]</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="err">}</span><span class="w"> </span>
<span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">WITH</span><span class="w"> </span><span class="p">(</span><span class="w"> </span><span class="err">{</span><span class="n">storage_parameter</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">value</span><span class="err">}</span><span class="w"> </span><span class="p">[,</span><span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="p">)</span><span class="w"> </span><span class="p">]</span>
<span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">ON</span><span class="w"> </span><span class="k">COMMIT</span><span class="w"> </span><span class="err">{</span><span class="w"> </span><span class="k">PRESERVE</span><span class="w"> </span><span class="k">ROWS</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">DELETE</span><span class="w"> </span><span class="k">ROWS</span><span class="w"> </span><span class="err">}</span><span class="w"> </span><span class="p">]</span>
<span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="n">COMPRESS</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">NOCOMPRESS</span><span class="w"> </span><span class="p">]</span>
<span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="n">DISTRIBUTE</span><span class="w"> </span><span class="k">BY</span><span class="w"> </span><span class="err">{</span><span class="w"> </span><span class="n">REPLICATION</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">ROUNDROBIN</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="err">{</span><span class="w"> </span><span class="n">HASH</span><span class="w"> </span><span class="p">(</span><span class="w"> </span><span class="k">column_name</span><span class="w"> </span><span class="p">[,...]</span><span class="w"> </span><span class="p">)</span><span class="w"> </span><span class="err">}</span><span class="w"> </span><span class="err">}</span><span class="w"> </span><span class="p">]</span>
<span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">TO</span><span class="w"> </span><span class="err">{</span><span class="w"> </span><span class="k">GROUP</span><span class="w"> </span><span class="n">groupname</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">NODE</span><span class="w"> </span><span class="p">(</span><span class="w"> </span><span class="n">nodename</span><span class="w"> </span><span class="p">[,</span><span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="p">)</span><span class="w"> </span><span class="err">}</span><span class="w"> </span><span class="p">]</span>
<span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">COMMENT</span><span class="w"> </span><span class="p">[</span><span class="o">=</span><span class="p">]</span><span class="w"> </span><span class="s1">'text'</span><span class="w"> </span><span class="p">];</span>
</pre></div></td></tr></table></div>
</div>
<ul id="EN-US_TOPIC_0000001188429064__u51eab43ce2b24d86b3e1d981e21fa644"><li id="EN-US_TOPIC_0000001188429064__l4f184948a45942409141cdb1165b3d81"><strong id="EN-US_TOPIC_0000001188429064__b84235270610227">column_constraint</strong> is as follows:<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001188429064__s6e3304ced7c14e75bb0f63b2af33255f"><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>
<span class="normal">6</span>
<span class="normal">7</span>
<span class="normal">8</span>
<span class="normal">9</span></pre></div></td><td class="code"><div><pre><span></span><span class="p">[</span><span class="w"> </span><span class="k">CONSTRAINT</span><span class="w"> </span><span class="k">constraint_name</span><span class="w"> </span><span class="p">]</span>
<span class="err">{</span><span class="w"> </span><span class="k">NOT</span><span class="w"> </span><span class="k">NULL</span><span class="w"> </span><span class="o">|</span>
<span class="w"> </span><span class="k">NULL</span><span class="w"> </span><span class="o">|</span>
<span class="w"> </span><span class="k">CHECK</span><span class="w"> </span><span class="p">(</span><span class="w"> </span><span class="n">expression</span><span class="w"> </span><span class="p">)</span><span class="w"> </span><span class="o">|</span>
<span class="w"> </span><span class="k">DEFAULT</span><span class="w"> </span><span class="n">default_expr</span><span class="w"> </span><span class="o">|</span>
<span class="w"> </span><span class="k">COMMENT</span><span class="w"> </span><span class="s1">'text'</span><span class="w"> </span><span class="o">|</span>
<span class="w"> </span><span class="k">UNIQUE</span><span class="w"> </span><span class="n">index_parameters</span><span class="w"> </span><span class="o">|</span>
<span class="w"> </span><span class="k">PRIMARY</span><span class="w"> </span><span class="k">KEY</span><span class="w"> </span><span class="n">index_parameters</span><span class="w"> </span><span class="err">}</span>
<span class="p">[</span><span class="w"> </span><span class="k">DEFERRABLE</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">NOT</span><span class="w"> </span><span class="k">DEFERRABLE</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">INITIALLY</span><span class="w"> </span><span class="k">DEFERRED</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">INITIALLY</span><span class="w"> </span><span class="k">IMMEDIATE</span><span class="w"> </span><span class="p">]</span>
</pre></div></td></tr></table></div>
</div>
</li></ul>
<ul id="EN-US_TOPIC_0000001188429064__u070f826fe6544b61872abf44e6512111"><li id="EN-US_TOPIC_0000001188429064__l072891e7e4844f89bf28ecb50eee1b74"><strong id="EN-US_TOPIC_0000001188429064__b842352706171324">compress_mode</strong> of a column is as follows:<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001188429064__s9c4ebbb1c85f409fac6f0b278c7f83b0"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="err">{</span><span class="w"> </span><span class="n">DELTA</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">PREFIX</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">DICTIONARY</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">NUMSTR</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">NOCOMPRESS</span><span class="w"> </span><span class="err">}</span>
</pre></div></td></tr></table></div>
</div>
</li><li id="EN-US_TOPIC_0000001188429064__l5447f854591b42e1a0b28e890cf928d1"><strong id="EN-US_TOPIC_0000001188429064__b84235270610618">table_constraint</strong> is as follows:<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001188429064__sf70e656023dc48a39b64c1b6433acc71"><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>
<span class="normal">6</span></pre></div></td><td class="code"><div><pre><span></span><span class="p">[</span><span class="w"> </span><span class="k">CONSTRAINT</span><span class="w"> </span><span class="k">constraint_name</span><span class="w"> </span><span class="p">]</span>
<span class="err">{</span><span class="w"> </span><span class="k">CHECK</span><span class="w"> </span><span class="p">(</span><span class="w"> </span><span class="n">expression</span><span class="w"> </span><span class="p">)</span><span class="w"> </span><span class="o">|</span>
<span class="w"> </span><span class="k">UNIQUE</span><span class="w"> </span><span class="p">(</span><span class="w"> </span><span class="k">column_name</span><span class="w"> </span><span class="p">[,</span><span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="p">)</span><span class="w"> </span><span class="n">index_parameters</span><span class="w"> </span><span class="o">|</span>
<span class="w"> </span><span class="k">PRIMARY</span><span class="w"> </span><span class="k">KEY</span><span class="w"> </span><span class="p">(</span><span class="w"> </span><span class="k">column_name</span><span class="w"> </span><span class="p">[,</span><span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="p">)</span><span class="w"> </span><span class="n">index_parameters</span><span class="w"> </span><span class="o">|</span>
<span class="w"> </span><span class="k">PARTIAL</span><span class="w"> </span><span class="k">CLUSTER</span><span class="w"> </span><span class="k">KEY</span><span class="w"> </span><span class="p">(</span><span class="w"> </span><span class="k">column_name</span><span class="w"> </span><span class="p">[,</span><span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="p">)</span><span class="w"> </span><span class="err">}</span>
<span class="p">[</span><span class="w"> </span><span class="k">DEFERRABLE</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">NOT</span><span class="w"> </span><span class="k">DEFERRABLE</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">INITIALLY</span><span class="w"> </span><span class="k">DEFERRED</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">INITIALLY</span><span class="w"> </span><span class="k">IMMEDIATE</span><span class="w"> </span><span class="p">]</span>
</pre></div></td></tr></table></div>
</div>
</li></ul>
<ul id="EN-US_TOPIC_0000001188429064__u147ed9cab742413da2c22e8026d659ec"><li id="EN-US_TOPIC_0000001188429064__l8cb55d220954403088edf67e4e32f784"><strong id="EN-US_TOPIC_0000001188429064__b84235270610642">like_option</strong> is as follows:<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001188429064__s67c0d2d2f5a04e7ba423354a916bf185"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="err">{</span><span class="w"> </span><span class="k">INCLUDING</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">EXCLUDING</span><span class="w"> </span><span class="err">}</span><span class="w"> </span><span class="err">{</span><span class="w"> </span><span class="k">DEFAULTS</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">CONSTRAINTS</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">INDEXES</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">STORAGE</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">COMMENTS</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">PARTITION</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">RELOPTIONS</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">DISTRIBUTION</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">DROPCOLUMNS</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">ALL</span><span class="w"> </span><span class="err">}</span>
</pre></div></td></tr></table></div>
</div>
</li><li id="EN-US_TOPIC_0000001188429064__li04965417494"><strong id="EN-US_TOPIC_0000001188429064__b8423527069548">index_parameters</strong> is as follows:<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001188429064__s5d41cbc0c47d433397704f5f3f596bb4"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="p">[</span><span class="w"> </span><span class="k">WITH</span><span class="w"> </span><span class="p">(</span><span class="w"> </span><span class="err">{</span><span class="n">storage_parameter</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">value</span><span class="err">}</span><span class="w"> </span><span class="p">[,</span><span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="p">)</span><span class="w"> </span><span class="p">]</span>
</pre></div></td></tr></table></div>
</div>
</li></ul>
</div>
<div class="section" id="EN-US_TOPIC_0000001188429064__s1a0c1ce222bb46dfb68a016610aea3a5"><h4 class="sectiontitle">Parameters</h4><ul id="EN-US_TOPIC_0000001188429064__u4a81a0d707ae45068ea150166c1b249d"><li id="EN-US_TOPIC_0000001188429064__lf971c986fe2e4125be8a8f625f6affd5"><strong id="EN-US_TOPIC_0000001188429064__a4ee5d12f41554c0a8148e84e32b06679">UNLOGGED</strong><p id="EN-US_TOPIC_0000001188429064__a80f651f260324dd4bf991e108fe3a63a">If this key word is specified, the created table is not a log table. Data written to unlogged tables is not written to the write-ahead log, which makes them considerably faster than ordinary tables. However, an unlogged table is automatically truncated after a crash or unclean shutdown, incurring data loss risks. The contents of an unlogged table are also not replicated to standby servers. Any indexes created on an unlogged table are not automatically logged as well.</p>
<p id="EN-US_TOPIC_0000001188429064__aa033b20b81a042e9b41d306fa692ad2b">Usage scenario: Unlogged tables do not ensure safe data. Users can back up data before using unlogged tables; for example, users should back up the data before a system upgrade.</p>
<p id="EN-US_TOPIC_0000001188429064__a2f1c759659684f7394c49bb0ca2b0412">Troubleshooting: If data is missing in the indexes of unlogged tables due to some unexpected operations such as an unclean shutdown, users should re-create the indexes with errors.</p>
<div class="notice" id="EN-US_TOPIC_0000001188429064__note6872102415351"><span class="noticetitle"><img src="public_sys-resources/notice_3.0-en-us.png"> </span><div class="noticebody"><p id="EN-US_TOPIC_0000001188429064__p17172193014350">The UNLOGGED table uses no primary/standby mechanism. In the case of system faults or abnormal breakpoints, data loss may occur. Therefore, the UNLOGGED table cannot be used to store basic data.</p>
</div></div>
</li><li id="EN-US_TOPIC_0000001188429064__l40601c13ccdb4b5d85be38edd4f99676"><strong id="EN-US_TOPIC_0000001188429064__a89e3dc3abfac4c428089799d71037e02">GLOBAL | LOCAL</strong><p id="EN-US_TOPIC_0000001188429064__p151823164457">When creating a temporary table, you can specify the <strong id="EN-US_TOPIC_0000001188429064__b171092177012">GLOBAL</strong> or <strong id="EN-US_TOPIC_0000001188429064__b366313191503">LOCAL</strong> keyword before <strong id="EN-US_TOPIC_0000001188429064__b962711292005">TEMP</strong> or <strong id="EN-US_TOPIC_0000001188429064__b498619311205">TEMPORARY</strong>. Currently, the two keywords are used to be compatible with the SQL standard. <span id="EN-US_TOPIC_0000001188429064__text1178310795">GaussDB(DWS)</span> will create a local temporary table regardless of whether <strong id="EN-US_TOPIC_0000001188429064__b1720519261114">GLOBAL</strong> or <strong id="EN-US_TOPIC_0000001188429064__b189803274116">LOCAL</strong> is specified.</p>
</li><li id="EN-US_TOPIC_0000001188429064__la8c031f4e4834cb0a68578e03dfdc407"><strong id="EN-US_TOPIC_0000001188429064__ad29cbd42d25f431baea8a5372eb9688a">TEMPORARY | TEMP</strong><p id="EN-US_TOPIC_0000001188429064__ade96caf3b58a440e9f1bc1815a7aa881">If <strong id="EN-US_TOPIC_0000001188429064__b842352706214543">TEMP</strong> or <strong id="EN-US_TOPIC_0000001188429064__b842352706214547">TEMPORARY</strong> is specified, the created table is a temporary table. Temporary tables are automatically dropped at the end of a session, or optionally at the end of the current transaction. Therefore, apart from CN and other CN errors connected by the current session, you can still create and use temporary table in the current session. Temporary tables are created only in the current session. If a DDL statement involves operations on temporary tables, a DDL error will be generated. Therefore, you are not advised to perform operations on temporary tables in DDL statements. <strong id="EN-US_TOPIC_0000001188429064__b8423527069813">TEMP</strong> is equivalent to <strong id="EN-US_TOPIC_0000001188429064__b8423527069818">TEMPORARY</strong>.</p>
<div class="notice" id="EN-US_TOPIC_0000001188429064__n6e16cd1e50d04bedbca2c396dfc17987"><span class="noticetitle"><img src="public_sys-resources/notice_3.0-en-us.png"> </span><div class="noticebody"><ul id="EN-US_TOPIC_0000001188429064__u4169b31d76e341d8bcf794eb1894a35c"><li id="EN-US_TOPIC_0000001188429064__lf03d0d8803e4428b9429afd47e61ca02">Temporary tables are visible to the current session through schema of the <strong id="EN-US_TOPIC_0000001188429064__b8423527069832">pg_temp</strong> start. Users should not delete schema started with <strong id="EN-US_TOPIC_0000001188429064__b8423527069846">pg_temp</strong>, <strong id="EN-US_TOPIC_0000001188429064__b8423527069851">pg_toast_temp</strong>.</li><li id="EN-US_TOPIC_0000001188429064__l08317ce8988e468486b25577e2c864ff">If <strong id="EN-US_TOPIC_0000001188429064__b842352706994">TEMPORARY</strong> or <strong id="EN-US_TOPIC_0000001188429064__b512478272214747">TEMP</strong> is not specified when you create a table and the schema of the specified table starts with <strong id="EN-US_TOPIC_0000001188429064__b8423527069915">pg_temp_</strong>, the table is created as a temporary table.</li></ul>
</div></div>
</li><li id="EN-US_TOPIC_0000001188429064__lc929efc9948741d3a177e98a1aefbbe4"><strong id="EN-US_TOPIC_0000001188429064__ac4c814ddf6754cd98d7ea10b7d3471f4">IF NOT EXISTS</strong><p id="EN-US_TOPIC_0000001188429064__a907e52a2875c4303b296eb9192898111">If <strong id="EN-US_TOPIC_0000001188429064__b1961294012926">IF NOT EXISTS</strong> is specified, a table will be created if there is no table using the specified name. If there is already a table using the specified name, no error will be reported. A message will be displayed indicating that the table already exists, and the database will skip table creation.</p>
</li><li id="EN-US_TOPIC_0000001188429064__lcacb45adeaab4dc690fff7670c8f1068"><strong id="EN-US_TOPIC_0000001188429064__accc4048091f74784a4329b2cff3870a2">table_name</strong><p id="EN-US_TOPIC_0000001188429064__a69479c547933434eb9ef0c547a2090dc">Specifies the name of the table to be created.</p>
<p id="EN-US_TOPIC_0000001188429064__p2293122101411">The table name can contain a maximum of 63 characters, including letters, digits, underscores (_), dollar signs ($), and number signs (#). It must start with a letter or underscore (_).</p>
<p id="EN-US_TOPIC_0000001188429064__p86124818267">A table name enclosed in double quotation marks can contain spaces and special characters. However, you are not advised to use these characters in a table name because they may make it difficult to reference and use. In addition, they may be processed differently under different database compatibility modes.</p>
</li><li id="EN-US_TOPIC_0000001188429064__l9617e926aec24a75b2c2472789705e99"><strong id="EN-US_TOPIC_0000001188429064__a114c6e26ec294f52a3fd16a29bb91ae6">column_name</strong><p id="EN-US_TOPIC_0000001188429064__a77a2b66dd4fa4e4099ffaa5c2233ffdb">Specifies the name of a column to be created in the new table.</p>
<p id="EN-US_TOPIC_0000001188429064__p231214106142">The column name can contain a maximum of 63 characters, including letters, digits, underscores (_), dollar signs ($), and number signs (#). It must start with a letter or underscore (_).</p>
</li><li id="EN-US_TOPIC_0000001188429064__l34f1a566739c48b4be821481538f5b81"><strong id="EN-US_TOPIC_0000001188429064__abf296480d6a249bfb6cf296a54adef2a">data_type</strong><p id="EN-US_TOPIC_0000001188429064__a2f57ce2d5cdb4c4d82556493aca949db">Specifies the data type of the column.</p>
<div class="note" id="EN-US_TOPIC_0000001188429064__note57291658143719"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001188429064__p20729195803714">In a database compatible with Teradata or MySQL syntax, if the data type of a column is set to DATE, the DATE type is returned. Otherwise, the TIMESTAMP type is returned.</p>
</div></div>
</li><li id="EN-US_TOPIC_0000001188429064__leae9e2e4c3b24cbc840a63fac26967bf"><strong id="EN-US_TOPIC_0000001188429064__abb452499ba06468a92aee28041dc612b">compress_mode</strong><p id="EN-US_TOPIC_0000001188429064__a5c5138063921460d8f0c10e4836ac142">Specifies the compress option of the table, only available for row-store table. The option specifies the algorithm preferentially used by table columns.</p>
<p id="EN-US_TOPIC_0000001188429064__p129479241166">This compression option is irrelevant to the adaptive compression algorithm of column-store tables. The adaptive compression algorithm is used for internal data storage of column-store tables and does not allow users to specify the compression mode. For details, see the description of the <a href="#EN-US_TOPIC_0000001188429064__l770ea1d44c9f44bf8d17c8cb0a26bac6">COMPRESSION</a> parameter.</p>
<div class="p" id="EN-US_TOPIC_0000001188429064__a1d9fc64d6a0c41129e29c2739c6cd491">Value range: DELTA, PREFIX, DICTIONARY, NUMSTR, NOCOMPRESS<ul id="EN-US_TOPIC_0000001188429064__ul11341230105714"><li id="EN-US_TOPIC_0000001188429064__li1213473010577">DELTA compression supports only data types with a length of 1 to 8 bytes (0 &lt; pg_type.typlen&lt;=8).</li><li id="EN-US_TOPIC_0000001188429064__li181342300575">PREFIX and NUMSTR compression support only variable-length data types (pg_type.typlen=-1) and NULL-terminated C strings (pg_type.typlen=-2).</li></ul>
</div>
</li><li id="EN-US_TOPIC_0000001188429064__l8833e8a37d8847e6a084aaa436a4785a"><strong id="EN-US_TOPIC_0000001188429064__a33d7e7f0a2f7440da6ad45191a997bc3">COLLATE collation</strong><p id="EN-US_TOPIC_0000001188429064__a83a9b3e7f11c48a7b26c5b90ef24b278">Assigns a collation to the column (which must be of a collatable data type). If no collation is specified, the default collation is used.</p>
</li><li id="EN-US_TOPIC_0000001188429064__l9f8eff5559b14ec7a69c0966fd7ebeae"><strong id="EN-US_TOPIC_0000001188429064__aac04cbe8532f40a4a75f915be05075d6">LIKE source_table [ like_option ... ]</strong><p id="EN-US_TOPIC_0000001188429064__ade1c6728f97a42d69c2fd4e170dcb5d2">Specifies a table from which the new table automatically copies all column names, their data types, and their not-null constraints.</p>
<p id="EN-US_TOPIC_0000001188429064__acbeb69fb11e142a79b4be1d441ba85b0">The new table and the source table are decoupled after creation is complete. Changes to the source table will not be applied to the new table, and it is not possible to include data of the new table in scans of the source table.</p>
<p id="EN-US_TOPIC_0000001188429064__a82dec42153404e0aa7bd8292fb41bad2">Columns and constraints copied by <strong id="EN-US_TOPIC_0000001188429064__b366873831783">LIKE</strong> are not merged with the same name. If the same name is specified explicitly or in another <strong id="EN-US_TOPIC_0000001188429064__b617509951783">LIKE</strong> clause, an error is reported.</p>
<ul id="EN-US_TOPIC_0000001188429064__u4ceb5f7c91f34aec96c9096ba1b9e166"><li id="EN-US_TOPIC_0000001188429064__l8ec43792af1e4657821db87fa1ee418b">The default expressions are copied from the source table to the new table only if <strong id="EN-US_TOPIC_0000001188429064__b84235270622257">INCLUDING DEFAULTS</strong> is specified. The default behavior is to exclude default expressions, resulting in the copied columns in the new table having default values <strong id="EN-US_TOPIC_0000001188429064__b15257491783">NULL</strong>.</li><li id="EN-US_TOPIC_0000001188429064__la1710617a89e4f4facb17d14d7bd42ff">The <strong id="EN-US_TOPIC_0000001188429064__b84235270622331">CHECK</strong> constraints are copied from the source table to the new table only when <strong id="EN-US_TOPIC_0000001188429064__b18927170822323">INCLUDING CONSTRAINTS</strong> is specified. Other types of constraints are never copied to the new table. <strong id="EN-US_TOPIC_0000001188429064__b49569357317">NOT NULL</strong> constraints are always copied to the new table. These rules also apply to column constraints and table constraints.</li><li id="EN-US_TOPIC_0000001188429064__l168e3a37406543daaca47673b43bcb21">Any indexes on the source table will not be created on the new table, unless the <strong id="EN-US_TOPIC_0000001188429064__en-us_topic_0058965796_b84235270611020">INCLUDING INDEXES</strong> clause is specified.</li><li id="EN-US_TOPIC_0000001188429064__l7f54e2e77bfb4e84a46e60847e15a9e8">STORAGE settings for the copied column definitions are copied only if <strong id="EN-US_TOPIC_0000001188429064__b84235270611028">INCLUDING STORAGE</strong> is specified. The default behavior is to exclude <strong id="EN-US_TOPIC_0000001188429064__b84235270611036">STORAGE</strong> settings.</li><li id="EN-US_TOPIC_0000001188429064__l00432959a35c499cbb32921fbeb51566">If <strong id="EN-US_TOPIC_0000001188429064__b27419559122947">INCLUDING COMMENTS</strong> is specified, comments for the copied columns, constraints, and indexes are copied. The default behavior is to exclude comments.</li><li id="EN-US_TOPIC_0000001188429064__l78294dafebc644a399f057babb13af76">If <strong id="EN-US_TOPIC_0000001188429064__b162321126145310">INCLUDING PARTITION</strong> is specified, the partition definitions of the source table are copied to the new table, and the new table no longer uses the <strong id="EN-US_TOPIC_0000001188429064__b15238226115318">PARTITION BY</strong> clause. The default behavior is to exclude partition definition of the source table.</li><li id="EN-US_TOPIC_0000001188429064__l32a4becd0ee04c068bcc5dcf578071d6">If <strong id="EN-US_TOPIC_0000001188429064__b84235270611052">INCLUDING RELOPTIONS</strong> is specified, the storage parameter (<strong id="EN-US_TOPIC_0000001188429064__b8423527061111">WITH</strong> clause of the source table) of the source table is copied to the new table. The default behavior is to exclude partition definition of the storage parameter of the source table.</li><li id="EN-US_TOPIC_0000001188429064__l5b63aefd78b048608255c5d45e1f2e59">If <strong id="EN-US_TOPIC_0000001188429064__b8423527061116">INCLUDING DISTRIBUTION</strong> is specified, the distribution information of the source table is copied to the new table, including distribution type and column, and the new table no longer use the <strong id="EN-US_TOPIC_0000001188429064__b84235270611111">DISTRIBUTE BY</strong> clause. The default behavior is to exclude distribution information of the source table.</li><li id="EN-US_TOPIC_0000001188429064__li640611365015">If <strong id="EN-US_TOPIC_0000001188429064__b214210495552">INCLUDING DROPCOLUMNS</strong> is specified, the deleted column information in the source table is copied to the new table. By default, the deleted column information of the source table is not copied.</li><li id="EN-US_TOPIC_0000001188429064__l10d4feca9efc478e8f8cdd64578db5ea"><strong id="EN-US_TOPIC_0000001188429064__b84235270622158">INCLUDING ALL</strong> contains the meaning of <strong id="EN-US_TOPIC_0000001188429064__b842352706221511">INCLUDING DEFAULTS</strong>, <strong id="EN-US_TOPIC_0000001188429064__b842352706221515">INCLUDING CONSTRAINTS</strong>, <strong id="EN-US_TOPIC_0000001188429064__b842352706221518">INCLUDING INDEXES</strong>, <strong id="EN-US_TOPIC_0000001188429064__b842352706221522">INCLUDING STORAGE</strong>, <strong id="EN-US_TOPIC_0000001188429064__b842352706221524">INCLUDING COMMENTS</strong>, <strong id="EN-US_TOPIC_0000001188429064__b842352706221528">INCLUDING PARTITION</strong>, <strong id="EN-US_TOPIC_0000001188429064__b842352706221530">INCLUDING RELOPTIONS</strong>, <strong id="EN-US_TOPIC_0000001188429064__b41672044105610">INCLUDING DISTRIBUTION</strong>, and <strong id="EN-US_TOPIC_0000001188429064__b171901013145718">INCLUDING DROPCOLUMNS</strong>. </li><li id="EN-US_TOPIC_0000001188429064__li153101438375">If EXCLUDING is specified, the specified parameters are not included.</li><li id="EN-US_TOPIC_0000001188429064__li37468519720">For an OBS multi-temperature table, all partitions of the new table are local hot partitions after <strong id="EN-US_TOPIC_0000001188429064__b17657113413254">INCLUDING PARTITION</strong> is specified.</li></ul>
<div class="notice" id="EN-US_TOPIC_0000001188429064__note114471820913"><span class="noticetitle"><img src="public_sys-resources/notice_3.0-en-us.png"> </span><div class="noticebody"><ul id="EN-US_TOPIC_0000001188429064__ul1245114202012"><li id="EN-US_TOPIC_0000001188429064__li645813202111">If the source table contains a sequence with the SERIAL, BIGSERIAL, or SMALLSERIAL data type, or a column in the source table is a sequence by default and the sequence is created for this table by using <strong id="EN-US_TOPIC_0000001188429064__b17601996185">CREATE SEQUENCE...</strong> <strong id="EN-US_TOPIC_0000001188429064__b76032129814">OWNED BY</strong>, these sequences will not be copied to the new table, and another sequence specific to the new table will be created. This is different from earlier versions. To share a sequence between the source table and new table, create a shared sequence (do not use <strong id="EN-US_TOPIC_0000001188429064__b164482944810">OWNED BY</strong>) and set a column in the source table to this sequence.</li><li id="EN-US_TOPIC_0000001188429064__li112431992510">You are not advised to set a column in the source table to the sequence specific to another table especially when the table is distributed in specific Node Groups, because doing so may result in <strong id="EN-US_TOPIC_0000001188429064__b579816143587">CREATE TABLE ... LIKE</strong> execution failures. In addition, doing so may cause the sequence to become invalid in the source sequence because the sequence will also be deleted from the source table when it is deleted from the table that the sequence is specific to. To share a sequence among multiple tables, you are advised to create a shared sequence for them.</li></ul>
</div></div>
</li><li id="EN-US_TOPIC_0000001188429064__l4af34b084f7c4b1a96c37516810dc04d"><strong id="EN-US_TOPIC_0000001188429064__a2761a7089649476bbf0299a61e9f23da">WITH ( { storage_parameter = value } [, ... ] )</strong><p id="EN-US_TOPIC_0000001188429064__ac10e4ce413a0489b927941d4d9e1e18e">Specifies an optional storage parameter for a table or an index.</p>
<div class="note" id="EN-US_TOPIC_0000001188429064__nb4e9ac710039431c818878c9ef231cb5"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001188429064__a3633deb081774802874582aa62fc0746">Using Numeric of any precision to define column, specifies precision p and scale s. When precision and scale are not specified, the input will be displayed.</p>
</div></div>
<p id="EN-US_TOPIC_0000001188429064__aa2fd5d776c8845a8ad24a34d286c09c7">The description of parameters is as follows:</p>
<ul id="EN-US_TOPIC_0000001188429064__u3170c562e94a492897636fbfcbcfb2b5"><li id="EN-US_TOPIC_0000001188429064__l24d1225dcddd4f08b059e91853936932">FILLFACTOR<p id="EN-US_TOPIC_0000001188429064__ac011eb472f2141c6834cf6a606c3d299"><a name="EN-US_TOPIC_0000001188429064__l24d1225dcddd4f08b059e91853936932"></a><a name="l24d1225dcddd4f08b059e91853936932"></a>The fillfactor of a table is a percentage between 10 and 100. 100 (complete packing) is the default value. When a smaller fillfactor is specified, <strong id="EN-US_TOPIC_0000001188429064__b2270294916957">INSERT</strong> operations pack table pages only to the indicated percentage. The remaining space on each page is reserved for updating rows on that page. This gives <strong id="EN-US_TOPIC_0000001188429064__b299995416957">UPDATE</strong> a chance to place the updated copy of a row on the same page, which is more efficient than placing it on a different page. For a table whose records are never updated, setting the fillfactor to 100 (complete packing) is the appropriate choice, but in heavily updated tables smaller fillfactors are appropriate. The parameter has no meaning for columnstore tables.</p>
<p id="EN-US_TOPIC_0000001188429064__a0a5934b8d9434bf489d67f14cc27868b">Value range: 10 to 100</p>
</li><li id="EN-US_TOPIC_0000001188429064__le578deaf72b64b2fba7c1ae284e30b15">ORIENTATION<p id="EN-US_TOPIC_0000001188429064__a255bea141fad4ab3bd9d37c304c3a315"><a name="EN-US_TOPIC_0000001188429064__le578deaf72b64b2fba7c1ae284e30b15"></a><a name="le578deaf72b64b2fba7c1ae284e30b15"></a>Specifies the storage mode (row-store, column-store) for table data. This parameter cannot be modified once it is set.</p>
<p id="EN-US_TOPIC_0000001188429064__a070516800fa944bfae754bd3a5e3ccc7">Valid value:</p>
<ul id="EN-US_TOPIC_0000001188429064__ua9832dec6c604f25a00e3a52cac1d7d9"><li id="EN-US_TOPIC_0000001188429064__l2c49a5929a3b47a59a24f5c8baaca843"><strong id="EN-US_TOPIC_0000001188429064__b842352706221833">ROW</strong> indicates that table data is stored in rows.<p id="EN-US_TOPIC_0000001188429064__a66f4ae52ca0d4df3aff0f52ed23f6c81"><strong id="EN-US_TOPIC_0000001188429064__b842352706221853">ROW</strong> applies to OLTP service, which has many interactive transactions. An interaction involves many columns in the table. Using ROW can improve the efficiency.</p>
</li><li id="EN-US_TOPIC_0000001188429064__le28dcda0112348209ae14aa1b9a6a2ca"><strong id="EN-US_TOPIC_0000001188429064__b0608142420116">COLUMN</strong> indicates that the data is stored in columns.<p id="EN-US_TOPIC_0000001188429064__a28561aef4f9f4a91897abd56177c3de9"><strong id="EN-US_TOPIC_0000001188429064__b9230165919119">COLUMN</strong> applies to the data warehouse service, which has a large amount of aggregation computing, and involves a few column operations.</p>
</li></ul>
<p id="EN-US_TOPIC_0000001188429064__ac8b51f82e0d849ba865ea4eb79b63afe">Default value: ROW (row-store)</p>
<div class="note" id="EN-US_TOPIC_0000001188429064__note967531791515"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001188429064__p6480151911261">In cluster 8.1.3 and later versions, the GUC parameter <strong id="EN-US_TOPIC_0000001188429064__b2881649194211">default_orientation</strong> (default value: <strong id="EN-US_TOPIC_0000001188429064__b1848102437">row</strong>) is added. If the storage mode is not specified when a table is created, by default, the table is created based on the value of the parameter (row, column, column enabledelta).</p>
</div></div>
</li><li id="EN-US_TOPIC_0000001188429064__l770ea1d44c9f44bf8d17c8cb0a26bac6"><a name="EN-US_TOPIC_0000001188429064__l770ea1d44c9f44bf8d17c8cb0a26bac6"></a><a name="l770ea1d44c9f44bf8d17c8cb0a26bac6"></a>COMPRESSION<p id="EN-US_TOPIC_0000001188429064__ac2dfb496dc8e4ce6a291fd888995f6e9"><a name="EN-US_TOPIC_0000001188429064__l770ea1d44c9f44bf8d17c8cb0a26bac6"></a><a name="l770ea1d44c9f44bf8d17c8cb0a26bac6"></a>Specifies the compression level of the table data. It determines the compression ratio and time. Generally, the higher the level of compression, the higher the ratio, the longer the time, and the lower the level of compression, the lower the ratio, the shorter the time. The actual compression ratio depends on the distribution characteristics of loading table data.</p>
<p id="EN-US_TOPIC_0000001188429064__ac519dc54e9f84c90b3c8cd208f43c883">Valid value:</p>
<div class="p" id="EN-US_TOPIC_0000001188429064__p5406162812317">The valid values for column-store tables are <strong id="EN-US_TOPIC_0000001188429064__b11212143744315">YES</strong>/<strong id="EN-US_TOPIC_0000001188429064__b17618738204312">NO</strong> and <strong id="EN-US_TOPIC_0000001188429064__b103841140134312">LOW</strong>/<strong id="EN-US_TOPIC_0000001188429064__b1144654317433">MIDDLE</strong>/<strong id="EN-US_TOPIC_0000001188429064__b1846219458430">HIGH</strong>, and the default is <strong id="EN-US_TOPIC_0000001188429064__b842352706112332">LOW</strong>. When this parameter is set to <strong id="EN-US_TOPIC_0000001188429064__b89622018406">YES</strong>, the compression level is <strong id="EN-US_TOPIC_0000001188429064__b59629012407">LOW</strong> by default.<div class="note" id="EN-US_TOPIC_0000001188429064__note141418320435"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="EN-US_TOPIC_0000001188429064__ul82263435309"><li id="EN-US_TOPIC_0000001188429064__li39874611479">Currently, row-store table compression is not supported.</li></ul>
</div></div>
</div>
<p id="EN-US_TOPIC_0000001188429064__p2810714202814"><span id="EN-US_TOPIC_0000001188429064__text621906510">GaussDB(DWS)</span> provides the following compression algorithms:</p>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001188429064__table340453215226" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Compression algorithms for column-based storage</caption><thead align="left"><tr id="EN-US_TOPIC_0000001188429064__row7405123242212"><th align="left" class="cellrowborder" valign="top" width="20%" id="mcps1.3.4.2.11.5.3.5.2.5.1.1"><p id="EN-US_TOPIC_0000001188429064__p19405232182210">COMPRESSION</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="26%" id="mcps1.3.4.2.11.5.3.5.2.5.1.2"><p id="EN-US_TOPIC_0000001188429064__p740553213223">NUMERIC</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="26%" id="mcps1.3.4.2.11.5.3.5.2.5.1.3"><p id="EN-US_TOPIC_0000001188429064__p9405232172213">STRING</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="28.000000000000004%" id="mcps1.3.4.2.11.5.3.5.2.5.1.4"><p id="EN-US_TOPIC_0000001188429064__p640533242216">INT</p>
</th>
</tr>
</thead>
<tbody><tr id="EN-US_TOPIC_0000001188429064__row7406332162215"><td class="cellrowborder" valign="top" width="20%" headers="mcps1.3.4.2.11.5.3.5.2.5.1.1 "><p id="EN-US_TOPIC_0000001188429064__p24060329223">LOW</p>
</td>
<td class="cellrowborder" valign="top" width="26%" headers="mcps1.3.4.2.11.5.3.5.2.5.1.2 "><p id="EN-US_TOPIC_0000001188429064__p84061732142214">Delta compression + RLE compression</p>
</td>
<td class="cellrowborder" valign="top" width="26%" headers="mcps1.3.4.2.11.5.3.5.2.5.1.3 "><p id="EN-US_TOPIC_0000001188429064__p194066323225">LZ4 compression</p>
</td>
<td class="cellrowborder" valign="top" width="28.000000000000004%" headers="mcps1.3.4.2.11.5.3.5.2.5.1.4 "><p id="EN-US_TOPIC_0000001188429064__p740614326221">Delta compression (RLE is optional.)</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001188429064__row11406133217228"><td class="cellrowborder" valign="top" width="20%" headers="mcps1.3.4.2.11.5.3.5.2.5.1.1 "><p id="EN-US_TOPIC_0000001188429064__p3406103242218">MIDDLE</p>
</td>
<td class="cellrowborder" valign="top" width="26%" headers="mcps1.3.4.2.11.5.3.5.2.5.1.2 "><p id="EN-US_TOPIC_0000001188429064__p1140683219229">Delta compression + RLE compression + LZ4 compression</p>
</td>
<td class="cellrowborder" valign="top" width="26%" headers="mcps1.3.4.2.11.5.3.5.2.5.1.3 "><p id="EN-US_TOPIC_0000001188429064__p640623292214">dict compression or LZ4 compression</p>
</td>
<td class="cellrowborder" valign="top" width="28.000000000000004%" headers="mcps1.3.4.2.11.5.3.5.2.5.1.4 "><p id="EN-US_TOPIC_0000001188429064__p1340653292210">Delta compression or LZ4 compression (RLE is optional)</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001188429064__row84061932202218"><td class="cellrowborder" valign="top" width="20%" headers="mcps1.3.4.2.11.5.3.5.2.5.1.1 "><p id="EN-US_TOPIC_0000001188429064__p340673252211">HIGH</p>
</td>
<td class="cellrowborder" valign="top" width="26%" headers="mcps1.3.4.2.11.5.3.5.2.5.1.2 "><p id="EN-US_TOPIC_0000001188429064__p11407103214224">Delta compression + RLE compression + zlib compression</p>
</td>
<td class="cellrowborder" valign="top" width="26%" headers="mcps1.3.4.2.11.5.3.5.2.5.1.3 "><p id="EN-US_TOPIC_0000001188429064__p164071532152219">dict compression or zlib compression</p>
</td>
<td class="cellrowborder" valign="top" width="28.000000000000004%" headers="mcps1.3.4.2.11.5.3.5.2.5.1.4 "><p id="EN-US_TOPIC_0000001188429064__p340717323228">Delta compression or zlib compression (RLE is optional)</p>
</td>
</tr>
</tbody>
</table>
</div>
</li><li id="EN-US_TOPIC_0000001188429064__l677fdcd156914cc8bdaaa4713c333b34">COMPRESSLEVEL<p id="EN-US_TOPIC_0000001188429064__a58c1b12b31464cfba45d9ce40aa51f4e"><a name="EN-US_TOPIC_0000001188429064__l677fdcd156914cc8bdaaa4713c333b34"></a><a name="l677fdcd156914cc8bdaaa4713c333b34"></a>Specifies the compression level of the table data. It determines the compression ratio and time. This divides a compression level into sublevels, providing you with more choices for compression rate and duration. As the value becomes greater, the compression rate becomes higher and duration longer at the same compression level. The parameter is only valid for column-store tables.</p>
<p id="EN-US_TOPIC_0000001188429064__a50ebabc106f1448c95d6b1c810e1aa48">Value range: 0 to 3. The default value is <strong id="EN-US_TOPIC_0000001188429064__b842352706222127">0</strong>.</p>
</li><li id="EN-US_TOPIC_0000001188429064__lff6a2288b8ec472993acbcf2b2d7c984">MAX_BATCHROW<p id="EN-US_TOPIC_0000001188429064__a55c284d6c0c843e0861506326473d715"><a name="EN-US_TOPIC_0000001188429064__lff6a2288b8ec472993acbcf2b2d7c984"></a><a name="lff6a2288b8ec472993acbcf2b2d7c984"></a>Specifies the maximum of a storage unit during data loading process. The parameter is only valid for column-store tables.</p>
<p id="EN-US_TOPIC_0000001188429064__p59361644122913">Value range: 10000 to 60000</p>
<p id="EN-US_TOPIC_0000001188429064__af17457566b404c3aa62bfef662c9fba3">Default value: 60,000</p>
</li><li id="EN-US_TOPIC_0000001188429064__l09d7b9048bcd4612a7e3529d8597419f">PARTIAL_CLUSTER_ROWS<p id="EN-US_TOPIC_0000001188429064__ad566fbb5176e467cbcaafdd158c25afc"><a name="EN-US_TOPIC_0000001188429064__l09d7b9048bcd4612a7e3529d8597419f"></a><a name="l09d7b9048bcd4612a7e3529d8597419f"></a>Specifies the number of records to be partial cluster stored during data loading process. The parameter is only valid for column-store tables.</p>
<p id="EN-US_TOPIC_0000001188429064__a743957d47ee549909ca4d0ebc5fb5ed4">Value range: 600000 to 2147483647</p>
<p id="EN-US_TOPIC_0000001188429064__p135274263713">Default value: 4,200,000</p>
</li><li id="EN-US_TOPIC_0000001188429064__li2613194271216">enable_delta<p id="EN-US_TOPIC_0000001188429064__p1761394219122"><a name="EN-US_TOPIC_0000001188429064__li2613194271216"></a><a name="li2613194271216"></a>Specifies whether to enable delta tables in column-store tables. The parameter is only valid for column-store tables.</p>
<p id="EN-US_TOPIC_0000001188429064__p561354210126">Default value: <strong id="EN-US_TOPIC_0000001188429064__b18489181710210">off</strong></p>
</li><li id="EN-US_TOPIC_0000001188429064__l70caac449c624b2aafb1efe4b6ba69f7">DELTAROW_THRESHOLD<p id="EN-US_TOPIC_0000001188429064__a405e51516cf94d89b2ecfe461f1cdfd8"><a name="EN-US_TOPIC_0000001188429064__l70caac449c624b2aafb1efe4b6ba69f7"></a><a name="l70caac449c624b2aafb1efe4b6ba69f7"></a>Specifies the upper limit of to-be-imported rows for triggering the data import to a delta table when data is to be imported to a column-store table. This parameter takes effect only if the <strong id="EN-US_TOPIC_0000001188429064__b83454182414">enable_delta</strong> table parameter is set to <strong id="EN-US_TOPIC_0000001188429064__b147114391302">on</strong>. The parameter is only valid for column-store tables.</p>
<p id="EN-US_TOPIC_0000001188429064__aad22c617d71142a991d7fc027213e78c">The value ranges from <strong id="EN-US_TOPIC_0000001188429064__b842352706155358">0</strong> to <strong id="EN-US_TOPIC_0000001188429064__b84235270615541">60000</strong>. The default value is <strong id="EN-US_TOPIC_0000001188429064__b842352706155424">6000</strong>.</p>
</li><li id="EN-US_TOPIC_0000001188429064__li650019179418">COLVERSION<p id="EN-US_TOPIC_0000001188429064__p35006179418"><a name="EN-US_TOPIC_0000001188429064__li650019179418"></a><a name="li650019179418"></a>Specifies the version of the column-store format. You can switch between different storage formats.</p>
<p id="EN-US_TOPIC_0000001188429064__p1850016171446">Valid value:</p>
<p id="EN-US_TOPIC_0000001188429064__p1050014175413"><strong id="EN-US_TOPIC_0000001188429064__b20944591851">1.0</strong>: Each column in a column-store table is stored in a separate file. The file name is <strong id="EN-US_TOPIC_0000001188429064__b198832225512">relfilenode.C1.0</strong>, <strong id="EN-US_TOPIC_0000001188429064__b66763253515">relfilenode.C2.0</strong>, <strong id="EN-US_TOPIC_0000001188429064__b1787492815518">relfilenode.C3.0</strong>, or similar.</p>
<p id="EN-US_TOPIC_0000001188429064__p1250012171411"><strong id="EN-US_TOPIC_0000001188429064__b10683155883413">2.0</strong>: All columns of a column-store table are combined and stored in a file. The file is named <strong id="EN-US_TOPIC_0000001188429064__b768315588341">relfilenode.C1.0</strong>.</p>
<p id="EN-US_TOPIC_0000001188429064__p19500917545">Default value: <strong id="EN-US_TOPIC_0000001188429064__b1189815251612">2.0</strong></p>
<p id="EN-US_TOPIC_0000001188429064__p135079255718">The value of <strong id="EN-US_TOPIC_0000001188429064__b1612615774010">COLVERSION</strong> can only be set to <strong id="EN-US_TOPIC_0000001188429064__b550718171406">2.0</strong> for OBS multi-temperature tables.</p>
<div class="note" id="EN-US_TOPIC_0000001188429064__note57078250414"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="EN-US_TOPIC_0000001188429064__ul184261158161110"><li id="EN-US_TOPIC_0000001188429064__li7426175820119">For clusters of version 8.1.0, the default value of this parameter is <strong id="EN-US_TOPIC_0000001188429064__b77141515215">1.0</strong>. For clusters of version 8.1.1 or later, the default value of this parameter is <strong id="EN-US_TOPIC_0000001188429064__b082384835216">2.0</strong>. If the cluster version is upgraded from 8.1.0 to 8.1.1 or later, the default value of this parameter changes from <strong id="EN-US_TOPIC_0000001188429064__b1630185285211">1.0</strong> to <strong id="EN-US_TOPIC_0000001188429064__b3911165518526">2.0</strong>.</li><li id="EN-US_TOPIC_0000001188429064__li442615820118">When creating a column-store table, set <strong id="EN-US_TOPIC_0000001188429064__b11315341476">COLVERSION</strong> to <strong id="EN-US_TOPIC_0000001188429064__b9131173419476">2.0</strong>. Compared with the <strong id="EN-US_TOPIC_0000001188429064__b181315349472">1.0</strong> storage format, the performance is significantly improved:<ol id="EN-US_TOPIC_0000001188429064__ol542614583118"><li id="EN-US_TOPIC_0000001188429064__li1426205811120">The time required for creating a column-store wide table is significantly reduced.</li><li id="EN-US_TOPIC_0000001188429064__li3426658191111">In the Roach data backup scenario, the backup time is significantly reduced.</li><li id="EN-US_TOPIC_0000001188429064__li1742655811117">The build and catch up time is greatly reduced.</li><li id="EN-US_TOPIC_0000001188429064__li7426195811118">The occupied disk space decreases significantly.</li></ol>
</li></ul>
</div></div>
</li><li id="EN-US_TOPIC_0000001188429064__li32608317479">SKIP_FPI_HINT<p id="EN-US_TOPIC_0000001188429064__p185568515461"><a name="EN-US_TOPIC_0000001188429064__li32608317479"></a><a name="li32608317479"></a>Indicates whether to skip the hint bits operation when the full-page writes (FPW) log needs to be written during sequential scanning.</p>
<div class="p" id="EN-US_TOPIC_0000001188429064__p3172164012188">Default value: <strong id="EN-US_TOPIC_0000001188429064__b94410361223">false</strong><div class="note" id="EN-US_TOPIC_0000001188429064__note177211636121818"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001188429064__p1721193631819">If <strong id="EN-US_TOPIC_0000001188429064__b1792110392228">SKIP_FPI_HINT</strong> is set to <strong id="EN-US_TOPIC_0000001188429064__b15922173962217">true</strong> and the checkpoint operation is performed on a table, no Xlog will be generated when the table is sequentially scanned. This applies to intermediate tables that are queried less frequently, reducing the size of Xlogs and improving query performance.</p>
</div></div>
</div>
</li></ul>
</li><li id="EN-US_TOPIC_0000001188429064__l8778c2de5deb44879d6adc63997b804b"><strong id="EN-US_TOPIC_0000001188429064__a4e0ed1cea7a94fb38f15fd9a17dde22f">ON COMMIT { PRESERVE ROWS | DELETE ROWS }</strong><p id="EN-US_TOPIC_0000001188429064__aa82d8f22c5ce4ed9b7aec0e5a647a24c"><strong id="EN-US_TOPIC_0000001188429064__b84235270622221">ON COMMIT</strong> determines what to do when you commit a temporary table creation operation.</p>
<ul id="EN-US_TOPIC_0000001188429064__uf04036b9aecb4e38a9a87afa68f8f826"><li id="EN-US_TOPIC_0000001188429064__lec0de098db28479b9d349b28aa654574"><strong id="EN-US_TOPIC_0000001188429064__b84235270692117">PRESERVE ROWS</strong> (Default): No special action is taken at the ends of transactions. The temporary table and its table data are unchanged.</li><li id="EN-US_TOPIC_0000001188429064__lb2a32fb7def94ffb85f1a4b4a8c7cbe5"><strong id="EN-US_TOPIC_0000001188429064__b84235270692128">DELETE ROWS</strong>: All rows in the temporary table will be deleted at the end of each transaction block.</li></ul>
</li><li id="EN-US_TOPIC_0000001188429064__l452d636623504de999b1861722855da0"><strong id="EN-US_TOPIC_0000001188429064__a0ddcb239173b4ef088d9bb07443df05f">COMPRESS | NOCOMPRESS</strong><p id="EN-US_TOPIC_0000001188429064__aba870fc5cf4b409a8a48c7d2976d16b9">If you specify <strong id="EN-US_TOPIC_0000001188429064__b84235270685040">COMPRESS</strong> in the <strong id="EN-US_TOPIC_0000001188429064__b842352706222332">CREATE TABLE</strong> statement, the compression feature is triggered in the case of a bulk <strong id="EN-US_TOPIC_0000001188429064__b522675911783">INSERT</strong> operation. If this feature is enabled, a scan is performed for all tuple data within the page to generate a dictionary and then the tuple data is compressed and stored. If <strong id="EN-US_TOPIC_0000001188429064__b6462771783">NOCOMPRESS</strong> is specified, the table is not compressed.</p>
<p id="EN-US_TOPIC_0000001188429064__ab61852391992405c930b2e42ca07d02a">Default value: <strong id="EN-US_TOPIC_0000001188429064__b842352706163420">NOCOMPRESS</strong>, tuple data is not compressed before storage.</p>
</li><li id="EN-US_TOPIC_0000001188429064__l1b1100015510493f95d6ef3eb261ea6f"><strong id="EN-US_TOPIC_0000001188429064__a44ff5ec06a60485dbe758a6c55a6d94f">DISTRIBUTE BY</strong><p id="EN-US_TOPIC_0000001188429064__a19cb82952a8146468059d792e8610de8">Specifies how the table is distributed or replicated between DNs.</p>
<p id="EN-US_TOPIC_0000001188429064__aab03e894b1604b919ed18088065dbf8f">Valid value:</p>
<ul id="EN-US_TOPIC_0000001188429064__u1d259cf19d074fda9764568b2a5d839d"><li id="EN-US_TOPIC_0000001188429064__l30d142a45e884e5cab2030dbd866588d"><strong id="EN-US_TOPIC_0000001188429064__b629718321047">REPLICATION</strong>: Each row in the table exists on all DNs, that is, each DN has complete table data.</li><li id="EN-US_TOPIC_0000001188429064__li108823195568"><strong id="EN-US_TOPIC_0000001188429064__b215211534547">ROUNDROBIN</strong>: Each row in the table is sent to each DN in sequence. This distribution policy prevents data skew. However, data distribution nodes are random. As a result, there is a higher probability that table redistribution is triggered during computing. This distribution policy is recommended for large tables with severe column skew. This value is supported only in 8.1.2 or later.</li><li id="EN-US_TOPIC_0000001188429064__l5371e22afc33433486d5e013fc7c916a"><strong id="EN-US_TOPIC_0000001188429064__b729810325413">HASH (column_name)</strong>: Each row of the table will be placed into all the DNs based on the hash value of the specified column.<div class="note" id="EN-US_TOPIC_0000001188429064__n0b3a96f26491458aa9c897d57966df8c"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="EN-US_TOPIC_0000001188429064__uf95d23edb74a44a6aa030f93ccdbeb6c"><li id="EN-US_TOPIC_0000001188429064__l0e39717ab5dd4af592c7c669ab565dac">When <strong id="EN-US_TOPIC_0000001188429064__b730893217410">DISTRIBUTE BY HASH (column_name)</strong> is specified, the primary key and its unique index must contain the <strong id="EN-US_TOPIC_0000001188429064__b123084322412">column_name</strong> column.</li><li id="EN-US_TOPIC_0000001188429064__l31a5501f79dd4645be7e6ce15068a67a">When <strong id="EN-US_TOPIC_0000001188429064__b43100327418">DISTRIBUTE BY HASH (column_name)</strong> in a referenced table is specified, the foreign key of the reference table must contain the <strong id="EN-US_TOPIC_0000001188429064__b203101232244">column_name</strong> column.</li><li id="EN-US_TOPIC_0000001188429064__li0412013539">If <strong id="EN-US_TOPIC_0000001188429064__b8390192318714">TO GROUP</strong> is set to a replication table node group (supported in 8.1.2 or later), <strong id="EN-US_TOPIC_0000001188429064__b105251437479">DISTRIBUTE BY</strong> must be set to <strong id="EN-US_TOPIC_0000001188429064__b81275411476">REPLICATION</strong>. If <strong id="EN-US_TOPIC_0000001188429064__b10374651877">DISTRIBUTE BY</strong> is not specified, the created table is automatically set as a replication table.</li><li id="EN-US_TOPIC_0000001188429064__li6887450733">The hybrid data warehouse (standalone) has only one DN. Therefore, the distribution rule is ignored and cannot be modified.</li></ul>
</div></div>
</li></ul>
<div class="p" id="EN-US_TOPIC_0000001188429064__p1251615105171">Default value: determined by the GUC parameter <strong id="EN-US_TOPIC_0000001188429064__b011716451285">default_distribution_mode</strong><ul id="EN-US_TOPIC_0000001188429064__ul878364963015"><li id="EN-US_TOPIC_0000001188429064__li14783249163014">When <strong id="EN-US_TOPIC_0000001188429064__b481114201399">default_distribution_mode</strong> is set to <strong id="EN-US_TOPIC_0000001188429064__b161741329198">roundrobin</strong>, the default value of <strong id="EN-US_TOPIC_0000001188429064__b1133003416912">DISTRIBUTE BY</strong> is selected according to the following rules:<ol id="EN-US_TOPIC_0000001188429064__ol137381934837"><li id="EN-US_TOPIC_0000001188429064__li87381341531">If the primary key or unique constraint is included during table creation, hash distribution is selected. The distribution column is the column corresponding to the primary key or unique constraint.</li><li id="EN-US_TOPIC_0000001188429064__li0741558414">If the primary key or unique constraint is not included during table creation, round-robin distribution is selected.</li></ol>
</li><li id="EN-US_TOPIC_0000001188429064__li1645915396371">When <strong id="EN-US_TOPIC_0000001188429064__b46060081120">default_distribution_mode</strong> is set to <strong id="EN-US_TOPIC_0000001188429064__b56071109117">hash</strong>, the default value of <strong id="EN-US_TOPIC_0000001188429064__b560719013112">DISTRIBUTE BY</strong> is selected according to the following rules:<ol id="EN-US_TOPIC_0000001188429064__ol115828818381"><li id="EN-US_TOPIC_0000001188429064__li38741447517">If the primary key or unique constraint is included during table creation, hash distribution is selected. The distribution column is the column corresponding to the primary key or unique constraint.</li><li id="EN-US_TOPIC_0000001188429064__li990712591559">If the primary key or unique constraint is not included during table creation but there are columns whose data types can be used as distribution columns, hash distribution is selected. The distribution column is the first column whose data type can be used as a distribution column.</li><li id="EN-US_TOPIC_0000001188429064__li462574677">If the primary key or unique constraint is not included during table creation and no column whose data type can be used as a distribution column exists, round-robin distribution is selected.</li></ol>
</li></ul>
</div>
<div class="p" id="EN-US_TOPIC_0000001188429064__p613875615407">The following data types can be used as distribution columns:<ul id="EN-US_TOPIC_0000001188429064__ul8929105634111"><li id="EN-US_TOPIC_0000001188429064__li18929256194113">Integer types: <strong id="EN-US_TOPIC_0000001188429064__b10277105577">TINYINT</strong>, <strong id="EN-US_TOPIC_0000001188429064__b15277180185710">SMALLINT</strong>, <strong id="EN-US_TOPIC_0000001188429064__b122776020577">INT</strong>, <strong id="EN-US_TOPIC_0000001188429064__b1027811035720">BIGINT</strong>, and <strong id="EN-US_TOPIC_0000001188429064__b6278508578">NUMERIC/DECIMAL</strong></li><li id="EN-US_TOPIC_0000001188429064__li148954319420">Character types: <strong id="EN-US_TOPIC_0000001188429064__b139251435713">CHAR</strong>, <strong id="EN-US_TOPIC_0000001188429064__b12399101418571">BPCHAR</strong>, <strong id="EN-US_TOPIC_0000001188429064__b13399514135715">VARCHAR</strong>, <strong id="EN-US_TOPIC_0000001188429064__b640018143576">VARCHAR2</strong>, <strong id="EN-US_TOPIC_0000001188429064__b540061425713">NVARCHAR2</strong>, and <strong id="EN-US_TOPIC_0000001188429064__b17401141465716">TEXT</strong></li><li id="EN-US_TOPIC_0000001188429064__li14231162624317">Date/time types: <strong id="EN-US_TOPIC_0000001188429064__b180321819578">DATE</strong>, <strong id="EN-US_TOPIC_0000001188429064__b1581041810574">TIME</strong>, <strong id="EN-US_TOPIC_0000001188429064__b19810718155717">TIMETZ</strong>, <strong id="EN-US_TOPIC_0000001188429064__b8811121825714">TIMESTAMP</strong>, <strong id="EN-US_TOPIC_0000001188429064__b15811818165720">TIMESTAMPTZ</strong>, <strong id="EN-US_TOPIC_0000001188429064__b28111189574">INTERVAL</strong>, and <strong id="EN-US_TOPIC_0000001188429064__b148121018105711">SMALLDATETIME</strong></li></ul>
</div>
<div class="note" id="EN-US_TOPIC_0000001188429064__note11344125310577"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001188429064__p581911512589">When you create a table, the choices of distribution keys and partition keys have major impact on SQL query performance. Therefore, choosing proper distribution column and partition key with strategies.</p>
<ul id="EN-US_TOPIC_0000001188429064__ul165341241165920"><li id="EN-US_TOPIC_0000001188429064__li95391941195912">Selecting an Appropriate Distribution Column<div class="p" id="EN-US_TOPIC_0000001188429064__p355034125910"><a name="EN-US_TOPIC_0000001188429064__li95391941195912"></a><a name="li95391941195912"></a>In the data distributed table using Hash, an appropriate distributed array should be used to distribute and store data on multiple DNs evenly, preventing data skew (uneven data distribution across several DNs). Determine the proper distribution column based on the following principles:<ol id="EN-US_TOPIC_0000001188429064__ol196761081903"><li id="EN-US_TOPIC_0000001188429064__li86761881012">Determine whether data is skewed.<p class="litext" id="EN-US_TOPIC_0000001188429064__p1523150301"><a name="EN-US_TOPIC_0000001188429064__li86761881012"></a><a name="li86761881012"></a>Connect to the database and run the following statements to check the number of tuples on each DN: Replace <em id="EN-US_TOPIC_0000001188429064__i133101074917">tablename</em> with the actual name of the table to be analyzed.</p>
<pre class="screen" id="EN-US_TOPIC_0000001188429064__screen027304016"><span id="EN-US_TOPIC_0000001188429064__text338107017"></span><strong id="EN-US_TOPIC_0000001188429064__b34220020016">SELECT a.count,b.node_name FROM (SELECT count(*) AS count,xc_node_id FROM</strong> <em id="EN-US_TOPIC_0000001188429064__i14471501011">tablename</em> <strong id="EN-US_TOPIC_0000001188429064__b1753170505">GROUP BY xc_node_id) a, pgxc_node b WHERE a.xc_node_id=b.node_id ORDER BY a.count DESC;</strong></pre>
<p class="litext" id="EN-US_TOPIC_0000001188429064__p357130904">If tuple numbers vary greatly (several times or tenfold) in each DN, a data skew occurs. Change the data distribution key based on the following principles:</p>
</li><li id="EN-US_TOPIC_0000001188429064__li10727210113">Run the ALTER TABLE statement to adjust the distribution column. The rules for selecting a distribution column are as follows:<p id="EN-US_TOPIC_0000001188429064__p662318401315"><a name="EN-US_TOPIC_0000001188429064__li10727210113"></a><a name="li10727210113"></a>The column value of the distribution column should be discrete so that data can be evenly distributed on each DN. 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.</p>
<p id="EN-US_TOPIC_0000001188429064__p185933181230">With the above principles met, you can select join conditions as distribution keys so that join tasks can be pushed down to DNs, reducing the amount of data transferred between the DNs.</p>
</li><li id="EN-US_TOPIC_0000001188429064__li8774175432513">If a proper distribution column cannot be found to make data evenly distributed on each DN, you can use the <strong id="EN-US_TOPIC_0000001188429064__b15229102411414">REPLICATION</strong> or <strong id="EN-US_TOPIC_0000001188429064__b197737291445">ROUNDROBIN</strong> data distribution mode. The <strong id="EN-US_TOPIC_0000001188429064__b241513501645">REPLICATION</strong> data distribution mode stores complete data on each DN. Therefore, if a table is large and no proper distribution column can be found, the <strong id="EN-US_TOPIC_0000001188429064__b3691713455">ROUNDROBIN</strong> data distribution mode is recommended. The <strong id="EN-US_TOPIC_0000001188429064__b974110314510">ROUNDROBIN</strong> data distribution mode is supported in 8.1.2 or later.</li></ol>
</div>
</li><li id="EN-US_TOPIC_0000001188429064__li202881859343">Selecting appropriate partition keys<p id="EN-US_TOPIC_0000001188429064__p1731014598411"><a name="EN-US_TOPIC_0000001188429064__li202881859343"></a><a name="li202881859343"></a>In range partitioning, the table is partitioned into ranges defined by a key column or set of columns, with no overlap between the ranges of values assigned to different partitions. Each range has a dedicated partition for data storage.</p>
<p id="EN-US_TOPIC_0000001188429064__p3310145913413">Modify partition keys to make the query result stored in the same or least partitions (partition pruning). Obtaining consecutive I/O to improve the query performance.</p>
<p id="EN-US_TOPIC_0000001188429064__p3310859042">In actual services, time is used to filter query objects. Therefore, you can use time as a partition key, and change the key value based on the total data volume and single data query volume.</p>
</li></ul>
</div></div>
</li><li id="EN-US_TOPIC_0000001188429064__l952d2eb00a7a47bbaa7a6eab40966b69"><strong id="EN-US_TOPIC_0000001188429064__ae3a58cce858a4746a33e116011f28202">TO { GROUP groupname | NODE ( nodename [, ... ] ) }</strong><p id="EN-US_TOPIC_0000001188429064__a337dcd05ab1646748b2fc1e83c683295"><strong id="EN-US_TOPIC_0000001188429064__b741414264256">TO GROUP</strong> specifies the Node Group in which the table is created. Currently, it cannot be used for HDFS tables. <strong id="EN-US_TOPIC_0000001188429064__b842352706152947">TO NODE</strong> is used for internal scale-out tools.</p>
<p id="EN-US_TOPIC_0000001188429064__p62633616499">In logical cluster mode, if <strong id="EN-US_TOPIC_0000001188429064__b187570309219">TO GROUP</strong> is not specified, the table is created in the node group associated with the logical cluster user by default. If the user, such as the administrator or a common user, does not manage the logical cluster, by default the table is created in the first logical cluster, which is the logical cluster with the smallest <strong id="EN-US_TOPIC_0000001188429064__b622612279240">OID</strong> in <strong id="EN-US_TOPIC_0000001188429064__b72769533242">pgxc_group</strong>.</p>
<p id="EN-US_TOPIC_0000001188429064__p14384553125810">If the node group specified by <strong id="EN-US_TOPIC_0000001188429064__b053765920260">TO GROUP</strong> is a replication table node group, the table is created on all CNs and DNs, but the replication table data is distributed only on the DNs in the replication table node group.</p>
</li><li id="EN-US_TOPIC_0000001188429064__li568919439420"><strong id="EN-US_TOPIC_0000001188429064__b1661611920208">COMMENT [=] 'text'</strong><p id="EN-US_TOPIC_0000001188429064__p18695881579">The <strong id="EN-US_TOPIC_0000001188429064__b980816463277">COMMENT</strong> clause can specify table comments during table creation.</p>
</li><li id="EN-US_TOPIC_0000001188429064__l46786c0bcc524132bca8ab0b74952295"><strong id="EN-US_TOPIC_0000001188429064__a2081b217eae24189b7d455b5dc28db22">CONSTRAINT constraint_name</strong><p id="EN-US_TOPIC_0000001188429064__a86f0e2090d1349a292dde96cf61b880e">Specifies a name for a column or table constraint. The optional constraint clauses specify constraints that new or updated rows must satisfy for an insert or update operation to succeed.</p>
<p id="EN-US_TOPIC_0000001188429064__a9431027fb104402da3f0f1ce9b3fbd06">There are two ways to define constraints:</p>
<ul id="EN-US_TOPIC_0000001188429064__u6c8f9d65434b4228813d5f953d724bf7"><li id="EN-US_TOPIC_0000001188429064__l69f9da027d804911b4ce17b7bfb2b245">A column constraint is defined as part of a column definition, and it is bound to a particular column.</li><li id="EN-US_TOPIC_0000001188429064__l203273641c2d4afea1f00e912eb4bd2b">A table constraint is not bound to any particular columns but can apply to more than one column.</li></ul>
</li><li id="EN-US_TOPIC_0000001188429064__l30d2b1740e0148bfb5f07e997f46ef1c"><strong id="EN-US_TOPIC_0000001188429064__af9431c6ac92a4982a9fa901e53f6421b">NOT NULL</strong><p id="EN-US_TOPIC_0000001188429064__aa3bb437f01a843d7ad643e881e8554db">Indicates that the column is not allowed to contain <strong id="EN-US_TOPIC_0000001188429064__b87912263144857">NULL</strong> values.</p>
</li><li id="EN-US_TOPIC_0000001188429064__l88137e4d693a48a1a9c6289b75da0f30"><strong id="EN-US_TOPIC_0000001188429064__a0351f2a212154d13a48788f2cc7b8b3d">NULL</strong><p id="EN-US_TOPIC_0000001188429064__ae2ce887f32fc409996a3c45909a044ad">The column is allowed to contain <strong id="EN-US_TOPIC_0000001188429064__b842352706104637">NULL</strong> values. This is the default setting.</p>
<p id="EN-US_TOPIC_0000001188429064__ab08d5c26192b40b9ae89282ab63c646f">This clause is only provided for compatibility with non-standard SQL databases. You are advised not to use this clause.</p>
</li><li id="EN-US_TOPIC_0000001188429064__l62ab5db2e605425ba1475dd7010404e4"><strong id="EN-US_TOPIC_0000001188429064__a445d552fe9ae4d1ea848bf15afd0ac5e">CHECK ( expression )</strong><p id="EN-US_TOPIC_0000001188429064__ae4bd05430ba64a65b7e09cedd26cda6c">Specifies an expression producing a Boolean result which new or updated rows must satisfy for an insert or update operation to succeed. Expressions evaluating to <strong id="EN-US_TOPIC_0000001188429064__b84235270616515">TRUE</strong> or <strong id="EN-US_TOPIC_0000001188429064__b84235270616518">UNKNOWN</strong> succeed. If any row of an insert or update operation produces a FALSE result, an error exception is raised and the insert or update does not alter the database.</p>
<p id="EN-US_TOPIC_0000001188429064__a105edc449f4247a68685d1758be67111">A check constraint specified as a column constraint should reference only the column's values, while an expression appearing in a table constraint can reference multiple columns.</p>
<div class="note" id="EN-US_TOPIC_0000001188429064__note354734852610"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001188429064__p755211489268"><strong id="EN-US_TOPIC_0000001188429064__b14435145412214">&lt;&gt;NULL</strong> and <strong id="EN-US_TOPIC_0000001188429064__b1243720541026">!=NULL</strong> are invalid in an expression. Change them to <strong id="EN-US_TOPIC_0000001188429064__b144741956221">IS NOT NULL</strong>.</p>
</div></div>
</li><li id="EN-US_TOPIC_0000001188429064__l723523fcfe234f5d9744697a100a2d5b"><strong id="EN-US_TOPIC_0000001188429064__ae12044be71b94ca7bff594caad8bcc1b">DEFAULT default_expr</strong><p id="EN-US_TOPIC_0000001188429064__a7e8fa85ca0d24fec803141c818493a08">Assigns a default data value for a column. The value can be any variable-free expressions (Subqueries and cross-references to other columns in the current table are not allowed). The data type of the default expression must match the data type of the column.</p>
<p id="EN-US_TOPIC_0000001188429064__a136aabf04ffe43678229512a34a07ad2">The default expression will be used in any insert operation that does not specify a value for the column. If there is no default value for a column, then the default value is <strong id="EN-US_TOPIC_0000001188429064__b842352706104725">NULL</strong>.</p>
</li><li id="EN-US_TOPIC_0000001188429064__li9964195916187"><strong id="EN-US_TOPIC_0000001188429064__b17673421111913">COMMENT</strong><strong id="EN-US_TOPIC_0000001188429064__b8385201192010"> 'text'</strong><p id="EN-US_TOPIC_0000001188429064__p163036125201">The <strong id="EN-US_TOPIC_0000001188429064__b1831163372820">COMMENT</strong> clause can specify a comment for a column.</p>
</li><li id="EN-US_TOPIC_0000001188429064__l3947318658d747c0b403f7087fd9a662"><strong id="EN-US_TOPIC_0000001188429064__a403ac85ea7d44ff095eb59aaf8819053">UNIQUE index_parameters</strong><p id="EN-US_TOPIC_0000001188429064__a470845db7cd14428bef79486a01d2295"><strong id="EN-US_TOPIC_0000001188429064__a8b6f1b6dbf8d4418a46a9bd65997d3ac">UNIQUE ( column_name [, ... ] ) index_parameters</strong></p>
<p id="EN-US_TOPIC_0000001188429064__aecada5190e5f468eaff4d903bea0f476">Specifies that a group of one or more columns of a table can contain only unique values.</p>
<p id="EN-US_TOPIC_0000001188429064__a6c5e538c0fed4378886b1628df00c1d9">For the purpose of a unique constraint, NULL is not considered equal.</p>
<div class="note" id="EN-US_TOPIC_0000001188429064__n5c787c39852f41ee98e8f9aec419aeb3"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001188429064__a647bf5485229466f9085fe5db6f6ed2c">If <strong id="EN-US_TOPIC_0000001188429064__b84235270610484">DISTRIBUTE BY REPLICATION</strong> is not specified, the column table that contains only unique values must contain distribution columns.</p>
</div></div>
</li><li id="EN-US_TOPIC_0000001188429064__l61a58f471c2a41178cea62e34b75609e"><strong id="EN-US_TOPIC_0000001188429064__aead44124bc5c4467b08efadb591637ac">PRIMARY KEY index_parameters</strong><p id="EN-US_TOPIC_0000001188429064__a139d3146dc50420b85805015313d97d0"><strong id="EN-US_TOPIC_0000001188429064__ad33d94e660bd41ce88f2504f99a0ef7d">PRIMARY KEY ( column_name [, ... ] ) index_parameters</strong></p>
<p id="EN-US_TOPIC_0000001188429064__a9cbb2d707be14fe591db68ecec5e0786">Specifies the primary key constraint specifies that a column or columns of a table can contain only unique (non-duplicate) and non-null values.</p>
<p id="EN-US_TOPIC_0000001188429064__af35e3b0d1eb8457b9fde40db514c6708">Only one primary key can be specified for a table.</p>
<div class="note" id="EN-US_TOPIC_0000001188429064__n18e8fd59d5ef457cbeec615f6f07d9fe"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001188429064__a612f61a539c94ce4841136a1e1d194a6">If <strong id="EN-US_TOPIC_0000001188429064__b18701033944">DISTRIBUTE BY REPLICATION</strong> is not specified, the column set with a primary key constraint must contain distributed columns.</p>
</div></div>
</li><li id="EN-US_TOPIC_0000001188429064__ld504902f528d4b15b74d4e19a9e80627"><strong id="EN-US_TOPIC_0000001188429064__a955d98a5445a42f1a9fa5d6de093af02">DEFERRABLE | NOT DEFERRABLE</strong><p id="EN-US_TOPIC_0000001188429064__a8933428d03e743088b176c549c43cfa0">Controls whether the constraint can be deferred. A constraint that is not deferrable will be checked immediately after every command. Checking of constraints that are deferrable can be postponed until the end of the transaction using the <strong id="EN-US_TOPIC_0000001188429064__b60118629161614">SET CONSTRAINTS</strong> command. <strong id="EN-US_TOPIC_0000001188429064__b37770752161614">NOT DEFERRABLE</strong> is the default value. Currently, only <strong id="EN-US_TOPIC_0000001188429064__b842352706165150">UNIQUE</strong> and <strong id="EN-US_TOPIC_0000001188429064__b842352706165153">PRIMARY KEY</strong> constraints of row-store tables accept this clause. All the other constraints are not deferrable.</p>
</li><li id="EN-US_TOPIC_0000001188429064__li490420236428"><strong id="EN-US_TOPIC_0000001188429064__b194681910164">PARTIAL CLUSTER KEY</strong><p id="EN-US_TOPIC_0000001188429064__p2024122110254">Specifies a partial cluster key for storage. When importing data to a column-store table, you can perform local data sorting by specified columns (single or multiple).</p>
</li><li id="EN-US_TOPIC_0000001188429064__le49188cd0ea9445bb11c4ffba407db2e"><strong id="EN-US_TOPIC_0000001188429064__abbad7cac0fba4d5184597e50e26b2d40">INITIALLY IMMEDIATE | INITIALLY DEFERRED</strong><p id="EN-US_TOPIC_0000001188429064__a23370860b6a340e982a08d6ede865ede">If a constraint is deferrable, this clause specifies the default time to check the constraint.</p>
<ul id="EN-US_TOPIC_0000001188429064__u882f54932fb14e639393bdb51c8f54de"><li id="EN-US_TOPIC_0000001188429064__lc2d668e5ba944b388e26f8ad78eb23d1">If the constraint is <strong id="EN-US_TOPIC_0000001188429064__b44131592161921">INITIALLY IMMEDIATE</strong> (default value), it is checked after each statement.</li><li id="EN-US_TOPIC_0000001188429064__ld299e8bbef5a4cf18d9fe7a0be476c4b">If the constraint is <strong id="EN-US_TOPIC_0000001188429064__b17889208161921">INITIALLY DEFERRED</strong>, it is checked only at the end of the transaction.</li></ul>
<p id="EN-US_TOPIC_0000001188429064__ae2d1db393a0a4242b3665193edc024ab">The constraint check time can be altered using the <strong id="EN-US_TOPIC_0000001188429064__b39739724161921">SET CONSTRAINTS</strong> command.</p>
</li></ul>
</div>
<div class="section" id="EN-US_TOPIC_0000001188429064__section75712037183317"><h4 class="sectiontitle">Example</h4><p id="EN-US_TOPIC_0000001188429064__p13831105315549">Define a unique column constraint for the table.</p>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001188429064__screen824712315720"><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>
<span class="normal"> 6</span>
<span class="normal"> 7</span>
<span class="normal"> 8</span>
<span class="normal"> 9</span>
<span class="normal">10</span>
<span class="normal">11</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">DROP</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="k">IF</span><span class="w"> </span><span class="k">EXISTS</span><span class="w"> </span><span class="n">CUSTOMER</span><span class="p">;</span>
<span class="k">CREATE</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="n">CUSTOMER</span>
<span class="p">(</span><span class="w"> </span>
<span class="w"> </span><span class="n">C_CUSTKEY</span><span class="w"> </span><span class="nb">BIGINT</span><span class="w"> </span><span class="k">NOT</span><span class="w"> </span><span class="k">NULL</span><span class="w"> </span><span class="k">CONSTRAINT</span><span class="w"> </span><span class="n">C_CUSTKEY_pk</span><span class="w"> </span><span class="k">PRIMARY</span><span class="w"> </span><span class="k">KEY</span><span class="w"> </span><span class="p">,</span><span class="w"> </span>
<span class="w"> </span><span class="n">C_NAME</span><span class="w"> </span><span class="nb">VARCHAR</span><span class="p">(</span><span class="mi">25</span><span class="p">)</span><span class="w"> </span><span class="p">,</span><span class="w"> </span>
<span class="w"> </span><span class="n">C_ADDRESS</span><span class="w"> </span><span class="nb">VARCHAR</span><span class="p">(</span><span class="mi">40</span><span class="p">)</span><span class="w"> </span><span class="p">,</span><span class="w"> </span>
<span class="w"> </span><span class="n">C_NATIONKEY</span><span class="w"> </span><span class="nb">INT</span><span class="w"> </span><span class="p">,</span><span class="w"> </span>
<span class="w"> </span><span class="n">C_PHONE</span><span class="w"> </span><span class="nb">CHAR</span><span class="p">(</span><span class="mi">15</span><span class="p">)</span><span class="w"> </span><span class="p">,</span><span class="w"> </span>
<span class="w"> </span><span class="n">C_ACCTBAL</span><span class="w"> </span><span class="nb">DECIMAL</span><span class="p">(</span><span class="mi">15</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span><span class="w"> </span>
<span class="p">)</span>
<span class="n">DISTRIBUTE</span><span class="w"> </span><span class="k">BY</span><span class="w"> </span><span class="n">HASH</span><span class="p">(</span><span class="n">C_CUSTKEY</span><span class="p">);</span>
</pre></div></td></tr></table></div>
</div>
<p id="EN-US_TOPIC_0000001188429064__p1783215534547">Define a primary key table constraint for a table. You can define a primary key table constraint on one or more columns of a table.</p>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001188429064__screen7206193511575"><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>
<span class="normal"> 6</span>
<span class="normal"> 7</span>
<span class="normal"> 8</span>
<span class="normal"> 9</span>
<span class="normal">10</span>
<span class="normal">11</span>
<span class="normal">12</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">DROP</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="k">IF</span><span class="w"> </span><span class="k">EXISTS</span><span class="w"> </span><span class="n">CUSTOMER</span><span class="p">;</span>
<span class="k">CREATE</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="n">CUSTOMER</span>
<span class="p">(</span><span class="w"> </span>
<span class="w"> </span><span class="n">C_CUSTKEY</span><span class="w"> </span><span class="nb">BIGINT</span><span class="w"> </span><span class="p">,</span><span class="w"> </span>
<span class="w"> </span><span class="n">C_NAME</span><span class="w"> </span><span class="nb">VARCHAR</span><span class="p">(</span><span class="mi">25</span><span class="p">)</span><span class="w"> </span><span class="p">,</span><span class="w"> </span>
<span class="w"> </span><span class="n">C_ADDRESS</span><span class="w"> </span><span class="nb">VARCHAR</span><span class="p">(</span><span class="mi">40</span><span class="p">)</span><span class="w"> </span><span class="p">,</span><span class="w"> </span>
<span class="w"> </span><span class="n">C_NATIONKEY</span><span class="w"> </span><span class="nb">INT</span><span class="w"> </span><span class="p">,</span><span class="w"> </span>
<span class="w"> </span><span class="n">C_PHONE</span><span class="w"> </span><span class="nb">CHAR</span><span class="p">(</span><span class="mi">15</span><span class="p">)</span><span class="w"> </span><span class="p">,</span><span class="w"> </span>
<span class="w"> </span><span class="n">C_ACCTBAL</span><span class="w"> </span><span class="nb">DECIMAL</span><span class="p">(</span><span class="mi">15</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span><span class="w"> </span><span class="p">,</span><span class="w"> </span>
<span class="w"> </span><span class="k">CONSTRAINT</span><span class="w"> </span><span class="n">C_CUSTKEY_KEY</span><span class="w"> </span><span class="k">PRIMARY</span><span class="w"> </span><span class="k">KEY</span><span class="p">(</span><span class="n">C_CUSTKEY</span><span class="p">,</span><span class="n">C_NAME</span><span class="p">)</span>
<span class="p">)</span>
<span class="n">DISTRIBUTE</span><span class="w"> </span><span class="k">BY</span><span class="w"> </span><span class="n">HASH</span><span class="p">(</span><span class="n">C_CUSTKEY</span><span class="p">,</span><span class="n">C_NAME</span><span class="p">);</span>
</pre></div></td></tr></table></div>
</div>
<p id="EN-US_TOPIC_0000001188429064__p883295395410">Define the <strong id="EN-US_TOPIC_0000001188429064__b1137874508112459">CHECK</strong> column constraint:</p>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001188429064__screen97220431583"><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>
<span class="normal">6</span>
<span class="normal">7</span>
<span class="normal">8</span>
<span class="normal">9</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">DROP</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="k">IF</span><span class="w"> </span><span class="k">EXISTS</span><span class="w"> </span><span class="n">CUSTOMER</span><span class="p">;</span>
<span class="k">CREATE</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="n">CUSTOMER</span>
<span class="p">(</span><span class="w"> </span>
<span class="w"> </span><span class="n">C_CUSTKEY</span><span class="w"> </span><span class="nb">BIGINT</span><span class="w"> </span><span class="k">NOT</span><span class="w"> </span><span class="k">NULL</span><span class="w"> </span><span class="k">CONSTRAINT</span><span class="w"> </span><span class="n">C_CUSTKEY_pk</span><span class="w"> </span><span class="k">PRIMARY</span><span class="w"> </span><span class="k">KEY</span><span class="w"> </span><span class="p">,</span><span class="w"> </span>
<span class="w"> </span><span class="n">C_NAME</span><span class="w"> </span><span class="nb">VARCHAR</span><span class="p">(</span><span class="mi">25</span><span class="p">)</span><span class="w"> </span><span class="p">,</span><span class="w"> </span>
<span class="w"> </span><span class="n">C_ADDRESS</span><span class="w"> </span><span class="nb">VARCHAR</span><span class="p">(</span><span class="mi">40</span><span class="p">)</span><span class="w"> </span><span class="p">,</span><span class="w"> </span>
<span class="w"> </span><span class="n">C_NATIONKEY</span><span class="w"> </span><span class="nb">INT</span><span class="w"> </span><span class="k">NOT</span><span class="w"> </span><span class="k">NULL</span><span class="w"> </span><span class="k">CHECK</span><span class="w"> </span><span class="p">(</span><span class="n">C_NATIONKEY</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span><span class="w"> </span>
<span class="p">)</span>
<span class="n">DISTRIBUTE</span><span class="w"> </span><span class="k">BY</span><span class="w"> </span><span class="n">HASH</span><span class="p">(</span><span class="n">C_CUSTKEY</span><span class="p">);</span>
</pre></div></td></tr></table></div>
</div>
<p id="EN-US_TOPIC_0000001188429064__p12833175318546">Define the <strong id="EN-US_TOPIC_0000001188429064__b1258131451112459">CHECK</strong> table constraint:</p>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001188429064__screen914013572581"><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>
<span class="normal"> 6</span>
<span class="normal"> 7</span>
<span class="normal"> 8</span>
<span class="normal"> 9</span>
<span class="normal">10</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">DROP</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="k">IF</span><span class="w"> </span><span class="k">EXISTS</span><span class="w"> </span><span class="n">CUSTOMER</span><span class="p">;</span>
<span class="k">CREATE</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="n">CUSTOMER</span>
<span class="p">(</span><span class="w"> </span>
<span class="w"> </span><span class="n">C_CUSTKEY</span><span class="w"> </span><span class="nb">BIGINT</span><span class="w"> </span><span class="k">NOT</span><span class="w"> </span><span class="k">NULL</span><span class="w"> </span><span class="k">CONSTRAINT</span><span class="w"> </span><span class="n">C_CUSTKEY_pk</span><span class="w"> </span><span class="k">PRIMARY</span><span class="w"> </span><span class="k">KEY</span><span class="w"> </span><span class="p">,</span><span class="w"> </span>
<span class="w"> </span><span class="n">C_NAME</span><span class="w"> </span><span class="nb">VARCHAR</span><span class="p">(</span><span class="mi">25</span><span class="p">)</span><span class="w"> </span><span class="p">,</span><span class="w"> </span>
<span class="w"> </span><span class="n">C_ADDRESS</span><span class="w"> </span><span class="nb">VARCHAR</span><span class="p">(</span><span class="mi">40</span><span class="p">)</span><span class="w"> </span><span class="p">,</span><span class="w"> </span>
<span class="w"> </span><span class="n">C_NATIONKEY</span><span class="w"> </span><span class="nb">INT</span><span class="w"> </span><span class="p">,</span><span class="w"> </span>
<span class="w"> </span><span class="k">CONSTRAINT</span><span class="w"> </span><span class="n">C_CUSTKEY_KEY2</span><span class="w"> </span><span class="k">CHECK</span><span class="p">(</span><span class="n">C_CUSTKEY</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="k">AND</span><span class="w"> </span><span class="n">C_NAME</span><span class="w"> </span><span class="o">&lt;&gt;</span><span class="w"> </span><span class="s1">''</span><span class="p">)</span>
<span class="p">)</span>
<span class="n">DISTRIBUTE</span><span class="w"> </span><span class="k">BY</span><span class="w"> </span><span class="n">HASH</span><span class="p">(</span><span class="n">C_CUSTKEY</span><span class="p">);</span>
</pre></div></td></tr></table></div>
</div>
<p id="EN-US_TOPIC_0000001188429064__p16833125314542">Create a column-store table and specify the storage format and compression mode:</p>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001188429064__screen1215719587599"><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>
<span class="normal"> 6</span>
<span class="normal"> 7</span>
<span class="normal"> 8</span>
<span class="normal"> 9</span>
<span class="normal">10</span>
<span class="normal">11</span>
<span class="normal">12</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">DROP</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="k">IF</span><span class="w"> </span><span class="k">EXISTS</span><span class="w"> </span><span class="n">customer_address</span><span class="p">;</span>
<span class="k">CREATE</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="n">customer_address</span>
<span class="p">(</span>
<span class="w"> </span><span class="n">ca_address_sk</span><span class="w"> </span><span class="nb">INTEGER</span><span class="w"> </span><span class="k">NOT</span><span class="w"> </span><span class="k">NULL</span><span class="w"> </span><span class="p">,</span>
<span class="w"> </span><span class="n">ca_address_id</span><span class="w"> </span><span class="nb">CHARACTER</span><span class="p">(</span><span class="mi">16</span><span class="p">)</span><span class="w"> </span><span class="k">NOT</span><span class="w"> </span><span class="k">NULL</span><span class="w"> </span><span class="p">,</span>
<span class="w"> </span><span class="n">ca_street_number</span><span class="w"> </span><span class="nb">CHARACTER</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span><span class="w"> </span><span class="p">,</span>
<span class="w"> </span><span class="n">ca_street_name</span><span class="w"> </span><span class="nb">CHARACTER</span><span class="w"> </span><span class="nb">varying</span><span class="p">(</span><span class="mi">60</span><span class="p">)</span><span class="w"> </span><span class="p">,</span>
<span class="w"> </span><span class="n">ca_street_type</span><span class="w"> </span><span class="nb">CHARACTER</span><span class="p">(</span><span class="mi">15</span><span class="p">)</span><span class="w"> </span><span class="p">,</span>
<span class="w"> </span><span class="n">ca_suite_number</span><span class="w"> </span><span class="nb">CHARACTER</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span><span class="w"> </span>
<span class="p">)</span>
<span class="k">WITH</span><span class="w"> </span><span class="p">(</span><span class="n">ORIENTATION</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">COLUMN</span><span class="p">,</span><span class="w"> </span><span class="n">COMPRESSION</span><span class="o">=</span><span class="n">HIGH</span><span class="p">,</span><span class="n">COLVERSION</span><span class="o">=</span><span class="mi">2</span><span class="p">.</span><span class="mi">0</span><span class="p">)</span>
<span class="n">DISTRIBUTE</span><span class="w"> </span><span class="k">BY</span><span class="w"> </span><span class="n">HASH</span><span class="w"> </span><span class="p">(</span><span class="n">ca_address_sk</span><span class="p">);</span>
</pre></div></td></tr></table></div>
</div>
<p id="EN-US_TOPIC_0000001188429064__p78337531549">Use <strong id="EN-US_TOPIC_0000001188429064__b1519219560112459">DEFAULT</strong> to declare a default value for column <strong id="EN-US_TOPIC_0000001188429064__b1733391228112459">W_STATE</strong>:</p>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001188429064__screen021814161104"><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>
<span class="normal"> 6</span>
<span class="normal"> 7</span>
<span class="normal"> 8</span>
<span class="normal"> 9</span>
<span class="normal">10</span>
<span class="normal">11</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">DROP</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="k">IF</span><span class="w"> </span><span class="k">EXISTS</span><span class="w"> </span><span class="n">warehouse_t</span><span class="p">;</span>
<span class="k">CREATE</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="n">warehouse_t</span>
<span class="p">(</span>
<span class="w"> </span><span class="n">W_WAREHOUSE_SK</span><span class="w"> </span><span class="nb">INTEGER</span><span class="w"> </span><span class="k">NOT</span><span class="w"> </span><span class="k">NULL</span><span class="p">,</span>
<span class="w"> </span><span class="n">W_WAREHOUSE_ID</span><span class="w"> </span><span class="nb">CHAR</span><span class="p">(</span><span class="mi">16</span><span class="p">)</span><span class="w"> </span><span class="k">NOT</span><span class="w"> </span><span class="k">NULL</span><span class="p">,</span>
<span class="w"> </span><span class="n">W_WAREHOUSE_NAME</span><span class="w"> </span><span class="nb">VARCHAR</span><span class="p">(</span><span class="mi">20</span><span class="p">)</span><span class="w"> </span><span class="k">UNIQUE</span><span class="w"> </span><span class="k">DEFERRABLE</span><span class="p">,</span>
<span class="w"> </span><span class="n">W_WAREHOUSE_SQ_FT</span><span class="w"> </span><span class="nb">INTEGER</span><span class="w"> </span><span class="p">,</span>
<span class="w"> </span><span class="n">W_COUNTY</span><span class="w"> </span><span class="nb">VARCHAR</span><span class="p">(</span><span class="mi">30</span><span class="p">)</span><span class="w"> </span><span class="p">,</span>
<span class="w"> </span><span class="n">W_STATE</span><span class="w"> </span><span class="nb">CHAR</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span><span class="w"> </span><span class="k">DEFAULT</span><span class="w"> </span><span class="s1">'GA'</span><span class="p">,</span>
<span class="w"> </span><span class="n">W_ZIP</span><span class="w"> </span><span class="nb">CHAR</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span><span class="w"> </span>
<span class="p">);</span>
</pre></div></td></tr></table></div>
</div>
<p id="EN-US_TOPIC_0000001188429064__p48347532545">Create the <strong id="EN-US_TOPIC_0000001188429064__b1472183630112459">CUSTOMER_bk</strong> table in LIKE mode:</p>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001188429064__screen979095915610"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
<span class="normal">2</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">DROP</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="k">IF</span><span class="w"> </span><span class="k">EXISTS</span><span class="w"> </span><span class="n">CUSTOMER_bk</span><span class="p">;</span>
<span class="k">CREATE</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="n">CUSTOMER_bk</span><span class="w"> </span><span class="p">(</span><span class="k">LIKE</span><span class="w"> </span><span class="n">CUSTOMER</span><span class="w"> </span><span class="k">INCLUDING</span><span class="w"> </span><span class="k">ALL</span><span class="p">);</span>
</pre></div></td></tr></table></div>
</div>
</div>
<div class="section" id="EN-US_TOPIC_0000001188429064__sbd5006c0aa874ae59e4fa1608060e587"><h4 class="sectiontitle">Helpful Links</h4><p id="EN-US_TOPIC_0000001188429064__af68d50a68ca240b5b4b865f60da19c34"><a href="dws_06_0142.html">ALTER TABLE</a>, <a href="dws_06_0276.html">RENAME TABLE</a>, <a href="dws_06_0208.html">DROP TABLE</a></p>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_06_0118.html">DDL Syntax</a></div>
</div>
</div>