pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Radoslav Nedyalkov <rnedyalkov@gmail.com>
Cc: Michael Lewis <mlewis@entrata.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: single table - fighting a seq scan
Date: Wed, 15 Jul 2020 10:58:27 -0400
Message-ID: <3065643.1594825107@sss.pgh.pa.us> (raw)
In-Reply-To: <CANhtRiY_Lr1w_-qkLhWwDHMkdbx6iE3W9eQ-iJLYSxiCQhWmJg@mail.gmail.com>
References: <CANhtRiZMKJEHHK-Y6HEkYKHNULWshbks37EVDj=wLYdhZ0_rGA@mail.gmail.com>
	<CAHOFxGqfRa7uPkG2dEv5U2rt_ZLORVvBYGXLK7t7ZG8HGQgeeQ@mail.gmail.com>
	<CANhtRiYzw79GB49fvK3GEn5X9i=sbeVH2SOOKe0nM=Hd7yt2Mg@mail.gmail.com>
	<CANhtRiaQ4HZR7D3_E3RayKH_zROJD_OSRe89eS5Y6cTrDZk6RA@mail.gmail.com>
	<2980741.1594764364@sss.pgh.pa.us>
	<CANhtRiY_Lr1w_-qkLhWwDHMkdbx6iE3W9eQ-iJLYSxiCQhWmJg@mail.gmail.com>

Radoslav Nedyalkov <rnedyalkov@gmail.com> writes:
> Shame on me. It's a partial index - *where is not null.*
> Put the* is not null *predicate in place and planner always goes for index.
> (tested with thousands of IN entries)
> CTE version always goes for index too even *without **is not null , *which
> led to a slight confusion.

Ah.  That's actually something we fixed in v12 (see [1]).  In the CTE
version, the planner can prove "x is not null" from "x = cte_value" even
without knowing what the CTE output value is, just on the basis that "="
is strict.  In the IN form, it's likewise possible to prove "x is not
null" from "x IN (list)", but you need a special test to recognize that.
With a short IN list, the planner converts IN to "x = this OR x = that
OR x = the-other ..."  and can make the proof from that formulation.
But we prevent it from trying that on long IN lists, because it'd eat
lots of cycles and perhaps not be able to prove the desired partial index
qual anyway.

			regards, tom lane

[1] https://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=65ce07e02





view thread (7+ messages)

Message-ID: <3065643.1594825107@sss.pgh.pa.us>
Permalink:  ../3065643.1594825107@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3065643.1594825107@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, rnedyalkov@gmail.com, mlewis@entrata.com
  Subject: Re: single table - fighting a seq scan
  In-Reply-To: <3065643.1594825107@sss.pgh.pa.us>
  References: <CANhtRiZMKJEHHK-Y6HEkYKHNULWshbks37EVDj=wLYdhZ0_rGA@mail.gmail.com> <CAHOFxGqfRa7uPkG2dEv5U2rt_ZLORVvBYGXLK7t7ZG8HGQgeeQ@mail.gmail.com> <CANhtRiYzw79GB49fvK3GEn5X9i=sbeVH2SOOKe0nM=Hd7yt2Mg@mail.gmail.com> <CANhtRiaQ4HZR7D3_E3RayKH_zROJD_OSRe89eS5Y6cTrDZk6RA@mail.gmail.com> <2980741.1594764364@sss.pgh.pa.us> <CANhtRiY_Lr1w_-qkLhWwDHMkdbx6iE3W9eQ-iJLYSxiCQhWmJg@mail.gmail.com> <3065643.1594825107@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