diff options
Diffstat (limited to 'src/backend/optimizer/plan/initsplan.c')
-rw-r--r-- | src/backend/optimizer/plan/initsplan.c | 60 |
1 files changed, 40 insertions, 20 deletions
diff --git a/src/backend/optimizer/plan/initsplan.c b/src/backend/optimizer/plan/initsplan.c index d3868b628d8..032aa024064 100644 --- a/src/backend/optimizer/plan/initsplan.c +++ b/src/backend/optimizer/plan/initsplan.c @@ -31,6 +31,7 @@ #include "parser/analyze.h" #include "rewrite/rewriteManip.h" #include "utils/lsyscache.h" +#include "utils/rel.h" #include "utils/typcache.h" /* These parameters are set by GUC */ @@ -2629,32 +2630,51 @@ add_base_clause_to_rel(PlannerInfo *root, Index relid, RestrictInfo *restrictinfo) { RelOptInfo *rel = find_base_rel(root, relid); + RangeTblEntry *rte = root->simple_rte_array[relid]; Assert(bms_membership(restrictinfo->required_relids) == BMS_SINGLETON); - /* Don't add the clause if it is always true */ - if (restriction_is_always_true(root, restrictinfo)) - return; - /* - * Substitute the origin qual with constant-FALSE if it is provably always - * false. Note that we keep the same rinfo_serial. + * For inheritance parent tables, we must always record the RestrictInfo + * in baserestrictinfo as is. If we were to transform or skip adding it, + * then the original wouldn't be available in apply_child_basequals. Since + * there are two RangeTblEntries for inheritance parents, one with + * inh==true and the other with inh==false, we're still able to apply this + * optimization to the inh==false one. The inh==true one is what + * apply_child_basequals() sees, whereas the inh==false one is what's used + * for the scan node in the final plan. + * + * We make an exception to this is for partitioned tables. For these, we + * always apply the constant-TRUE and constant-FALSE transformations. A + * qual which is either of these for a partitioned table must also be that + * for all of its child partitions. */ - if (restriction_is_always_false(root, restrictinfo)) + if (!rte->inh || rte->relkind == RELKIND_PARTITIONED_TABLE) { - int save_rinfo_serial = restrictinfo->rinfo_serial; - - restrictinfo = make_restrictinfo(root, - (Expr *) makeBoolConst(false, false), - restrictinfo->is_pushed_down, - restrictinfo->has_clone, - restrictinfo->is_clone, - restrictinfo->pseudoconstant, - 0, /* security_level */ - restrictinfo->required_relids, - restrictinfo->incompatible_relids, - restrictinfo->outer_relids); - restrictinfo->rinfo_serial = save_rinfo_serial; + /* Don't add the clause if it is always true */ + if (restriction_is_always_true(root, restrictinfo)) + return; + + /* + * Substitute the origin qual with constant-FALSE if it is provably + * always false. Note that we keep the same rinfo_serial. + */ + if (restriction_is_always_false(root, restrictinfo)) + { + int save_rinfo_serial = restrictinfo->rinfo_serial; + + restrictinfo = make_restrictinfo(root, + (Expr *) makeBoolConst(false, false), + restrictinfo->is_pushed_down, + restrictinfo->has_clone, + restrictinfo->is_clone, + restrictinfo->pseudoconstant, + 0, /* security_level */ + restrictinfo->required_relids, + restrictinfo->incompatible_relids, + restrictinfo->outer_relids); + restrictinfo->rinfo_serial = save_rinfo_serial; + } } /* Add clause to rel's restriction list */ |