Re: Incorrect result in certain expressions of anti-join

From: Pantelis Theodosiou <ypercube(at)gmail(dot)com>
To: Torbjörn Gannholm <torbjorn(dot)gannholm(at)gmail(dot)com>
Cc: "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: Incorrect result in certain expressions of anti-join
Date: 2025-01-07 22:03:50
Message-ID: CAE3TBxxWeJFc0Eckq2ze_4XNMnct=zQhy73R22LLuxp-2pjw-w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tuesday, January 7, 2025, Torbjörn Gannholm <torbjorn(dot)gannholm(at)gmail(dot)com>
wrote:

> To reproduce:
>
> create table foo (a text);
> Insert into foo values ('foo');
> create table bar (a text);
> insert into bar values ('foo'), ('bar');
>
> Now the following expression of anti-join gives the correct result:
> select * from bar LEFT JOIN foo ON foo.a = bar.a WHERE foo.a IS NULL;
> a | a
> -----+---
> bar |
> (1 row)
>
> However, a slight change and the anti-condition is simply ignored and the
> unexpected (IMO incorrect) result is returned. I would expect it either to
> work or to cause an error:
> select * from bar LEFT JOIN foo ON foo.a = bar.a AND foo.a IS NULL;
> a | a
> -----+---
> foo |
> bar |
> (2 rows)
>
>
The result is correct. The two queries are not equivalent. The join
condition on the second query evaluates to false for all combinations as
foo.a has no null values.

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message David G. Johnston 2025-01-07 23:19:47 Re: Incorrect result in certain expressions of anti-join
Previous Message Thomas Munro 2025-01-07 21:57:20 Re: BUG #18146: Rows reappearing in Tables after Auto-Vacuum Failure in PostgreSQL on Windows