Re: row estimate for partial index - Mailing list pgsql-general

From Tom Lane
Subject Re: row estimate for partial index
Date
Msg-id 1860907.1673881178@sss.pgh.pa.us
Whole thread Raw
In response to Re: row estimate for partial index  (Harmen <harmen@lijzij.de>)
Responses Re: row estimate for partial index
List pgsql-general
Harmen <harmen@lijzij.de> writes:
> On Sat, Jan 14, 2023 at 11:23:07AM -0500, Tom Lane wrote:
>> If you are running a reasonably recent PG version you should be able to
>> fix that by setting up "extended statistics" on that pair of columns:

>   CREATE STATISTICS dist4 (ndistinct) ON deleted, org_id FROM contactsbool;
>   CREATE STATISTICS dist4b (ndistinct) ON org_id, deleted FROM contactsbool;

1. ndistinct is not the correct stats type for this problem.
(I think dependencies is, but generally speaking, it's not worth
trying to be smarter than the system about which ones you need.
Just create 'em all.)

2. Per the CREATE STATISTICS man page, the order of the columns is
not significant, so you're just doubling the amount of work for
ANALYZE without gaining anything.

I think you will find that

CREATE STATISTICS stats1 ON deleted, org_id FROM contactsbool;

is enough to fix this.  It improved the estimate for me in
v14 and HEAD, anyway.

            regards, tom lane



pgsql-general by date:

Previous
From: HECTOR INGERTO
Date:
Subject: RE: Are ZFS snapshots unsafe when PGSQL is spreading through multiple zpools?
Next
From: Joe Conway
Date:
Subject: Re: glibc initdb options vs icu compatibility questions (PG15)