Re: Wrong results with right-semi-joins

Richard Guo <guofenglinux@gmail.com>

From: Richard Guo <guofenglinux@gmail.com>
To: Melanie Plageman <melanieplageman@gmail.com>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2024-12-12T02:44:42Z
Lists: pgsql-hackers
On Wed, Dec 11, 2024 at 11:27 AM Richard Guo <guofenglinux@gmail.com> wrote:
> I spent some time on this and came up with a simpler query to
> reproduce the issue.
>
> explain (costs off)
> select * from tbl_rs t1 join
>   lateral (select * from tbl_rs t2 where t2.a in
>             (select t1.a+t3.a from tbl_rs t3) and t2.a < 5)
>   on true;
>                 QUERY PLAN
> -------------------------------------------
>  Nested Loop
>    ->  Seq Scan on tbl_rs t1
>    ->  Hash Right Semi Join
>          Hash Cond: ((t1.a + t3.a) = t2.a)
>          ->  Seq Scan on tbl_rs t3
>          ->  Hash
>                ->  Seq Scan on tbl_rs t2
>                      Filter: (a < 5)
> (8 rows)
>
> Without the fix, this query returns 3 rows rather than the expected 6.
>
> Maybe I should update the test case introduced in 5668a857d to this
> one.

Done.

Thanks
Richard



Commits

  1. Improve the test case from 5668a857d

  2. Fix right-semi-joins in HashJoin rescans

  3. Support "Right Semi Join" plan shapes