Hi, The proposed patch removes make_temptable_name_n() in matview.c. This function is used only once and can be replaced with psprintf().
-- Best regards, Aleksander Alekseev
From 6f2084f4663173c35f3d7f06f4f6a941d37c3ca1 Mon Sep 17 00:00:00 2001 From: Aleksander Alekseev <[email protected]> Date: Wed, 8 Oct 2025 17:11:54 +0300 Subject: [PATCH v1] Remove make_temptable_name_n() The named function is used in matview.c only once and doesn't do much. Replace it with a simple psprintf() call. Author: Aleksander Alekseev <[email protected]> Reviewed-by: TODO FIXME Discussion: TODO FIXME --- src/backend/commands/matview.c | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/src/backend/commands/matview.c b/src/backend/commands/matview.c index 441de55ac24..961cd8c6242 100644 --- a/src/backend/commands/matview.c +++ b/src/backend/commands/matview.c @@ -61,7 +61,6 @@ static void transientrel_shutdown(DestReceiver *self); static void transientrel_destroy(DestReceiver *self); static uint64 refresh_matview_datafill(DestReceiver *dest, Query *query, const char *queryString, bool is_create); -static char *make_temptable_name_n(char *tempname, int n); static void refresh_by_match_merge(Oid matviewOid, Oid tempOid, Oid relowner, int save_sec_context); static void refresh_by_heap_swap(Oid matviewOid, Oid OIDNewHeap, char relpersistence); @@ -556,28 +555,6 @@ transientrel_destroy(DestReceiver *self) pfree(self); } - -/* - * Given a qualified temporary table name, append an underscore followed by - * the given integer, to make a new table name based on the old one. - * The result is a palloc'd string. - * - * As coded, this would fail to make a valid SQL name if the given name were, - * say, "FOO"."BAR". Currently, the table name portion of the input will - * never be double-quoted because it's of the form "pg_temp_NNN", cf - * make_new_heap(). But we might have to work harder someday. - */ -static char * -make_temptable_name_n(char *tempname, int n) -{ - StringInfoData namebuf; - - initStringInfo(&namebuf); - appendStringInfoString(&namebuf, tempname); - appendStringInfo(&namebuf, "_%d", n); - return namebuf.data; -} - /* * refresh_by_match_merge * @@ -634,7 +611,7 @@ refresh_by_match_merge(Oid matviewOid, Oid tempOid, Oid relowner, tempRel = table_open(tempOid, NoLock); tempname = quote_qualified_identifier(get_namespace_name(RelationGetNamespace(tempRel)), RelationGetRelationName(tempRel)); - diffname = make_temptable_name_n(tempname, 2); + diffname = psprintf("%s_%d", tempname, 2); relnatts = RelationGetNumberOfAttributes(matviewRel); -- 2.43.0
