mirror of
https://github.com/postgres/postgres.git
synced 2025-06-11 20:28:21 +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:
@ -134,6 +134,18 @@ typedef struct PgFdwConnState
|
||||
AsyncRequest *pendingAreq; /* pending async request */
|
||||
} PgFdwConnState;
|
||||
|
||||
/*
|
||||
* Method used by ANALYZE to sample remote rows.
|
||||
*/
|
||||
typedef enum PgFdwSamplingMethod
|
||||
{
|
||||
ANALYZE_SAMPLE_OFF, /* no remote sampling */
|
||||
ANALYZE_SAMPLE_AUTO, /* choose by server version */
|
||||
ANALYZE_SAMPLE_RANDOM, /* remote random() */
|
||||
ANALYZE_SAMPLE_SYSTEM, /* TABLESAMPLE system */
|
||||
ANALYZE_SAMPLE_BERNOULLI /* TABLESAMPLE bernoulli */
|
||||
} PgFdwSamplingMethod;
|
||||
|
||||
/* in postgres_fdw.c */
|
||||
extern int set_transmission_modes(void);
|
||||
extern void reset_transmission_modes(int nestlevel);
|
||||
@ -211,7 +223,10 @@ extern void deparseDirectDeleteSql(StringInfo buf, PlannerInfo *root,
|
||||
List *returningList,
|
||||
List **retrieved_attrs);
|
||||
extern void deparseAnalyzeSizeSql(StringInfo buf, Relation rel);
|
||||
extern void deparseAnalyzeTuplesSql(StringInfo buf, Relation rel);
|
||||
extern void deparseAnalyzeSql(StringInfo buf, Relation rel,
|
||||
PgFdwSamplingMethod sample_method,
|
||||
double sample_frac,
|
||||
List **retrieved_attrs);
|
||||
extern void deparseTruncateSql(StringInfo buf,
|
||||
List *rels,
|
||||
|
Reference in New Issue
Block a user