Skip to content

Commit 33fc9a5

Browse files
authored
Merge pull request #290 from ChenHuajun/master
PG12翻译explain.sgml,insert.sgml,perform.sgml,pgstatstatements.sgml,pgt…
2 parents 4367782 + b8d6836 commit 33fc9a5

File tree

5 files changed

+308
-90
lines changed

5 files changed

+308
-90
lines changed

postgresql/doc/src/sgml/perform.sgml

Lines changed: 117 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,19 +1541,23 @@ ____________________________________________________________________________-->
15411541

15421542
<!--==========================orignal english content==========================
15431543
<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.
15531554
</para>
15541555
____________________________________________________________________________-->
15551556
<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>的标识。
15571561
</para>
15581562
</sect2>
15591563

@@ -1842,6 +1846,15 @@ ____________________________________________________________________________-->
18421846
<primary>pg_statistic_ext</primary>
18431847
</indexterm>
18441848

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+
18451858
<!--==========================orignal english content==========================
18461859
<para>
18471860
It is common to see slow queries running bad execution plans because
@@ -1881,12 +1894,13 @@ ____________________________________________________________________________-->
18811894
interest in the statistics. Actual data collection is performed
18821895
by <command>ANALYZE</command> (either a manual command, or background
18831896
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+
18851899
catalog.
18861900
</para>
18871901
____________________________________________________________________________-->
18881902
<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>目录中看到。
18901904
</para>
18911905

18921906
<!--==========================orignal english content==========================
@@ -1999,14 +2013,14 @@ ____________________________________________________________________________-->
19992013
<para>
20002014
这里是一个收集函数依赖统计信息的例子:
20012015
<programlisting>
2002-
CREATE STATISTICS stts (dependencies) ON zip, city FROM zipcodes;
2016+
CREATE STATISTICS stts (dependencies) ON city, zip FROM zipcodes;
20032017

20042018
ANALYZE zipcodes;
20052019

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)
20082022
WHERE stxname = 'stts';
2009-
stxname | stxkeys | stxdependencies
2023+
stxname | stxkeys | stxddependencies
20102024
---------+---------+------------------------------------------
20112025
stts | 1 5 | {"1 => 5": 1.000000, "5 => 1": 0.423130}
20122026
(1 row)
@@ -2154,12 +2168,12 @@ ____________________________________________________________________________-->
21542168
<para>
21552169
继续之前的例子,ZIP代码表中的可区分值计数可能像这样:
21562170
<programlisting>
2157-
CREATE STATISTICS stts2 (ndistinct) ON zip, state, city FROM zipcodes;
2171+
CREATE STATISTICS stts2 (ndistinct) ON city, state, zip FROM zipcodes;
21582172

21592173
ANALYZE zipcodes;
21602174

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)
21632177
WHERE stxname = 'stts2';
21642178
-[ RECORD 1 ]--------------------------------------------------------
21652179
k | 1 2 5
@@ -2181,6 +2195,89 @@ ____________________________________________________________________________-->
21812195
建议只对实际用于分组的列组合以及分组数错误估计导致了糟糕计划的列组合创建<literal>ndistinct</literal>统计信息对象。否则,<command>ANALYZE</command>循环只会被浪费。
21822196
</para>
21832197
</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+
21842281
</sect2>
21852282
</sect1>
21862283

@@ -2825,7 +2922,7 @@ ____________________________________________________________________________-->
28252922

28262923
<sect2 id="populate-pg-dump">
28272924
<!--==========================orignal english content==========================
2828-
<title>Some Notes About <application>pg_dump</application></title>
2925+
<title>Some Notes about <application>pg_dump</application></title>
28292926
____________________________________________________________________________-->
28302927
<title>关于<application>pg_dump</application>的一些注记</title>
28312928

postgresql/doc/src/sgml/pgstatstatements.sgml

