From 445ce15702f701423a0fed3defe3a43662c7cd8d Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 7 Jan 2009 22:40:49 +0000 Subject: Create a third option named "partition" for constraint_exclusion, and make it the default. This setting enables constraint exclusion checks only for appendrel members (ie, inheritance children and UNION ALL arms), which are the cases in which constraint exclusion is most likely to be useful. Avoiding the overhead for simple queries that are unlikely to benefit should bring the cost down to the point where this is a reasonable default setting. Per today's discussion. --- src/backend/optimizer/util/plancat.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/backend/optimizer/util') diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index 948c0602136..f4f8ac8a763 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.153 2009/01/01 17:23:45 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.154 2009/01/07 22:40:49 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -27,6 +27,7 @@ #include "nodes/makefuncs.h" #include "nodes/nodeFuncs.h" #include "optimizer/clauses.h" +#include "optimizer/cost.h" #include "optimizer/plancat.h" #include "optimizer/predtest.h" #include "optimizer/prep.h" @@ -43,7 +44,7 @@ /* GUC parameter */ -bool constraint_exclusion = false; +int constraint_exclusion = CONSTRAINT_EXCLUSION_PARTITION; /* Hook for plugins to get control in get_relation_info() */ get_relation_info_hook_type get_relation_info_hook = NULL; @@ -561,8 +562,9 @@ get_relation_constraints(PlannerInfo *root, * self-inconsistent restrictions, or restrictions inconsistent with the * relation's CHECK constraints. * - * Note: this examines only rel->relid and rel->baserestrictinfo; therefore - * it can be called before filling in other fields of the RelOptInfo. + * Note: this examines only rel->relid, rel->reloptkind, and + * rel->baserestrictinfo; therefore it can be called before filling in + * other fields of the RelOptInfo. */ bool relation_excluded_by_constraints(PlannerInfo *root, @@ -573,8 +575,10 @@ relation_excluded_by_constraints(PlannerInfo *root, List *safe_constraints; ListCell *lc; - /* Skip the test if constraint exclusion is disabled */ - if (!constraint_exclusion) + /* Skip the test if constraint exclusion is disabled for the rel */ + if (constraint_exclusion == CONSTRAINT_EXCLUSION_OFF || + (constraint_exclusion == CONSTRAINT_EXCLUSION_PARTITION && + rel->reloptkind != RELOPT_OTHER_MEMBER_REL)) return false; /* -- cgit v1.2.3