Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8461424

Browse files
committed
Fixup various StringInfo function usages
This adjusts various appendStringInfo* function calls to use a more appropriate and efficient function with the same behavior. For example, use appendStringInfoChar() when appending a single character rather than appendStringInfo() and appendStringInfoString() when no formatting is required rather than using appendStringInfo(). All adjustments made here are in code that's new to v17, so it makes sense to fix these now rather than wait a few years and make backpatching harder. Discussion: https://postgr.es/m/CAApHDvojY2UvMiO+9_55ArTj10P1LBNJyyoGB+C65BLDNT0GsQ@mail.gmail.com Reviewed-by: Nathan Bossart, Tom Lane
1 parent ff9f72c commit 8461424

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

contrib/postgres_fdw/deparse.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1887,7 +1887,7 @@ deparseFromExprForRel(StringInfo buf, PlannerInfo *root, RelOptInfo *foreignrel,
18871887
}
18881888

18891889
/* Close parentheses for EXISTS subquery */
1890-
appendStringInfo(&str, ")");
1890+
appendStringInfoChar(&str, ')');
18911891

18921892
*additional_conds = lappend(*additional_conds, str.data);
18931893
}
@@ -1921,7 +1921,7 @@ deparseFromExprForRel(StringInfo buf, PlannerInfo *root, RelOptInfo *foreignrel,
19211921
*/
19221922
if (fpinfo->jointype == JOIN_SEMI)
19231923
{
1924-
appendStringInfo(buf, "%s", join_sql_o.data);
1924+
appendBinaryStringInfo(buf, join_sql_o.data, join_sql_o.len);
19251925
}
19261926
else
19271927
{

src/backend/replication/logical/slotsync.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,7 @@ ReplSlotSyncWorkerMain(char *startup_data, size_t startup_data_len)
13111311
if (cluster_name[0])
13121312
appendStringInfo(&app_name, "%s_%s", cluster_name, "slotsync worker");
13131313
else
1314-
appendStringInfo(&app_name, "%s", "slotsync worker");
1314+
appendStringInfoString(&app_name, "slotsync worker");
13151315

13161316
/*
13171317
* Establish the connection to the primary server for slot

src/backend/replication/logical/tablesync.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ copy_table(Relation rel)
11541154
appendStringInfoString(&cmd, quote_identifier(lrel.attnames[i]));
11551155
}
11561156

1157-
appendStringInfoString(&cmd, ")");
1157+
appendStringInfoChar(&cmd, ')');
11581158
}
11591159

11601160
appendStringInfoString(&cmd, " TO STDOUT");

src/backend/utils/adt/ri_triggers.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -426,13 +426,13 @@ RI_FKey_check(TriggerData *trigdata)
426426
{
427427
Oid fk_type = RIAttType(fk_rel, riinfo->fk_attnums[riinfo->nkeys - 1]);
428428

429-
appendStringInfo(&querybuf, ") x1 HAVING ");
429+
appendStringInfoString(&querybuf, ") x1 HAVING ");
430430
sprintf(paramname, "$%d", riinfo->nkeys);
431431
ri_GenerateQual(&querybuf, "",
432432
paramname, fk_type,
433433
riinfo->agged_period_contained_by_oper,
434434
"pg_catalog.range_agg", ANYMULTIRANGEOID);
435-
appendStringInfo(&querybuf, "(x1.r)");
435+
appendStringInfoString(&querybuf, "(x1.r)");
436436
}
437437

438438
/* Prepare and save the plan */
@@ -594,13 +594,13 @@ ri_Check_Pk_Match(Relation pk_rel, Relation fk_rel,
594594
{
595595
Oid fk_type = RIAttType(fk_rel, riinfo->fk_attnums[riinfo->nkeys - 1]);
596596

597-
appendStringInfo(&querybuf, ") x1 HAVING ");
597+
appendStringInfoString(&querybuf, ") x1 HAVING ");
598598
sprintf(paramname, "$%d", riinfo->nkeys);
599599
ri_GenerateQual(&querybuf, "",
600600
paramname, fk_type,
601601
riinfo->agged_period_contained_by_oper,
602602
"pg_catalog.range_agg", ANYMULTIRANGEOID);
603-
appendStringInfo(&querybuf, "(x1.r)");
603+
appendStringInfoString(&querybuf, "(x1.r)");
604604
}
605605

606606
/* Prepare and save the plan */

src/backend/utils/adt/ruleutils.c

+10-10
Original file line numberDiff line numberDiff line change
@@ -7176,16 +7176,16 @@ get_merge_query_def(Query *query, deparse_context *context,
71767176
switch (action->matchKind)
71777177
{
71787178
case MERGE_WHEN_MATCHED:
7179-
appendStringInfo(buf, "MATCHED");
7179+
appendStringInfoString(buf, "MATCHED");
71807180
break;
71817181
case MERGE_WHEN_NOT_MATCHED_BY_SOURCE:
7182-
appendStringInfo(buf, "NOT MATCHED BY SOURCE");
7182+
appendStringInfoString(buf, "NOT MATCHED BY SOURCE");
71837183
break;
71847184
case MERGE_WHEN_NOT_MATCHED_BY_TARGET:
71857185
if (haveNotMatchedBySource)
7186-
appendStringInfo(buf, "NOT MATCHED BY TARGET");
7186+
appendStringInfoString(buf, "NOT MATCHED BY TARGET");
71877187
else
7188-
appendStringInfo(buf, "NOT MATCHED");
7188+
appendStringInfoString(buf, "NOT MATCHED");
71897189
break;
71907190
default:
71917191
elog(ERROR, "unrecognized matchKind: %d",
@@ -8850,18 +8850,18 @@ get_json_expr_options(JsonExpr *jsexpr, deparse_context *context,
88508850
if (jsexpr->op == JSON_QUERY_OP)
88518851
{
88528852
if (jsexpr->wrapper == JSW_CONDITIONAL)
8853-
appendStringInfo(context->buf, " WITH CONDITIONAL WRAPPER");
8853+
appendStringInfoString(context->buf, " WITH CONDITIONAL WRAPPER");
88548854
else if (jsexpr->wrapper == JSW_UNCONDITIONAL)
8855-
appendStringInfo(context->buf, " WITH UNCONDITIONAL WRAPPER");
8855+
appendStringInfoString(context->buf, " WITH UNCONDITIONAL WRAPPER");
88568856
/* The default */
88578857
else if (jsexpr->wrapper == JSW_NONE || jsexpr->wrapper == JSW_UNSPEC)
8858-
appendStringInfo(context->buf, " WITHOUT WRAPPER");
8858+
appendStringInfoString(context->buf, " WITHOUT WRAPPER");
88598859

88608860
if (jsexpr->omit_quotes)
8861-
appendStringInfo(context->buf, " OMIT QUOTES");
8861+
appendStringInfoString(context->buf, " OMIT QUOTES");
88628862
/* The default */
88638863
else
8864-
appendStringInfo(context->buf, " KEEP QUOTES");
8864+
appendStringInfoString(context->buf, " KEEP QUOTES");
88658865
}
88668866

88678867
if (jsexpr->on_empty && jsexpr->on_empty->btype != default_behavior)
@@ -10206,7 +10206,7 @@ get_rule_expr(Node *node, deparse_context *context,
1020610206
JSON_BEHAVIOR_NULL :
1020710207
JSON_BEHAVIOR_FALSE);
1020810208

10209-
appendStringInfoString(buf, ")");
10209+
appendStringInfoChar(buf, ')');
1021010210
}
1021110211
break;
1021210212

0 commit comments

Comments
 (0)