1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +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

@ -326,6 +326,41 @@ OPTIONS (ADD password_required 'false');
frequently updated, the local statistics will soon be obsolete.
</para>
<para>
The following option controls how such an <command>ANALYZE</command>
operation behaves:
</para>
<variablelist>
<varlistentry>
<term><literal>analyze_sampling</literal> (<type>text</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
samples the data on the remote side, or reads and transfers all data
and performs the sampling locally. The supported values
are <literal>off</literal>, <literal>random</literal>,
<literal>system</literal>, <literal>bernoulli</literal>
and <literal>auto</literal>. <literal>off</literal> disables remote
sampling, so all data are transferred and sampled locally.
<literal>random</literal> performs remote sampling using the
<literal>random()</literal> function to choose returned rows,
while <literal>system</literal> and <literal>bernoulli</literal> rely
on the built-in <literal>TABLESAMPLE</literal> methods of those
names. <literal>random</literal> works on all remote server versions,
while <literal>TABLESAMPLE</literal> is supported only since 9.5.
<literal>auto</literal> (the default) picks the recommended sampling
method automatically; currently it means
either <literal>bernoulli</literal> or <literal>random</literal>
depending on the remote server version.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect3>
<sect3>