Fix calculation of relid sets for partitionwise child joins.
commit3c90dcd039149716454378bd270673f781b5c19f
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 21 Jul 2023 16:00:14 +0000 (21 12:00 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 21 Jul 2023 16:00:14 +0000 (21 12:00 -0400)
treeea4433d0b5343ef68261f946004e212c12d42c60
parent7c7412cae3ea8f8accdec1022969a9360b74f253
Fix calculation of relid sets for partitionwise child joins.

Applying add_outer_joins_to_relids() to a child join doesn't actually
work, even if we've built a SpecialJoinInfo specialized to the child,
because that function will also compare the join's relids to elements
of the main join_info_list, which only deal in regular relids not
child relids.  This mistake escaped detection by the existing
partitionwise join tests because they didn't test any cases where
add_outer_joins_to_relids() needs to add additional OJ relids (that
is, any cases where join reordering per identity 3 is possible).

Instead, let's apply adjust_child_relids() to the relids of the parent
join.  This requires minor code reordering to collect the relevant
AppendRelInfo structures first, but that's work we'd do shortly anyway.

Report and fix by Richard Guo; cosmetic changes by me

Discussion: https://postgr.es/m/CAMbWs49NCNbyubZWgci3o=_OTY=snCfAPtMnM-32f3mm-K-Ckw@mail.gmail.com
src/backend/optimizer/path/joinrels.c
src/backend/optimizer/util/relnode.c
src/test/regress/expected/partition_join.out
src/test/regress/sql/partition_join.sql