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>
74 lines
12 KiB
HTML
74 lines
12 KiB
HTML
<a name="EN-US_TOPIC_0000001233563195"></a><a name="EN-US_TOPIC_0000001233563195"></a>
|
|
|
|
<h1 class="topictitle1">Analyzing a Table</h1>
|
|
<div id="body8662426"><p id="EN-US_TOPIC_0000001233563195__en-us_topic_0165786590_p946942918443">The execution plan generator needs to use table statistics to generate the most effective query execution plan to improve query performance. After data is imported, you are advised to run the <strong id="EN-US_TOPIC_0000001233563195__b17513940154811">ANALYZE</strong> statement to update table statistics. The statistics are stored in the <strong id="EN-US_TOPIC_0000001233563195__b10451035112513">PG_STATISTIC</strong> system catalog.</p>
|
|
<div class="section" id="EN-US_TOPIC_0000001233563195__s58c50bcfbc4e4cdba2e53106605146e9"><h4 class="sectiontitle">Analyzing a Table</h4><p id="EN-US_TOPIC_0000001233563195__p238015529189"><strong id="EN-US_TOPIC_0000001233563195__b198811532102919">ANALYZE</strong> supports row-store, column-store, HDFS, and OBS tables in ORC or CARBONDATA format. <strong id="EN-US_TOPIC_0000001233563195__b127412903441650">ANALYZE</strong> can also collect statistics about specified columns of a local table.</p>
|
|
<div class="p" id="EN-US_TOPIC_0000001233563195__a7cc15e152c4e4c3cbbfe1d13ecdff2f3">Do <strong id="EN-US_TOPIC_0000001233563195__b157661949134716">ANALYZE</strong> to the <strong id="EN-US_TOPIC_0000001233563195__b155963119479">product_info</strong> table.<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001233563195__s979739f990cb4f37bd0266e3f6267dff"><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">ANALYZE</span><span class="w"> </span><span class="n">product_info</span><span class="p">;</span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001233563195__s801617bf20944c38a55450b9bfd9886c"><h4 class="sectiontitle">Automatically Analyzing a Table</h4><p id="EN-US_TOPIC_0000001233563195__p19664541171114"><span id="EN-US_TOPIC_0000001233563195__text1605141589">GaussDB(DWS)</span> provides automatic table analysis for the following two scenarios.</p>
|
|
<ul id="EN-US_TOPIC_0000001233563195__ul92414274576"><li id="EN-US_TOPIC_0000001233563195__li1524142718574">If <strong id="EN-US_TOPIC_0000001233563195__b659614203813">ANALYZE</strong> is triggered because a query contains a table that has no statistics or a table whose amount of data modification reaches the threshold, and the execution plan does not use Fast Query Shipping (FQS), the GUC parameter <a href="dws_04_0912.html#EN-US_TOPIC_0000001188323574__section114241119217">autoanalyze</a> is used to control the automatic collection of table statistics. In this case, a better execution plan is generated based on the collected statistics.</li><li id="EN-US_TOPIC_0000001233563195__li124111273576">If <a href="dws_04_0923.html#EN-US_TOPIC_0000001188482222__s8d6c38309e594a16a07f79ae412b63c6">autovacuum</a> is set to <strong id="EN-US_TOPIC_0000001233563195__b1015921916396">on</strong>, the system periodically starts the autovacuum thread and automatically collects statistics on the tables whose amount of data modification reaches the threshold for triggering <strong id="EN-US_TOPIC_0000001233563195__b315921993916">ANALYZE</strong> in the background.
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001233563195__table15764105915511" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Automatically Analyzing a Table</caption><thead align="left"><tr id="EN-US_TOPIC_0000001233563195__row1376575915519"><th align="left" class="cellrowborder" valign="top" width="15%" id="mcps1.3.3.3.2.4.2.6.1.1"><p id="EN-US_TOPIC_0000001233563195__p16887107185211">Trigger Mode</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="20%" id="mcps1.3.3.3.2.4.2.6.1.2"><p id="EN-US_TOPIC_0000001233563195__p128871471525">Trigger Condition</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="20%" id="mcps1.3.3.3.2.4.2.6.1.3"><p id="EN-US_TOPIC_0000001233563195__p128872785214">Scaling Frequency</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="20%" id="mcps1.3.3.3.2.4.2.6.1.4"><p id="EN-US_TOPIC_0000001233563195__p1888715705210">Control Parameter</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="25%" id="mcps1.3.3.3.2.4.2.6.1.5"><p id="EN-US_TOPIC_0000001233563195__p588715710524">Remarks</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="EN-US_TOPIC_0000001233563195__row376519598512"><td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.3.3.2.4.2.6.1.1 "><p id="EN-US_TOPIC_0000001233563195__p1888777135220">Synchronization</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.3.3.3.2.4.2.6.1.2 "><p id="EN-US_TOPIC_0000001233563195__p183523154237">Statistics are completely missing.</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.3.3.3.2.4.2.6.1.3 "><p id="EN-US_TOPIC_0000001233563195__p1888818714529">At each query execution</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.3.3.3.2.4.2.6.1.4 "><p id="EN-US_TOPIC_0000001233563195__p1988819705219">autoanalyze</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="25%" headers="mcps1.3.3.3.2.4.2.6.1.5 "><p id="EN-US_TOPIC_0000001233563195__p68880785210">Statistics are cleared when the primary table is truncated.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001233563195__row137661759135116"><td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.3.3.2.4.2.6.1.1 "><p id="EN-US_TOPIC_0000001233563195__p1888107105218">Synchronization</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.3.3.3.2.4.2.6.1.2 "><p id="EN-US_TOPIC_0000001233563195__p1188810710522">The amount of modified data reaches the <strong id="EN-US_TOPIC_0000001233563195__b191061340112810">ANALYZE</strong> threshold.</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.3.3.3.2.4.2.6.1.3 "><p id="EN-US_TOPIC_0000001233563195__p18881372522">At each query execution</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.3.3.3.2.4.2.6.1.4 "><p id="EN-US_TOPIC_0000001233563195__p88888718523">autoanalyze</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="25%" headers="mcps1.3.3.3.2.4.2.6.1.5 "><p id="EN-US_TOPIC_0000001233563195__p1588887195219">ANALYZE is triggered before the optimal plan is determined.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001233563195__row5766115916518"><td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.3.3.2.4.2.6.1.1 "><p id="EN-US_TOPIC_0000001233563195__p2888157125210">Asynchronization</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.3.3.3.2.4.2.6.1.2 "><p id="EN-US_TOPIC_0000001233563195__p1788827205215">The amount of modified data reaches the <strong id="EN-US_TOPIC_0000001233563195__b47271319153111">ANALYZE</strong> threshold.</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.3.3.3.2.4.2.6.1.3 "><p id="EN-US_TOPIC_0000001233563195__p178886725211">Autovacuum thread polling check</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.3.3.3.2.4.2.6.1.4 "><p id="EN-US_TOPIC_0000001233563195__p1488814710520">autovacuum_mode, autovacuum_naptime</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="25%" headers="mcps1.3.3.3.2.4.2.6.1.5 "><p id="EN-US_TOPIC_0000001233563195__p1188917125212">The lock times out in 2 seconds, and the execution times out in 5 minutes.</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</li></ul>
|
|
<div class="notice" id="EN-US_TOPIC_0000001233563195__n7a798b99736b4a369485f46a951b36d8"><span class="noticetitle"><img src="public_sys-resources/notice_3.0-en-us.png"> </span><div class="noticebody"><ul id="EN-US_TOPIC_0000001233563195__uc9bdf3bc75d9450387764ec85db22014"><li id="EN-US_TOPIC_0000001233563195__ld57755929f6445fda15c496a2785d6ad">The autoanalyze function supports only the default sampling mode and not the percentage sampling mode.</li><li id="EN-US_TOPIC_0000001233563195__en-us_topic_0165786590_li46072462362">The autoanalyze function does not collect multi-column statistics, which only supports percentage sampling.</li><li id="EN-US_TOPIC_0000001233563195__li45581216329"><strong id="EN-US_TOPIC_0000001233563195__b12583101618403">AUTOANALYZE</strong> is triggered because a query contains a table that has no statistics or a table whose amount of data modification reaches the threshold. In this case, <strong id="EN-US_TOPIC_0000001233563195__b149461919184113">AUTOANALYZE</strong> cannot be triggered for foreign tables or temporary tables with the <strong id="EN-US_TOPIC_0000001233563195__b1386042921711">ON COMMIT [DELETE ROWS | DROP]</strong> option.</li><li id="EN-US_TOPIC_0000001233563195__li5751815332">If the amount of data modification reaches the threshold for triggering <strong id="EN-US_TOPIC_0000001233563195__b14175311184617">ANALYZE</strong>, the amount of data modification exceeds <strong id="EN-US_TOPIC_0000001233563195__b394291724713">autovacuum_analyze_threshold</strong> + <strong id="EN-US_TOPIC_0000001233563195__b55967349479">autovacuum_analyze_scale_factor * </strong><em id="EN-US_TOPIC_0000001233563195__i6347123816475">reltuples</em>. <em id="EN-US_TOPIC_0000001233563195__i2064664354717">reltuples</em> indicates the estimated number of rows in the table recorded in <strong id="EN-US_TOPIC_0000001233563195__b19838121220480">pg_class</strong>.</li><li id="EN-US_TOPIC_0000001233563195__en-us_topic_0165786590_li36086467365">The autoanalyze function triggered by a scheduled <strong id="EN-US_TOPIC_0000001233563195__b53037414171">autovacuum</strong> thread supports only row-store and column-store tables. It does not support foreign tables, HDFS tables, OBS foreign tables, temporary tables, unlogged tables, or toast tables.</li><li id="EN-US_TOPIC_0000001233563195__li6988133165515">When <strong id="EN-US_TOPIC_0000001233563195__b15620177135611">ANALYZE</strong> is triggered during a query, a level-4 lock is added to all partitions in the partitioned table. The lock is released only after the transaction containing the query is committed. The level-4 lock does not block adding, deletion, modification, and query operations, but blocks partition modification operations such as <strong id="EN-US_TOPIC_0000001233563195__b57772825818">TRUNCATE</strong>. You can set <strong id="EN-US_TOPIC_0000001233563195__b1391918318589">object_mtime_record_mode</strong> to <strong id="EN-US_TOPIC_0000001233563195__b147861738125816">disable_partition</strong> to release the partition locks in advance.</li><li id="EN-US_TOPIC_0000001233563195__li1584913294">The autovacuum function also depends on the following two GUC parameters in addition to <strong id="EN-US_TOPIC_0000001233563195__b11817455431">autovacuum</strong>:<ul id="EN-US_TOPIC_0000001233563195__ul1648434922917"><li id="EN-US_TOPIC_0000001233563195__li1148454922912"><a href="dws_04_0920.html#EN-US_TOPIC_0000001233883261__s4682d08468f84845bfdc6ae9477126e8">track_counts</a> must be set to <strong id="EN-US_TOPIC_0000001233563195__b11421143810285">on</strong> to enable statistics collection about the database.</li><li id="EN-US_TOPIC_0000001233563195__li134841494298"><a href="dws_04_0923.html#EN-US_TOPIC_0000001188482222__s502d4304994d4da5bd3cda661aab27ac">autovacuum_max_workers</a> must be set to a value greater than 0 to specify the maximum number of concurrent autovacuum threads.</li></ul>
|
|
</li></ul>
|
|
</div></div>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_04_0988.html">Other Operations</a></div>
|
|
</div>
|
|
</div>
|
|
|