Sample postgres_fdw tables remotely during ANALYZE
authorTomas Vondra <tomas.vondra@postgresql.org>
Fri, 30 Dec 2022 22:14:53 +0000 (23:14 +0100)
committerTomas Vondra <tomas.vondra@postgresql.org>
Fri, 30 Dec 2022 22:16:01 +0000 (23:16 +0100)
commit8ad51b5f446b5c19ba2c0033a0f7b3180b3b6d95
treede0cd74753d56a785ce61315a0044383faf8e9eb
parent02699bc1fd3b7fccba2e6b55189a148ef69b8a00
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).
contrib/postgres_fdw/deparse.c
contrib/postgres_fdw/expected/postgres_fdw.out
contrib/postgres_fdw/option.c
contrib/postgres_fdw/postgres_fdw.c
contrib/postgres_fdw/postgres_fdw.h
contrib/postgres_fdw/sql/postgres_fdw.sql
doc/src/sgml/postgres-fdw.sgml