pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Owen Nelson <onelson@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Understanding partial index selection
Date: Tue, 28 Nov 2023 18:07:57 -0500
Message-ID: <186558.1701212877@sss.pgh.pa.us> (raw)
In-Reply-To: <CAG-u7ziq87b2spN_sPeVktM=GFLGNFsB2dVqSY745A6cJCmr8w@mail.gmail.com>
References: <CAG-u7ziq87b2spN_sPeVktM=GFLGNFsB2dVqSY745A6cJCmr8w@mail.gmail.com>

Owen Nelson <onelson@gmail.com> writes:
> The hope is the sub-select would leverage the index
> "message_payload_not_null_pidx" but when I `EXPLAIN ANALYZE` the query, I
> see a seq scan instead.

I think your problem is the horrid rowcount misestimation here:

>                                 ->  Seq Scan on message message_1 (cost=0.00..2050554.24 rows=6175068 width=38) (actual time=8424.977..20880.945 rows=65 loops=1)
>                                       Filter: ((payload IS NOT NULL) AND (expiration <= now()))
>                                       Rows Removed by Filter: 37772897

The planner seems to think that about a sixth of the table satisfies
the filter condition, which is way more than enough to discourage it
from using an indexscan.  If it had gotten an estimate within even
one or two orders of magnitude of the reality of 65 rows, it'd have
gone for an indexscan, I'm pretty sure.

Are your ANALYZE stats up to date on this table?  If so, there must
be some strong correlation between the payload and expiration
conditions that the planner doesn't know about.  Perhaps creating
extended statistics on those two columns would help.

			regards, tom lane





view thread (8+ messages)  latest in thread

Message-ID: <186558.1701212877@sss.pgh.pa.us>
Permalink:  ../186558.1701212877@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/186558.1701212877@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, onelson@gmail.com
  Subject: Re: Understanding partial index selection
  In-Reply-To: <186558.1701212877@sss.pgh.pa.us>
  References: <CAG-u7ziq87b2spN_sPeVktM=GFLGNFsB2dVqSY745A6cJCmr8w@mail.gmail.com> <186558.1701212877@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