Check relkind before using TABLESAMPLE in postgres_fdw
authorTomas Vondra <tomas.vondra@postgresql.org>
Sat, 7 Jan 2023 13:22:09 +0000 (14:22 +0100)
committerTomas Vondra <tomas.vondra@postgresql.org>
Sat, 7 Jan 2023 13:39:33 +0000 (14:39 +0100)
commit57d11ef028d126f95595c08c62ffb4c5147d0f86
treecee77c832db4d0c2c6f821b64b44455f09a310df
parentd913928c9c5e905d0062d1e7237b7fb5fbde61ed
Check relkind before using TABLESAMPLE in postgres_fdw

Check the remote relkind before trying to use TABLESAMPLE to acquire
sample from the remote relation. Even if the remote server version has
TABLESAMPLE support, the foreign table may point to incompatible relkind
(e.g. a view or a sequence).

If the relkind does not support TABLESAMPLE, error out if TABLESAMPLE
was requested specifically (as system/bernoulli), or fallback to random
just like we do for old server versions.

We currently end up disabling sampling for such relkind values anyway,
due to reltuples being -1 or 1, but that seems rather accidental, and
might get broken by improving reltuples estimates, etc.  So better to
make the check explicit.

Reported-by: Tom Lane
Discussion: https://postgr.es/m/951485.1672461744%40sss.pgh.pa.us
contrib/postgres_fdw/deparse.c
contrib/postgres_fdw/postgres_fdw.c
contrib/postgres_fdw/postgres_fdw.h