Re: BUG #19963: INNER JOIN ON qual evaluated as scan filter even when the inner input is empty

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: vectorplanck(at)gmail(dot)com
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19963: INNER JOIN ON qual evaluated as scan filter even when the inner input is empty
Date: 2026-12-01 15:14:53
Message-ID: 1562185.1796138093@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> For an INNER JOIN whose ON condition references only the outer relation,
> PostgreSQL pushes
> the ON qual into the outer scan's `Filter` and evaluates it **once per outer
> row**, even when
> the inner input is **empty**.

This is not a bug. The join must start by pulling some row from one
input or the other, and it started by trying to pull from t, and that
failed. Sure, it could instead have pulled first from e (and then
skipped t altogether upon discovering that e is empty). But that
would merely swap the failure cases around.

More generally, we explicitly disavow any concern for this sort of
thing so far as WHERE and JOIN clauses are concerned [1]. If you need
to control order of evaluation of an unsafe qual clause, you need to
work with multiple query levels with an optimization fence (e.g.,
WITH MATERIALIZED) between them.

regards, tom lane

[1] https://www.postgresql.org/docs/current/sql-expressions.html#SYNTAX-EXPRESS-EVAL

In response to

Browse pgsql-bugs by date

  From Date Subject
Previous Message Konstantin Knizhnik 2026-12-01 15:05:29 Re: BUG #19519: REPACK can fail due to missing chunk for toast value