3
我有關於pg_statistic
表的問題,它存儲來自ANALYZE的數據。有人能告訴我這張表的列是什麼?我有名單here,但我不知道(不明白)這一列是什麼:stanullfrac
,stadistinct
,stakindN
,staopN
,stanumbersN
,stavaluesN
。PostgreSQL + ANALYZE + pg_statistic表
我有關於pg_statistic
表的問題,它存儲來自ANALYZE的數據。有人能告訴我這張表的列是什麼?我有名單here,但我不知道(不明白)這一列是什麼:stanullfrac
,stadistinct
,stakindN
,staopN
,stanumbersN
,stavaluesN
。PostgreSQL + ANALYZE + pg_statistic表
對我來說似乎很簡單。特別是如果你看看裏面定義的更人性化pg_stat視圖(\d+ pg_stats
)
例如,說:使用
select * from pg_statistic where starelid = 23825 and staattnum=2;
starelid | 23825 => table (oid)
staattnum | 2 => column 2
stanullfrac | 0 => 0% null valuess
stadistinct | -0.484307 => about 48% are distict, i.e., the average repetition is about 2
stakind1 | 1 => code '1' : most common vals
stavalues1 | {"John","Mary" ... => values of most common valss
stanumbers1 | {0.0086,0.0064 ... => percentage occurrence of common vals
stakind2 | 2 => code '2' : histogram bounds
stavalues2 | {-,"AAA", ... => values (bounds) for histogram intervals
stanumbers2 |
stakind3 | 3 => code '3' => correlation
stavalues3 |
stanumbers3 | {0.00826469} => correlation coefficient
同樣的事情human_readable pg_stats
觀點:
select * from pg_stats where tablename = 'persons' and attname = 'first_name';
schemaname | public
tablename | persons
attname | first_name
inherited | f
null_frac | 0
avg_width | 11
n_distinct | -0.484307
most_common_vals | {"John","Mary"...
most_common_freqs | {0.00867898,0.00640832...
histogram_bounds | {-,"AAA"...
correlation | 0.00826469
_關於48%是distict,即平均重複約爲2_這是什麼意思? 你能告訴我'staopN'列有什麼?下一個問題 - 是否有任何數據類型的列表(和他們的數字)? –
@KrzysztofTrzos:這只是概率:如果你拋出'D' distict元素,每個元素有一個平均重複'n',那麼期望的總數是'T = nD',因此'1/n = D/T'(不同元素佔總元素的比例)。 – leonbloy
@KrzysztofTrzos:在pg_operator中定義的操作符的staopN查閱者。如果你想查看統計信息,我認爲它不是非常相關的,我猜它只在優化器內部使用。 – leonbloy