mirror of
https://github.com/postgres/postgres.git
synced 2026-10-23 13:29:09 +03:00
postgres_fdw: Rename option "restore_stats" to "import_stats".
The option added by commit28972b6fcwas named "restore_stats", because it was calling pg_restore_relation_stats()/pg_restore_attribute_stats() in place of fetching a remote rowsample. However, those code paths have been replaced with calls to import_relation_statistics()/import_attribute_statistics() (cf. commit54cd6fc83), so the option is now slightly misnamed. Switch the option to "import_stats", which more closely reflects both the functions being called internally, and the user's perception of what the operation is doing. Back-patch to v19 where commit28972b6fcwent in. Suggested-by: Etsuro Fujita <etsuro.fujita@gmail.com> Author: Corey Huinker <corey.huinker@gmail.com> Discussion: https://postgr.es/m/CADkLM%3DezuspTk3VD-2EM6XtFP-Dfz7cJKtnbn0cB6gocsAgu1g%40mail.gmail.com Backpatch-through: 19
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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},
|
||||
|
||||
@@ -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;
|
||||
|
||||
/*
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user