gpt4 book ai didi

sql - 如何查看ANALYZE使用的统计目标?

转载 作者:行者123 更新时间:2023-11-29 11:11:09 25 4
gpt4 key购买 nike

如何检查 ANALYZE 使用的当前统计目标?

最佳答案

统计目标的设置按列存储在目录表中 pg_attribute .你可以这样设置:

ALTER TABLE myschama.mytable ALTER mycolumn SET STATISTICS 1234;

然后像这样检查:

SELECT attstattarget
FROM pg_attribute
WHERE attrelid = 'myschama.mytable'::regclass
AND attname = 'mycolumn';

或者您只需在 pgAdmin 的对象浏览器中查看创建脚本,如果值与 default_statistics_target 中的默认值不同,则会将其附加到此处.

我在 attstattarget 上引用手册:

attstattarget controls the level of detail of statistics accumulatedfor this column by ANALYZE. A zero value indicates that no statisticsshould be collected. A negative value says to use the system defaultstatistics target. The exact meaning of positive values is datatype-dependent. For scalar data types, attstattarget is both thetarget number of "most common values" to collect, and the targetnumber of histogram bins to create.

大胆强调我的。

普通索引列的统计信息与列统计信息相同,并且在统计表中没有单独的条目。但是 Postgres 为索引 expressions 收集单独的统计数据。这些可以以类似的方式进行调整:

ALTER INDEX myschema.myidx ALTER COLUMN 1 SET STATISTICS 1235;

在没有实际列名的情况下,序号用于寻址索引列,对应于pg_attribute.attnum:

SELECT attstattarget
FROM pg_attribute
WHERE attrelid = 'myschama.myidx'::regclass
AND attnum = 1;

该设置只会在下次手动或通过 autovacuum 运行 ANALYZE 时实际影响列统计信息。

关于sql - 如何查看ANALYZE使用的统计目标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15034622/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com