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:
@@ -491,20 +491,20 @@ static void
|
||||
check_publications(WalReceiverConn *wrconn, List *publications)
|
||||
{
|
||||
WalRcvExecResult *res;
|
||||
StringInfo cmd;
|
||||
StringInfoData cmd;
|
||||
TupleTableSlot *slot;
|
||||
List *publicationsCopy = NIL;
|
||||
Oid tableRow[1] = {TEXTOID};
|
||||
|
||||
cmd = makeStringInfo();
|
||||
appendStringInfoString(cmd, "SELECT t.pubname FROM\n"
|
||||
initStringInfo(&cmd);
|
||||
appendStringInfoString(&cmd, "SELECT t.pubname FROM\n"
|
||||
" pg_catalog.pg_publication t WHERE\n"
|
||||
" t.pubname IN (");
|
||||
GetPublicationsStr(publications, cmd, true);
|
||||
appendStringInfoChar(cmd, ')');
|
||||
GetPublicationsStr(publications, &cmd, true);
|
||||
appendStringInfoChar(&cmd, ')');
|
||||
|
||||
res = walrcv_exec(wrconn, cmd->data, 1, tableRow);
|
||||
destroyStringInfo(cmd);
|
||||
res = walrcv_exec(wrconn, cmd.data, 1, tableRow);
|
||||
pfree(cmd.data);
|
||||
|
||||
if (res->status != WALRCV_OK_TUPLES)
|
||||
ereport(ERROR,
|
||||
@@ -535,15 +535,17 @@ check_publications(WalReceiverConn *wrconn, List *publications)
|
||||
if (list_length(publicationsCopy))
|
||||
{
|
||||
/* Prepare the list of non-existent publication(s) for error message. */
|
||||
StringInfo pubnames = makeStringInfo();
|
||||
StringInfoData pubnames;
|
||||
|
||||
GetPublicationsStr(publicationsCopy, pubnames, false);
|
||||
initStringInfo(&pubnames);
|
||||
|
||||
GetPublicationsStr(publicationsCopy, &pubnames, false);
|
||||
ereport(WARNING,
|
||||
errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg_plural("publication %s does not exist on the publisher",
|
||||
"publications %s do not exist on the publisher",
|
||||
list_length(publicationsCopy),
|
||||
pubnames->data));
|
||||
pubnames.data));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2885,12 +2887,13 @@ fetch_relation_list(WalReceiverConn *wrconn, List *publications)
|
||||
int server_version = walrcv_server_version(wrconn);
|
||||
bool check_columnlist = (server_version >= 150000);
|
||||
int column_count = check_columnlist ? 4 : 3;
|
||||
StringInfo pub_names = makeStringInfo();
|
||||
StringInfoData pub_names;
|
||||
|
||||
initStringInfo(&cmd);
|
||||
initStringInfo(&pub_names);
|
||||
|
||||
/* Build the pub_names comma-separated string. */
|
||||
GetPublicationsStr(publications, pub_names, true);
|
||||
GetPublicationsStr(publications, &pub_names, true);
|
||||
|
||||
/* Get the list of relations from the publisher */
|
||||
if (server_version >= 160000)
|
||||
@@ -2917,7 +2920,7 @@ fetch_relation_list(WalReceiverConn *wrconn, List *publications)
|
||||
" FROM pg_publication\n"
|
||||
" WHERE pubname IN ( %s )) AS gpt\n"
|
||||
" ON gpt.relid = c.oid\n",
|
||||
pub_names->data);
|
||||
pub_names.data);
|
||||
|
||||
/* From version 19, inclusion of sequences in the target is supported */
|
||||
if (server_version >= 190000)
|
||||
@@ -2926,7 +2929,7 @@ fetch_relation_list(WalReceiverConn *wrconn, List *publications)
|
||||
" SELECT DISTINCT s.schemaname, s.sequencename, " CppAsString2(RELKIND_SEQUENCE) "::\"char\" AS relkind, NULL::int2vector AS attrs\n"
|
||||
" FROM pg_catalog.pg_publication_sequences s\n"
|
||||
" WHERE s.pubname IN ( %s )",
|
||||
pub_names->data);
|
||||
pub_names.data);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2939,10 +2942,10 @@ fetch_relation_list(WalReceiverConn *wrconn, List *publications)
|
||||
|
||||
appendStringInfo(&cmd, "FROM pg_catalog.pg_publication_tables t\n"
|
||||
" WHERE t.pubname IN ( %s )",
|
||||
pub_names->data);
|
||||
pub_names.data);
|
||||
}
|
||||
|
||||
destroyStringInfo(pub_names);
|
||||
pfree(pub_names.data);
|
||||
|
||||
res = walrcv_exec(wrconn, cmd.data, column_count, tableRow);
|
||||
pfree(cmd.data);
|
||||
|
||||
Reference in New Issue
Block a user