Lines changed: 93 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -643,30 +643,41 @@ ____________________________________________________________________________-->
643643
<variablelist>
644644
<varlistentry>
645645
<!--==========================orignal english content==========================
646-
<term>
647-
<function>pg_stat_statements_reset() returns void</function>
646+
<term>
647+
<function>pg_stat_statements_reset(userid Oid, dbid Oid, queryid bigint) returns void</function>
648648
<indexterm>
649649
<primary>pg_stat_statements_reset</primary>
650650
</indexterm>
651651
</term>
652652
____________________________________________________________________________-->
653-
<term>
654-
<function>pg_stat_statements_reset() 返回 void</function>
655-
<indexterm>
656-
<primary>pg_stat_statements_reset</primary>
657-
</indexterm>
653+
<term>
654+
<function>pg_stat_statements_reset(userid Oid, dbid Oid, queryid bigint) returns void</function>
655+
<indexterm>
656+
<primary>pg_stat_statements_reset</primary>
657+
</indexterm>
658658
</term>
659659

660660
<listitem>
661661
<!--==========================orignal english content==========================
662662
<para>
663-
<function>pg_stat_statements_reset</function> discards all statistics
664-
gathered so far by <filename>pg_stat_statements</filename>.
665-
By default, this function can only be executed by superusers.
663+
<function>pg_stat_statements_reset</function> discards statistics
664+
gathered so far by <filename>pg_stat_statements</filename> corresponding
665+
to the specified <structfield>userid</structfield>, <structfield>dbid</structfield>
666+
and <structfield>queryid</structfield>. If any of the parameters are not
667+
specified, the default value <literal>0</literal>(invalid) is used for
668+
each of them and the statistics that match with other parameters will be
669+
reset. If no parameter is specified or all the specified parameters are
670+
<literal>0</literal>(invalid), it will discard all statistics. By
671+
default, this function can only be executed by superusers. Access may be
672+
granted to others using <command>GRANT</command>.
666673
</para>
667674
____________________________________________________________________________-->
668675
<para>
669-
<function>pg_stat_statements_reset</function>抛弃目前由<filename>pg_stat_statements</filename>收集的所有统计信息。默认情况下,这个函数只能被超级用户执行。
676+
<function>pg_stat_statements_reset</function>丢弃到目前为止与指定的<structfield>userid</structfield>,
677+
<structfield>dbid</structfield>和<structfield>queryid</structfield>相对应的<filename>pg_stat_statements</filename>收集的统计信息。
678+
如果有任何参数未被指定,那么将对这些参数使用默认值<literal>0</literal>(无效),并且将重置与其他参数匹配的统计信息。
679+
如果未指定任何参数,或者所有指定的参数均为<literal>0</literal>(无效),则它将丢弃所有统计信息。
680+
默认情况下,此功能只能由超级用户执行。可以使用<command>GRANT</command>授予其他人访问权限。
670681
</para>
671682
</listitem>
672683
</varlistentry>
@@ -948,36 +959,87 @@ bench=# \x
948959
bench=# SELECT query, calls, total_time, rows, 100.0 * shared_blks_hit /
949960
nullif(shared_blks_hit + shared_blks_read, 0) AS hit_percent
950961
FROM pg_stat_statements ORDER BY total_time DESC LIMIT 5;
951-
-[ RECORD 1 ]---------------------------------------------------------------------
952-
query | UPDATE pgbench_branches SET bbalance = bbalance + $1 WHERE bid = $2;
962+
-[ RECORD 1 ]--------------------------------------------------------------------
963+
query | UPDATE pgbench_branches SET bbalance = bbalance + $1 WHERE bid = $2
953964
calls | 3000
954-
total_time | 9609.00100000002
955-
rows | 2836
956-
hit_percent | 99.9778970000200936
957-
-[ RECORD 2 ]---------------------------------------------------------------------
958-
query | UPDATE pgbench_tellers SET tbalance = tbalance + $1 WHERE tid = $2;
965+
total_time | 25565.855387
966+
rows | 3000
967+
hit_percent | 100.0000000000000000
968+
-[ RECORD 2 ]--------------------------------------------------------------------
969+
query | UPDATE pgbench_tellers SET tbalance = tbalance + $1 WHERE tid = $2
959970
calls | 3000
960-
total_time | 8015.156
961-
rows | 2990
962-
hit_percent | 99.9731126579631345
963-
-[ RECORD 3 ]---------------------------------------------------------------------
971+
total_time | 20756.669379
972+
rows | 3000
973+
hit_percent | 100.0000000000000000
974+
-[ RECORD 3 ]--------------------------------------------------------------------
964975
query | copy pgbench_accounts from stdin
965976
calls | 1
966-
total_time | 310.624
977+
total_time | 291.865911
967978
rows | 100000
968-
hit_percent | 0.30395136778115501520
969-
-[ RECORD 4 ]---------------------------------------------------------------------
970-
query | UPDATE pgbench_accounts SET abalance = abalance + $1 WHERE aid = $2;
979+
hit_percent | 100.0000000000000000
980+
-[ RECORD 4 ]--------------------------------------------------------------------
981+
query | UPDATE pgbench_accounts SET abalance = abalance + $1 WHERE aid = $2
971982
calls | 3000
972-
total_time | 271.741999999997
983+
total_time | 271.232977
973984
rows | 3000
974-
hit_percent | 93.7968855088209426
975-
-[ RECORD 5 ]---------------------------------------------------------------------
985+
hit_percent | 98.5723926698852723
986+
-[ RECORD 5 ]--------------------------------------------------------------------
976987
query | alter table pgbench_accounts add primary key (aid)
977988
calls | 1
978-
total_time | 81.42
989+
total_time | 160.588563
979990
rows | 0
980-
hit_percent | 34.4947735191637631
991+
hit_percent | 100.0000000000000000
992+
993+
994+
bench=# SELECT pg_stat_statements_reset(0,0,s.queryid) FROM pg_stat_statements AS s
995+
WHERE s.query = 'UPDATE pgbench_branches SET bbalance = bbalance + $1 WHERE bid = $2';
996+
997+
bench=# SELECT query, calls, total_time, rows, 100.0 * shared_blks_hit /
998+
nullif(shared_blks_hit + shared_blks_read, 0) AS hit_percent
999+
FROM pg_stat_statements ORDER BY total_time DESC LIMIT 5;
1000+
-[ RECORD 1 ]--------------------------------------------------------------------
1001+
query | UPDATE pgbench_tellers SET tbalance = tbalance + $1 WHERE tid = $2
1002+
calls | 3000
1003+
total_time | 20756.669379
1004+
rows | 3000
1005+
hit_percent | 100.0000000000000000
1006+
-[ RECORD 2 ]--------------------------------------------------------------------
1007+
query | copy pgbench_accounts from stdin
1008+
calls | 1
1009+
total_time | 291.865911
1010+
rows | 100000
1011+
hit_percent | 100.0000000000000000
1012+
-[ RECORD 3 ]--------------------------------------------------------------------
1013+
query | UPDATE pgbench_accounts SET abalance = abalance + $1 WHERE aid = $2
1014+
calls | 3000
1015+
total_time | 271.232977
1016+
rows | 3000
1017+
hit_percent | 98.5723926698852723
1018+
-[ RECORD 4 ]--------------------------------------------------------------------
1019+
query | alter table pgbench_accounts add primary key (aid)
1020+
calls | 1
1021+
total_time | 160.588563
1022+
rows | 0
1023+
hit_percent | 100.0000000000000000
1024+
-[ RECORD 5 ]--------------------------------------------------------------------
1025+
query | vacuum analyze pgbench_accounts
1026+
calls | 1
1027+
total_time | 136.448116
1028+
rows | 0
1029+
hit_percent | 99.9201915403032721
1030+
1031+
bench=# SELECT pg_stat_statements_reset(0,0,0);
1032+
1033+
bench=# SELECT query, calls, total_time, rows, 100.0 * shared_blks_hit /
1034+
nullif(shared_blks_hit + shared_blks_read, 0) AS hit_percent
1035+
FROM pg_stat_statements ORDER BY total_time DESC LIMIT 5;
1036+
-[ RECORD 1 ]---------------------------------------
1037+
query | SELECT pg_stat_statements_reset(0,0,0)
1038+
calls | 1
1039+
total_time | 0.189497
1040+
rows | 1
1041+
hit_percent |
1042+
9811043
</screen>
9821044
</sect2>
9831045

0 commit comments

Comments
 (0)