Re: IS NOT DISTINCT FROM + Indexing

From: Andres Freund <andres(at)anarazel(dot)de>
To: Peter Geoghegan <pg(at)heroku(dot)com>
Cc: "Jonathan S(dot) Katz" <jonathan(dot)katz(at)excoventures(dot)com>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: IS NOT DISTINCT FROM + Indexing
Date: 2014-07-21 23:57:15
Message-ID: 20140721235715.GC4629@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2014-07-21 16:51:32 -0700, Peter Geoghegan wrote:
> On Mon, Jul 21, 2014 at 4:16 PM, Jonathan S. Katz
> <jonathan(dot)katz(at)excoventures(dot)com> wrote:
> > With NULLs being indexable, I was wondering if there was some reason why IS NOT DISTINCT FROM could not use the index?
>
> FWIW this works:
>
> postgres=# explain analyze select * from orders where orderid in (5, null);

I rather doubt it will. x in (y1, ... yn) is essentially expanded to x =
y1 OR x = y2, ... OR x = yn. I.e. the NULL comparison will be done using
normal equality comparison and thus not return a row with a NULL
orderid. Am I missing something?

> I think that it would almost be a Simple Matter of Programming to make
> IS NOT DISTINCT FROM indexable. Under the hood, IS DISTINCT FROM isn't
> very different to using the equality operator:

But yea, it probably wouldn't take very much for that.

Greetings,

Andres Freund

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2014-07-22 00:02:25 Re: IS NOT DISTINCT FROM + Indexing
Previous Message Peter Geoghegan 2014-07-21 23:51:32 Re: IS NOT DISTINCT FROM + Indexing