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_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/cbcccca71e48fa683f520b1d36108d9b35373f75

Modified Files
--------------
src/backend/optimizer/plan/analyzejoins.c | 30 +++++++++++++++++++++++-------
1 file changed, 23 insertions(+), 7 deletions(-)

Reply via email to