forked from docs/doc-exports
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com> Co-authored-by: luhuayi <luhuayi@huawei.com> Co-committed-by: luhuayi <luhuayi@huawei.com>
83 lines
14 KiB
HTML
83 lines
14 KiB
HTML
<a name="EN-US_TOPIC_0000001811515641"></a><a name="EN-US_TOPIC_0000001811515641"></a>
|
|
|
|
<h1 class="topictitle1">REINDEX</h1>
|
|
<div id="body8662426"><div class="section" id="EN-US_TOPIC_0000001811515641__s2408714640f44914afb1d73a1ff6f926"><h4 class="sectiontitle">Function</h4><p id="EN-US_TOPIC_0000001811515641__p941089202816"><strong id="EN-US_TOPIC_0000001811515641__b1415908711355">REINDEX</strong> rebuilds an index using the data stored in the index's table, replacing the old copy of the index.</p>
|
|
<p id="EN-US_TOPIC_0000001811515641__aa4f97700241345f18e9283704448c6a1">There are several scenarios in which <strong id="EN-US_TOPIC_0000001811515641__en-us_topic_0058965688_b6032292311355">REINDEX</strong> can be used:</p>
|
|
<ul id="EN-US_TOPIC_0000001811515641__u761a4296491b4570bc4d9264cc3cf565"><li id="EN-US_TOPIC_0000001811515641__l0905e2c31e7541bd95214becb6ae0aed">An index has become corrupted, and no longer contains valid data.</li><li id="EN-US_TOPIC_0000001811515641__l3afa5bfb01f044feb0b85247ae5e7318">An index has become "bloated", that is, it contains many empty or nearly-empty pages.</li><li id="EN-US_TOPIC_0000001811515641__l1ff944b7da284f7e9962f06aff0da360">You have altered a storage parameter (such as fillfactor) for an index, and wish to ensure that the change has taken full effect.<p id="EN-US_TOPIC_0000001811515641__a9467aed1eb4c4612a7858dd76f552fdc"><a name="EN-US_TOPIC_0000001811515641__l1ff944b7da284f7e9962f06aff0da360"></a><a name="l1ff944b7da284f7e9962f06aff0da360"></a>An index build with the <strong id="EN-US_TOPIC_0000001811515641__b3624657711355">CONCURRENTLY</strong> option failed, leaving an "invalid" index.</p>
|
|
</li></ul>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001811515641__s6d84bc4a91cd44d0b0ca7cef5c78e748"><h4 class="sectiontitle">Precautions</h4><p id="EN-US_TOPIC_0000001811515641__p11141274225">Index reconstruction of the <strong id="EN-US_TOPIC_0000001811515641__b20355136628">REINDEX DATABASE</strong> or <strong id="EN-US_TOPIC_0000001811515641__b335620368218">SYSTEM</strong> type cannot be performed in transaction blocks.</p>
|
|
<p id="EN-US_TOPIC_0000001811515641__p89421627112213">In the storage-compute decoupling architecture, REINDEX full database indexes are not supported.</p>
|
|
<div class="warning" id="EN-US_TOPIC_0000001811515641__note19477181112319"><span class="warningtitle"><img src="public_sys-resources/warning_3.0-en-us.png"> </span><div class="warningbody"><ul id="EN-US_TOPIC_0000001811515641__en-us_topic_0000001188270532_ul1383351419310"><li id="EN-US_TOPIC_0000001811515641__en-us_topic_0000001188270532_li1083320141131">Do not perform the <strong id="EN-US_TOPIC_0000001811515641__en-us_topic_0000001188270532_b20295165811313">CREATE INDEX</strong> and <strong id="EN-US_TOPIC_0000001811515641__en-us_topic_0000001188270532_b14296155813137">REINDEX</strong> operations on large tables during peak hours.</li><li id="EN-US_TOPIC_0000001811515641__en-us_topic_0000001188270532_li148717165313">For more information about development and design specifications, see "GaussDB(DWS) Development and Design Proposal" in the <em id="EN-US_TOPIC_0000001811515641__en-us_topic_0000001188270532_i8692812146">Data Warehouse Service (DWS) Developer Guide</em>.</li></ul>
|
|
</div></div>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001811515641__s2ad49636a7bb4be197afcb21d36f207e"><h4 class="sectiontitle">Syntax</h4><ul id="EN-US_TOPIC_0000001811515641__ul111021233144313"><li id="EN-US_TOPIC_0000001811515641__li610216338434">Recreate indexes for the entire database or system catalogs.<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001811515641__screen12102103384318"><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="k">REINDEX</span><span class="w"> </span><span class="err">{</span><span class="w"> </span><span class="k">DATABASE</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">SYSTEM</span><span class="w"> </span><span class="err">}</span><span class="w"> </span><span class="n">name</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">FORCE</span><span class="w"> </span><span class="p">];</span>
|
|
</pre></div></td></tr></table></div>
|
|
</div>
|
|
</li></ul>
|
|
<ul id="EN-US_TOPIC_0000001811515641__ul1510217330433"><li id="EN-US_TOPIC_0000001811515641__li155531946981">Recreate an ordinary index or an index on an ordinary table.<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001811515641__screen1082913477816"><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="k">REINDEX</span><span class="w"> </span><span class="err">{</span><span class="w"> </span><span class="k">INDEX</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="err">}</span><span class="w"> </span><span class="n">name</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">FORCE</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">WITHOUT</span><span class="w"> </span><span class="n">UNUSABLE</span><span class="w"> </span><span class="p">]</span>
|
|
</pre></div></td></tr></table></div>
|
|
</div>
|
|
</li><li id="EN-US_TOPIC_0000001811515641__li1310218331434">Recreate an index partition or an index on a partition.<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001811515641__screen2102133384312"><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">REINDEX</span><span class="w"> </span><span class="err">{</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">TABLE</span><span class="err">}</span><span class="w"> </span><span class="n">name</span>
|
|
<span class="w"> </span><span class="n">PARTITION</span><span class="w"> </span><span class="n">partition_name</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">FORCE</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">WITHOUT</span><span class="w"> </span><span class="n">UNUSABLE</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_0000001811515641__sd99ea912bc4643ffaba030ec6c7ff12c"><h4 class="sectiontitle">Parameter Description</h4><ul id="EN-US_TOPIC_0000001811515641__u58d54590cdaf47058f685c58596b7af0"><li id="EN-US_TOPIC_0000001811515641__lab848cf62e60423b864e85c3676e0e48"><strong id="EN-US_TOPIC_0000001811515641__b5139449714957">INDEX</strong><p id="EN-US_TOPIC_0000001811515641__afcf9117787d643d7a832d746298c9559">Recreates the specified index.</p>
|
|
</li><li id="EN-US_TOPIC_0000001811515641__l5a90593a93ff4d079575ba4d04d89c41"><strong id="EN-US_TOPIC_0000001811515641__b2822377614101">TABLE</strong><p id="EN-US_TOPIC_0000001811515641__ad201f7f461bb4a2c95165f6d3c1788b0">Recreates all indexes of the specified table. If the table has a secondary TOAST table, that is reindexed as well.</p>
|
|
</li><li id="EN-US_TOPIC_0000001811515641__ld9bca3e2dc3b4ce08aa7b8abf7749cf6"><strong id="EN-US_TOPIC_0000001811515641__b4819684214104">DATABASE</strong><p id="EN-US_TOPIC_0000001811515641__abaa7643d6f91426398329e75dc255c36">Recreates all indexes within the current database.</p>
|
|
</li><li id="EN-US_TOPIC_0000001811515641__l86817872095a4e4c84d5d8a626c3bb23"><strong id="EN-US_TOPIC_0000001811515641__b912210514108">SYSTEM</strong><p id="EN-US_TOPIC_0000001811515641__ae55d0c4bd410484a9168e0188a74c160">Recreates all indexes on system catalogs within the current database. Indexes on user tables are not processed.</p>
|
|
</li><li id="EN-US_TOPIC_0000001811515641__l10474c56e0c54b5faae475cc2e72874d"><strong id="EN-US_TOPIC_0000001811515641__b24633835141013">name</strong><p id="EN-US_TOPIC_0000001811515641__a556f1422c33d4936be3ac389c11368c6">Name of the specific index, table, or database to be reindexed. Index and table names can be schema-qualified.</p>
|
|
<div class="note" id="EN-US_TOPIC_0000001811515641__n90b512b43dd4468b88653dba58d461dd"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001811515641__a74db54d0705b4325a24ae3ae552b983b"><strong id="EN-US_TOPIC_0000001811515641__b9582988185454">REINDEX DATABASE</strong> and <strong id="EN-US_TOPIC_0000001811515641__b19138028185454">SYSTEM</strong> can create indexes for only the current database. Therefore, <strong id="EN-US_TOPIC_0000001811515641__b38024531185454">name</strong> must be the same as the current database name.</p>
|
|
</div></div>
|
|
</li><li id="EN-US_TOPIC_0000001811515641__lbe60805c15ad44e68987381136e8b655"><strong id="EN-US_TOPIC_0000001811515641__b12670019141017">FORCE</strong><p id="EN-US_TOPIC_0000001811515641__a02e13f6f2d1449cfa78d90efee272217">This is an obsolete option. It is ignored if specified.</p>
|
|
</li><li id="EN-US_TOPIC_0000001811515641__li612514515146"><strong id="EN-US_TOPIC_0000001811515641__b17409124382219">WITHOUT UNUSABLE</strong><p id="EN-US_TOPIC_0000001811515641__p15718855191414">If this parameter is specified, the <strong id="EN-US_TOPIC_0000001811515641__b185897261231">UNUSABLE</strong> indexes or <strong id="EN-US_TOPIC_0000001811515641__b1358922611313">UNUSABLE</strong> index partitions on the object is ignored during <strong id="EN-US_TOPIC_0000001811515641__b5590192616310">REINDEX</strong>. This parameter is supported only by 9.1.0.100 and later versions.</p>
|
|
</li><li id="EN-US_TOPIC_0000001811515641__l3ec2f49e723c4c8ca61e716140c5e785"><strong id="EN-US_TOPIC_0000001811515641__b45988090141022">partition_name</strong><p id="EN-US_TOPIC_0000001811515641__a24a356f4aabd41caaa2f59df1cb6b45f">Specifies the name of the partition or index partition to be reindexed.</p>
|
|
<p id="EN-US_TOPIC_0000001811515641__aba1d4b9e25a74627b89e2da36a8827e8">Value range:</p>
|
|
<ul id="EN-US_TOPIC_0000001811515641__udbb7eff3b1454928ad2ba6303869c157"><li id="EN-US_TOPIC_0000001811515641__ldefa4ac534ae4a058427c9ffed938ad6">If it is <strong id="EN-US_TOPIC_0000001811515641__en-us_topic_0058965688_b8423527069266">REINDEX INDEX</strong>, specify the name of an index partition.</li><li id="EN-US_TOPIC_0000001811515641__lb50e1865cac24da1a5fcbf5deb380a11">If it is <strong id="EN-US_TOPIC_0000001811515641__en-us_topic_0058965688_b84235270692615">REINDEX TABLE</strong>, specify the name of a partition.</li></ul>
|
|
</li></ul>
|
|
<div class="notice" id="EN-US_TOPIC_0000001811515641__n4fd10f1769d742e3b767352d0d307585"><span class="noticetitle"><img src="public_sys-resources/notice_3.0-en-us.png"> </span><div class="noticebody"><p id="EN-US_TOPIC_0000001811515641__a69f25b63675449d3b36531721cd6482a">Index reconstruction of the <strong id="EN-US_TOPIC_0000001811515641__b2657647111543">REINDEX DATABASE</strong> or <strong id="EN-US_TOPIC_0000001811515641__b3786165011543">SYSTEM</strong> type cannot be performed in transaction blocks.</p>
|
|
</div></div>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001811515641__se3cfaa0f85684c5da3ac7678d7cbdefb"><h4 class="sectiontitle">Examples</h4><p id="EN-US_TOPIC_0000001811515641__p19479113717585">Rebuild a single index.</p>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001811515641__screen1711712346593"><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="k">REINDEX</span><span class="w"> </span><span class="k">INDEX</span><span class="w"> </span><span class="n">tpcds</span><span class="p">.</span><span class="n">tpcds_customer_index1</span><span class="p">;</span>
|
|
</pre></div></td></tr></table></div>
|
|
</div>
|
|
<p id="EN-US_TOPIC_0000001811515641__p104781437145814">Rebuild all indexes on the <strong id="EN-US_TOPIC_0000001811515641__b37943150133518"><span id="EN-US_TOPIC_0000001811515641__text47006614133518">tpcds.</span>customer_t1</strong> table.</p>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001811515641__screen1858101718594"><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="k">REINDEX</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="n">tpcds</span><span class="p">.</span><span class="n">customer_t1</span><span class="p">;</span>
|
|
</pre></div></td></tr></table></div>
|
|
</div>
|
|
<p id="EN-US_TOPIC_0000001811515641__p9978442377">Rebuild the partition index of partition <strong id="EN-US_TOPIC_0000001811515641__b191073410314">P1</strong> in the partitioned table <strong id="EN-US_TOPIC_0000001811515641__b611134738">customer_address</strong>.</p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001811515641__screen1391722133815">DROP TABLE IF EXISTS customer_address;
|
|
CREATE TABLE customer_address
|
|
(
|
|
ca_address_sk INTEGER NOT NULL ,
|
|
ca_address_id CHARACTER(16) NOT NULL ,
|
|
ca_street_number CHARACTER(10) ,
|
|
ca_street_name CHARACTER varying(60) ,
|
|
ca_street_type CHARACTER(15) ,
|
|
ca_suite_number CHARACTER(10)
|
|
)
|
|
DISTRIBUTE BY HASH (ca_address_sk)
|
|
PARTITION BY RANGE(ca_address_sk)
|
|
(
|
|
PARTITION P1 VALUES LESS THAN(2450815),
|
|
PARTITION P2 VALUES LESS THAN(2451179),
|
|
PARTITION P3 VALUES LESS THAN(2451544),
|
|
PARTITION P4 VALUES LESS THAN(MAXVALUE)
|
|
);
|
|
|
|
CREATE INDEX customer_address_index on customer_address(CA_ADDRESS_SK) LOCAL;
|
|
|
|
REINDEX TABLE customer_address PARTITION P1;</pre>
|
|
</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>
|
|
|