diff --git a/contrib/postgres_fdw/option.c b/contrib/postgres_fdw/option.c index e1d4c47..0d3426f 100644 --- a/contrib/postgres_fdw/option.c +++ b/contrib/postgres_fdw/option.c @@ -113,6 +113,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS) (void) defGetBoolean(def); } else if (strcmp(def->defname, "fdw_startup_cost") == 0 || + strcmp(def->defname, "fetch_size") == 0 || strcmp(def->defname, "fdw_tuple_cost") == 0) { /* these must have a non-negative numeric value */ @@ -155,6 +156,9 @@ InitPgFdwOptions(void) /* updatable is available on both server and table */ {"updatable", ForeignServerRelationId, false}, {"updatable", ForeignTableRelationId, false}, + /* fetch_size is available on both server and table */ + {"fetch_size", ForeignServerRelationId, false}, + {"fetch_size", ForeignTableRelationId, false}, {NULL, InvalidOid, false} }; diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c index 5de1835..2729ba3 100644 --- a/contrib/postgres_fdw/postgres_fdw.c +++ b/contrib/postgres_fdw/postgres_fdw.c @@ -46,6 +46,9 @@ PG_MODULE_MAGIC; /* Default CPU cost to process 1 row (above and beyond cpu_tuple_cost). */ #define DEFAULT_FDW_TUPLE_COST 0.01 +/* default fetch size */ +#define DEFAULT_FETCH_SIZE 100 + /* * FDW-specific planner information kept in RelOptInfo.fdw_private for a * foreign table. This information is collected by postgresGetForeignRelSize. @@ -73,6 +76,7 @@ typedef struct PgFdwRelationInfo bool use_remote_estimate; Cost fdw_startup_cost; Cost fdw_tuple_cost; + int fetch_size; /* Cached catalog information. */ ForeignTable *table; @@ -156,6 +160,9 @@ typedef struct PgFdwScanState /* working memory contexts */ MemoryContext batch_cxt; /* context holding current batch of tuples */ MemoryContext temp_cxt; /* context for per-tuple temporary data */ + + /* fetch size */ + int fetch_size; /* how many rows to get per fetch */ } PgFdwScanState; /* @@ -395,12 +402,13 @@ postgresGetForeignRelSize(PlannerInfo *root, fpinfo->server = GetForeignServer(fpinfo->table->serverid); /* - * Extract user-settable option values. Note that per-table setting of + * Extract user-settable option values. Note that per-table settings of * use_remote_estimate overrides per-server setting. */ fpinfo->use_remote_estimate = false; fpinfo->fdw_startup_cost = DEFAULT_FDW_STARTUP_COST; fpinfo->fdw_tuple_cost = DEFAULT_FDW_TUPLE_COST; + fpinfo->fetch_size = DEFAULT_FETCH_SIZE; foreach(lc, fpinfo->server->options) { @@ -412,16 +420,17 @@ postgresGetForeignRelSize(PlannerInfo *root, fpinfo->fdw_startup_cost = strtod(defGetString(def), NULL); else if (strcmp(def->defname, "fdw_tuple_cost") == 0) fpinfo->fdw_tuple_cost = strtod(defGetString(def), NULL); + else if (strcmp(def->defname, "fetch_size") == 0) + fpinfo->fetch_size = strtod(defGetString(def), NULL); } foreach(lc, fpinfo->table->options) { DefElem *def = (DefElem *) lfirst(lc); if (strcmp(def->defname, "use_remote_estimate") == 0) - { fpinfo->use_remote_estimate = defGetBoolean(def); - break; /* only need the one value */ - } + else if (strcmp(def->defname, "fetch_size") == 0) + fpinfo->fetch_size = strtod(defGetString(def), NULL); } /* @@ -979,6 +988,14 @@ postgresBeginForeignScan(ForeignScanState *node, int eflags) fsstate->param_values = (const char **) palloc0(numParams * sizeof(char *)); else fsstate->param_values = NULL; + + + + ForeignTable *table; + ForeignServer *server; + + fsstate->fetch_size = + fpinfo->fetch_size = DEFAULT_FETCH_SIZE; } /*