aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-08-27 17:50:38 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2016-08-27 17:50:38 -0400
commitb9fe6cbc81ea120a39be755f23d6615486c11618 (patch)
tree1f7b860f3877d4d7f6e9ccbf99af8ab237c3d59d /src/backend/commands
parente796d0abab0f9508326c0aa721fe1475548fbe4e (diff)
downloadpostgresql-b9fe6cbc81ea120a39be755f23d6615486c11618.tar.gz
postgresql-b9fe6cbc81ea120a39be755f23d6615486c11618.zip
Add macros to make AllocSetContextCreate() calls simpler and safer.
I found that half a dozen (nearly 5%) of our AllocSetContextCreate calls had typos in the context-sizing parameters. While none of these led to especially significant problems, they did create minor inefficiencies, and it's now clear that expecting people to copy-and-paste those calls accurately is not a great idea. Let's reduce the risk of future errors by introducing single macros that encapsulate the common use-cases. Three such macros are enough to cover all but two special-purpose contexts; those two calls can be left as-is, I think. While this patch doesn't in itself improve matters for third-party extensions, it doesn't break anything for them either, and they can gradually adopt the simplified notation over time. In passing, change TopMemoryContext to use the default allocation parameters. Formerly it could only be extended 8K at a time. That was probably reasonable when this code was written; but nowadays we create many more contexts than we did then, so that it's not unusual to have a couple hundred K in TopMemoryContext, even without considering various dubious code that sticks other things there. There seems no good reason not to let it use growing blocks like most other contexts. Back-patch to 9.6, mostly because that's still close enough to HEAD that it's easy to do so, and keeping the branches in sync can be expected to avoid some future back-patching pain. The bugs fixed by these changes don't seem to be significant enough to justify fixing them further back. Discussion: <21072.1472321324@sss.pgh.pa.us>
Diffstat (limited to 'src/backend/commands')
-rw-r--r--src/backend/commands/analyze.c12
-rw-r--r--src/backend/commands/cluster.c4
-rw-r--r--src/backend/commands/copy.c8
-rw-r--r--src/backend/commands/event_trigger.c8
-rw-r--r--src/backend/commands/indexcmds.c4
-rw-r--r--src/backend/commands/policy.c4
-rw-r--r--src/backend/commands/trigger.c8
-rw-r--r--src/backend/commands/vacuum.c4
8 files changed, 13 insertions, 39 deletions
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index 9ac71220a2a..c617abb223b 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -332,9 +332,7 @@ do_analyze_rel(Relation onerel, int options, VacuumParams *params,
*/
anl_context = AllocSetContextCreate(CurrentMemoryContext,
"Analyze",
- ALLOCSET_DEFAULT_MINSIZE,
- ALLOCSET_DEFAULT_INITSIZE,
- ALLOCSET_DEFAULT_MAXSIZE);
+ ALLOCSET_DEFAULT_SIZES);
caller_context = MemoryContextSwitchTo(anl_context);
/*
@@ -504,9 +502,7 @@ do_analyze_rel(Relation onerel, int options, VacuumParams *params,
col_context = AllocSetContextCreate(anl_context,
"Analyze Column",
- ALLOCSET_DEFAULT_MINSIZE,
- ALLOCSET_DEFAULT_INITSIZE,
- ALLOCSET_DEFAULT_MAXSIZE);
+ ALLOCSET_DEFAULT_SIZES);
old_context = MemoryContextSwitchTo(col_context);
for (i = 0; i < attr_cnt; i++)
@@ -688,9 +684,7 @@ compute_index_stats(Relation onerel, double totalrows,
ind_context = AllocSetContextCreate(anl_context,
"Analyze Index",
- ALLOCSET_DEFAULT_MINSIZE,
- ALLOCSET_DEFAULT_INITSIZE,
- ALLOCSET_DEFAULT_MAXSIZE);
+ ALLOCSET_DEFAULT_SIZES);
old_context = MemoryContextSwitchTo(ind_context);
for (ind = 0; ind < nindexes; ind++)
diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c
index 43bbd905919..dc1f79f5948 100644
--- a/src/backend/commands/cluster.c
+++ b/src/backend/commands/cluster.c
@@ -204,9 +204,7 @@ cluster(ClusterStmt *stmt, bool isTopLevel)
*/
cluster_context = AllocSetContextCreate(PortalContext,
"Cluster",
- ALLOCSET_DEFAULT_MINSIZE,
- ALLOCSET_DEFAULT_INITSIZE,
- ALLOCSET_DEFAULT_MAXSIZE);
+ ALLOCSET_DEFAULT_SIZES);
/*
* Build the list of relations to cluster. Note that this lives in
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index f45b3304ae9..5947e720934 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -1340,9 +1340,7 @@ BeginCopy(bool is_from,
*/
cstate->copycontext = AllocSetContextCreate(CurrentMemoryContext,
"COPY",
- ALLOCSET_DEFAULT_MINSIZE,
- ALLOCSET_DEFAULT_INITSIZE,
- ALLOCSET_DEFAULT_MAXSIZE);
+ ALLOCSET_DEFAULT_SIZES);
oldcontext = MemoryContextSwitchTo(cstate->copycontext);
@@ -1895,9 +1893,7 @@ CopyTo(CopyState cstate)
*/
cstate->rowcontext = AllocSetContextCreate(CurrentMemoryContext,
"COPY TO",
- ALLOCSET_DEFAULT_MINSIZE,
- ALLOCSET_DEFAULT_INITSIZE,
- ALLOCSET_DEFAULT_MAXSIZE);
+ ALLOCSET_DEFAULT_SIZES);
if (cstate->binary)
{
diff --git a/src/backend/commands/event_trigger.c b/src/backend/commands/event_trigger.c
index 50c89b827b2..ac4c4ecbe77 100644
--- a/src/backend/commands/event_trigger.c
+++ b/src/backend/commands/event_trigger.c
@@ -1018,9 +1018,7 @@ EventTriggerInvoke(List *fn_oid_list, EventTriggerData *trigdata)
*/
context = AllocSetContextCreate(CurrentMemoryContext,
"event trigger context",
- ALLOCSET_DEFAULT_MINSIZE,
- ALLOCSET_DEFAULT_INITSIZE,
- ALLOCSET_DEFAULT_MAXSIZE);
+ ALLOCSET_DEFAULT_SIZES);
oldcontext = MemoryContextSwitchTo(context);
/* Call each event trigger. */
@@ -1226,9 +1224,7 @@ EventTriggerBeginCompleteQuery(void)
cxt = AllocSetContextCreate(TopMemoryContext,
"event trigger state",
- ALLOCSET_DEFAULT_MINSIZE,
- ALLOCSET_DEFAULT_INITSIZE,
- ALLOCSET_DEFAULT_MAXSIZE);
+ ALLOCSET_DEFAULT_SIZES);
state = MemoryContextAlloc(cxt, sizeof(EventTriggerQueryState));
state->cxt = cxt;
slist_init(&(state->SQLDropList));
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index d14d540b26e..85817c65302 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -1903,9 +1903,7 @@ ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind,
*/
private_context = AllocSetContextCreate(PortalContext,
"ReindexMultipleTables",
- ALLOCSET_DEFAULT_MINSIZE,
- ALLOCSET_DEFAULT_INITSIZE,
- ALLOCSET_DEFAULT_MAXSIZE);
+ ALLOCSET_SMALL_SIZES);
/*
* Define the search keys to find the objects to reindex. For a schema, we
diff --git a/src/backend/commands/policy.c b/src/backend/commands/policy.c
index bc2e4af82a3..d694cf80be3 100644
--- a/src/backend/commands/policy.c
+++ b/src/backend/commands/policy.c
@@ -201,9 +201,7 @@ RelationBuildRowSecurity(Relation relation)
*/
rscxt = AllocSetContextCreate(CacheMemoryContext,
"row security descriptor",
- ALLOCSET_SMALL_MINSIZE,
- ALLOCSET_SMALL_INITSIZE,
- ALLOCSET_SMALL_MAXSIZE);
+ ALLOCSET_SMALL_SIZES);
/*
* Since rscxt lives under CacheMemoryContext, it is long-lived. Use a
diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c
index 99a659a1027..9de22a13d75 100644
--- a/src/backend/commands/trigger.c
+++ b/src/backend/commands/trigger.c
@@ -3339,9 +3339,7 @@ afterTriggerAddEvent(AfterTriggerEventList *events,
afterTriggers.event_cxt =
AllocSetContextCreate(TopTransactionContext,
"AfterTriggerEvents",
- ALLOCSET_DEFAULT_MINSIZE,
- ALLOCSET_DEFAULT_INITSIZE,
- ALLOCSET_DEFAULT_MAXSIZE);
+ ALLOCSET_DEFAULT_SIZES);
/*
* Chunk size starts at 1KB and is allowed to increase up to 1MB.
@@ -3780,9 +3778,7 @@ afterTriggerInvokeEvents(AfterTriggerEventList *events,
per_tuple_context =
AllocSetContextCreate(CurrentMemoryContext,
"AfterTriggerTupleContext",
- ALLOCSET_DEFAULT_MINSIZE,
- ALLOCSET_DEFAULT_INITSIZE,
- ALLOCSET_DEFAULT_MAXSIZE);
+ ALLOCSET_DEFAULT_SIZES);
for_each_chunk(chunk, *events)
{
diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c
index 0563e634743..58bbf5548bc 100644
--- a/src/backend/commands/vacuum.c
+++ b/src/backend/commands/vacuum.c
@@ -209,9 +209,7 @@ vacuum(int options, RangeVar *relation, Oid relid, VacuumParams *params,
*/
vac_context = AllocSetContextCreate(PortalContext,
"Vacuum",
- ALLOCSET_DEFAULT_MINSIZE,
- ALLOCSET_DEFAULT_INITSIZE,
- ALLOCSET_DEFAULT_MAXSIZE);
+ ALLOCSET_DEFAULT_SIZES);
/*
* If caller didn't give us a buffer strategy object, make one in the