diff options
Diffstat (limited to 'src/backend/optimizer/util/inherit.c')
-rw-r--r-- | src/backend/optimizer/util/inherit.c | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/src/backend/optimizer/util/inherit.c b/src/backend/optimizer/util/inherit.c index 5c7acf8a901..4797312ae53 100644 --- a/src/backend/optimizer/util/inherit.c +++ b/src/backend/optimizer/util/inherit.c @@ -822,11 +822,13 @@ expand_appendrel_subquery(PlannerInfo *root, RelOptInfo *rel, /* * apply_child_basequals * Populate childrel's base restriction quals from parent rel's quals, - * translating them using appinfo. + * translating Vars using appinfo and re-checking for quals which are + * constant-TRUE or constant-FALSE when applied to this child relation. * * If any of the resulting clauses evaluate to constant false or NULL, we * return false and don't apply any quals. Caller should mark the relation as - * a dummy rel in this case, since it doesn't need to be scanned. + * a dummy rel in this case, since it doesn't need to be scanned. Constant + * true quals are ignored. */ bool apply_child_basequals(PlannerInfo *root, RelOptInfo *parentrel, @@ -875,6 +877,7 @@ apply_child_basequals(PlannerInfo *root, RelOptInfo *parentrel, { Node *onecq = (Node *) lfirst(lc2); bool pseudoconstant; + RestrictInfo *childrinfo; /* check for pseudoconstant (no Vars or volatile functions) */ pseudoconstant = @@ -886,15 +889,23 @@ apply_child_basequals(PlannerInfo *root, RelOptInfo *parentrel, root->hasPseudoConstantQuals = true; } /* reconstitute RestrictInfo with appropriate properties */ - childquals = lappend(childquals, - make_restrictinfo(root, - (Expr *) onecq, - rinfo->is_pushed_down, - rinfo->has_clone, - rinfo->is_clone, - pseudoconstant, - rinfo->security_level, - NULL, NULL, NULL)); + childrinfo = make_restrictinfo(root, + (Expr *) onecq, + rinfo->is_pushed_down, + rinfo->has_clone, + rinfo->is_clone, + pseudoconstant, + rinfo->security_level, + NULL, NULL, NULL); + + /* Restriction is proven always false */ + if (restriction_is_always_false(root, childrinfo)) + return false; + /* Restriction is proven always true, so drop it */ + if (restriction_is_always_true(root, childrinfo)) + continue; + + childquals = lappend(childquals, childrinfo); /* track minimum security level among child quals */ cq_min_security = Min(cq_min_security, rinfo->security_level); } |