From 90af8a5804a82fed5a093131ec9c0890212465b4 Mon Sep 17 00:00:00 2001
From: Corey Huinker <corey.huinker@gmail.com>
Date: Tue, 11 Aug 2026 13:00:33 -0400
Subject: [PATCH v1] Rename postgres_fdw option restore_stats to import_stats

The new option restore_stats was named so because it was calling
pg_restore_relation_stats() and pg_restore_attribute_stats() in place of
fetching a remote rowsample.  However, those codes path have been
replaced with calls to import_relation_statistics() and
import_attribute_statistics(), so the "restore_stats" options on the
foreign server and foreign table are now slightly misnamed.

Switch both options to "import_stats", which more closely reflects both
the functions being called internally, and the user's perception of what
the operation is doing.
---
 doc/src/sgml/postgres-fdw.sgml                 |  6 +++---
 contrib/postgres_fdw/expected/postgres_fdw.out |  6 +++---
 contrib/postgres_fdw/option.c                  |  8 ++++----
 contrib/postgres_fdw/postgres_fdw.c            | 16 ++++++++--------
 contrib/postgres_fdw/sql/postgres_fdw.sql      |  6 +++---
 5 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/doc/src/sgml/postgres-fdw.sgml b/doc/src/sgml/postgres-fdw.sgml
index 8b0669f672d..171a009b610 100644
--- a/doc/src/sgml/postgres-fdw.sgml
+++ b/doc/src/sgml/postgres-fdw.sgml
@@ -365,13 +365,13 @@ OPTIONS (ADD password_required 'false');
     </varlistentry>
 
     <varlistentry>
-     <term><literal>restore_stats</literal> (<type>boolean</type>)</term>
+     <term><literal>import_stats</literal> (<type>boolean</type>)</term>
      <listitem>
       <para>
        This option, which can be specified for a foreign table or a foreign
        server, determines if <command>ANALYZE</command> on a foreign table
        will instead attempt to fetch the existing statistics for the foreign
-       table on the remote server, and restore those statistics directly to
+       table on the remote server, and import those statistics directly to
        the local server.  If the attempt failed, statistics are collected by
        row sampling on the foreign table.
        This option is only useful if the remote table is one that can have
@@ -386,7 +386,7 @@ OPTIONS (ADD password_required 'false');
        If the foreign table is a partition of a partitioned table, analyzing
        the partitioned table will still result in row sampling on the foreign
        table regardless of this setting, though direct analysis of the foreign
-       table would have attempted to fetch and restore remote statistics first.
+       table would have attempted to fetch and import remote statistics first.
       </para>
      </listitem>
     </varlistentry>
diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index 5a77671d35f..d5390ef62d0 100644
--- a/contrib/postgres_fdw/expected/postgres_fdw.out
+++ b/contrib/postgres_fdw/expected/postgres_fdw.out
@@ -13110,7 +13110,7 @@ CREATE TABLE simport_table (c1 int, c2 text);
 CREATE FOREIGN TABLE simport_ftable (c1 int, c2 text, cx int)
        SERVER loopback OPTIONS (table_name 'simport_table');
 ALTER FOREIGN TABLE simport_ftable ALTER COLUMN cx OPTIONS (ADD column_name 'c1');
-ALTER FOREIGN TABLE simport_ftable OPTIONS (ADD restore_stats 'true');
+ALTER FOREIGN TABLE simport_ftable OPTIONS (ADD import_stats 'true');
 ANALYZE simport_ftable;                   -- should fail
 WARNING:  could not import statistics for foreign table "public.simport_ftable" --- remote table "public.simport_table" has no relation statistics to import
 ANALYZE simport_table;
@@ -13195,14 +13195,14 @@ ERROR:  column "c1" of relation "simport_ftable" appears more than once
 CREATE VIEW simport_view AS SELECT * FROM simport_table;
 CREATE FOREIGN TABLE simport_fview (c1 int, c2 text)
        SERVER loopback OPTIONS (table_name 'simport_view');
-ALTER FOREIGN TABLE simport_fview OPTIONS (ADD restore_stats 'true');
+ALTER FOREIGN TABLE simport_fview OPTIONS (ADD import_stats 'true');
 ANALYZE simport_fview;                    -- should fail
 WARNING:  could not import statistics for foreign table "public.simport_fview" --- remote table "public.simport_view" is of relkind "v" which cannot have statistics
 -- This tests build_remattrmap()'s deparsing of column names that include
 -- single quotes or backslashes
 CREATE TABLE dtest_table ("col'quote" int, "col\backslash" int);
 CREATE FOREIGN TABLE dtest_ftable ("col'quote" int, "col\backslash" int)
-       SERVER loopback OPTIONS (table_name 'dtest_table', restore_stats 'true');
+       SERVER loopback OPTIONS (table_name 'dtest_table', import_stats 'true');
 INSERT INTO dtest_table SELECT g, g FROM generate_series(1, 10) g;
 ANALYZE dtest_table;
 ANALYZE VERBOSE dtest_ftable;             -- should work
diff --git a/contrib/postgres_fdw/option.c b/contrib/postgres_fdw/option.c
index 79b16c3f318..5b539c4eeef 100644
--- a/contrib/postgres_fdw/option.c
+++ b/contrib/postgres_fdw/option.c
@@ -121,7 +121,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 			strcmp(def->defname, "parallel_commit") == 0 ||
 			strcmp(def->defname, "parallel_abort") == 0 ||
 			strcmp(def->defname, "keep_connections") == 0 ||
