Commit 110d8172 authored by David Rowley's avatar David Rowley

Fixup some appendStringInfo and appendPQExpBuffer calls

A number of places were using appendStringInfo() when they could have been
using appendStringInfoString() instead.  While there's no functionality
change there, it's just more efficient to use appendStringInfoString()
when no formatting is required.  Likewise for some
appendStringInfoString() calls which were just appending a single char.
We can just use appendStringInfoChar() for that.

Additionally, many places were using appendPQExpBuffer() when they could
have used appendPQExpBufferStr(). Change those too.

Patch by Zhijie Hou, but further searching by me found significantly more
places that deserved the same treatment.

Author: Zhijie Hou, David Rowley
Discussion: https://postgr.es/m/cb172cf4361e4c7ba7167429070979d4@G08CNEXMBPEKD05.g08.fujitsu.local
parent 73c381ce
......@@ -2591,7 +2591,7 @@ postgresExplainForeignScan(ForeignScanState *node, ExplainState *es)
quote_identifier(relname));
}
else
appendStringInfo(relations, "%s",
appendStringInfoString(relations,
quote_identifier(relname));
refname = (char *) list_nth(es->rtable_names, rti - 1);
if (refname == NULL)
......
......@@ -606,7 +606,7 @@ pg_output_stream_start(LogicalDecodingContext *ctx, TestDecodingData *data, Reor
if (data->include_xids)
appendStringInfo(ctx->out, "opening a streamed block for transaction TXN %u", txn->xid);
else
appendStringInfo(ctx->out, "opening a streamed block for transaction");
appendStringInfoString(ctx->out, "opening a streamed block for transaction");
OutputPluginWrite(ctx, last_write);
}
......@@ -623,7 +623,7 @@ pg_decode_stream_stop(LogicalDecodingContext *ctx,
if (data->include_xids)
appendStringInfo(ctx->out, "closing a streamed block for transaction TXN %u", txn->xid);
else
appendStringInfo(ctx->out, "closing a streamed block for transaction");
appendStringInfoString(ctx->out, "closing a streamed block for transaction");
OutputPluginWrite(ctx, true);
}
......@@ -641,7 +641,7 @@ pg_decode_stream_abort(LogicalDecodingContext *ctx,
if (data->include_xids)
appendStringInfo(ctx->out, "aborting streamed (sub)transaction TXN %u", txn->xid);
else
appendStringInfo(ctx->out, "aborting streamed (sub)transaction");
appendStringInfoString(ctx->out, "aborting streamed (sub)transaction");
OutputPluginWrite(ctx, true);
}
......@@ -660,7 +660,7 @@ pg_decode_stream_commit(LogicalDecodingContext *ctx,
if (data->include_xids)
appendStringInfo(ctx->out, "committing streamed transaction TXN %u", txn->xid);
else
appendStringInfo(ctx->out, "committing streamed transaction");
appendStringInfoString(ctx->out, "committing streamed transaction");
if (data->include_timestamp)
appendStringInfo(ctx->out, " (at %s)",
......@@ -693,7 +693,7 @@ pg_decode_stream_change(LogicalDecodingContext *ctx,
if (data->include_xids)
appendStringInfo(ctx->out, "streaming change for TXN %u", txn->xid);
else
appendStringInfo(ctx->out, "streaming change for transaction");
appendStringInfoString(ctx->out, "streaming change for transaction");
OutputPluginWrite(ctx, true);
}
......@@ -745,6 +745,6 @@ pg_decode_stream_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
if (data->include_xids)
appendStringInfo(ctx->out, "streaming truncate for TXN %u", txn->xid);
else
appendStringInfo(ctx->out, "streaming truncate for transaction");
appendStringInfoString(ctx->out, "streaming truncate for transaction");
OutputPluginWrite(ctx, true);
}
......@@ -37,7 +37,7 @@ dbase_desc(StringInfo buf, XLogReaderState *record)
xl_dbase_drop_rec *xlrec = (xl_dbase_drop_rec *) rec;
int i;
appendStringInfo(buf, "dir");
appendStringInfoString(buf, "dir");
for (i = 0; i < xlrec->ntablespaces; i++)
appendStringInfo(buf, " %u/%u",
xlrec->tablespace_ids[i], xlrec->db_id);
......
......@@ -2768,14 +2768,14 @@ show_incremental_sort_group_info(IncrementalSortGroupInfo *groupInfo,
groupInfo->groupCount);
/* plural/singular based on methodNames size */
if (list_length(methodNames) > 1)
appendStringInfo(es->str, "s: ");
appendStringInfoString(es->str, "s: ");
else
appendStringInfo(es->str, ": ");
appendStringInfoString(es->str, ": ");
foreach(methodCell, methodNames)
{
appendStringInfo(es->str, "%s", (char *) methodCell->ptr_value);
appendStringInfoString(es->str, (char *) methodCell->ptr_value);
if (foreach_current_index(methodCell) < list_length(methodNames) - 1)
appendStringInfo(es->str, ", ");
appendStringInfoString(es->str, ", ");
}
if (groupInfo->maxMemorySpaceUsed > 0)
......@@ -2882,11 +2882,11 @@ show_incremental_sort_info(IncrementalSortState *incrsortstate,
if (prefixsortGroupInfo->groupCount > 0)
{
if (es->format == EXPLAIN_FORMAT_TEXT)
appendStringInfo(es->str, "\n");
appendStringInfoChar(es->str, '\n');
show_incremental_sort_group_info(prefixsortGroupInfo, "Pre-sorted", true, es);
}
if (es->format == EXPLAIN_FORMAT_TEXT)
appendStringInfo(es->str, "\n");
appendStringInfoChar(es->str, '\n');
}
if (incrsortstate->shared_info != NULL)
......@@ -2925,11 +2925,11 @@ show_incremental_sort_info(IncrementalSortState *incrsortstate,
if (prefixsortGroupInfo->groupCount > 0)
{
if (es->format == EXPLAIN_FORMAT_TEXT)
appendStringInfo(es->str, "\n");
appendStringInfoChar(es->str, '\n');
show_incremental_sort_group_info(prefixsortGroupInfo, "Pre-sorted", true, es);
}
if (es->format == EXPLAIN_FORMAT_TEXT)
appendStringInfo(es->str, "\n");
appendStringInfoChar(es->str, '\n');
if (es->workers_state)
ExplainCloseWorker(n, es);
......
......@@ -112,7 +112,7 @@ AddFileToBackupManifest(backup_manifest_info *manifest, const char *spcoid,
initStringInfo(&buf);
if (manifest->first_file)
{
appendStringInfoString(&buf, "\n");
appendStringInfoChar(&buf, '\n');
manifest->first_file = false;
}
else
......@@ -152,7 +152,7 @@ AddFileToBackupManifest(backup_manifest_info *manifest, const char *spcoid,
enlargeStringInfo(&buf, 128);
buf.len += pg_strftime(&buf.data[buf.len], 128, "%Y-%m-%d %H:%M:%S %Z",
pg_gmtime(&mtime));
appendStringInfoString(&buf, "\"");
appendStringInfoChar(&buf, '"');
/* Add checksum information. */
if (checksum_ctx->type != CHECKSUM_TYPE_NONE)
......@@ -168,7 +168,7 @@ AddFileToBackupManifest(backup_manifest_info *manifest, const char *spcoid,
enlargeStringInfo(&buf, 2 * checksumlen);
buf.len += hex_encode((char *) checksumbuf, checksumlen,
&buf.data[buf.len]);
appendStringInfoString(&buf, "\"");
appendStringInfoChar(&buf, '"');
}
/* Close out the object. */
......
......@@ -427,7 +427,7 @@ libpqrcv_startstreaming(WalReceiverConn *conn,
if (options->proto.logical.streaming &&
PQserverVersion(conn->streamConn) >= 140000)
appendStringInfo(&cmd, ", streaming 'on'");
appendStringInfoString(&cmd, ", streaming 'on'");
pubnames = options->proto.logical.publication_names;
pubnames_str = stringlist_to_identifierstr(conn->streamConn, pubnames);
......
......@@ -774,7 +774,7 @@ copy_table(Relation rel)
* For non-tables, we need to do COPY (SELECT ...), but we can't just
* do SELECT * because we need to not copy generated columns.
*/
appendStringInfo(&cmd, "COPY (SELECT ");
appendStringInfoString(&cmd, "COPY (SELECT ");
for (int i = 0; i < lrel.natts; i++)
{
appendStringInfoString(&cmd, quote_identifier(lrel.attnames[i]));
......
......@@ -660,7 +660,7 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
else if (v->content.anybounds.first == v->content.anybounds.last)
{
if (v->content.anybounds.first == PG_UINT32_MAX)
appendStringInfo(buf, "**{last}");
appendStringInfoString(buf, "**{last}");
else
appendStringInfo(buf, "**{%u}",
v->content.anybounds.first);
......
......@@ -1663,7 +1663,7 @@ RI_PartitionRemove_Check(Trigger *trigger, Relation fk_rel, Relation pk_rel)
appendStringInfo(&querybuf, ") WHERE %s AND (",
constraintDef);
else
appendStringInfo(&querybuf, ") WHERE (");
appendStringInfoString(&querybuf, ") WHERE (");
sep = "";
for (i = 0; i < riinfo->nkeys; i++)
......
......@@ -5250,7 +5250,7 @@ get_select_query_def(Query *query, deparse_context *context,
appendContextKeyword(context, " FETCH FIRST ",
-PRETTYINDENT_STD, PRETTYINDENT_STD, 0);
get_rule_expr(query->limitCount, context, false);
appendStringInfo(buf, " ROWS WITH TIES");
appendStringInfoString(buf, " ROWS WITH TIES");
}
else
{
......@@ -11362,7 +11362,7 @@ get_range_partbound_string(List *bound_datums)
memset(&context, 0, sizeof(deparse_context));
context.buf = buf;
appendStringInfoString(buf, "(");
appendStringInfoChar(buf, '(');
sep = "";
foreach(cell, bound_datums)
{
......
......@@ -1375,7 +1375,7 @@ expand_foreign_server_name_patterns(Archive *fout,
for (cell = patterns->head; cell; cell = cell->next)
{
appendPQExpBuffer(query,
appendPQExpBufferStr(query,
"SELECT oid FROM pg_catalog.pg_foreign_server s\n");
processSQLNamePattern(GetConnection(fout), query, cell->val, false,
false, NULL, "s.srvname", NULL, NULL);
......@@ -4250,20 +4250,16 @@ getSubscriptions(Archive *fout)
username_subquery);
if (fout->remoteVersion >= 140000)
appendPQExpBuffer(query,
" s.subbinary,\n");
appendPQExpBufferStr(query, " s.subbinary,\n");
else
appendPQExpBuffer(query,
" false AS subbinary,\n");
appendPQExpBufferStr(query, " false AS subbinary,\n");
if (fout->remoteVersion >= 140000)
appendPQExpBuffer(query,
" s.substream\n");
appendPQExpBufferStr(query, " s.substream\n");
else
appendPQExpBuffer(query,
" false AS substream\n");
appendPQExpBufferStr(query, " false AS substream\n");
appendPQExpBuffer(query,
appendPQExpBufferStr(query,
"FROM pg_subscription s\n"
"WHERE s.subdbid = (SELECT oid FROM pg_database\n"
" WHERE datname = current_database())");
......@@ -4376,10 +4372,10 @@ dumpSubscription(Archive *fout, SubscriptionInfo *subinfo)
appendPQExpBufferStr(query, "NONE");
if (strcmp(subinfo->subbinary, "t") == 0)
appendPQExpBuffer(query, ", binary = true");
appendPQExpBufferStr(query, ", binary = true");
if (strcmp(subinfo->substream, "f") != 0)
appendPQExpBuffer(query, ", streaming = on");
appendPQExpBufferStr(query, ", streaming = on");
if (strcmp(subinfo->subsynccommit, "off") != 0)
appendPQExpBuffer(query, ", synchronous_commit = %s", fmtId(subinfo->subsynccommit));
......@@ -11845,7 +11841,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
asPart = createPQExpBuffer();
/* Fetch function-specific details */
appendPQExpBuffer(query,
appendPQExpBufferStr(query,
"SELECT\n"
"proretset,\n"
"prosrc,\n"
......@@ -11856,12 +11852,12 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
"(SELECT lanname FROM pg_catalog.pg_language WHERE oid = prolang) AS lanname,\n");
if (fout->remoteVersion >= 80300)
appendPQExpBuffer(query,
appendPQExpBufferStr(query,
"proconfig,\n"
"procost,\n"
"prorows,\n");
else
appendPQExpBuffer(query,
appendPQExpBufferStr(query,
"null AS proconfig,\n"
"0 AS procost,\n"
"0 AS prorows,\n");
......@@ -11872,55 +11868,55 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
* In 8.4 and up we rely on pg_get_function_arguments and
* pg_get_function_result instead of examining proallargtypes etc.
*/
appendPQExpBuffer(query,
appendPQExpBufferStr(query,
"pg_catalog.pg_get_function_arguments(oid) AS funcargs,\n"
"pg_catalog.pg_get_function_identity_arguments(oid) AS funciargs,\n"
"pg_catalog.pg_get_function_result(oid) AS funcresult,\n");
}
else if (fout->remoteVersion >= 80100)
appendPQExpBuffer(query,
appendPQExpBufferStr(query,
"proallargtypes,\n"
"proargmodes,\n"
"proargnames,\n");
else
appendPQExpBuffer(query,
appendPQExpBufferStr(query,
"null AS proallargtypes,\n"
"null AS proargmodes,\n"
"proargnames,\n");
if (fout->remoteVersion >= 90200)
appendPQExpBuffer(query,
appendPQExpBufferStr(query,
"proleakproof,\n");
else
appendPQExpBuffer(query,
appendPQExpBufferStr(query,
"false AS proleakproof,\n");
if (fout->remoteVersion >= 90500)
appendPQExpBuffer(query,
appendPQExpBufferStr(query,
"array_to_string(protrftypes, ' ') AS protrftypes,\n");
if (fout->remoteVersion >= 90600)
appendPQExpBuffer(query,
appendPQExpBufferStr(query,
"proparallel,\n");
else
appendPQExpBuffer(query,
appendPQExpBufferStr(query,
"'u' AS proparallel,\n");
if (fout->remoteVersion >= 110000)
appendPQExpBuffer(query,
appendPQExpBufferStr(query,
"prokind,\n");
else if (fout->remoteVersion >= 80400)
appendPQExpBuffer(query,
appendPQExpBufferStr(query,
"CASE WHEN proiswindow THEN 'w' ELSE 'f' END AS prokind,\n");
else
appendPQExpBuffer(query,
appendPQExpBufferStr(query,
"'f' AS prokind,\n");
if (fout->remoteVersion >= 120000)
appendPQExpBuffer(query,
appendPQExpBufferStr(query,
"prosupport\n");
else
appendPQExpBuffer(query,
appendPQExpBufferStr(query,
"'-' AS prosupport\n");
appendPQExpBuffer(query,
......@@ -13891,7 +13887,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo)
details = createPQExpBuffer();
/* Get aggregate-specific details */
appendPQExpBuffer(query,
appendPQExpBufferStr(query,
"SELECT\n"
"aggtransfn,\n"
"aggfinalfn,\n"
......@@ -13899,19 +13895,19 @@ dumpAgg(Archive *fout, AggInfo *agginfo)
"agginitval,\n");
if (fout->remoteVersion >= 80100)
appendPQExpBuffer(query,
appendPQExpBufferStr(query,
"aggsortop,\n");
else
appendPQExpBuffer(query,
appendPQExpBufferStr(query,
"0 AS aggsortop,\n");
if (fout->remoteVersion >= 80400)
appendPQExpBuffer(query,
appendPQExpBufferStr(query,
"pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n"
"pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n");
if (fout->remoteVersion >= 90400)
appendPQExpBuffer(query,
appendPQExpBufferStr(query,
"aggkind,\n"
"aggmtransfn,\n"
"aggminvtransfn,\n"
......@@ -13923,7 +13919,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo)
"aggmtransspace,\n"
"aggminitval,\n");
else
appendPQExpBuffer(query,
appendPQExpBufferStr(query,
"'n' AS aggkind,\n"
"'-' AS aggmtransfn,\n"
"'-' AS aggminvtransfn,\n"
......@@ -13936,24 +13932,24 @@ dumpAgg(Archive *fout, AggInfo *agginfo)
"NULL AS aggminitval,\n");
if (fout->remoteVersion >= 90600)
appendPQExpBuffer(query,
appendPQExpBufferStr(query,
"aggcombinefn,\n"
"aggserialfn,\n"
"aggdeserialfn,\n"
"proparallel,\n");
else
appendPQExpBuffer(query,
appendPQExpBufferStr(query,
"'-' AS aggcombinefn,\n"
"'-' AS aggserialfn,\n"
"'-' AS aggdeserialfn,\n"
"'u' AS proparallel,\n");
if (fout->remoteVersion >= 110000)
appendPQExpBuffer(query,
appendPQExpBufferStr(query,
"aggfinalmodify,\n"
"aggmfinalmodify\n");
else
appendPQExpBuffer(query,
appendPQExpBufferStr(query,
"'0' AS aggfinalmodify,\n"
"'0' AS aggmfinalmodify\n");
......
......@@ -158,13 +158,13 @@ check_for_data_type_usage(ClusterInfo *cluster, const char *typename,
/* Ranges were introduced in 9.2 */
if (GET_MAJOR_VERSION(cluster->major_version) >= 902)
appendPQExpBuffer(&querybuf,
appendPQExpBufferStr(&querybuf,
" UNION ALL "
/* ranges containing any type selected so far */
" SELECT t.oid FROM pg_catalog.pg_type t, pg_catalog.pg_range r, x "
" WHERE t.typtype = 'r' AND r.rngtypid = t.oid AND r.rngsubtype = x.oid");
appendPQExpBuffer(&querybuf,
appendPQExpBufferStr(&querybuf,
" ) foo "
") "
/* now look for stored columns of any such type */
......
......@@ -6137,15 +6137,14 @@ listOperatorClasses(const char *access_method_pattern,
" pg_catalog.pg_get_userbyid(c.opcowner) AS \"%s\"\n",
gettext_noop("Operator family"),
gettext_noop("Owner"));
appendPQExpBuffer(&buf,
appendPQExpBufferStr(&buf,
"\nFROM pg_catalog.pg_opclass c\n"
" LEFT JOIN pg_catalog.pg_am am on am.oid = c.opcmethod\n"
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.opcnamespace\n"
" LEFT JOIN pg_catalog.pg_type t ON t.oid = c.opcintype\n"
" LEFT JOIN pg_catalog.pg_namespace tn ON tn.oid = t.typnamespace\n"
);
" LEFT JOIN pg_catalog.pg_namespace tn ON tn.oid = t.typnamespace\n");
if (verbose)
appendPQExpBuffer(&buf,
appendPQExpBufferStr(&buf,
" LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = c.opcfamily\n"
" LEFT JOIN pg_catalog.pg_namespace ofn ON ofn.oid = of.opfnamespace\n");
......@@ -6216,11 +6215,10 @@ listOperatorFamilies(const char *access_method_pattern,
appendPQExpBuffer(&buf,
",\n pg_catalog.pg_get_userbyid(f.opfowner) AS \"%s\"\n",
gettext_noop("Owner"));
appendPQExpBuffer(&buf,
appendPQExpBufferStr(&buf,
"\nFROM pg_catalog.pg_opfamily f\n"
" LEFT JOIN pg_catalog.pg_am am on am.oid = f.opfmethod\n"
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = f.opfnamespace\n"
);
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = f.opfnamespace\n");
if (access_method_pattern)
have_where = processSQLNamePattern(pset.db, &buf, access_method_pattern,
......@@ -6240,7 +6238,7 @@ listOperatorFamilies(const char *access_method_pattern,
"tn.nspname", "t.typname",
"pg_catalog.format_type(t.oid, NULL)",
"pg_catalog.pg_type_is_visible(t.oid)");
appendPQExpBuffer(&buf, " )\n");
appendPQExpBufferStr(&buf, " )\n");
}
appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
......@@ -6307,13 +6305,13 @@ listOpFamilyOperators(const char *access_method_pattern,
appendPQExpBuffer(&buf,
", ofs.opfname AS \"%s\"\n",
gettext_noop("Sort opfamily"));
appendPQExpBuffer(&buf,
appendPQExpBufferStr(&buf,
"FROM pg_catalog.pg_amop o\n"
" LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = o.amopfamily\n"
" LEFT JOIN pg_catalog.pg_am am ON am.oid = of.opfmethod AND am.oid = o.amopmethod\n"
" LEFT JOIN pg_catalog.pg_namespace nsf ON of.opfnamespace = nsf.oid\n");
if (verbose)
appendPQExpBuffer(&buf,
appendPQExpBufferStr(&buf,
" LEFT JOIN pg_catalog.pg_opfamily ofs ON ofs.oid = o.amopsortfamily\n");
if (access_method_pattern)
......@@ -6393,7 +6391,7 @@ listOpFamilyFunctions(const char *access_method_pattern,
", ap.amproc::pg_catalog.regprocedure AS \"%s\"\n",
gettext_noop("Function"));
appendPQExpBuffer(&buf,
appendPQExpBufferStr(&buf,
"FROM pg_catalog.pg_amproc ap\n"
" LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = ap.amprocfamily\n"
" LEFT JOIN pg_catalog.pg_am am ON am.oid = of.opfmethod\n"
......
......@@ -614,7 +614,7 @@ get_parallel_object_list(PGconn *conn, ReindexType type,
{
case REINDEX_DATABASE:
Assert(user_list == NULL);
appendPQExpBuffer(&catalog_query,
appendPQExpBufferStr(&catalog_query,
"SELECT c.relname, ns.nspname\n"
" FROM pg_catalog.pg_class c\n"
" JOIN pg_catalog.pg_namespace ns"
......@@ -637,7 +637,7 @@ get_parallel_object_list(PGconn *conn, ReindexType type,
* All the tables from all the listed schemas are grabbed at
* once.
*/
appendPQExpBuffer(&catalog_query,
appendPQExpBufferStr(&catalog_query,
"SELECT c.relname, ns.nspname\n"
" FROM pg_catalog.pg_class c\n"
" JOIN pg_catalog.pg_namespace ns"
......@@ -652,14 +652,14 @@ get_parallel_object_list(PGconn *conn, ReindexType type,
const char *nspname = cell->val;
if (nsp_listed)
appendPQExpBuffer(&catalog_query, ", ");
appendPQExpBufferStr(&catalog_query, ", ");
else
nsp_listed = true;
appendStringLiteralConn(&catalog_query, nspname, conn);
}
appendPQExpBuffer(&catalog_query, ")\n"
appendPQExpBufferStr(&catalog_query, ")\n"
" ORDER BY c.relpages DESC;");
}
break;
......
......@@ -216,7 +216,7 @@ PLy_traceback(PyObject *e, PyObject *v, PyObject *tb,
else if (strcmp(e_module_s, "builtins") == 0
|| strcmp(e_module_s, "__main__") == 0
|| strcmp(e_module_s, "exceptions") == 0)
appendStringInfo(&xstr, "%s", e_type_s);
appendStringInfoString(&xstr, e_type_s);
else
appendStringInfo(&xstr, "%s.%s", e_module_s, e_type_s);
appendStringInfo(&xstr, ": %s", vstr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment