analyze.7

来自「PostgreSQL 8.2中增加了很多企业用户所需要的功能和性能上的提高,其开」· 7 代码 · 共 99 行

7
99
字号
.\\" auto-generated by docbook2man-spec $Revision: 1.1.1.1 $.TH "ANALYZE" "" "2008-01-03" "SQL - Language Statements" "SQL Commands".SH NAMEANALYZE \- collect statistics about a database.SH SYNOPSIS.sp.nfANALYZE [ VERBOSE ] [ \fItable\fR [ (\fIcolumn\fR [, ...] ) ] ].sp.fi.SH "DESCRIPTION".PP\fBANALYZE\fR collects statistics about the contentsof tables in the database, and stores the results in the systemtable pg_statistic. Subsequently, the queryplanner uses these statistics to help determine the most efficientexecution plans for queries..PPWith no parameter, \fBANALYZE\fR examines every table in thecurrent database. With a parameter, \fBANALYZE\fR examinesonly that table. It is further possible to give a list of column names,in which case only the statistics for those columns are collected..SH "PARAMETERS".TP\fBVERBOSE\fREnables display of progress messages..TP\fB\fItable\fB\fRThe name (possibly schema-qualified) of a specific table toanalyze. Defaults to all tables in the current database..TP\fB\fIcolumn\fB\fRThe name of a specific column to analyze. Defaults to all columns..SH "OUTPUTS".PPWhen VERBOSE is specified, \fBANALYZE\fR emitsprogress messages to indicate which table is currently beingprocessed. Various statistics about the tables are printed as well..SH "NOTES".PPIt is a good idea to run \fBANALYZE\fR periodically, orjust after making major changes in the contents of a table. Accuratestatistics will help the planner to choose the most appropriate queryplan, and thereby improve the speed of query processing. A commonstrategy is to run VACUUM [\fBvacuum\fR(7)]and \fBANALYZE\fR once a day during a low-usage time of day..PPUnlike \fBVACUUM FULL\fR, \fBANALYZE\fRrequires only a read lock on the target table, so it can run inparallel with other activity on the table..PPThe statistics collected by \fBANALYZE\fR usuallyinclude a list of some of the most common values in each column anda histogram showing the approximate data distribution in eachcolumn. One or both of these may be omitted if\fBANALYZE\fR deems them uninteresting (for example,in a unique-key column, there are no common values) or if thecolumn data type does not support the appropriate operators. Thereis more information about the statistics in in the documentation..PPFor large tables, \fBANALYZE\fR takes a random sampleof the table contents, rather than examining every row. Thisallows even very large tables to be analyzed in a small amount oftime. Note, however, that the statistics are only approximate, andwill change slightly each time \fBANALYZE\fR is run,even if the actual table contents did not change. This may resultin small changes in the planner's estimated costs shown by\fBEXPLAIN\fR. In rare situations, thisnon-determinism will cause the query optimizer to choose adifferent query plan between runs of \fBANALYZE\fR. Toavoid this, raise the amount of statistics collected by\fBANALYZE\fR, as described below..PPThe extent of analysis can be controlled by adjusting thedefault_statistics_target configuration variable, oron a column-by-column basis by setting the per-column statisticstarget with \fBALTER TABLE ... ALTER COLUMN ... SETSTATISTICS\fR (see ALTER TABLE [\fBalter_table\fR(7)]). The target value sets themaximum number of entries in the most-common-value list and themaximum number of bins in the histogram. The default target valueis 10, but this can be adjusted up or down to trade off accuracy ofplanner estimates against the time taken for\fBANALYZE\fR and the amount of space occupied inpg_statistic. In particular, setting thestatistics target to zero disables collection of statistics forthat column. It may be useful to do that for columns that arenever used as part of the WHERE, GROUP BY,or ORDER BY clauses of queries, since the planner willhave no use for statistics on such columns..PPThe largest statistics target among the columns being analyzed determinesthe number of table rows sampled to prepare the statistics. Increasingthe target causes a proportional increase in the time and space neededto do \fBANALYZE\fR..SH "COMPATIBILITY".PPThere is no \fBANALYZE\fR statement in the SQL standard.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?