Commit 7012b132 authored by Robert Haas's avatar Robert Haas

postgres_fdw: Push down aggregates to remote servers.

Now that the upper planner uses paths, and now that we have proper hooks
to inject paths into the upper planning process, it's possible for
foreign data wrappers to arrange to push aggregates to the remote side
instead of fetching all of the rows and aggregating them locally.  This
figures to be a massive win for performance, so teach postgres_fdw to
do it.

Jeevan Chalke and Ashutosh Bapat.  Reviewed by Ashutosh Bapat with
additional testing by Prabhat Sahu.  Various mostly cosmetic changes
by me.
parent 709e461b
This diff is collapsed.
This diff is collapsed.
...@@ -92,6 +92,9 @@ typedef struct PgFdwRelationInfo ...@@ -92,6 +92,9 @@ typedef struct PgFdwRelationInfo
RelOptInfo *innerrel; RelOptInfo *innerrel;
JoinType jointype; JoinType jointype;
List *joinclauses; List *joinclauses;
/* Grouping information */
List *grouped_tlist;
} PgFdwRelationInfo; } PgFdwRelationInfo;
/* in postgres_fdw.c */ /* in postgres_fdw.c */
...@@ -155,7 +158,7 @@ extern void deparseAnalyzeSql(StringInfo buf, Relation rel, ...@@ -155,7 +158,7 @@ extern void deparseAnalyzeSql(StringInfo buf, Relation rel,
List **retrieved_attrs); List **retrieved_attrs);
extern void deparseStringLiteral(StringInfo buf, const char *val); extern void deparseStringLiteral(StringInfo buf, const char *val);
extern Expr *find_em_expr_for_rel(EquivalenceClass *ec, RelOptInfo *rel); extern Expr *find_em_expr_for_rel(EquivalenceClass *ec, RelOptInfo *rel);
extern List *build_tlist_to_deparse(RelOptInfo *foreign_rel); extern List *build_tlist_to_deparse(RelOptInfo *foreignrel);
extern void deparseSelectStmtForRel(StringInfo buf, PlannerInfo *root, extern void deparseSelectStmtForRel(StringInfo buf, PlannerInfo *root,
RelOptInfo *foreignrel, List *tlist, RelOptInfo *foreignrel, List *tlist,
List *remote_conds, List *pathkeys, List *remote_conds, List *pathkeys,
......
This diff is collapsed.
...@@ -3243,7 +3243,14 @@ create_foreignscan_plan(PlannerInfo *root, ForeignPath *best_path, ...@@ -3243,7 +3243,14 @@ create_foreignscan_plan(PlannerInfo *root, ForeignPath *best_path,
/* Copy foreign server OID; likewise, no need to make FDW do this */ /* Copy foreign server OID; likewise, no need to make FDW do this */
scan_plan->fs_server = rel->serverid; scan_plan->fs_server = rel->serverid;
/* Likewise, copy the relids that are represented by this foreign scan */ /*
* Likewise, copy the relids that are represented by this foreign scan. An
* upper rel doesn't have relids set, but it covers all the base relations
* participating in the underlying scan, so use root's all_baserels.
*/
if (rel->reloptkind == RELOPT_UPPER_REL)
scan_plan->fs_relids = root->all_baserels;
else
scan_plan->fs_relids = best_path->path.parent->relids; scan_plan->fs_relids = best_path->path.parent->relids;
/* /*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment