aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2017-12-01 10:58:08 -0500
committerRobert Haas <rhaas@postgresql.org>2017-12-01 10:59:09 -0500
commit1cbc17aaca82b2e262912da96c49b2e1d2f492e7 (patch)
tree2f2e834cf21ceda00457b3bb92c42efa8301a783
parent59c8078744b5febf549c8b53171242cf667b87a1 (diff)
downloadpostgresql-1cbc17aaca82b2e262912da96c49b2e1d2f492e7.tar.gz
postgresql-1cbc17aaca82b2e262912da96c49b2e1d2f492e7.zip
Try to exclude partitioned tables in toto.
Ashutosh Bapat, reviewed by Jeevan Chalke. Comment by me. Discussion: http://postgr.es/m/CAFjFpRcuRaydz88CY_aQekmuvmN2A9ax5z0k=ppT+s8KS8xMRA@mail.gmail.com
-rw-r--r--src/backend/optimizer/util/plancat.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c
index 199a2631a11..f7438714c49 100644
--- a/src/backend/optimizer/util/plancat.c
+++ b/src/backend/optimizer/util/plancat.c
@@ -1414,8 +1414,18 @@ relation_excluded_by_constraints(PlannerInfo *root,
if (predicate_refuted_by(safe_restrictions, safe_restrictions, false))
return true;
- /* Only plain relations have constraints */
- if (rte->rtekind != RTE_RELATION || rte->inh)
+ /*
+ * Only plain relations have constraints. In a partitioning hierarchy,
+ * but not with regular table inheritance, it's OK to assume that any
+ * constraints that hold for the parent also hold for every child; for
+ * instance, table inheritance allows the parent to have constraints
+ * marked NO INHERIT, but table partitioning does not. We choose to check
+ * whether the partitioning parents can be excluded here; doing so
+ * consumes some cycles, but potentially saves us the work of excluding
+ * each child individually.
+ */
+ if (rte->rtekind != RTE_RELATION ||
+ (rte->inh && rte->relkind != RELKIND_PARTITIONED_TABLE))
return false;
/*