From f9e4f0b8d0d60936854d3ef5aef017030bb96759 Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <lic@highgo.com>
Date: Thu, 8 Jan 2026 13:53:56 +0800
Subject: [PATCH v1] Standardize relation name formatting in ANALYZE messages

ANALYZE VERBOSE currently reports relation names in several different
formats within the same command output, such as unqualified names,
schema-qualified names, and fully qualified database.schema.relation
names. This inconsistency is confusing and makes the output harder to
read and parse.

Unify ANALYZE-related messages to consistently use
quote_qualified_identifier(schema, relation) for relation names.

This preserves quoting behavior while providing a stable and consistent
naming format across all ANALYZE output. There is no behavioral change
to ANALYZE itself; this patch only adjusts user-visible message text.

Author: Chao Li <lic@highgo.com>
---
 src/backend/commands/analyze.c | 45 ++++++++++++++++++----------------
 1 file changed, 24 insertions(+), 21 deletions(-)

diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index a483424152c..b979e9b1efb 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -46,6 +46,7 @@
 #include "storage/procarray.h"
 #include "utils/attoptcache.h"
 #include "utils/datum.h"
+#include "utils/builtins.h"
 #include "utils/guc.h"
 #include "utils/lsyscache.h"
 #include "utils/memutils.h"
@@ -95,7 +96,7 @@ static void update_attstats(Oid relid, bool inh,
 							int natts, VacAttrStats **vacattrstats);
 static Datum std_fetch_func(VacAttrStatsP stats, int rownum, bool *isNull);
 static Datum ind_fetch_func(VacAttrStatsP stats, int rownum, bool *isNull);
-
+static const char *format_relation_qualified_name(Relation rel);
 
 /*
  *	analyze_rel() -- analyze one relation
@@ -212,7 +213,7 @@ analyze_rel(Oid relid, RangeVar *relation,
 		{
 			ereport(WARNING,
 					(errmsg("skipping \"%s\" --- cannot analyze this foreign table",
-							RelationGetRelationName(onerel))));
+							format_relation_qualified_name(onerel))));
 			relation_close(onerel, ShareUpdateExclusiveLock);
 			return;
 		}
@@ -229,7 +230,7 @@ analyze_rel(Oid relid, RangeVar *relation,
 		if (!(params.options & VACOPT_VACUUM))
 			ereport(WARNING,
 					(errmsg("skipping \"%s\" --- cannot analyze non-tables or special system tables",
-							RelationGetRelationName(onerel))));
+							format_relation_qualified_name(onerel))));
 		relation_close(onerel, ShareUpdateExclusiveLock);
 		return;
 	}
@@ -319,14 +320,12 @@ do_analyze_rel(Relation onerel, const VacuumParams params,
 							  params.log_analyze_min_duration >= 0));
 	if (inh)
 		ereport(elevel,
-				(errmsg("analyzing \"%s.%s\" inheritance tree",
-						get_namespace_name(RelationGetNamespace(onerel)),
-						RelationGetRelationName(onerel))));
+				(errmsg("analyzing \"%s\" inheritance tree",
+						format_relation_qualified_name(onerel))));
 	else
 		ereport(elevel,
-				(errmsg("analyzing \"%s.%s\"",
-						get_namespace_name(RelationGetNamespace(onerel)),
-						RelationGetRelationName(onerel))));
+				(errmsg("analyzing \"%s\"",
+						format_relation_qualified_name(onerel))));
 
 	/*
 	 * Set up a working context so that we can easily free whatever junk gets
@@ -805,14 +804,12 @@ do_analyze_rel(Relation onerel, const VacuumParams params,
 			initStringInfo(&buf);
 
 			if (AmAutoVacuumWorkerProcess())
-				msgfmt = _("automatic analyze of table \"%s.%s.%s\"\n");
+				msgfmt = _("automatic analyze of table \"%s\"\n");
 			else
-				msgfmt = _("finished analyzing table \"%s.%s.%s\"\n");
+				msgfmt = _("finished analyzing table \"%s\"\n");
 
 			appendStringInfo(&buf, msgfmt,
-							 get_database_name(MyDatabaseId),
-							 get_namespace_name(RelationGetNamespace(onerel)),
-							 RelationGetRelationName(onerel));
+							 format_relation_qualified_name(onerel));
 			if (track_cost_delay_timing)
 			{
 				/*
@@ -1352,7 +1349,7 @@ acquire_sample_rows(Relation onerel, int elevel,
 			(errmsg("\"%s\": scanned %d of %u pages, "
 					"containing %.0f live rows and %.0f dead rows; "
 					"%d rows in sample, %.0f estimated total rows",
-					RelationGetRelationName(onerel),
+					format_relation_qualified_name(onerel),
 					bs.m, totalblocks,
 					liverows, deadrows,
 					numrows, *totalrows)));
@@ -1433,9 +1430,8 @@ acquire_inherited_sample_rows(Relation onerel, int elevel,
 		CommandCounterIncrement();
 		SetRelationHasSubclass(RelationGetRelid(onerel), false);
 		ereport(elevel,
-				(errmsg("skipping analyze of \"%s.%s\" inheritance tree --- this inheritance tree contains no child tables",
-						get_namespace_name(RelationGetNamespace(onerel)),
-						RelationGetRelationName(onerel))));
+				(errmsg("skipping analyze of \"%s\" inheritance tree --- this inheritance tree contains no child tables",
+						format_relation_qualified_name(onerel))));
 		return 0;
 	}
 
@@ -1531,9 +1527,8 @@ acquire_inherited_sample_rows(Relation onerel, int elevel,
 	if (!has_child)
 	{
 		ereport(elevel,
-				(errmsg("skipping analyze of \"%s.%s\" inheritance tree --- this inheritance tree contains no analyzable child tables",
-						get_namespace_name(RelationGetNamespace(onerel)),
-						RelationGetRelationName(onerel))));
+				(errmsg("skipping analyze of \"%s\" inheritance tree --- this inheritance tree contains no analyzable child tables",
+						format_relation_qualified_name(onerel))));
 		return 0;
 	}
 
@@ -3093,3 +3088,11 @@ analyze_mcv_list(int *mcv_counts,
 	}
 	return num_mcv;
 }
+
+static const char *
+format_relation_qualified_name(Relation rel)
+{
+	return quote_qualified_identifier(
+									  get_namespace_name(RelationGetNamespace(rel)),
+									  RelationGetRelationName(rel));
+}
-- 
2.39.5 (Apple Git-154)

