1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

Sample postgres_fdw tables remotely during ANALYZE

When collecting ANALYZE sample on foreign tables, postgres_fdw fetched
all rows and performed the sampling locally. For large tables this means
transferring and immediately discarding large amounts of data.

This commit allows the sampling to be performed on the remote server,
transferring only the much smaller sample. The sampling is performed
using the built-in TABLESAMPLE methods (system, bernoulli) or random()
function, depending on the remote server version.

Remote sampling can be enabled by analyze_sampling on the foreign server
and/or foreign table, with supported values 'off', 'auto', 'system',
'bernoulli' and 'random'. The default value is 'auto' which uses either
'bernoulli' (TABLESAMPLE method) or 'random' (for remote servers without
TABLESAMPLE support).
This commit is contained in:
Tomas Vondra
2022-12-30 23:14:53 +01:00
parent 02699bc1fd
commit 8ad51b5f44
7 changed files with 397 additions and 9 deletions

View File

@ -210,6 +210,23 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
errmsg("sslcert and sslkey are superuser-only"),
errhint("User mappings with the sslcert or sslkey options set may only be created or modified by the superuser.")));
}
else if (strcmp(def->defname, "analyze_sampling") == 0)
{
char *value;
value = defGetString(def);
/* we recognize off/auto/random/system/bernoulli */
if (strcmp(value, "off") != 0 &&
strcmp(value, "auto") != 0 &&
strcmp(value, "random") != 0 &&
strcmp(value, "system") != 0 &&
strcmp(value, "bernoulli") != 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid value for string option \"%s\": %s",
def->defname, value)));
}
}
PG_RETURN_VOID();
@ -257,6 +274,10 @@ InitPgFdwOptions(void)
{"keep_connections", ForeignServerRelationId, false},
{"password_required", UserMappingRelationId, false},
/* sampling is available on both server and table */
{"analyze_sampling", ForeignServerRelationId, false},
{"analyze_sampling", ForeignTableRelationId, false},
/*
* sslcert and sslkey are in fact libpq options, but we repeat them
* here to allow them to appear in both foreign server context (when