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>
70 lines
9.9 KiB
HTML
70 lines
9.9 KiB
HTML
<a name="EN-US_TOPIC_0000001188270532"></a><a name="EN-US_TOPIC_0000001188270532"></a>
|
|
|
|
<h1 class="topictitle1">REINDEX</h1>
|
|
<div id="body8662426"><div class="section" id="EN-US_TOPIC_0000001188270532__s2408714640f44914afb1d73a1ff6f926"><h4 class="sectiontitle">Function</h4><p id="EN-US_TOPIC_0000001188270532__p941089202816"><strong id="EN-US_TOPIC_0000001188270532__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_0000001188270532__aa4f97700241345f18e9283704448c6a1">There are several scenarios in which <strong id="EN-US_TOPIC_0000001188270532__en-us_topic_0058965688_b6032292311355">REINDEX</strong> can be used:</p>
|
|
<ul id="EN-US_TOPIC_0000001188270532__u761a4296491b4570bc4d9264cc3cf565"><li id="EN-US_TOPIC_0000001188270532__l0905e2c31e7541bd95214becb6ae0aed">An index has become corrupted, and no longer contains valid data.</li><li id="EN-US_TOPIC_0000001188270532__l3afa5bfb01f044feb0b85247ae5e7318">An index has become "bloated", that is, it contains many empty or nearly-empty pages.</li><li id="EN-US_TOPIC_0000001188270532__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_0000001188270532__a9467aed1eb4c4612a7858dd76f552fdc"><a name="EN-US_TOPIC_0000001188270532__l1ff944b7da284f7e9962f06aff0da360"></a><a name="l1ff944b7da284f7e9962f06aff0da360"></a>An index build with the <strong id="EN-US_TOPIC_0000001188270532__b3624657711355">CONCURRENTLY</strong> option failed, leaving an "invalid" index.</p>
|
|
</li></ul>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001188270532__s6d84bc4a91cd44d0b0ca7cef5c78e748"><h4 class="sectiontitle">Precautions</h4><p id="EN-US_TOPIC_0000001188270532__ac387b50dcae144d2b968f9d6c792b735">Index reconstruction of the <strong id="EN-US_TOPIC_0000001188270532__b2657647111543">REINDEX DATABASE</strong> or <strong id="EN-US_TOPIC_0000001188270532__b3786165011543">SYSTEM</strong> type cannot be performed in transaction blocks.</p>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001188270532__s2ad49636a7bb4be197afcb21d36f207e"><h4 class="sectiontitle">Syntax</h4><ul id="EN-US_TOPIC_0000001188270532__u741b93a137bb4aeba5a6df342c640972"><li id="EN-US_TOPIC_0000001188270532__lf04e060f151a4bef9afeeb4c42257cc8">Rebuild a general index.<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001188270532__s33d192ccd0a045c780fa3ecd5792082a"><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="o">|</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_0000001188270532__uf9d5a0b9e7b847f899019dd8f5f1b067"><li id="EN-US_TOPIC_0000001188270532__l7e13603eadea40d197d4606761f0e13d">Rebuild an index partition.<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001188270532__sb8a85f391e9b4c34a81ac545e1669462"><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="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="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="p">];</span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
</li></ul>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001188270532__sd99ea912bc4643ffaba030ec6c7ff12c"><h4 class="sectiontitle">Parameter Description</h4><ul id="EN-US_TOPIC_0000001188270532__u58d54590cdaf47058f685c58596b7af0"><li id="EN-US_TOPIC_0000001188270532__lab848cf62e60423b864e85c3676e0e48"><strong id="EN-US_TOPIC_0000001188270532__b5139449714957">INDEX</strong><p id="EN-US_TOPIC_0000001188270532__afcf9117787d643d7a832d746298c9559">Recreates the specified index.</p>
|
|
</li><li id="EN-US_TOPIC_0000001188270532__l5a90593a93ff4d079575ba4d04d89c41"><strong id="EN-US_TOPIC_0000001188270532__b2822377614101">TABLE</strong><p id="EN-US_TOPIC_0000001188270532__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_0000001188270532__ld9bca3e2dc3b4ce08aa7b8abf7749cf6"><strong id="EN-US_TOPIC_0000001188270532__b4819684214104">DATABASE</strong><p id="EN-US_TOPIC_0000001188270532__abaa7643d6f91426398329e75dc255c36">Recreates all indexes within the current database.</p>
|
|
</li><li id="EN-US_TOPIC_0000001188270532__l86817872095a4e4c84d5d8a626c3bb23"><strong id="EN-US_TOPIC_0000001188270532__b912210514108">SYSTEM</strong><p id="EN-US_TOPIC_0000001188270532__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_0000001188270532__l10474c56e0c54b5faae475cc2e72874d"><strong id="EN-US_TOPIC_0000001188270532__b24633835141013">name</strong><p id="EN-US_TOPIC_0000001188270532__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_0000001188270532__n90b512b43dd4468b88653dba58d461dd"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001188270532__a74db54d0705b4325a24ae3ae552b983b"><strong id="EN-US_TOPIC_0000001188270532__b9582988185454">REINDEX DATABASE</strong> and <strong id="EN-US_TOPIC_0000001188270532__b19138028185454">SYSTEM</strong> can create indexes for only the current database. Therefore, <strong id="EN-US_TOPIC_0000001188270532__b38024531185454">name</strong> must be the same as the current database name.</p>
|
|
</div></div>
|
|
</li><li id="EN-US_TOPIC_0000001188270532__lbe60805c15ad44e68987381136e8b655"><strong id="EN-US_TOPIC_0000001188270532__b12670019141017">FORCE</strong><p id="EN-US_TOPIC_0000001188270532__a02e13f6f2d1449cfa78d90efee272217">This is an obsolete option. It is ignored if specified.</p>
|
|
</li><li id="EN-US_TOPIC_0000001188270532__l3ec2f49e723c4c8ca61e716140c5e785"><strong id="EN-US_TOPIC_0000001188270532__b45988090141022">partition_name</strong><p id="EN-US_TOPIC_0000001188270532__a24a356f4aabd41caaa2f59df1cb6b45f">Specifies the name of the partition or index partition to be reindexed.</p>
|
|
<p id="EN-US_TOPIC_0000001188270532__aba1d4b9e25a74627b89e2da36a8827e8">Value range:</p>
|
|
<ul id="EN-US_TOPIC_0000001188270532__udbb7eff3b1454928ad2ba6303869c157"><li id="EN-US_TOPIC_0000001188270532__ldefa4ac534ae4a058427c9ffed938ad6">If it is <strong id="EN-US_TOPIC_0000001188270532__en-us_topic_0058965688_b8423527069266">REINDEX INDEX</strong>, specify the name of an index partition.</li><li id="EN-US_TOPIC_0000001188270532__lb50e1865cac24da1a5fcbf5deb380a11">If it is <strong id="EN-US_TOPIC_0000001188270532__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_0000001188270532__n4fd10f1769d742e3b767352d0d307585"><span class="noticetitle"><img src="public_sys-resources/notice_3.0-en-us.png"> </span><div class="noticebody"><p id="EN-US_TOPIC_0000001188270532__a69f25b63675449d3b36531721cd6482a">Index reconstruction of the <strong id="EN-US_TOPIC_0000001188270532__b867395435">REINDEX DATABASE</strong> or <strong id="EN-US_TOPIC_0000001188270532__b367662321">SYSTEM</strong> type cannot be performed in transaction blocks.</p>
|
|
</div></div>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001188270532__se3cfaa0f85684c5da3ac7678d7cbdefb"><h4 class="sectiontitle">Examples</h4><p id="EN-US_TOPIC_0000001188270532__p9978442377">Rebuild the partition index of partition <strong id="EN-US_TOPIC_0000001188270532__b12374306158">P1</strong> in the partitioned table <strong id="EN-US_TOPIC_0000001188270532__b13317165631418">customer_address</strong>:</p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001188270532__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>
|
|
|