forked from docs/doc-exports
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com> Co-authored-by: Yang, Tong <yangtong2@huawei.com> Co-committed-by: Yang, Tong <yangtong2@huawei.com>
81 lines
8.9 KiB
HTML
81 lines
8.9 KiB
HTML
<a name="mrs_01_1429"></a><a name="mrs_01_1429"></a>
|
|
|
|
<h1 class="topictitle1">ALTER TABLE COMPACTION</h1>
|
|
<div id="body1595920211272"><div class="section" id="mrs_01_1429__s4eff9985730f42b1ac43cae7682c04d0"><h4 class="sectiontitle">Function</h4><p id="mrs_01_1429__a2a6ed53a17a14b03859f7762811525c3">The <b><span class="cmdname" id="mrs_01_1429__cmdname14822104512123">ALTER TABLE COMPACTION</span></b> command is used to merge a specified number of segments into a single segment. This improves the query performance of a table.</p>
|
|
</div>
|
|
<div class="section" id="mrs_01_1429__sb9f3196f54464d9facea781bca33f75f"><h4 class="sectiontitle">Syntax</h4><p id="mrs_01_1429__ad2a7fe15cfcc4d3ab9d733454fba1645"><b><span class="cmdname" id="mrs_01_1429__cmdname179717497124">ALTER TABLE</span></b><i><span class="varname" id="mrs_01_1429__v468e30e0948a4950a3264b18adb3b09f">[db_name.]table_name COMPACT 'MINOR/MAJOR<span id="mrs_01_1429__text92711545181315">/SEGMENT_INDEX</span>';</span></i></p>
|
|
<p id="mrs_01_1429__p277710225103"><b><span class="cmdname" id="mrs_01_1429__cmdname16777112201012">ALTER TABLE</span></b><i><span class="varname" id="mrs_01_1429__varname10777142216109">[db_name.]table_name COMPACT 'CUSTOM' WHERE SEGMENT.ID IN (id1, id2, ...);</span></i></p>
|
|
</div>
|
|
<div class="section" id="mrs_01_1429__sa088f78d884347fbae3ab2e25159126f"><h4 class="sectiontitle">Parameter Description</h4>
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="mrs_01_1429__tf4e96778927e42dcb9df9c496d684799" frame="border" border="1" rules="all"><caption><b>Table 1 </b>ALTER TABLE COMPACTION parameters</caption><thead align="left"><tr id="mrs_01_1429__r570845a8d9c944ec93042c6ff1d7291b"><th align="left" class="cellrowborder" valign="top" width="20.95%" id="mcps1.3.3.2.2.3.1.1"><p id="mrs_01_1429__a705eb782b792493393903c94817e58ae">Parameter</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="79.05%" id="mcps1.3.3.2.2.3.1.2"><p id="mrs_01_1429__ac5e778adfa284769bb63888bcad6250f">Description</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="mrs_01_1429__reac058474e3d41e79831bd4ca0678b7f"><td class="cellrowborder" valign="top" width="20.95%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_1429__a34d365aec2ad41468598c5cb45598ef7">db_name</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="79.05%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_1429__aa97458f730e9427bbc3234f5fe0d17be">Database name. If this parameter is not specified, the current database is selected.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="mrs_01_1429__r6d676a5c8fd047129020fda1e5e8dbbe"><td class="cellrowborder" valign="top" width="20.95%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_1429__aaacd15a0ede04cb7b06275c0d6704de6">table_name</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="79.05%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_1429__ad1a11e201abc43d8ab01ebf4d6c3150f">Table name.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="mrs_01_1429__row12431164018146"><td class="cellrowborder" valign="top" width="20.95%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_1429__p11431124051420">MINOR</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="79.05%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_1429__p043134019140">Minor compaction. For details, see <a href="mrs_01_1415.html">Combining Segments</a>.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="mrs_01_1429__row1226116433148"><td class="cellrowborder" valign="top" width="20.95%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_1429__p1426154341420">MAJOR</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="79.05%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_1429__p182616430144">Major compaction. For details, see <a href="mrs_01_1415.html">Combining Segments</a>.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="mrs_01_1429__row3942134515145"><td class="cellrowborder" valign="top" width="20.95%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_1429__p79421245151415">SEGMENT_INDEX</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="79.05%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_1429__p1942945121413">This configuration enables you to merge all the CarbonData index files (<strong id="mrs_01_1429__b145156437443">.carbonindex</strong>) inside a segment to a single CarbonData index merge file (<strong id="mrs_01_1429__b947895564419">.carbonindexmerge</strong>). This enhances the first query performance. For more information, see <a href="mrs_01_1415.html#mrs_01_1415__t9ba7557f991f4d6caad3710c4a51b9f2">Table 1</a>.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="mrs_01_1429__row15344124151115"><td class="cellrowborder" valign="top" width="20.95%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_1429__p9345846114">CUSTOM</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="79.05%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_1429__p1234524141116">Custom compaction. For details, see <a href="mrs_01_1415.html#mrs_01_1415__li68503712544">Combining Segments</a>.</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="mrs_01_1429__s052c1bb0ea4b4677a592016efaae6d36"><h4 class="sectiontitle">Precautions</h4><p id="mrs_01_1429__a31c8d8ffb1f4411bbfbf2abc7916270f">N/A</p>
|
|
</div>
|
|
<div class="section" id="mrs_01_1429__sd7ed1bc618ec4c0ea2c9af3bef556391"><h4 class="sectiontitle">Examples</h4><p id="mrs_01_1429__a8a46e26e62644ee181e83b438f612306"><b><span class="cmdname" id="mrs_01_1429__cmdname07576115105">ALTER TABLE ProductDatabase COMPACT 'MINOR';</span></b></p>
|
|
<p id="mrs_01_1429__a3316b71035c8480095d80c23874821af"><b><span class="cmdname" id="mrs_01_1429__cmdname167410512101">ALTER TABLE ProductDatabase COMPACT 'MAJOR';</span></b></p>
|
|
<p id="mrs_01_1429__p72395436191"><b><span class="cmdname" id="mrs_01_1429__cmdname1583013717207">ALTER TABLE ProductDatabase COMPACT 'SEGMENT_INDEX';</span></b></p>
|
|
<p id="mrs_01_1429__p13951947185110"><b><span class="cmdname" id="mrs_01_1429__cmdname12395174715115">ALTER TABLE ProductDatabase COMPACT 'CUSTOM' WHERE SEGMENT.ID IN (0, 1);</span></b></p>
|
|
</div>
|
|
<div class="section" id="mrs_01_1429__s19b6f7bd7ee3472b9bfe85999ee5cbbb"><h4 class="sectiontitle">System Response</h4><p id="mrs_01_1429__a0cc71e62e1d849a781093dd25dc6d549"><b><span class="cmdname" id="mrs_01_1429__cmdname7860185681211">ALTER TABLE COMPACTION</span></b> does not show the response of the compaction because it is run in the background.</p>
|
|
<p id="mrs_01_1429__ab426d09774b6422a81469092db09cade">If you want to view the response of minor and major compactions, you can check the logs or run the <i><b><span class="cmdname" style="font-family:Arial" id="mrs_01_1429__cmdname1751111216464">SHOW SEGMENTS</span></b></i> command.</p>
|
|
<p id="mrs_01_1429__a17bbe719e44e45a4b2c49ba57d975e73">Example:</p>
|
|
<pre class="screen" id="mrs_01_1429__sd9661f67e7844e51b522d8feeea7f385">+------+------------+--------------------------+------------------+------------+------------+-------------+--------------+--+
|
|
| ID | Status | Load Start Time | Load Time Taken | Partition | Data Size | Index Size | File Format |
|
|
+------+------------+--------------------------+------------------+------------+------------+-------------+--------------+--+
|
|
| 3 | Success | 2020-09-28 22:53:26.336 | 3.726S | {} | 6.47KB | 3.30KB | columnar_v3 |
|
|
| 2 | Success | 2020-09-28 22:53:01.702 | 6.688S | {} | 6.47KB | 3.30KB | columnar_v3 |
|
|
| 1 | Compacted | 2020-09-28 22:51:15.242 | 5.82S | {} | 6.50KB | 3.43KB | columnar_v3 |
|
|
| 0.1 | Success | 2020-10-30 20:49:24.561 | 16.66S | {} | 12.87KB | 6.91KB | columnar_v3 |
|
|
| 0 | Compacted | 2020-09-28 22:51:02.6 | 6.819S | {} | 6.50KB | 3.43KB | columnar_v3 |
|
|
+------+------------+--------------------------+------------------+------------+------------+-------------+--------------+--+</pre>
|
|
<p id="mrs_01_1429__a68eb567286c6483d91830fbfbe0213b6">In the preceding information:</p>
|
|
<ul id="mrs_01_1429__ud2232034cf1247628a3dbefba47a8d81"><li id="mrs_01_1429__l14723e129b1c4fb891122b2cc8fe9846"><strong id="mrs_01_1429__b63141227174617">Compacted</strong> indicates that data has been compacted. </li><li id="mrs_01_1429__l378bb5c42d3646b3a89127f1c1a08e81"><strong id="mrs_01_1429__b1463182984619">0.1</strong> indicates the compacting result of segment 0 and segment 1. </li></ul>
|
|
<p id="mrs_01_1429__a707a023b8a0a4621902b96da6f648d25">The compact operation does not incur any change to other operations.</p>
|
|
<p id="mrs_01_1429__a19c5a7b6ed0141a7bf0fc48dbe871fed">Compacted segments, such as segment 0 and segment 1, become useless. To save space, before you perform other operations, run the <i><b><span class="cmdname" style="font-family:Arial" id="mrs_01_1429__cmdname84731056194613">CLEAN FILES</span></b></i> command to delete compacted segments. For more information about the <b><span class="cmdname" id="mrs_01_1429__cmdname13611010273">CLEAN FILES</span></b> command, see <a href="mrs_01_1448.html">CLEAN FILES</a>.</p>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="mrs_01_1424.html">DDL</a></div>
|
|
</div>
|
|
</div>
|
|
|