aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2010-03-30 21:58:11 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2010-03-30 21:58:11 +0000
commitd174a4adbb7423ee5ff30aa98043db4521ffd1be (patch)
treeddbcea5d50df5337bcfc6c5969232b2e492a71de /src
parent2a77355ea1e53bc234ed0b5fda8ec9f304f6797a (diff)
downloadpostgresql-d174a4adbb7423ee5ff30aa98043db4521ffd1be.tar.gz
postgresql-d174a4adbb7423ee5ff30aa98043db4521ffd1be.zip
Fix "constraint_exclusion = partition" logic so that it will also attempt
constraint exclusion on an inheritance set that is the target of an UPDATE or DELETE query. Per gripe from Marc Cousin. Back-patch to 8.4 where the feature was introduced.
Diffstat (limited to 'src')
-rw-r--r--src/backend/nodes/outfuncs.c3
-rw-r--r--src/backend/optimizer/plan/planner.c4
-rw-r--r--src/backend/optimizer/util/plancat.c7
-rw-r--r--src/include/nodes/relation.h4
4 files changed, 13 insertions, 5 deletions
diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c
index 37bafae46ea..dba8d4b6690 100644
--- a/src/backend/nodes/outfuncs.c
+++ b/src/backend/nodes/outfuncs.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.384 2010/03/28 22:59:32 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.385 2010/03/30 21:58:10 tgl Exp $
*
* NOTES
* Every node type that can appear in stored rules' parsetrees *must*
@@ -1559,6 +1559,7 @@ _outPlannerInfo(StringInfo str, PlannerInfo *node)
WRITE_NODE_FIELD(sort_pathkeys);
WRITE_FLOAT_FIELD(total_table_pages, "%.0f");
WRITE_FLOAT_FIELD(tuple_fraction, "%.4f");
+ WRITE_BOOL_FIELD(hasInheritedTarget);
WRITE_BOOL_FIELD(hasJoinRTEs);
WRITE_BOOL_FIELD(hasHavingQual);
WRITE_BOOL_FIELD(hasPseudoConstantQuals);
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 356fe17df4b..317a7e87f33 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.266 2010/02/26 02:00:45 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.267 2010/03/30 21:58:10 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -307,6 +307,7 @@ subquery_planner(PlannerGlobal *glob, Query *parse,
root->eq_classes = NIL;
root->append_rel_list = NIL;
root->rowMarks = NIL;
+ root->hasInheritedTarget = false;
root->hasRecursion = hasRecursion;
if (hasRecursion)
@@ -749,6 +750,7 @@ inheritance_planner(PlannerInfo *root)
adjust_appendrel_attrs((Node *) parse,
appinfo);
subroot.init_plans = NIL;
+ subroot.hasInheritedTarget = true;
/* We needn't modify the child's append_rel_list */
/* There shouldn't be any OJ info to translate, as yet */
Assert(subroot.join_info_list == NIL);
diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c
index fdce5bb5a3f..10800b488f6 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.162 2010/01/05 21:53:58 rhaas Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.163 2010/03/30 21:58:10 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -580,7 +580,10 @@ relation_excluded_by_constraints(PlannerInfo *root,
/* 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))
+ !(rel->reloptkind == RELOPT_OTHER_MEMBER_REL ||
+ (root->hasInheritedTarget &&
+ rel->reloptkind == RELOPT_BASEREL &&
+ rel->relid == root->parse->resultRelation))))
return false;
/*
diff --git a/src/include/nodes/relation.h b/src/include/nodes/relation.h
index 45cb17c52b8..bdee19cc3a9 100644
--- a/src/include/nodes/relation.h
+++ b/src/include/nodes/relation.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/nodes/relation.h,v 1.185 2010/03/28 22:59:33 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/nodes/relation.h,v 1.186 2010/03/30 21:58:11 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -197,6 +197,8 @@ typedef struct PlannerInfo
double tuple_fraction; /* tuple_fraction passed to query_planner */
+ bool hasInheritedTarget; /* true if parse->resultRelation is an
+ * inheritance child rel */
bool hasJoinRTEs; /* true if any RTEs are RTE_JOIN kind */
bool hasHavingQual; /* true if havingQual was non-null */
bool hasPseudoConstantQuals; /* true if any RestrictInfo has