1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-18 02:02:55 +03:00

Fix semijoin unique-ification for child relations

For a child relation, we should not assume that its parent's
unique-ified relation (or unique-ified path in v18) always exists.  In
cases where all RHS columns that need to be unique-ified are equated
to constants, the unique-ified relation/path for the parent table is
not built, as there are no columns left to unique-ify.  Failing to
account for this can result in a SIGSEGV crash during planning.

This patch checks whether the parent's unique-ified relation or path
exists and skips unique-ification of the child relation if it does
not.

Author: Richard Guo <guofenglinux@gmail.com>
Discussion: https://postgr.es/m/CAMbWs49MOdLW2c+qbLHHBt8VBu=4ONpM91D19=AWeW93eFUF6A@mail.gmail.com
Backpatch-through: 18
This commit is contained in:
Richard Guo
2025-08-29 13:14:12 +09:00
parent fabd8b8e2a
commit 97b0f36bde
3 changed files with 106 additions and 0 deletions

View File

@@ -8307,6 +8307,15 @@ create_unique_paths(PlannerInfo *root, RelOptInfo *rel, SpecialJoinInfo *sjinfo)
if (!(sjinfo->semi_can_btree || sjinfo->semi_can_hash))
return NULL;
/*
* Punt if this is a child relation and we failed to build a unique-ified
* relation for its parent. This can happen if all the RHS columns were
* found to be equated to constants when unique-ifying the parent table,
* leaving no columns to unique-ify.
*/
if (IS_OTHER_REL(rel) && rel->top_parent->unique_rel == NULL)
return NULL;
/*
* When called during GEQO join planning, we are in a short-lived memory
* context. We must make sure that the unique rel and any subsidiary data