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

2023-11-01 Thread Dimitrios Apostolou
Thank you all for the answers, they covered me well. Is this worth a bug report? I can file one if the issue is not known. No. It's just a missing optimisation. We know about it. It's good I shot an email first then. FWIW my usual way in other projects would be to check the bugtracker, and

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

2023-10-31 Thread Tom Lane
David Rowley 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 plan

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

2023-10-31 Thread David Rowley
On Wed, 1 Nov 2023 at 11:41, Dimitrios Apostolou wrote: > I'm wondering why the planner doesn't see that the left table is very small > and follow a different path. > From an abstract computer science POV, I would > > 1. sort the left table (the right one is already indexed) > 2. "merge" the two

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

2023-10-31 Thread David G. Johnston
On Tue, Oct 31, 2023 at 3:41 PM Dimitrios Apostolou wrote: > > Is this worth a bug report? I can file one if the issue is not known. > Or am I misunderstanding the implications of the SELECT-EXCEPT query? > > In the meantime I have replaced the query with a LEFT OUTER JOIN which > performs much b