1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

postgres_fdw: Perform the (FINAL, NULL) upperrel operations remotely.

The upper-planner pathification allows FDWs to arrange to push down
different types of upper-stage operations to the remote side.  This
commit teaches postgres_fdw to do it for the (FINAL, NULL) upperrel,
which is responsible for doing LockRows, LIMIT, and/or ModifyTable.
This provides the ability for postgres_fdw to handle SELECT commands
so that it 1) skips the LockRows step (if any) (note that this is
safe since it performs early locking) and 2) pushes down the LIMIT
and/or OFFSET restrictions (if any) to the remote side.  This doesn't
handle the INSERT/UPDATE/DELETE cases.

Author: Etsuro Fujita
Reviewed-By: Antonin Houska and Jeff Janes
Discussion: https://postgr.es/m/87pnz1aby9.fsf@news-spur.riddles.org.uk
This commit is contained in:
Etsuro Fujita
2019-04-02 20:30:45 +09:00
parent aef65db676
commit d50d172e51
7 changed files with 656 additions and 390 deletions

View File

@ -1830,6 +1830,7 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
bool final_target_parallel_safe;
RelOptInfo *current_rel;
RelOptInfo *final_rel;
FinalPathExtraData extra;
ListCell *lc;
/* Tweak caller-supplied tuple_fraction if have LIMIT/OFFSET */
@ -2389,6 +2390,11 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
}
}
extra.limit_needed = limit_needed(parse);
extra.limit_tuples = limit_tuples;
extra.count_est = count_est;
extra.offset_est = offset_est;
/*
* If there is an FDW that's responsible for all baserels of the query,
* let it consider adding ForeignPaths.
@ -2397,12 +2403,12 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
final_rel->fdwroutine->GetForeignUpperPaths)
final_rel->fdwroutine->GetForeignUpperPaths(root, UPPERREL_FINAL,
current_rel, final_rel,
NULL);
&extra);
/* Let extensions possibly add some more paths */
if (create_upper_paths_hook)
(*create_upper_paths_hook) (root, UPPERREL_FINAL,
current_rel, final_rel, NULL);
current_rel, final_rel, &extra);
/* Note: currently, we leave it to callers to do set_cheapest() */
}