1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-30 21:42:05 +03:00

Allow FDWs and custom scan providers to replace joins with scans.

Foreign data wrappers can use this capability for so-called "join
pushdown"; that is, instead of executing two separate foreign scans
and then joining the results locally, they can generate a path which
performs the join on the remote server and then is scanned locally.
This commit does not extend postgres_fdw to take advantage of this
capability; it just provides the infrastructure.

Custom scan providers can use this in a similar way.  Previously,
it was only possible for a custom scan provider to scan a single
relation.  Now, it can scan an entire join tree, provided of course
that it knows how to produce the same results that the join would
have produced if executed normally.

KaiGai Kohei, reviewed by Shigeru Hanada, Ashutosh Bapat, and me.
This commit is contained in:
Robert Haas
2015-05-01 08:50:35 -04:00
parent 2b22795b32
commit e7cb7ee145
20 changed files with 448 additions and 71 deletions

View File

@ -102,7 +102,7 @@ ForeignScanState *
ExecInitForeignScan(ForeignScan *node, EState *estate, int eflags)
{
ForeignScanState *scanstate;
Relation currentRelation;
Index scanrelid = node->scan.scanrelid;
FdwRoutine *fdwroutine;
/* check for unsupported flags */
@ -141,16 +141,24 @@ ExecInitForeignScan(ForeignScan *node, EState *estate, int eflags)
ExecInitScanTupleSlot(estate, &scanstate->ss);
/*
* open the base relation and acquire appropriate lock on it.
* open the base relation and acquire an appropriate lock on it;
* also, get and assign the scan type
*/
currentRelation = ExecOpenScanRelation(estate, node->scan.scanrelid, eflags);
scanstate->ss.ss_currentRelation = currentRelation;
if (scanrelid > 0)
{
Relation currentRelation;
/*
* get the scan type from the relation descriptor. (XXX at some point we
* might want to let the FDW editorialize on the scan tupdesc.)
*/
ExecAssignScanType(&scanstate->ss, RelationGetDescr(currentRelation));
currentRelation = ExecOpenScanRelation(estate, scanrelid, eflags);
scanstate->ss.ss_currentRelation = currentRelation;
ExecAssignScanType(&scanstate->ss, RelationGetDescr(currentRelation));
}
else
{
TupleDesc ps_tupdesc;
ps_tupdesc = ExecCleanTypeFromTL(node->fdw_ps_tlist, false);
ExecAssignScanType(&scanstate->ss, ps_tupdesc);
}
/*
* Initialize result tuple type and projection info.
@ -161,7 +169,7 @@ ExecInitForeignScan(ForeignScan *node, EState *estate, int eflags)
/*
* Acquire function pointers from the FDW's handler, and init fdw_state.
*/
fdwroutine = GetFdwRoutineForRelation(currentRelation, true);
fdwroutine = GetFdwRoutine(node->fdw_handler);
scanstate->fdwroutine = fdwroutine;
scanstate->fdw_state = NULL;
@ -193,7 +201,8 @@ ExecEndForeignScan(ForeignScanState *node)
ExecClearTuple(node->ss.ss_ScanTupleSlot);
/* close the relation. */
ExecCloseScanRelation(node->ss.ss_currentRelation);
if (node->ss.ss_currentRelation)
ExecCloseScanRelation(node->ss.ss_currentRelation);
}
/* ----------------------------------------------------------------