Re: Looking for an efficient way to replace efficient NOT IN when landling very large data

From: Shaozhong SHI <shishaozhong(at)gmail(dot)com>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: Re: Looking for an efficient way to replace efficient NOT IN when landling very large data
Date: 2023-04-11 09:44:02
Message-ID: CA+i5Jwa6evCRWGZ8C2oW4jRdXKBu0ot_rjqKCq7sVepBAkCzoA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Tue, 11 Apr 2023 at 10:33, David Rowley <dgrowleyml(at)gmail(dot)com> wrote:

> On Tue, 11 Apr 2023 at 21:28, Shaozhong SHI <shishaozhong(at)gmail(dot)com>
> wrote:
> >
> > Select a.id, a.name, b.id, b.name from a_large_table a, definitive b
> where (a.id, b.name) not in
> > (select b.id, b.name from definitive b)
> >
> > is very slow.
> >
> > Is there a faster way to do so?
>
> It depends on what your exact requirements are for the NULL handling
> that NOT IN provides. Do you need the query to return 0 rows if b.id
> and b.name are null? This question is moot if none of the columns or
> either table allow NULLs.
>
> If you don't require that, then you'll give the planner more
> flexibility to choose a more efficient plan if you use NOT EXISTS
> instead.
>
> David
>

I would like to try out an example of NOT EXISTS way and see how the
replacement works.

Regards,

David

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message kunwar singh 2023-04-20 16:01:02 PostgreSQL Objects design
Previous Message David Rowley 2023-04-11 09:33:42 Re: Looking for an efficient way to replace efficient NOT IN when landling very large data