Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1cbc17a

Browse files
committed
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
1 parent 59c8078 commit 1cbc17a

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/backend/optimizer/util/plancat.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,8 +1414,18 @@ relation_excluded_by_constraints(PlannerInfo *root,
14141414
if (predicate_refuted_by(safe_restrictions, safe_restrictions, false))
14151415
return true;
14161416

1417-
/* Only plain relations have constraints */
1418-
if (rte->rtekind != RTE_RELATION || rte->inh)
1417+
/*
1418+
* Only plain relations have constraints. In a partitioning hierarchy,
1419+
* but not with regular table inheritance, it's OK to assume that any
1420+
* constraints that hold for the parent also hold for every child; for
1421+
* instance, table inheritance allows the parent to have constraints
1422+
* marked NO INHERIT, but table partitioning does not. We choose to check
1423+
* whether the partitioning parents can be excluded here; doing so
1424+
* consumes some cycles, but potentially saves us the work of excluding
1425+
* each child individually.
1426+
*/
1427+
if (rte->rtekind != RTE_RELATION ||
1428+
(rte->inh && rte->relkind != RELKIND_PARTITIONED_TABLE))
14191429
return false;
14201430

14211431
/*

0 commit comments

Comments
 (0)