Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d174a4a

Browse files
committed
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.
1 parent 2a77355 commit d174a4a

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

src/backend/nodes/outfuncs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.384 2010/03/28 22:59:32 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.385 2010/03/30 21:58:10 tgl Exp $
1212
*
1313
* NOTES
1414
* Every node type that can appear in stored rules' parsetrees *must*
@@ -1559,6 +1559,7 @@ _outPlannerInfo(StringInfo str, PlannerInfo *node)
15591559
WRITE_NODE_FIELD(sort_pathkeys);
15601560
WRITE_FLOAT_FIELD(total_table_pages, "%.0f");
15611561
WRITE_FLOAT_FIELD(tuple_fraction, "%.4f");
1562+
WRITE_BOOL_FIELD(hasInheritedTarget);
15621563
WRITE_BOOL_FIELD(hasJoinRTEs);
15631564
WRITE_BOOL_FIELD(hasHavingQual);
15641565
WRITE_BOOL_FIELD(hasPseudoConstantQuals);

src/backend/optimizer/plan/planner.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.266 2010/02/26 02:00:45 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.267 2010/03/30 21:58:10 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -307,6 +307,7 @@ subquery_planner(PlannerGlobal *glob, Query *parse,
307307
root->eq_classes = NIL;
308308
root->append_rel_list = NIL;
309309
root->rowMarks = NIL;
310+
root->hasInheritedTarget = false;
310311

311312
root->hasRecursion = hasRecursion;
312313
if (hasRecursion)
@@ -749,6 +750,7 @@ inheritance_planner(PlannerInfo *root)
749750
adjust_appendrel_attrs((Node *) parse,
750751
appinfo);
751752
subroot.init_plans = NIL;
753+
subroot.hasInheritedTarget = true;
752754
/* We needn't modify the child's append_rel_list */
753755
/* There shouldn't be any OJ info to translate, as yet */
754756
Assert(subroot.join_info_list == NIL);

src/backend/optimizer/util/plancat.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.162 2010/01/05 21:53:58 rhaas Exp $
12+
* $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.163 2010/03/30 21:58:10 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -580,7 +580,10 @@ relation_excluded_by_constraints(PlannerInfo *root,
580580
/* Skip the test if constraint exclusion is disabled for the rel */
581581
if (constraint_exclusion == CONSTRAINT_EXCLUSION_OFF ||
582582
(constraint_exclusion == CONSTRAINT_EXCLUSION_PARTITION &&
583-
rel->reloptkind != RELOPT_OTHER_MEMBER_REL))
583+
!(rel->reloptkind == RELOPT_OTHER_MEMBER_REL ||
584+
(root->hasInheritedTarget &&
585+
rel->reloptkind == RELOPT_BASEREL &&
586+
rel->relid == root->parse->resultRelation))))
584587
return false;
585588

586589
/*

src/include/nodes/relation.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/nodes/relation.h,v 1.185 2010/03/28 22:59:33 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/nodes/relation.h,v 1.186 2010/03/30 21:58:11 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -197,6 +197,8 @@ typedef struct PlannerInfo
197197

198198
double tuple_fraction; /* tuple_fraction passed to query_planner */
199199

200+
bool hasInheritedTarget; /* true if parse->resultRelation is an
201+
* inheritance child rel */
200202
bool hasJoinRTEs; /* true if any RTEs are RTE_JOIN kind */
201203
bool hasHavingQual; /* true if havingQual was non-null */
202204
bool hasPseudoConstantQuals; /* true if any RestrictInfo has

0 commit comments

Comments
 (0)