Re: Optimising a two column OR check

From: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
To: Justin Pryzby <pryzby(at)telsasoft(dot)com>
Cc: Ivan Voras <ivoras(at)gmail(dot)com>, postgres performance list <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Optimising a two column OR check
Date: 2019-10-12 15:17:58
Message-ID: CAMkU=1w1F0t7c78mJMF7DdBbk50aGy3-AROGzcbdPrS0ApmGAA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Sat, Oct 12, 2019 at 10:43 AM Justin Pryzby <pryzby(at)telsasoft(dot)com> wrote:

> On Sat, Oct 12, 2019 at 04:39:56PM +0200, Ivan Voras wrote:
> > With seqscan disabled, I get this plan on 9.6:
> > Bitmap Heap Scan on friend (cost=8.42..19.01 rows=14 width=8)
> ...
> > I expected to get an index-only scan in this situation, as that would be
> a
> > very common query. Is there a way to actually make this sort of query
> > resolvable with an index-only scan? Maybe a different table structure
> would
> > help?
>

It would have to scan the entire index to find the cases where user2_id=42
but user1_id is not constrained. Technically User1_id would be constrained
to be less than 42, but I don't think the planner will take that into
account.

> The v11 release notes have this relevant item:
>
> https://www.postgresql.org/docs/11/release-11.html
> |Allow bitmap scans to perform index-only scans when possible (Alexander
> Kuzmenkov)
>
>
But this is not one of those cases. It is only possible when the only data
needed is whether the row exists or not.

Cheers,

Jeff

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message MichaelDBA 2019-10-12 15:27:55 Re: Optimising a two column OR check
Previous Message Andrew Gierth 2019-10-12 15:16:50 Re: Optimising a two column OR check