diff options
author | Tomas Vondra <tomas.vondra@postgresql.org> | 2023-01-07 14:22:09 +0100 |
---|---|---|
committer | Tomas Vondra <tomas.vondra@postgresql.org> | 2023-01-07 14:39:33 +0100 |
commit | 57d11ef028d126f95595c08c62ffb4c5147d0f86 (patch) | |
tree | cee77c832db4d0c2c6f821b64b44455f09a310df /contrib/postgres_fdw/deparse.c | |
parent | d913928c9c5e905d0062d1e7237b7fb5fbde61ed (diff) | |
download | postgresql-57d11ef028d126f95595c08c62ffb4c5147d0f86.tar.gz postgresql-57d11ef028d126f95595c08c62ffb4c5147d0f86.zip |
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
Diffstat (limited to 'contrib/postgres_fdw/deparse.c')
-rw-r--r-- | contrib/postgres_fdw/deparse.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/contrib/postgres_fdw/deparse.c b/contrib/postgres_fdw/deparse.c index 4461fb06f02..21237d18ef8 100644 --- a/contrib/postgres_fdw/deparse.c +++ b/contrib/postgres_fdw/deparse.c @@ -2368,14 +2368,15 @@ deparseAnalyzeSizeSql(StringInfo buf, Relation rel) } /* - * Construct SELECT statement to acquire the number of rows of a relation. + * Construct SELECT statement to acquire the number of rows and the relkind of + * a relation. * * Note: we just return the remote server's reltuples value, which might * be off a good deal, but it doesn't seem worth working harder. See * comments in postgresAcquireSampleRowsFunc. */ void -deparseAnalyzeTuplesSql(StringInfo buf, Relation rel) +deparseAnalyzeInfoSql(StringInfo buf, Relation rel) { StringInfoData relname; @@ -2383,7 +2384,7 @@ deparseAnalyzeTuplesSql(StringInfo buf, Relation rel) initStringInfo(&relname); deparseRelation(&relname, rel); - appendStringInfoString(buf, "SELECT reltuples FROM pg_catalog.pg_class WHERE oid = "); + appendStringInfoString(buf, "SELECT reltuples, relkind FROM pg_catalog.pg_class WHERE oid = "); deparseStringLiteral(buf, relname.data); appendStringInfoString(buf, "::pg_catalog.regclass"); } |