Skip to content

Commit 82d8ab6

Browse files
committed
Fix the plan-invalidation mechanism to treat regclass constants that refer to
a relation as a reason to invalidate a plan when the relation changes. This handles scenarios such as dropping/recreating a sequence that is referenced by nextval('seq') in a cached plan. Rather than teach plancache.c all about digging through plan trees to find regclass Consts, we charge the planner's setrefs.c with making a list of the relation OIDs on which each plan depends. That way the list can be built cheaply during a plan tree traversal that has to happen anyway. Per bug #3662 and subsequent discussion.
1 parent 68b08b2 commit 82d8ab6

File tree

10 files changed

+223
-101
lines changed

10 files changed

+223
-101
lines changed

src/backend/nodes/copyfuncs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Portions Copyright (c) 1994, Regents of the University of California
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.382 2007/09/03 18:46:30 tgl Exp $
18+
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.383 2007/10/11 18:05:26 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -83,6 +83,7 @@ _copyPlannedStmt(PlannedStmt *from)
8383
COPY_BITMAPSET_FIELD(rewindPlanIDs);
8484
COPY_NODE_FIELD(returningLists);
8585
COPY_NODE_FIELD(rowMarks);
86+
COPY_NODE_FIELD(relationOids);
8687
COPY_SCALAR_FIELD(nParamExec);
8788

8889
return newnode;

src/backend/nodes/outfuncs.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/nodes/outfuncs.c,v 1.314 2007/08/31 01:44:05 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.315 2007/10/11 18:05:27 tgl Exp $
1212
*
1313
* NOTES
1414
* Every node type that can appear in stored rules' parsetrees *must*
@@ -250,6 +250,7 @@ _outPlannedStmt(StringInfo str, PlannedStmt *node)
250250
WRITE_BITMAPSET_FIELD(rewindPlanIDs);
251251
WRITE_NODE_FIELD(returningLists);
252252
WRITE_NODE_FIELD(rowMarks);
253+
WRITE_NODE_FIELD(relationOids);
253254
WRITE_INT_FIELD(nParamExec);
254255
}
255256

@@ -1300,6 +1301,7 @@ _outPlannerGlobal(StringInfo str, PlannerGlobal *node)
13001301
WRITE_NODE_FIELD(subrtables);
13011302
WRITE_BITMAPSET_FIELD(rewindPlanIDs);
13021303
WRITE_NODE_FIELD(finalrtable);
1304+
WRITE_NODE_FIELD(relationOids);
13031305
}
13041306

13051307
static void

src/backend/optimizer/plan/planner.c

Lines changed: 5 additions & 2 deletions
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.222 2007/09/20 17:56:31 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.223 2007/10/11 18:05:27 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -134,6 +134,7 @@ standard_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
134134
glob->subrtables = NIL;
135135
glob->rewindPlanIDs = NULL;
136136
glob->finalrtable = NIL;
137+
glob->relationOids = NIL;
137138
glob->transientPlan = false;
138139

139140
/* Determine what fraction of the plan is likely to be scanned */
@@ -194,6 +195,7 @@ standard_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
194195
result->rewindPlanIDs = glob->rewindPlanIDs;
195196
result->returningLists = root->returningLists;
196197
result->rowMarks = parse->rowMarks;
198+
result->relationOids = glob->relationOids;
197199
result->nParamExec = list_length(glob->paramlist);
198200

199201
return result;
@@ -1184,7 +1186,8 @@ grouping_planner(PlannerInfo *root, double tuple_fraction)
11841186
List *rlist;
11851187

11861188
Assert(parse->resultRelation);
1187-
rlist = set_returning_clause_references(parse->returningList,
1189+
rlist = set_returning_clause_references(root->glob,
1190+
parse->returningList,
11881191
result_plan,
11891192
parse->resultRelation);
11901193
root->returningLists = list_make1(rlist);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy