]> begriffs open source - ai-pg/blob - full-docs/txt/catalog-pg-statistic.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / catalog-pg-statistic.txt
1
2 52.51. pg_statistic #
3
4    The catalog pg_statistic stores statistical data about the contents of
5    the database. Entries are created by ANALYZE and subsequently used by
6    the query planner. Note that all the statistical data is inherently
7    approximate, even assuming that it is up-to-date.
8
9    Normally there is one entry, with stainherit = false, for each table
10    column that has been analyzed. If the table has inheritance children or
11    partitions, a second entry with stainherit = true is also created. This
12    row represents the column's statistics over the inheritance tree, i.e.,
13    statistics for the data you'd see with SELECT column FROM table*,
14    whereas the stainherit = false row represents the results of SELECT
15    column FROM ONLY table.
16
17    pg_statistic also stores statistical data about the values of index
18    expressions. These are described as if they were actual data columns;
19    in particular, starelid references the index. No entry is made for an
20    ordinary non-expression index column, however, since it would be
21    redundant with the entry for the underlying table column. Currently,
22    entries for index expressions always have stainherit = false.
23
24    Since different kinds of statistics might be appropriate for different
25    kinds of data, pg_statistic is designed not to assume very much about
26    what sort of statistics it stores. Only extremely general statistics
27    (such as nullness) are given dedicated columns in pg_statistic.
28    Everything else is stored in “slots”, which are groups of associated
29    columns whose content is identified by a code number in one of the
30    slot's columns. For more information see
31    src/include/catalog/pg_statistic.h.
32
33    pg_statistic should not be readable by the public, since even
34    statistical information about a table's contents might be considered
35    sensitive. (Example: minimum and maximum values of a salary column
36    might be quite interesting.) pg_stats is a publicly readable view on
37    pg_statistic that only exposes information about those tables that are
38    readable by the current user.
39
40    Table 52.51. pg_statistic Columns
41
42    Column Type
43
44    Description
45
46    starelid oid (references pg_class.oid)
47
48    The table or index that the described column belongs to
49
50    staattnum int2 (references pg_attribute.attnum)
51
52    The number of the described column
53
54    stainherit bool
55
56    If true, the stats include values from child tables, not just the
57    values in the specified relation
58
59    stanullfrac float4
60
61    The fraction of the column's entries that are null
62
63    stawidth int4
64
65    The average stored width, in bytes, of nonnull entries
66
67    stadistinct float4
68
69    The number of distinct nonnull data values in the column. A value
70    greater than zero is the actual number of distinct values. A value less
71    than zero is the negative of a multiplier for the number of rows in the
72    table; for example, a column in which about 80% of the values are
73    nonnull and each nonnull value appears about twice on average could be
74    represented by stadistinct = -0.4. A zero value means the number of
75    distinct values is unknown.
76
77    stakindN int2
78
79    A code number indicating the kind of statistics stored in the Nth
80    “slot” of the pg_statistic row.
81
82    staopN oid (references pg_operator.oid)
83
84    An operator used to derive the statistics stored in the Nth “slot”. For
85    example, a histogram slot would show the < operator that defines the
86    sort order of the data. Zero if the statistics kind does not require an
87    operator.
88
89    stacollN oid (references pg_collation.oid)
90
91    The collation used to derive the statistics stored in the Nth “slot”.
92    For example, a histogram slot for a collatable column would show the
93    collation that defines the sort order of the data. Zero for
94    noncollatable data.
95
96    stanumbersN float4[]
97
98    Numerical statistics of the appropriate kind for the Nth “slot”, or
99    null if the slot kind does not involve numerical values
100
101    stavaluesN anyarray
102
103    Column data values of the appropriate kind for the Nth “slot”, or null
104    if the slot kind does not store any data values. Each array's element
105    values are actually of the specific column's data type, or a related
106    type such as an array's element type, so there is no way to define
107    these columns' type more specifically than anyarray.