pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Harmen <harmen@lijzij.de>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: row estimate for partial index
Date: Mon, 16 Jan 2023 09:59:38 -0500
Message-ID: <1860907.1673881178@sss.pgh.pa.us> (raw)
In-Reply-To: <20230116085523.GK91568@arp.lijzij.de>
References: <20230113150159.GJ91568@arp.lijzij.de>
	<1008139.1673713387@sss.pgh.pa.us>
	<20230116085523.GK91568@arp.lijzij.de>

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





view thread (5+ messages)  latest in thread

Message-ID: <1860907.1673881178@sss.pgh.pa.us>
Permalink:  ../1860907.1673881178@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1860907.1673881178@sss.pgh.pa.us

 · 

reply

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: tgl@sss.pgh.pa.us, harmen@lijzij.de
  Subject: Re: row estimate for partial index
  In-Reply-To: <1860907.1673881178@sss.pgh.pa.us>
  References: <20230113150159.GJ91568@arp.lijzij.de> <1008139.1673713387@sss.pgh.pa.us> <20230116085523.GK91568@arp.lijzij.de> <1860907.1673881178@sss.pgh.pa.us>

* 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