Refactor addition of PlaceHolderVars to joinrel targetlists.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 17 Aug 2022 20:12:23 +0000 (16:12 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 17 Aug 2022 20:12:23 +0000 (16:12 -0400)
commitafa0ec30bfd18611ec5bc4dfa394dc8838aece21
tree33ca16fcc475cd9154ad89a32813454d5c8f9ea5
parentb3ff6c742f6c7f750e9f74476576839cb039e1ab
Refactor addition of PlaceHolderVars to joinrel targetlists.

Make build_joinrel_tlist() responsible for adding PHVs that were
already computed in one or the other input relation, and therefore
change add_placeholders_to_joinrel() to only add PHVs that will be
newly computed in this joinrel's output.  This makes the handling
of PHVs in build_joinrel_tlist() more like its handling of plain
Vars, which seems like a good thing on intelligibility grounds
and will simplify planned future changes.  There is a purely
cosmetic side-effect that the order of entries in the joinrel's
tlist may change; but since it becomes more like the order of
entries in the input tlists, that's not bad.

The reason it wasn't done like this originally was the potential
cost of looking up PlaceHolderInfo entries to consult ph_needed.
Now that that's O(1) it shouldn't hurt.

Discussion: https://postgr.es/m/1405792.1660677844@sss.pgh.pa.us
src/backend/optimizer/util/placeholder.c
src/backend/optimizer/util/relnode.c
src/test/regress/expected/join.out