forked from docs/doc-exports
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com> Co-authored-by: Lu, Huayi <luhuayi@huawei.com> Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
133 lines
18 KiB
HTML
133 lines
18 KiB
HTML
<a name="EN-US_TOPIC_0000001460562840"></a><a name="EN-US_TOPIC_0000001460562840"></a>
|
||
|
||
<h1 class="topictitle1">Selecting a Table Storage Mode</h1>
|
||
<div id="body8662426"><p id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_a35793774fa89413a8d9b38c1faa43ecb"><span id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_text629907801">GaussDB(DWS)</span> supports hybrid row and column storage. When creating a table, you can set the table storage mode to row storage or column storage.</p>
|
||
<p id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_p1224113373474">Row storage stores tables to disk partitions by row, and column storage stores tables to disk partitions by column. By default, a table is created in row storage mode. For details about differences between row storage and column storage, see <a href="#EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_fig1417354233018">Figure 1</a>.</p>
|
||
<div class="fignone" id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_fig1417354233018"><a name="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_fig1417354233018"></a><a name="en-us_topic_0000001233883387_fig1417354233018"></a><span class="figcap"><b>Figure 1 </b>Differences between row storage and column storage</span><p id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_p2765151514716"><span><img id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_image977211513475" src="figure/en-us_image_0000001188323816.png" width="523.6875" height="412.389243" title="Click to enlarge" class="imgResize"></span></p>
|
||
</div>
|
||
<p id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_p14563281225">In the preceding figure, the upper left part is a row-store table, and the upper right part shows how the row-store table is stored on a disk; the lower left part is a column-store table, and the lower right part shows how the column-store table is stored on a disk.</p>
|
||
<p id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_p593044011456">The row/column storage of a table is specified by the <strong id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_b6155622504848">orientation</strong> attribute in the table definition. The value <strong id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_b10193129734848">row</strong> indicates a row-store table and <strong id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_b9608087864848">column</strong> indicates a column-store table. The default value is <strong id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_b6898425204848">row</strong>. Each storage mode applies to specific scenarios. Select an appropriate mode when creating a table.</p>
|
||
|
||
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_table8447131119519" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Table storage modes and scenarios</caption><thead align="left"><tr id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_row16451411125113"><th align="left" class="cellrowborder" valign="top" width="15%" id="mcps1.3.6.2.5.1.1"><p id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_p7453131117518"><strong id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_b846112611550">Storage Mode</strong></p>
|
||
</th>
|
||
<th align="left" class="cellrowborder" valign="top" width="25%" id="mcps1.3.6.2.5.1.2"><p id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_p199221916145119"><strong id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_b020482817558">Benefit</strong></p>
|
||
</th>
|
||
<th align="left" class="cellrowborder" valign="top" width="25%" id="mcps1.3.6.2.5.1.3"><p id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_p164535117512"><strong id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_b8825193125515">Drawback</strong></p>
|
||
</th>
|
||
<th align="left" class="cellrowborder" valign="top" width="35%" id="mcps1.3.6.2.5.1.4"><p id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_p8476155824718"><strong id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_b126317466554">Application Scenarios</strong></p>
|
||
</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody><tr id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_row445671111516"><td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.6.2.5.1.1 "><p id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_p124571811115110">Row storage</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="25%" headers="mcps1.3.6.2.5.1.2 "><p id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_p1654125142613">Data is stored by row. When you query a row of data, you can quickly locate the target row.</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="25%" headers="mcps1.3.6.2.5.1.3 "><p id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_p1727415115212">All data in the queried row is read while only a few columns are needed.</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="35%" headers="mcps1.3.6.2.5.1.4 "><ol id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_ol1044032793810"><li id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_li14441527123813">The number of columns in the table is small, and most fields in the table are queried.</li><li id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_li14441027143816">Point queries (simple index–based query that returns only a few records) are performed.</li><li id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_li14441227103817">Add, Delete, Modify, and Query operations on entire rows are frequently performed.</li></ol>
|
||
</td>
|
||
</tr>
|
||
<tr id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_row1546241120517"><td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.6.2.5.1.1 "><p id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_p6462111105112">Column storage</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="25%" headers="mcps1.3.6.2.5.1.2 "><ol id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_ol1124734083813"><li id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_li42479402383">Only necessary columns in a query are read.</li><li id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_li20247174053814">The homogeneity of data within a column facilitates efficient compression.</li></ol>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="25%" headers="mcps1.3.6.2.5.1.3 "><p id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_p10861152822910">It is not suitable for INSERT or UPDATE operations on a small amount of data.</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="35%" headers="mcps1.3.6.2.5.1.4 "><ol id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_ol16205312388"><li id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_li1620631133816">Query a few columns in a table that contains a large number of columns.</li><li id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_li152013110383">Statistical analysis queries (requiring a large number of association and grouping operations)</li><li id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_li12073123816">Ad hoc queries (using uncertain query conditions and unable to utilize indexes to scan row-store tables)</li></ol>
|
||
</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_s885c354da1704fd193b3cc0cba17cdbc"><h4 class="sectiontitle">Creating a Row-store Table</h4><p id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_p4551134972113">For example, to create a row-store table named <strong id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_b1173642521719">customer_t1</strong>, run the following command:</p>
|
||
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_se238062b7f784b798369e733400b22e6"><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="k">CREATE</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="n">customer_t1</span>
|
||
<span class="p">(</span>
|
||
<span class="w"> </span><span class="n">state_ID</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="n">state_NAME</span><span class="w"> </span><span class="n">VARCHAR2</span><span class="p">(</span><span class="mi">40</span><span class="p">),</span>
|
||
<span class="w"> </span><span class="n">area_ID</span><span class="w"> </span><span class="nb">NUMBER</span>
|
||
<span class="p">);</span>
|
||
</pre></div></td></tr></table></div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_s09cb093bc88c4aba8e18d28454738108"><h4 class="sectiontitle">Creating a column-store table.</h4><p id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_p167853416225">For example, to create a column-store table named <strong id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_b178881615204">customer_t2</strong>, run the following command:</p>
|
||
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_s0e07eb391fc2431fb331653d2eafce9c"><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></pre></div></td><td class="code"><div><pre><span></span><span class="k">CREATE</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="n">customer_t2</span>
|
||
<span class="p">(</span>
|
||
<span class="w"> </span><span class="n">state_ID</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="n">state_NAME</span><span class="w"> </span><span class="n">VARCHAR2</span><span class="p">(</span><span class="mi">40</span><span class="p">),</span>
|
||
<span class="w"> </span><span class="n">area_ID</span><span class="w"> </span><span class="nb">NUMBER</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>
|
||
</pre></div></td></tr></table></div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_section682371819574"><h4 class="sectiontitle">Table Compression</h4><p id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_p9338103972816">Table compression can be enabled when a table is created. Table compression enables data in the table to be stored in compressed format to reduce memory usage.</p>
|
||
<p id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_p3543204816453">In scenarios where I/O is large (much data is read and written) and CPU is sufficient (little data is computed), select a high compression ratio. In scenarios where I/O is small and CPU is insufficient, select a low compression ratio. Based on this principle, you are advised to select different compression ratios and test and compare the results to select the optimal compression ratio as required. Specify a compressions ratio using the <strong id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_b20522855034848">COMPRESSION</strong> parameter. The supported values are as follows:</p>
|
||
<ul id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_ul5200824144712"><li id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_en-us_topic_0059778169_la31f2968ca084c8fa724eabd79789670">The valid value of column-store tables is <strong id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_b10388335014848">YES</strong>, <strong id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_b14526582014848">NO</strong>, <strong id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_b3515469434848">LOW</strong>, <strong id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_b13172344734848">MIDDLE</strong>, or <strong id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_b6997647634848">HIGH</strong>, and the default value is <strong id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_b13616020984848">LOW</strong>.</li><li id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_li1895768105414">The valid values of row-store tables are <strong id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_b6740732234848">YES</strong> and <strong id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_b18006700934848">NO</strong>, and the default is <strong id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_b10486701864848">NO</strong>. (The row-store table compression function is not put into commercial use. To use this function, contact technical support.)</li></ul>
|
||
<p id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_p12568343122916">The service scenarios applicable to each compression level are described in the following table.</p>
|
||
|
||
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_table17210162018919" frame="border" border="1" rules="all"><thead align="left"><tr id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_row021315201199"><th align="left" class="cellrowborder" valign="top" width="24%" id="mcps1.3.9.6.1.3.1.1"><p id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_p162131420299">Compression Level</p>
|
||
</th>
|
||
<th align="left" class="cellrowborder" valign="top" width="76%" id="mcps1.3.9.6.1.3.1.2"><p id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_p152134205917">Application Scenario</p>
|
||
</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody><tr id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_row6213112013913"><td class="cellrowborder" valign="top" width="24%" headers="mcps1.3.9.6.1.3.1.1 "><p id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_p1921314201192">LOW</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="76%" headers="mcps1.3.9.6.1.3.1.2 "><p id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_p182139201997">The system CPU usage is high and the disk storage space is sufficient.</p>
|
||
</td>
|
||
</tr>
|
||
<tr id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_row72131420397"><td class="cellrowborder" valign="top" width="24%" headers="mcps1.3.9.6.1.3.1.1 "><p id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_p8912132972415">MIDDLE</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="76%" headers="mcps1.3.9.6.1.3.1.2 "><p id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_p82131520497">The system CPU usage is moderate and the disk storage space is insufficient.</p>
|
||
</td>
|
||
</tr>
|
||
<tr id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_row821372011920"><td class="cellrowborder" valign="top" width="24%" headers="mcps1.3.9.6.1.3.1.1 "><p id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_p821322018920">HIGH</p>
|
||
</td>
|
||
<td class="cellrowborder" valign="top" width="76%" headers="mcps1.3.9.6.1.3.1.2 "><p id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_p1021316201912">The system CPU usage is low and the disk storage space is insufficient.</p>
|
||
</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<p id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_p12325345115116">For example, to create a compressed column-store table named <strong id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_b2061245582015">customer_t3</strong>, run the following command:</p>
|
||
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001460562840__en-us_topic_0000001233883387_screen199406151215"><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></pre></div></td><td class="code"><div><pre><span></span><span class="k">CREATE</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="n">customer_t3</span>
|
||
<span class="p">(</span>
|
||
<span class="w"> </span><span class="n">state_ID</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="n">state_NAME</span><span class="w"> </span><span class="n">VARCHAR2</span><span class="p">(</span><span class="mi">40</span><span class="p">),</span>
|
||
<span class="w"> </span><span class="n">area_ID</span><span class="w"> </span><span class="nb">NUMBER</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="n">COMPRESSION</span><span class="o">=</span><span class="n">middle</span><span class="p">);</span>
|
||
</pre></div></td></tr></table></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div>
|
||
<div class="familylinks">
|
||
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_04_0016.html">Defining Database Objects</a></div>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
<script language="JavaScript">
|
||
<!--
|
||
image_size('.imgResize');
|
||
var msg_imageMax = "view original image";
|
||
var msg_imageClose = "close";
|
||
//--></script> |