Skip to content

Commit ee33b95

Browse files
committed
Improve the plan cache invalidation mechanism to make it invalidate plans
when user-defined functions used in a plan are modified. Also invalidate plans when schemas, operators, or operator classes are modified; but for these cases we just invalidate everything rather than tracking exact dependencies, since these types of objects seldom change in a production database. Tom Lane; loosely based on a patch by Martin Pihlak.
1 parent c06629c commit ee33b95

File tree

18 files changed

+521
-274
lines changed

18 files changed

+521
-274
lines changed

src/backend/catalog/namespace.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
1515
* IDENTIFICATION
16-
* $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.111 2008/09/01 20:42:43 tgl Exp $
16+
* $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.112 2008/09/09 18:58:08 tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -187,7 +187,7 @@ static void recomputeNamespacePath(void);
187187
static void InitTempTableNamespace(void);
188188
static void RemoveTempRelations(Oid tempNamespaceId);
189189
static void RemoveTempRelationsCallback(int code, Datum arg);
190-
static void NamespaceCallback(Datum arg, Oid relid);
190+
static void NamespaceCallback(Datum arg, int cacheid, ItemPointer tuplePtr);
191191

192192
/* These don't really need to appear in any header file */
193193
Datum pg_table_is_visible(PG_FUNCTION_ARGS);
@@ -3094,7 +3094,7 @@ InitializeSearchPath(void)
30943094
* Syscache inval callback function
30953095
*/
30963096
static void
3097-
NamespaceCallback(Datum arg, Oid relid)
3097+
NamespaceCallback(Datum arg, int cacheid, ItemPointer tuplePtr)
30983098
{
30993099
/* Force search path to be recomputed on next use */
31003100
baseSearchPathValid = false;

src/backend/nodes/copyfuncs.c

Lines changed: 20 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.404 2008/09/01 20:42:44 tgl Exp $
18+
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.405 2008/09/09 18:58:08 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -88,6 +88,7 @@ _copyPlannedStmt(PlannedStmt *from)
8888
COPY_NODE_FIELD(returningLists);
8989
COPY_NODE_FIELD(rowMarks);
9090
COPY_NODE_FIELD(relationOids);
91+
COPY_NODE_FIELD(invalItems);
9192
COPY_SCALAR_FIELD(nParamExec);
9293

9394
return newnode;
@@ -689,6 +690,21 @@ _copyLimit(Limit *from)
689690
return newnode;
690691
}
691692

693+
/*
694+
* _copyPlanInvalItem
695+
*/
696+
static PlanInvalItem *
697+
_copyPlanInvalItem(PlanInvalItem *from)
698+
{
699+
PlanInvalItem *newnode = makeNode(PlanInvalItem);
700+
701+
COPY_SCALAR_FIELD(cacheId);
702+
/* tupleId isn't really a "scalar", but this works anyway */
703+
COPY_SCALAR_FIELD(tupleId);
704+
705+
return newnode;
706+
}
707+
692708
/* ****************************************************************
693709
* primnodes.h copy functions
694710
* ****************************************************************
@@ -3157,6 +3173,9 @@ copyObject(void *from)
31573173
case T_Limit:
31583174
retval = _copyLimit(from);
31593175
break;
3176+
case T_PlanInvalItem:
3177+
retval = _copyPlanInvalItem(from);
3178+
break;
31603179

31613180
/*
31623181
* PRIMITIVE NODES

src/backend/nodes/outfuncs.c

Lines changed: 22 additions & 6 deletions
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.338 2008/09/01 20:42:44 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.339 2008/09/09 18:58:08 tgl Exp $
1212
*
1313
* NOTES
1414
* Every node type that can appear in stored rules' parsetrees *must*
@@ -255,6 +255,7 @@ _outPlannedStmt(StringInfo str, PlannedStmt *node)
255255
WRITE_NODE_FIELD(returningLists);
256256
WRITE_NODE_FIELD(rowMarks);
257257
WRITE_NODE_FIELD(relationOids);
258+
WRITE_NODE_FIELD(invalItems);
258259
WRITE_INT_FIELD(nParamExec);
259260
}
260261

@@ -593,6 +594,14 @@ _outUnique(StringInfo str, Unique *node)
593594
appendStringInfo(str, " %u", node->uniqOperators[i]);
594595
}
595596

597+
static void
598+
_outHash(StringInfo str, Hash *node)
599+
{
600+
WRITE_NODE_TYPE("HASH");
601+
602+
_outPlanInfo(str, (Plan *) node);
603+
}
604+
596605
static void
597606
_outSetOp(StringInfo str, SetOp *node)
598607
{
@@ -631,11 +640,14 @@ _outLimit(StringInfo str, Limit *node)
631640
}
632641

633642
static void
634-
_outHash(StringInfo str, Hash *node)
643+
_outPlanInvalItem(StringInfo str, PlanInvalItem *node)
635644
{
636-
WRITE_NODE_TYPE("HASH");
645+
WRITE_NODE_TYPE("PLANINVALITEM");
637646

638-
_outPlanInfo(str, (Plan *) node);
647+
WRITE_INT_FIELD(cacheId);
648+
appendStringInfo(str, " :tupleId (%u,%u)",
649+
ItemPointerGetBlockNumber(&node->tupleId),
650+
ItemPointerGetOffsetNumber(&node->tupleId));
639651
}
640652

641653
/*****************************************************************************
@@ -1354,6 +1366,7 @@ _outPlannerGlobal(StringInfo str, PlannerGlobal *node)
13541366
WRITE_BITMAPSET_FIELD(rewindPlanIDs);
13551367
WRITE_NODE_FIELD(finalrtable);
13561368
WRITE_NODE_FIELD(relationOids);
1369+
WRITE_NODE_FIELD(invalItems);
13571370
}
13581371

13591372
static void
@@ -2206,14 +2219,17 @@ _outNode(StringInfo str, void *obj)
22062219
case T_Unique:
22072220
_outUnique(str, obj);
22082221
break;
2222+
case T_Hash:
2223+
_outHash(str, obj);
2224+
break;
22092225
case T_SetOp:
22102226
_outSetOp(str, obj);
22112227
break;
22122228
case T_Limit:
22132229
_outLimit(str, obj);
22142230
break;
2215-
case T_Hash:
2216-
_outHash(str, obj);
2231+
case T_PlanInvalItem:
2232+
_outPlanInvalItem(str, obj);
22172233
break;
22182234
case T_Alias:
22192235
_outAlias(str, obj);

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.242 2008/08/17 01:19:59 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.243 2008/09/09 18:58:08 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -140,6 +140,7 @@ standard_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
140140
glob->rewindPlanIDs = NULL;
141141
glob->finalrtable = NIL;
142142
glob->relationOids = NIL;
143+
glob->invalItems = NIL;
143144
glob->transientPlan = false;
144145

145146
/* Determine what fraction of the plan is likely to be scanned */
@@ -213,6 +214,7 @@ standard_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
213214
result->returningLists = root->returningLists;
214215
result->rowMarks = parse->rowMarks;
215216
result->relationOids = glob->relationOids;
217+
result->invalItems = glob->invalItems;
216218
result->nParamExec = list_length(glob->paramlist);
217219

218220
return result;

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