agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
pgsql: Remove quals made redundant by reducing outer joins to antijoins
5+ messages / 1 participants
[nested] [flat]

* pgsql: Remove quals made redundant by reducing outer joins to antijoins
@ 2026-09-02 04:40 Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 5+ messages in thread

From: Richard Guo @ 2026-09-02 04:40 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Remove quals made redundant by reducing outer joins to antijoins

When reduce_outer_joins reduces an outer join to an antijoin, any IS
NULL qual on a Var from the antijoin's nullable side is necessarily
true.  Previously, such quals were discarded later in
distribute_qual_to_rels, mainly to avoid bogus selectivity estimates.
But that discard was incomplete: the qual remained in the jointree,
while its Vars were not counted in attr_needed.  Since commit
2ebf25e7d, join removal edits the jointree and expects it to contain
no other references to a removed rel, so it could remove a rel that
such a discarded qual still references, and then trip an assertion on
the qual's stale Var.

To fix, move this processing to an earlier phase: such quals are now
removed from the jointree by reduce_outer_joins itself.  This way
later phases see a consistent query tree, and
check_redundant_nullability_qual is no longer needed, so remove it.

Back-patch to v16, as with commit 2ebf25e7d.

Reported-by: Tender Wang <tndrwang@gmail.com>
Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAHewXNk8b0TsSy4dL=CO7FXL2W3WBm0BcdP-zwNJePa-Qj4HzA@mail.gmail.com
Backpatch-through: 16

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/ad4b80b6f49bcac519175fcb632aa94cdb7f6948

Modified Files
--------------
src/backend/optimizer/plan/initsplan.c    | 61 --------------------
src/backend/optimizer/prep/prepjointree.c | 92 ++++++++++++++++++++++++++++---
src/backend/optimizer/util/clauses.c      | 11 ++--
src/test/regress/expected/join.out        | 62 +++++++++++++++++++++
src/test/regress/sql/join.sql             | 30 ++++++++++
5 files changed, 183 insertions(+), 73 deletions(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Remove quals made redundant by reducing outer joins to antijoins
@ 2026-09-02 04:40 Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 5+ messages in thread

From: Richard Guo @ 2026-09-02 04:40 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Remove quals made redundant by reducing outer joins to antijoins

When reduce_outer_joins reduces an outer join to an antijoin, any IS
NULL qual on a Var from the antijoin's nullable side is necessarily
true.  Previously, such quals were discarded later in
distribute_qual_to_rels, mainly to avoid bogus selectivity estimates.
But that discard was incomplete: the qual remained in the jointree,
while its Vars were not counted in attr_needed.  Since commit
2ebf25e7d, join removal edits the jointree and expects it to contain
no other references to a removed rel, so it could remove a rel that
such a discarded qual still references, and then trip an assertion on
the qual's stale Var.

To fix, move this processing to an earlier phase: such quals are now
removed from the jointree by reduce_outer_joins itself.  This way
later phases see a consistent query tree, and
check_redundant_nullability_qual is no longer needed, so remove it.

Back-patch to v16, as with commit 2ebf25e7d.

Reported-by: Tender Wang <tndrwang@gmail.com>
Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAHewXNk8b0TsSy4dL=CO7FXL2W3WBm0BcdP-zwNJePa-Qj4HzA@mail.gmail.com
Backpatch-through: 16

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/763d563eaec82528fdd49c07830a2dae00567778

Modified Files
--------------
src/backend/optimizer/plan/initsplan.c    | 61 ---------------------
src/backend/optimizer/prep/prepjointree.c | 89 ++++++++++++++++++++++++++++---
src/backend/optimizer/util/clauses.c      | 11 ++--
src/test/regress/expected/join.out        | 36 +++++++++++++
src/test/regress/sql/join.sql             | 18 +++++++
5 files changed, 143 insertions(+), 72 deletions(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Remove quals made redundant by reducing outer joins to antijoins
@ 2026-09-02 04:40 Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 5+ messages in thread

From: Richard Guo @ 2026-09-02 04:40 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Remove quals made redundant by reducing outer joins to antijoins

When reduce_outer_joins reduces an outer join to an antijoin, any IS
NULL qual on a Var from the antijoin's nullable side is necessarily
true.  Previously, such quals were discarded later in
distribute_qual_to_rels, mainly to avoid bogus selectivity estimates.
But that discard was incomplete: the qual remained in the jointree,
while its Vars were not counted in attr_needed.  Since commit
2ebf25e7d, join removal edits the jointree and expects it to contain
no other references to a removed rel, so it could remove a rel that
such a discarded qual still references, and then trip an assertion on
the qual's stale Var.

To fix, move this processing to an earlier phase: such quals are now
removed from the jointree by reduce_outer_joins itself.  This way
later phases see a consistent query tree, and
check_redundant_nullability_qual is no longer needed, so remove it.

Back-patch to v16, as with commit 2ebf25e7d.

Reported-by: Tender Wang <tndrwang@gmail.com>
Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAHewXNk8b0TsSy4dL=CO7FXL2W3WBm0BcdP-zwNJePa-Qj4HzA@mail.gmail.com
Backpatch-through: 16

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/e509be9ceea96c579c2f67329069b13515bcc556

Modified Files
--------------
src/backend/optimizer/plan/initsplan.c    | 61 ---------------------
src/backend/optimizer/prep/prepjointree.c | 91 ++++++++++++++++++++++++++++---
src/backend/optimizer/util/clauses.c      | 11 ++--
src/test/regress/expected/join.out        | 40 ++++++++++++++
src/test/regress/sql/join.sql             | 25 +++++++++
5 files changed, 155 insertions(+), 73 deletions(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Remove quals made redundant by reducing outer joins to antijoins
@ 2026-09-02 04:40 Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 5+ messages in thread

From: Richard Guo @ 2026-09-02 04:40 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Remove quals made redundant by reducing outer joins to antijoins

When reduce_outer_joins reduces an outer join to an antijoin, any IS
NULL qual on a Var from the antijoin's nullable side is necessarily
true.  Previously, such quals were discarded later in
distribute_qual_to_rels, mainly to avoid bogus selectivity estimates.
But that discard was incomplete: the qual remained in the jointree,
while its Vars were not counted in attr_needed.  Since commit
2ebf25e7d, join removal edits the jointree and expects it to contain
no other references to a removed rel, so it could remove a rel that
such a discarded qual still references, and then trip an assertion on
the qual's stale Var.

To fix, move this processing to an earlier phase: such quals are now
removed from the jointree by reduce_outer_joins itself.  This way
later phases see a consistent query tree, and
check_redundant_nullability_qual is no longer needed, so remove it.

Back-patch to v16, as with commit 2ebf25e7d.

Reported-by: Tender Wang <tndrwang@gmail.com>
Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAHewXNk8b0TsSy4dL=CO7FXL2W3WBm0BcdP-zwNJePa-Qj4HzA@mail.gmail.com
Backpatch-through: 16

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/197a41aa6ee9f9e1467eaee43c04cf52a8367067

Modified Files
--------------
src/backend/optimizer/plan/initsplan.c    | 61 ---------------------
src/backend/optimizer/prep/prepjointree.c | 91 ++++++++++++++++++++++++++++---
src/backend/optimizer/util/clauses.c      | 11 ++--
src/test/regress/expected/join.out        | 40 ++++++++++++++
src/test/regress/sql/join.sql             | 25 +++++++++
5 files changed, 155 insertions(+), 73 deletions(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Remove quals made redundant by reducing outer joins to antijoins
@ 2026-09-02 04:40 Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 5+ messages in thread

From: Richard Guo @ 2026-09-02 04:40 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Remove quals made redundant by reducing outer joins to antijoins

When reduce_outer_joins reduces an outer join to an antijoin, any IS
NULL qual on a Var from the antijoin's nullable side is necessarily
true.  Previously, such quals were discarded later in
distribute_qual_to_rels, mainly to avoid bogus selectivity estimates.
But that discard was incomplete: the qual remained in the jointree,
while its Vars were not counted in attr_needed.  Since commit
2ebf25e7d, join removal edits the jointree and expects it to contain
no other references to a removed rel, so it could remove a rel that
such a discarded qual still references, and then trip an assertion on
the qual's stale Var.

To fix, move this processing to an earlier phase: such quals are now
removed from the jointree by reduce_outer_joins itself.  This way
later phases see a consistent query tree, and
check_redundant_nullability_qual is no longer needed, so remove it.

Back-patch to v16, as with commit 2ebf25e7d.

Reported-by: Tender Wang <tndrwang@gmail.com>
Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAHewXNk8b0TsSy4dL=CO7FXL2W3WBm0BcdP-zwNJePa-Qj4HzA@mail.gmail.com
Backpatch-through: 16

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/fc8ed6362404c2abfb87f9f291aa9d19b8323d8c

Modified Files
--------------
src/backend/optimizer/plan/initsplan.c    | 61 --------------------
src/backend/optimizer/prep/prepjointree.c | 93 ++++++++++++++++++++++++++++---
src/backend/optimizer/util/clauses.c      | 11 ++--
src/test/regress/expected/join.out        | 40 +++++++++++++
src/test/regress/sql/join.sql             | 25 +++++++++
5 files changed, 157 insertions(+), 73 deletions(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2026-09-02 04:40 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-09-02 04:40 pgsql: Remove quals made redundant by reducing outer joins to antijoins Richard Guo <rguo@postgresql.org>
2026-09-02 04:40 pgsql: Remove quals made redundant by reducing outer joins to antijoins Richard Guo <rguo@postgresql.org>
2026-09-02 04:40 pgsql: Remove quals made redundant by reducing outer joins to antijoins Richard Guo <rguo@postgresql.org>
2026-09-02 04:40 pgsql: Remove quals made redundant by reducing outer joins to antijoins Richard Guo <rguo@postgresql.org>
2026-09-02 04:40 pgsql: Remove quals made redundant by reducing outer joins to antijoins Richard Guo <rguo@postgresql.org>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox