Standardize usages of appendStringInfo and appendPQExpBuffer
authorDavid Rowley <drowley@postgresql.org>
Thu, 3 Jun 2021 04:38:03 +0000 (16:38 +1200)
committerDavid Rowley <drowley@postgresql.org>
Thu, 3 Jun 2021 04:38:03 +0000 (16:38 +1200)
Fix a few places that were using appendStringInfo() when they should have
been using appendStringInfoString().  Also some cases of
appendPQExpBuffer() that would have been better suited to use
appendPQExpBufferChar(), and finally, some places that used
appendPQExpBuffer() when appendPQExpBufferStr() would have suited better.

There are no bugs are being fixed here.  The aim is just to make the code
use the most optimal function for the job.

All the code being changed here is new to PG14.  It makes sense to fix
these before we branch for PG15.  There are a few other places that we
could fix, but those cases are older code so fixing those seems less
worthwhile as it may cause unnecessary back-patching pain in the future.

Author: Hou Zhijie
Discussion: https://postgr.es/m/OS0PR01MB5716732158B1C4142C6FE375943D9@OS0PR01MB5716.jpnprd01.prod.outlook.com

src/backend/access/brin/brin_minmax_multi.c
src/backend/access/heap/vacuumlazy.c
src/bin/pg_amcheck/pg_amcheck.c
src/bin/psql/describe.c

index bd14184d767261bf76a625c390004386977e8a73..c62a3c8ba8c677c6f54f3c55bef02fa025048c96 100644 (file)
@@ -3084,7 +3084,7 @@ brin_minmax_multi_summary_out(PG_FUNCTION_ARGS)
 
        a = FunctionCall1(&fmgrinfo, ranges_deserialized->values[idx++]);
 
-       appendStringInfo(&str, "%s", DatumGetPointer(a));
+       appendStringInfoString(&str, DatumGetPointer(a));
 
        b = cstring_to_text(str.data);
 
index ad3feb88b3be994507bcdd1c8f69d0aaa5e4b257..4b600e951a56af8058b83f7d9735f3bcddbbaeab 100644 (file)
@@ -783,18 +783,18 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
                    msgfmt = _(" %u pages from table (%.2f%% of total) had %lld dead item identifiers removed\n");
 
                    if (vacrel->nindexes == 0 || vacrel->num_index_scans == 0)
-                       appendStringInfo(&buf, _("index scan not needed:"));
+                       appendStringInfoString(&buf, _("index scan not needed:"));
                    else
-                       appendStringInfo(&buf, _("index scan needed:"));
+                       appendStringInfoString(&buf, _("index scan needed:"));
                }
                else
                {
                    msgfmt = _(" %u pages from table (%.2f%% of total) have %lld dead item identifiers\n");
 
                    if (!vacrel->do_failsafe)
-                       appendStringInfo(&buf, _("index scan bypassed:"));
+                       appendStringInfoString(&buf, _("index scan bypassed:"));
                    else
-                       appendStringInfo(&buf, _("index scan bypassed by failsafe:"));
+                       appendStringInfoString(&buf, _("index scan bypassed by failsafe:"));
                }
                orig_rel_pages = vacrel->rel_pages + vacrel->pages_removed;
                appendStringInfo(&buf, msgfmt,
index 37103e18cbe8516441a0e0dfd1297e547350810c..6b97d635c3217f0bd09958182b0d3d6da71888eb 100644 (file)
@@ -844,7 +844,7 @@ prepare_heap_command(PQExpBuffer sql, RelationInfo *rel, PGconn *conn)
    if (opts.endblock >= 0)
        appendPQExpBuffer(sql, ", endblock := " INT64_FORMAT, opts.endblock);
 
-   appendPQExpBuffer(sql, ")");
+   appendPQExpBufferChar(sql, ')');
 }
 
 /*
index 195f8d8cd2d32e406f82ab6b3002217d45d86b2a..2abf255798c0d20953d1c15f008de9f8c16be845 100644 (file)
@@ -2934,7 +2934,7 @@ describeOneTableDetails(const char *schemaname,
 
                    if (has_some && !has_all)
                    {
-                       appendPQExpBuffer(&buf, " (");
+                       appendPQExpBufferStr(&buf, " (");
 
                        /* options */
                        if (has_ndistinct)
@@ -2954,7 +2954,7 @@ describeOneTableDetails(const char *schemaname,
                            appendPQExpBuffer(&buf, "%smcv", gotone ? ", " : "");
                        }
 
-                       appendPQExpBuffer(&buf, ")");
+                       appendPQExpBufferChar(&buf, ')');
                    }
 
                    appendPQExpBuffer(&buf, " ON %s FROM %s",
@@ -3577,7 +3577,7 @@ describeOneTableDetails(const char *schemaname,
                    child_relkind == RELKIND_PARTITIONED_INDEX)
                    appendPQExpBufferStr(&buf, ", PARTITIONED");
                if (strcmp(PQgetvalue(result, i, 2), "t") == 0)
-                   appendPQExpBuffer(&buf, " (DETACH PENDING)");
+                   appendPQExpBufferStr(&buf, " (DETACH PENDING)");
                if (i < tuples - 1)
                    appendPQExpBufferChar(&buf, ',');