Re: Inefficient query plan for SELECT ... EXCEPT ...

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: Dimitrios Apostolou <jimis(at)gmx(dot)net>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Inefficient query plan for SELECT ... EXCEPT ...
Date: 2023-11-01 00:52:07
Message-ID: 2664450.1698799927@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

David Rowley <dgrowleyml(at)gmail(dot)com> writes:
> It would be possible to have some sort of MergeExcept operator and
> have the planner consider that. Unfortunately, since the upper planner
> was changed a few years ago to have it consider paths the same as the
> join planner does, nobody has yet come back to the union planner to
> properly pathify that. I do have a WIP patch to do this work, but I
> wasn't planning on improving EXCEPT, only UNION. Making it work for
> EXCEPT and INTERSECT would require a new executor operator.

Yeah. We're moderately good about UNION ALL, but UNION/INTERSECT/EXCEPT
are an area that nobody has ever gotten around to optimizing: the two
sub-queries will be planned independently and then fed to a simplistic
set-operation node. Maybe that'll get better someday but don't hold
your breath. In the meantime, try to recast an EXCEPT query as an
antijoin.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message veem v 2023-11-01 04:09:47 Re: Question on Aurora postgres
Previous Message Alan Evans 2023-11-01 00:24:17 Feature/Suggestion: libpq/psql support for libsecret (formerly gnome-keyring)