pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Dirschel, Steve <steve.dirschel@thomsonreuters.com>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Postgres NOT IN vs NOT EXISTS optimization
Date: Tue, 14 Jun 2022 12:09:16 -0400
Message-ID: <76344.1655222956@sss.pgh.pa.us> (raw)
In-Reply-To: <DM6PR03MB43322310B08F8F3D531315FCFAAA9@DM6PR03MB4332.namprd03.prod.outlook.com>
References: <DM6PR03MB43322310B08F8F3D531315FCFAAA9@DM6PR03MB4332.namprd03.prod.outlook.com>

"Dirschel, Steve" <steve.dirschel@thomsonreuters.com> writes:
> Is Postgres able to drive the query the same way with the NOT IN as the
> NOT EXISTS is doing or is that only available if the query has a NOT
> EXISTS?

NOT IN is not optimized very well in PG, because of the strange
semantics that the SQL spec demands when the sub-query produces any
null values.  There's been some interest in detecting cases where
we can prove that the subquery produces no nulls and then optimizing
it into NOT EXISTS, but it seems like a lot of work for not-great
return, so nothing's happened (yet).  Perhaps Oracle does something
like that already, or perhaps they're just ignoring the semantics
problem; they do not have a reputation for hewing closely to the
spec on behavior regarding nulls.

			regards, tom lane





view thread (5+ messages)  latest in thread

Message-ID: <76344.1655222956@sss.pgh.pa.us>
Permalink:  ../76344.1655222956@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/76344.1655222956@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, steve.dirschel@thomsonreuters.com
  Subject: Re: Postgres NOT IN vs NOT EXISTS optimization
  In-Reply-To: <76344.1655222956@sss.pgh.pa.us>
  References: <DM6PR03MB43322310B08F8F3D531315FCFAAA9@DM6PR03MB4332.namprd03.prod.outlook.com> <76344.1655222956@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