mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
Use stack allocated StringInfoDatas, where possible
Various places that were using StringInfo but didn't need that StringInfo to exist beyond the scope of the function were using makeStringInfo(), which allocates both a StringInfoData and the buffer it uses as two separate allocations. It's more efficient for these cases to use a StringInfoData on the stack and initialize it with initStringInfo(), which only allocates the string buffer. This also simplifies the cleanup, in a few cases. Author: Mats Kindahl <mats.kindahl@gmail.com> Reviewed-by: David Rowley <dgrowleyml@gmail.com> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Discussion: https://postgr.es/m/4379aac8-26f1-42f2-a356-ff0e886228d3@gmail.com
This commit is contained in:
@@ -2841,7 +2841,7 @@ postgresExplainForeignScan(ForeignScanState *node, ExplainState *es)
|
||||
*/
|
||||
if (list_length(fdw_private) > FdwScanPrivateRelations)
|
||||
{
|
||||
StringInfo relations;
|
||||
StringInfoData relations;
|
||||
char *rawrelations;
|
||||
char *ptr;
|
||||
int minrti,
|
||||
@@ -2875,7 +2875,7 @@ postgresExplainForeignScan(ForeignScanState *node, ExplainState *es)
|
||||
rtoffset = bms_next_member(plan->fs_base_relids, -1) - minrti;
|
||||
|
||||
/* Now we can translate the string */
|
||||
relations = makeStringInfo();
|
||||
initStringInfo(&relations);
|
||||
ptr = rawrelations;
|
||||
while (*ptr)
|
||||
{
|
||||
@@ -2897,24 +2897,24 @@ postgresExplainForeignScan(ForeignScanState *node, ExplainState *es)
|
||||
char *namespace;
|
||||
|
||||
namespace = get_namespace_name_or_temp(get_rel_namespace(rte->relid));
|
||||
appendStringInfo(relations, "%s.%s",
|
||||
appendStringInfo(&relations, "%s.%s",
|
||||
quote_identifier(namespace),
|
||||
quote_identifier(relname));
|
||||
}
|
||||
else
|
||||
appendStringInfoString(relations,
|
||||
appendStringInfoString(&relations,
|
||||
quote_identifier(relname));
|
||||
refname = (char *) list_nth(es->rtable_names, rti - 1);
|
||||
if (refname == NULL)
|
||||
refname = rte->eref->aliasname;
|
||||
if (strcmp(refname, relname) != 0)
|
||||
appendStringInfo(relations, " %s",
|
||||
appendStringInfo(&relations, " %s",
|
||||
quote_identifier(refname));
|
||||
}
|
||||
else
|
||||
appendStringInfoChar(relations, *ptr++);
|
||||
appendStringInfoChar(&relations, *ptr++);
|
||||
}
|
||||
ExplainPropertyText("Relations", relations->data, es);
|
||||
ExplainPropertyText("Relations", relations.data, es);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -66,12 +66,13 @@ triggered_change_notification(PG_FUNCTION_ARGS)
|
||||
TupleDesc tupdesc;
|
||||
char *channel;
|
||||
char operation;
|
||||
StringInfo payload = makeStringInfo();
|
||||
StringInfoData payload;
|
||||
bool foundPK;
|
||||
|
||||
List *indexoidlist;
|
||||
ListCell *indexoidscan;
|
||||
|
||||
initStringInfo(&payload);
|
||||
/* make sure it's called as a trigger */
|
||||
if (!CALLED_AS_TRIGGER(fcinfo))
|
||||
ereport(ERROR,
|
||||
@@ -149,22 +150,22 @@ triggered_change_notification(PG_FUNCTION_ARGS)
|
||||
|
||||
foundPK = true;
|
||||
|
||||
strcpy_quoted(payload, RelationGetRelationName(rel), '"');
|
||||
appendStringInfoCharMacro(payload, ',');
|
||||
appendStringInfoCharMacro(payload, operation);
|
||||
strcpy_quoted(&payload, RelationGetRelationName(rel), '"');
|
||||
appendStringInfoCharMacro(&payload, ',');
|
||||
appendStringInfoCharMacro(&payload, operation);
|
||||
|
||||
for (i = 0; i < indnkeyatts; i++)
|
||||
{
|
||||
int colno = index->indkey.values[i];
|
||||
Form_pg_attribute attr = TupleDescAttr(tupdesc, colno - 1);
|
||||
|
||||
appendStringInfoCharMacro(payload, ',');
|
||||
strcpy_quoted(payload, NameStr(attr->attname), '"');
|
||||
appendStringInfoCharMacro(payload, '=');
|
||||
strcpy_quoted(payload, SPI_getvalue(trigtuple, tupdesc, colno), '\'');
|
||||
appendStringInfoCharMacro(&payload, ',');
|
||||
strcpy_quoted(&payload, NameStr(attr->attname), '"');
|
||||
appendStringInfoCharMacro(&payload, '=');
|
||||
strcpy_quoted(&payload, SPI_getvalue(trigtuple, tupdesc, colno), '\'');
|
||||
}
|
||||
|
||||
Async_Notify(channel, payload->data);
|
||||
Async_Notify(channel, payload.data);
|
||||
}
|
||||
ReleaseSysCache(indexTuple);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user