memory_context_change.patch
text/x-patch
Filename: memory_context_change.patch
Type: text/x-patch
Part: 0
Patch
Format: unified
| File | + | − |
|---|---|---|
| src/backend/optimizer/plan/planner.c | 22 | 0 |
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index d8c5dd3..abc34aa 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -54,6 +54,7 @@
#include "utils/rel.h"
#include "utils/selfuncs.h"
#include "utils/lsyscache.h"
+#include "utils/memutils.h"
#include "utils/syscache.h"
@@ -192,6 +193,9 @@ standard_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
Plan *top_plan;
ListCell *lp,
*lr;
+ MemoryContext temp_context;
+ int i;
+ MemoryContext default_context;
/* Cursor options may come from caller or from DECLARE CURSOR stmt */
if (parse->utilityStmt &&
@@ -432,6 +436,24 @@ standard_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
result->invalItems = glob->invalItems;
result->nParamExec = glob->nParamExec;
+ temp_context = AllocSetContextCreate(CurrentMemoryContext,
+ "TemporaryContext",
+ ALLOCSET_DEFAULT_SIZES);
+
+ /* Test the time impact of creating and destroying 1000 memory contexts. */
+ for (i = 0; i < 1000; i++)
+ {
+ RelOptInfo *rel;
+ default_context = MemoryContextSwitchTo(temp_context);
+ rel = makeNode(RelOptInfo);
+ pfree(rel);
+ MemoryContextSwitchTo(default_context);
+ MemoryContextResetAndDeleteChildren(temp_context);
+ }
+
+ MemoryContextSwitchTo(default_context);
+ MemoryContextDelete(temp_context);
+
return result;
}