Re: Why isn't an index scan being used?

From: Justin Pryzby <pryzby(at)telsasoft(dot)com>
To: Michael Lewis <mlewis(at)entrata(dot)com>
Cc: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>, Abi Noda <a(at)abinoda(dot)com>, pgsql-performance(at)lists(dot)postgresql(dot)org
Subject: Re: Why isn't an index scan being used?
Date: 2019-02-20 08:05:00
Message-ID: 20190220080500.GO28750@telsasoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Tue, Feb 19, 2019 at 09:29:46PM -0700, Michael Lewis wrote:
> On Tue, Feb 19, 2019, 8:00 PM Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk> wrote:
>
> > >>>>> "Abi" == Abi Noda <a(at)abinoda(dot)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

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Jeff Janes 2019-02-20 14:58:22 Re: Why isn't an index scan being used?
Previous Message Abi Noda 2019-02-20 04:58:43 Re: Why isn't an index scan being used?