Re: n_distinct off by a factor of 1000

Поиск
Список
Период
Сортировка
От Fabio Pardi
Тема Re: n_distinct off by a factor of 1000
Дата
Msg-id 486df039-f581-411c-c169-6d87ce81bcf6@portavita.eu
обсуждение исходный текст
Ответ на n_distinct off by a factor of 1000  (Klaudie Willis <Klaudie.Willis@protonmail.com>)
Ответы Re: n_distinct off by a factor of 1000  (Adrian Klaver <adrian.klaver@aklaver.com>)
Список pgsql-general

On 23/06/2020 14:42, Klaudie Willis wrote:
I got my first hint of why this problem occurs when I looked at the statistics.  For the column in question, "instrument_ref" the statistics claimed it to be:

The default_statistics_target=500, and analyze has been run.
select * from pg_stats where attname like 'instr%_ref'; -- Result: 40.000
select count(distinct instrumentid_ref) from bigtable -- Result: 33 385 922 (!!)

That is an astonishing difference of almost a 1000X. 


I think you are counting 2 different things here.

The first query returns all the columns "like 'instr%_ref'" present in the statistics (so in the whole cluster), while the second is counting the actual number of different rows in bigtable.


regards,

fabio pardi

В списке pgsql-general по дате отправления:

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: pg_dump empty tables
Следующее
От: Adrian Klaver
Дата:
Сообщение: Re: n_distinct off by a factor of 1000