-			strcmp(def->defname, "restore_stats") == 0 ||
+			strcmp(def->defname, "import_stats") == 0 ||
 			strcmp(def->defname, "use_scram_passthrough") == 0)
 		{
 			/* these accept only boolean values */
@@ -276,9 +276,9 @@ InitPgFdwOptions(void)
 		/* sampling is available on both server and table */
 		{"analyze_sampling", ForeignServerRelationId, false},
 		{"analyze_sampling", ForeignTableRelationId, false},
-		/* restore_stats is available on both server and table */
-		{"restore_stats", ForeignServerRelationId, false},
-		{"restore_stats", ForeignTableRelationId, false},
+		/* import_stats is available on both server and table */
+		{"import_stats", ForeignServerRelationId, false},
+		{"import_stats", ForeignTableRelationId, false},
 
 		{"use_scram_passthrough", ForeignServerRelationId, false},
 		{"use_scram_passthrough", UserMappingRelationId, false},
diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c
index b9739610131..0469a761a9d 100644
--- a/contrib/postgres_fdw/postgres_fdw.c
+++ b/contrib/postgres_fdw/postgres_fdw.c
@@ -5458,7 +5458,7 @@ analyze_row_processor(PGresult *res, int row, PgFdwAnalyzeState *astate)
 
 /*
  * postgresImportForeignStatistics
- * 		Attempt to fetch/restore remote statistics instead of sampling.
+ * 		Attempt to import remote statistics instead of sampling.
  */
 static bool
 postgresImportForeignStatistics(Relation relation, List *va_cols, int elevel)
@@ -5471,7 +5471,7 @@ postgresImportForeignStatistics(Relation relation, List *va_cols, int elevel)
 	RemoteAttributeMapping *remattrmap = NULL;
 	int			attrcnt = 0;
 	TimestampTz starttime = 0;
-	bool		restore_stats = false;
+	bool		import_stats = false;
 	bool		ok = false;
 	ListCell   *lc;
 
@@ -5481,7 +5481,7 @@ postgresImportForeignStatistics(Relation relation, List *va_cols, int elevel)
 	server = GetForeignServer(table->serverid);
 
 	/*
-	 * Check whether the restore_stats option is enabled on the foreign table.
+	 * Check whether the import_stats option is enabled on the foreign table.
 	 * If not, silently ignore the foreign table.
 	 *
 	 * Server-level options can be overridden by table-level options, so check
@@ -5491,9 +5491,9 @@ postgresImportForeignStatistics(Relation relation, List *va_cols, int elevel)
 	{
 		DefElem    *def = (DefElem *) lfirst(lc);
 
-		if (strcmp(def->defname, "restore_stats") == 0)
+		if (strcmp(def->defname, "import_stats") == 0)
 		{
-			restore_stats = defGetBoolean(def);
+			import_stats = defGetBoolean(def);
 			break;
 		}
 	}
@@ -5501,13 +5501,13 @@ postgresImportForeignStatistics(Relation relation, List *va_cols, int elevel)
 	{
 		DefElem    *def = (DefElem *) lfirst(lc);
 
-		if (strcmp(def->defname, "restore_stats") == 0)
+		if (strcmp(def->defname, "import_stats") == 0)
 		{
-			restore_stats = defGetBoolean(def);
+			import_stats = defGetBoolean(def);
 			break;
 		}
 	}
-	if (!restore_stats)
+	if (!import_stats)
 		return false;
 
 	/*
diff --git a/contrib/postgres_fdw/sql/postgres_fdw.sql b/contrib/postgres_fdw/sql/postgres_fdw.sql
index 54d09040d0d..1d771391c07 100644
--- a/contrib/postgres_fdw/sql/postgres_fdw.sql
+++ b/contrib/postgres_fdw/sql/postgres_fdw.sql
@@ -4626,7 +4626,7 @@ CREATE TABLE simport_table (c1 int, c2 text);
 CREATE FOREIGN TABLE simport_ftable (c1 int, c2 text, cx int)
        SERVER loopback OPTIONS (table_name 'simport_table');
 ALTER FOREIGN TABLE simport_ftable ALTER COLUMN cx OPTIONS (ADD column_name 'c1');
-ALTER FOREIGN TABLE simport_ftable OPTIONS (ADD restore_stats 'true');
+ALTER FOREIGN TABLE simport_ftable OPTIONS (ADD import_stats 'true');
 
 ANALYZE simport_ftable;                   -- should fail
 
@@ -4682,7 +4682,7 @@ ANALYZE simport_ftable (c1, c1);          -- should fail
 CREATE VIEW simport_view AS SELECT * FROM simport_table;
 CREATE FOREIGN TABLE simport_fview (c1 int, c2 text)
        SERVER loopback OPTIONS (table_name 'simport_view');
-ALTER FOREIGN TABLE simport_fview OPTIONS (ADD restore_stats 'true');
+ALTER FOREIGN TABLE simport_fview OPTIONS (ADD import_stats 'true');
 
 ANALYZE simport_fview;                    -- should fail
 
@@ -4690,7 +4690,7 @@ ANALYZE simport_fview;                    -- should fail
 -- single quotes or backslashes
 CREATE TABLE dtest_table ("col'quote" int, "col\backslash" int);
 CREATE FOREIGN TABLE dtest_ftable ("col'quote" int, "col\backslash" int)
-       SERVER loopback OPTIONS (table_name 'dtest_table', restore_stats 'true');
+       SERVER loopback OPTIONS (table_name 'dtest_table', import_stats 'true');
 
 INSERT INTO dtest_table SELECT g, g FROM generate_series(1, 10) g;
 ANALYZE dtest_table;

base-commit: 1d1d7b0e9c99a6c7b2bb874b5c7f6806e5940f04
-- 
2.55.0

