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;
/*