50.89. pg_stats_ext

Представление pg_stats_ext открывает доступ к информации в каталогах pg_statistic_ext и pg_statistic_ext_data. Это представление даёт доступ только к тем строкам pg_statistic_ext и pg_statistic_ext_data, что соответствуют таблицам, которые пользователь может читать: таким, образом это представление можно без опасений разрешить читать всем.

Кроме того, представление pg_stats_ext специально разработано для подачи информации в более понятном виде, чем нижележащие каталоги — ценой того, что его схему приходится расширять всякий раз, когда в pg_statistic_ext добавляются новые типы расширенной статистики.

Таблица 50.90. Столбцы pg_stats_ext

NameТипСсылкиОписание
schemanamenamepg_namespace.nspnameИмя схемы, содержащей таблицу
tablenamenamepg_class.relnameИмя таблицы
statistics_schemanamenamepg_namespace.nspnameИмя схемы, содержащей расширенную статистику
statistics_namenamepg_statistic_ext.stxnameИмя расширенной статистики
statistics_owneroidpg_authid.oidВладелец расширенной статистики
attnamesname[]pg_attribute.attnameИмена столбцов, для которых определена данная расширенная статистика
kindstext[] Типы расширенной статистики, включённые для данной записи
n_distinctpg_ndistinct Количество различных комбинаций значений столбцов. Число больше нуля представляет примерное количество различных скомбинированных значений. Если это число меньше нуля, его модуль представляет количество различных значений, делённое на количество строк. (Отрицательная форма применяется, когда ANALYZE полагает, что число различных значений, скорее всего, будет расти по мере роста таблицы; положительная, когда в столбце, вероятно, будет фиксированное количество возможных значений.) Например, -1 указывает на такую комбинацию столбцов, в которой количество различных значений совпадает с количеством строк.
dependenciespg_dependencies Статистика по функциональным зависимостям
most_common_valsanyarray Список самых частых комбинаций значений в столбцах. (NULL, если не находятся комбинации, встречающиеся чаще других.)
most_common_val_nullsanyarray Список флагов NULL для самых частых комбинаций значений. (NULL, когда most_common_vals — NULL.)
most_common_freqsreal[] Список частот самых частых комбинаций, то есть число их вхождений, делённое на общее количество строк. (NULL, когда most_common_vals — NULL.)
most_common_base_freqsreal[] Список базовых частот самых частых комбинаций, то есть произведение частот отдельных значений. (NULL, когда most_common_vals — NULL.)

Максимальным числом записей в полях-массивах можно управлять на уровне столбцов, используя команду ALTER TABLE SET STATISTICS, или глобально, задав параметр времени выполнения default_statistics_target.

50.89. pg_stats_ext

The view pg_stats_ext provides access to the information stored in the pg_statistic_ext and pg_statistic_ext_data catalogs. This view allows access only to rows of pg_statistic_ext and pg_statistic_ext_data that correspond to tables the user has permission to read, and therefore it is safe to allow public read access to this view.

pg_stats_ext is also designed to present the information in a more readable format than the underlying catalogs — at the cost that its schema must be extended whenever new types of extended statistics are added to pg_statistic_ext.

Table 50.90. pg_stats_ext Columns

NameTypeReferencesDescription
schemanamenamepg_namespace.nspnameName of schema containing table
tablenamenamepg_class.relnameName of table
statistics_schemanamenamepg_namespace.nspnameName of schema containing extended statistic
statistics_namenamepg_statistic_ext.stxnameName of extended statistics
statistics_owneroidpg_authid.oidOwner of the extended statistics
attnamesname[]pg_attribute.attnameNames of the columns the extended statistics is defined on
kindstext[] Types of extended statistics enabled for this record
n_distinctpg_ndistinct N-distinct counts for combinations of column values. If greater than zero, the estimated number of distinct values in the combination. If less than zero, the negative of the number of distinct values divided by the number of rows. (The negated form is used when ANALYZE believes that the number of distinct values is likely to increase as the table grows; the positive form is used when the column seems to have a fixed number of possible values.) For example, -1 indicates a unique combination of columns in which the number of distinct combinations is the same as the number of rows.
dependenciespg_dependencies Functional dependency statistics
most_common_valsanyarray  A list of the most common combinations of values in the columns. (Null if no combinations seem to be more common than any others.)
most_common_val_nullsanyarray  A list of NULL flags for the most common combinations of values. (Null when most_common_vals is.)
most_common_freqsreal[]  A list of the frequencies of the most common combinations, i.e., number of occurrences of each divided by total number of rows. (Null when most_common_vals is.)
most_common_base_freqsreal[]  A list of the base frequencies of the most common combinations, i.e., product of per-value frequencies. (Null when most_common_vals is.)

The maximum number of entries in the array fields can be controlled on a column-by-column basis using the ALTER TABLE SET STATISTICS command, or globally by setting the default_statistics_target run-time parameter.

FAQ