From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Fabio Pardi <f.pardi@portavita.eu>
To: pgsql-general@lists.postgresql.org
Subject: Re: n_distinct off by a factor of 1000
Date: Tue, 23 Jun 2020 07:14:14 -0700
Message-ID: <3c310268-52f2-b960-8efd-bc15b08da7a7@aklaver.com> (raw)
In-Reply-To: <486df039-f581-411c-c169-6d87ce81bcf6@portavita.eu>
References: <6bPRS-MZZcCSPnyGrlbezd8xcvHM0xPQCjDiFH86jAsT4npY3SjXxsis6sUehdrJfHKeP222YgnrGiNgv6pwNC7wowUs3DgEnl5K4Dr7tW4=@protonmail.com>
<486df039-f581-411c-c169-6d87ce81bcf6@portavita.eu>
On 6/23/20 7:05 AM, Fabio Pardi wrote:
>
> 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.
I believe the OP actually meant the query to be:
select n_distinct from pg_stats where attname like 'instr%_ref';
>
>
> regards,
>
> fabio pardi
--
Adrian Klaver
adrian.klaver@aklaver.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: adrian.klaver@aklaver.com, f.pardi@portavita.eu
Subject: Re: n_distinct off by a factor of 1000
In-Reply-To: <3c310268-52f2-b960-8efd-bc15b08da7a7@aklaver.com>
References: <6bPRS-MZZcCSPnyGrlbezd8xcvHM0xPQCjDiFH86jAsT4npY3SjXxsis6sUehdrJfHKeP222YgnrGiNgv6pwNC7wowUs3DgEnl5K4Dr7tW4=@protonmail.com> <486df039-f581-411c-c169-6d87ce81bcf6@portavita.eu> <3c310268-52f2-b960-8efd-bc15b08da7a7@aklaver.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox