pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Justin Pryzby <pryzby@telsasoft.com>
To: Michael Lewis <mlewis@entrata.com>
Cc: Andrew Gierth <andrew@tao11.riddles.org.uk>
Cc: Abi Noda <a@abinoda.com>
Cc: pgsql-performance@lists.postgresql.org
Subject: Re: Why isn't an index scan being used?
Date: Wed, 20 Feb 2019 02:05:00 -0600
Message-ID: <20190220080500.GO28750@telsasoft.com> (raw)
In-Reply-To: <CAHOFxGowsSLFNLAwpQ5gFPw4F1nT19gNLHRnav0fNL6sykCZbQ@mail.gmail.com>
References: <CAM37AMPQjpDWNy58W442FSBLEJwLJGgp=xmZts=mj2QzEz-CFw@mail.gmail.com>
	<87ftsji2tb.fsf@news-spur.riddles.org.uk>
	<CAHOFxGowsSLFNLAwpQ5gFPw4F1nT19gNLHRnav0fNL6sykCZbQ@mail.gmail.com>

On Tue, Feb 19, 2019 at 09:29:46PM -0700, Michael Lewis wrote:
> On Tue, Feb 19, 2019, 8:00 PM Andrew Gierth <andrew@tao11.riddles.org.uk> wrote:
> 
> > >>>>> "Abi" == Abi Noda <a@abinoda.com> writes:
> >  Abi> However, when I index the closed column, a bitmap scan is used
> >  Abi> instead of an index scan, with slightly slower performance. Why
> >  Abi> isn't an index scan being used, given that the exact same number
> >  Abi> of rows are at play as in my query on the state column?
> >
> > Most likely difference is the correlation estimate for the conditions.
> > The cost of an index scan includes a factor based on how well correlated
> > the physical position of rows is with the index order, because this
> > affects the number of random seeks in the scan. But for nulls this
> > estimate cannot be performed, and bitmapscan is cheaper than plain
> > indexscan on poorly correlated data.
> 
> Does this imply that the optimizer would always prefer the bitmapscan
> rather than index scan even if random page cost = 1, aka sequential cost,
> when the correlation is unknown like a null? Or only when it thinks random
> access is more expensive by some significant factor?

No; for one, since for a bitmap scan, the heap scan can't begin until the index
scan is done, so there's a high(er) initial cost.

Otherwise bitmap scan could always be used and all access could be ordered
(even if not sequential).

Justin




view thread (9+ messages)  latest in thread

Message-ID: <20190220080500.GO28750@telsasoft.com>
Permalink:  ../20190220080500.GO28750@telsasoft.com/
Also on:    postgresql.org/message-id/20190220080500.GO28750@telsasoft.com

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: pryzby@telsasoft.com, mlewis@entrata.com, andrew@tao11.riddles.org.uk, a@abinoda.com, pgsql-performance@lists.postgresql.org
  Subject: Re: Why isn't an index scan being used?
  In-Reply-To: <20190220080500.GO28750@telsasoft.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