Fix self-join elimination to avoid inheritance scans. Self-join elimination failed to check for inheritance cases, which has two big problems. First, a unique index on the parent table isn't sufficient to prove uniqueness across its children too. Second, since we matched RTEs by OID without considering rte->inh, we could try to merge "mytable" with "mytable ONLY", which doesn't even represent the same set of rows.
We can fix both issues by just skipping RTEs that have inh set. preprocess_relation_rtes already cleared that flag for tables known not to have inheritance children, so this doesn't break SJE for the cases where it's valid. Author: Tender Wang <[email protected]> Reviewed-by: Tom Lane <[email protected]> Discussion: https://postgr.es/m/cahewxnn4ejcqevann_fpkq3ojwabxq8pxcj-dzybeq6_4xs...@mail.gmail.com Backpatch-through: 18 Branch ------ REL_18_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/ebf82fae68b7e8e9773a84561f87f45368953eae Modified Files -------------- src/backend/optimizer/plan/analyzejoins.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-)
