@@ -1541,19 +1541,23 @@ ____________________________________________________________________________-->
1541
1541
1542
1542
<!--==========================orignal english content==========================
1543
1543
<para>
1544
- Generally, the <command>EXPLAIN</command> output will display details for
1545
- every plan node which was generated by the query planner. However, there
1546
- are cases where the executor is able to determine that certain nodes are
1547
- not required; currently, the only node type to support this is the
1548
- <literal>Append</literal> node. This node type has the ability to discard
1549
- subnodes which it is able to determine won't contain any records required
1550
- by the query. It is possible to determine that nodes have been removed in
1551
- this way by the presence of a "Subplans Removed" property in the
1552
- <command>EXPLAIN</command> output.
1544
+ Normally, <command>EXPLAIN</command> will display every plan node
1545
+ created by the planner. However, there are cases where the executor
1546
+ can determine that certain nodes need not be executed because they
1547
+ cannot produce any rows, based on parameter values that were not
1548
+ available at planning time. (Currently this can only happen for child
1549
+ nodes of an Append or MergeAppend node that is scanning a partitioned
1550
+ table.) When this happens, those plan nodes are omitted from
1551
+ the <command>EXPLAIN</command> output and a <literal>Subplans
1552
+ Removed: <replaceable>N</replaceable></literal> annotation appears
1553
+ instead.
1553
1554
</para>
1554
1555
____________________________________________________________________________-->
1555
1556
<para>
1556
- 通常,<command>EXPLAIN</command>输出将显示查询规划器生成的每个计划节点的详细情况。不过,有一些情况中执行器能够确定特定的节点不是必需的。当前,唯一支持这种行动的节点类型是<literal>Append</literal>节点。这种节点类型有能力丢弃掉确定不会产生查询所需记录的子节点。可以通过<command>EXPLAIN</command>输出中的“Subplans Removed”属性的存在确定已经被移除的节点。
1557
+ 通常,<command>EXPLAIN</command>将显示规划器生成的每个计划节点。
1558
+ 但是,在某些情况下,执行器可以不执行某些节点,因为根据规划时不可用的参数值能确定这些节点无法产生任何行。
1559
+ (当前,这仅会在扫描分区表的Append或MergeAppend节点的子节点中发生。)
1560
+ 发生这种情况时,将从<command>EXPLAIN</command>输出中省略这些计划节点,并显示<literal>Subplans Removed:<replaceable>N</replaceable></literal>的标识。
1557
1561
</para>
1558
1562
</sect2>
1559
1563
@@ -1842,6 +1846,15 @@ ____________________________________________________________________________-->
1842
1846
<primary>pg_statistic_ext</primary>
1843
1847
</indexterm>
1844
1848
1849
+ <!--==========================orignal english content==========================
1850
+ <indexterm>
1851
+ <primary>pg_statistic_ext_data</primary>
1852
+ </indexterm>
1853
+ ____________________________________________________________________________-->
1854
+ <indexterm>
1855
+ <primary>pg_statistic_ext_data</primary>
1856
+ </indexterm>
1857
+
1845
1858
<!--==========================orignal english content==========================
1846
1859
<para>
1847
1860
It is common to see slow queries running bad execution plans because
@@ -1881,12 +1894,13 @@ ____________________________________________________________________________-->
1881
1894
interest in the statistics. Actual data collection is performed
1882
1895
by <command>ANALYZE</command> (either a manual command, or background
1883
1896
auto-analyze). The collected values can be examined in the
1884
- <link linkend="catalog-pg-statistic-ext"><structname>pg_statistic_ext</structname></link>
1897
+ <link linkend="catalog-pg-statistic-ext-data"><structname>pg_statistic_ext_data</structname></link>
1898
+
1885
1899
catalog.
1886
1900
</para>
1887
1901
____________________________________________________________________________-->
1888
1902
<para>
1889
- 统计信息对象可以使用<xref linkend="sql-createstatistics"/>命令创建。这样一个对象的创建仅仅是创建了一个目录项来表示对统计信息有兴趣。实际的数据收集是由<command>ANALYZE</command>(或者是一个手工命令,或者是后台的自动分析)执行的。收集到的值可以在<link linkend="catalog-pg-statistic-ext"><structname>pg_statistic_ext </structname></link>目录中看到。
1903
+ 统计信息对象可以使用<xref linkend="sql-createstatistics"/>命令创建。这样一个对象的创建仅仅是创建了一个目录项来表示对统计信息有兴趣。实际的数据收集是由<command>ANALYZE</command>(或者是一个手工命令,或者是后台的自动分析)执行的。收集到的值可以在<link linkend="catalog-pg-statistic-ext-data "><structname>pg_statistic_ext_data </structname></link>目录中看到。
1890
1904
</para>
1891
1905
1892
1906
<!--==========================orignal english content==========================
@@ -1999,14 +2013,14 @@ ____________________________________________________________________________-->
1999
2013
<para>
2000
2014
这里是一个收集函数依赖统计信息的例子:
2001
2015
<programlisting>
2002
- CREATE STATISTICS stts (dependencies) ON zip, city FROM zipcodes;
2016
+ CREATE STATISTICS stts (dependencies) ON city, zip FROM zipcodes;
2003
2017
2004
2018
ANALYZE zipcodes;
2005
2019
2006
- SELECT stxname, stxkeys, stxdependencies
2007
- FROM pg_statistic_ext
2020
+ SELECT stxname, stxkeys, stxddependencies
2021
+ FROM pg_statistic_ext join pg_statistic_ext_data on (oid = stxoid)
2008
2022
WHERE stxname = 'stts';
2009
- stxname | stxkeys | stxdependencies
2023
+ stxname | stxkeys | stxddependencies
2010
2024
---------+---------+------------------------------------------
2011
2025
stts | 1 5 | {"1 => 5": 1.000000, "5 => 1": 0.423130}
2012
2026
(1 row)
@@ -2154,12 +2168,12 @@ ____________________________________________________________________________-->
2154
2168
<para>
2155
2169
继续之前的例子,ZIP代码表中的可区分值计数可能像这样:
2156
2170
<programlisting>
2157
- CREATE STATISTICS stts2 (ndistinct) ON zip , state, city FROM zipcodes;
2171
+ CREATE STATISTICS stts2 (ndistinct) ON city , state, zip FROM zipcodes;
2158
2172
2159
2173
ANALYZE zipcodes;
2160
2174
2161
- SELECT stxkeys AS k, stxndistinct AS nd
2162
- FROM pg_statistic_ext
2175
+ SELECT stxkeys AS k, stxdndistinct AS nd
2176
+ FROM pg_statistic_ext join pg_statistic_ext_data on (oid = stxoid)
2163
2177
WHERE stxname = 'stts2';
2164
2178
-[ RECORD 1 ]--------------------------------------------------------
2165
2179
k | 1 2 5
@@ -2181,6 +2195,89 @@ ____________________________________________________________________________-->
2181
2195
建议只对实际用于分组的列组合以及分组数错误估计导致了糟糕计划的列组合创建<literal>ndistinct</literal>统计信息对象。否则,<command>ANALYZE</command>循环只会被浪费。
2182
2196
</para>
2183
2197
</sect3>
2198
+
2199
+ <sect3>
2200
+ <!--==========================orignal english content==========================
2201
+ <title>Multivariate MCV Lists</title>
2202
+ ____________________________________________________________________________-->
2203
+ <title>多元MCV列表</title>
2204
+
2205
+ <!--==========================orignal english content==========================
2206
+ <para>
2207
+ Another type of statistics stored for each column are most-common value
2208
+ lists. This allows very accurate estimates for individual columns, but
2209
+ may result in significant misestimates for queries with conditions on
2210
+ multiple columns.
2211
+ </para>
2212
+ ____________________________________________________________________________-->
2213
+ <para>
2214
+ 为每列存储的另一种统计信息是频繁值列表。 这样可以对单个列进行非常准确的估计,但是对于在多个列上具有条件的查询,可能会导致严重的错误估计。
2215
+ </para>
2216
+
2217
+ <!--==========================orignal english content==========================
2218
+ <para>
2219
+ To improve such estimates, <command>ANALYZE</command> can collect MCV
2220
+ lists on combinations of columns. Similarly to functional dependencies
2221
+ and n-distinct coefficients, it's impractical to do this for every
2222
+ possible column grouping. Even more so in this case, as the MCV list
2223
+ (unlike functional dependencies and n-distinct coefficients) does store
2224
+ the common column values. So data is collected only for those groups
2225
+ of columns appearing together in a statistics object defined with the
2226
+ <literal>mcv</literal> option.
2227
+ </para>
2228
+ ____________________________________________________________________________-->
2229
+ <para>
2230
+ 为了改善这种估计,<command>ANALYZE</command>可以收集列组合上的MCV列表。
2231
+ 与功能依赖和n-distinct系数类似,对每种可能的列分组进行此操作都是不切实际的。
2232
+ 在这种情况下,甚至更是如此,因为MCV列表(与功能依赖性和n-distinct系数不同)存储了公共列值。
2233
+ 因此,仅收集在使用<literal>mcv</literal>选项定义的统计对象中同时出现的那些列组的数据。
2234
+ </para>
2235
+
2236
+ <para>
2237
+ 继续前面的示例,邮政编码表的MCV列表可能类似于以下内容(与更简单的统计信息不同,它需要一个函数来检查MCV内容):
2238
+
2239
+ <programlisting>
2240
+ CREATE STATISTICS stts3 (mcv) ON city, state FROM zipcodes;
2241
+
2242
+ ANALYZE zipcodes;
2243
+
2244
+ SELECT m.* FROM pg_statistic_ext join pg_statistic_ext_data on (oid = stxoid),
2245
+ pg_mcv_list_items(stxdmcv) m WHERE stxname = 'stts3';
2246
+
2247
+ index | values | nulls | frequency | base_frequency
2248
+ -------+------------------------+-------+-----------+----------------
2249
+ 0 | {Washington, DC} | {f,f} | 0.003467 | 2.7e-05
2250
+ 1 | {Apo, AE} | {f,f} | 0.003067 | 1.9e-05
2251
+ 2 | {Houston, TX} | {f,f} | 0.002167 | 0.000133
2252
+ 3 | {El Paso, TX} | {f,f} | 0.002 | 0.000113
2253
+ 4 | {New York, NY} | {f,f} | 0.001967 | 0.000114
2254
+ 5 | {Atlanta, GA} | {f,f} | 0.001633 | 3.3e-05
2255
+ 6 | {Sacramento, CA} | {f,f} | 0.001433 | 7.8e-05
2256
+ 7 | {Miami, FL} | {f,f} | 0.0014 | 6e-05
2257
+ 8 | {Dallas, TX} | {f,f} | 0.001367 | 8.8e-05
2258
+ 9 | {Chicago, IL} | {f,f} | 0.001333 | 5.1e-05
2259
+ ...
2260
+ (99 rows)
2261
+ </programlisting>
2262
+ 这表明城市和州的最常见组合是华盛顿特区,实际频率(在样本中)约为0.35%。
2263
+ 组合的基本频率(根据简单的每列频率计算)仅为0.0027%,导致两个数量级的低估。
2264
+ </para>
2265
+
2266
+ <!--==========================orignal english content==========================
2267
+ <para>
2268
+ It's advisable to create <acronym>MCV</acronym> statistics objects only
2269
+ on combinations of columns that are actually used in conditions together,
2270
+ and for which misestimation of the number of groups is resulting in bad
2271
+ plans. Otherwise, the <command>ANALYZE</command> and planning cycles
2272
+ are just wasted.
2273
+ </para>
2274
+ ____________________________________________________________________________-->
2275
+ <para>
2276
+ 建议仅在实际在条件中一起使用的列的组合上创建<acronym>MCV</acronym>统计对象,对于这些组合,错误估计组数会导致糟糕的执行计划。
2277
+ 否则,只会浪费<command>ANALYZE</command>和规划时间。
2278
+ </para>
2279
+ </sect3>
2280
+
2184
2281
</sect2>
2185
2282
</sect1>
2186
2283
@@ -2825,7 +2922,7 @@ ____________________________________________________________________________-->
2825
2922
2826
2923
<sect2 id="populate-pg-dump">
2827
2924
<!--==========================orignal english content==========================
2828
- <title>Some Notes About <application>pg_dump</application></title>
2925
+ <title>Some Notes about <application>pg_dump</application></title>
2829
2926
____________________________________________________________________________-->
2830
2927
<title>关于<application>pg_dump</application>的一些注记</title>
2831
2928
0 commit comments