Clear more substructure of a dead relation during join removal. The tablesample and securityQuals subtrees of a RangeTblEntry can include Vars, which will cause trouble if they point at a removed rel and are visited during later processing. Hence, clear those fields during join removal, as we already do for the subquery field. remove_useless_outer_joins got this right for securityQuals but not tablesample, while remove_self_join_rel missed doing it for securityQuals. (It escapes trouble for tablesample only because we made a policy decision to never touch sampled relations for SJE.)
Oversight in 2ebf25e7d. Back-patch to v16, like that commit (but the SJE issue only goes as far back as v18). Author: shihao zhong <[email protected]> Reviewed-by: Tom Lane <[email protected]> Discussion: https://postgr.es/m/CAGRkXqSOAT1yop44B8jwacL_91rxK=quou8of3nlmb9ngao...@mail.gmail.com Backpatch-through: 16 Branch ------ REL_18_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/18aca7257eb0330d7ea6391a085ff45d57496ce2 Modified Files -------------- src/backend/optimizer/plan/analyzejoins.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
