Header And Logo

| The world's most advanced open source database.


nodeForeignscan.c File Reference

#include "postgres.h"
#include "executor/executor.h"
#include "executor/nodeForeignscan.h"
#include "foreign/fdwapi.h"
#include "utils/rel.h"
Include dependency graph for nodeForeignscan.c:

Go to the source code of this file.


static TupleTableSlotForeignNext (ForeignScanState *node)
static bool ForeignRecheck (ForeignScanState *node, TupleTableSlot *slot)
TupleTableSlotExecForeignScan (ForeignScanState *node)
ForeignScanStateExecInitForeignScan (ForeignScan *node, EState *estate, int eflags)
void ExecEndForeignScan (ForeignScanState *node)
void ExecReScanForeignScan (ForeignScanState *node)

Function Documentation

void ExecEndForeignScan ( ForeignScanState node  ) 
TupleTableSlot* ExecForeignScan ( ForeignScanState node  ) 

Definition at line 89 of file nodeForeignscan.c.

References ExecScan(), ForeignNext(), and ForeignRecheck().

Referenced by ExecProcNode().

ForeignScanState* ExecInitForeignScan ( ForeignScan node,
EState estate,
int  eflags 

Definition at line 102 of file nodeForeignscan.c.

References Assert, FdwRoutine::BeginForeignScan, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecAssignExprContext(), ExecAssignResultTypeFromTL(), ExecAssignScanProjectionInfo(), ExecAssignScanType(), ExecInitExpr(), ExecInitResultTupleSlot(), ExecInitScanTupleSlot(), ExecOpenScanRelation(), ForeignScanState::fdw_state, ForeignScanState::fdwroutine, GetFdwRoutineForRelation(), makeNode, Scan::plan, PlanState::plan, ScanState::ps, PlanState::ps_TupFromTlist, Plan::qual, PlanState::qual, RelationGetDescr, ForeignScan::scan, Scan::scanrelid, ForeignScanState::ss, ScanState::ss_currentRelation, PlanState::state, Plan::targetlist, and PlanState::targetlist.

Referenced by ExecInitNode().

    ForeignScanState *scanstate;
    Relation    currentRelation;
    FdwRoutine *fdwroutine;

    /* check for unsupported flags */
    Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));

     * create state structure
    scanstate = makeNode(ForeignScanState);
    scanstate->ss.ps.plan = (Plan *) node;
    scanstate->ss.ps.state = estate;

     * Miscellaneous initialization
     * create expression context for node
    ExecAssignExprContext(estate, &scanstate->ss.ps);

    scanstate->ss.ps.ps_TupFromTlist = false;

     * initialize child expressions
    scanstate->ss.ps.targetlist = (List *)
        ExecInitExpr((Expr *) node->scan.plan.targetlist,
                     (PlanState *) scanstate);
    scanstate->ss.ps.qual = (List *)
        ExecInitExpr((Expr *) node->scan.plan.qual,
                     (PlanState *) scanstate);

     * tuple table initialization
    ExecInitResultTupleSlot(estate, &scanstate->ss.ps);
    ExecInitScanTupleSlot(estate, &scanstate->ss);

     * open the base relation and acquire appropriate lock on it.
    currentRelation = ExecOpenScanRelation(estate, node->scan.scanrelid, eflags);
    scanstate->ss.ss_currentRelation = 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));

     * Initialize result tuple type and projection info.

     * Acquire function pointers from the FDW's handler, and init fdw_state.
    fdwroutine = GetFdwRoutineForRelation(currentRelation, true);
    scanstate->fdwroutine = fdwroutine;
    scanstate->fdw_state = NULL;

     * Tell the FDW to initiate the scan.
    fdwroutine->BeginForeignScan(scanstate, eflags);

    return scanstate;

void ExecReScanForeignScan ( ForeignScanState node  ) 
static TupleTableSlot * ForeignNext ( ForeignScanState node  )  [static]

Definition at line 41 of file nodeForeignscan.c.

References ExecMaterializeSlot(), ForeignScanState::fdwroutine, ForeignScan::fsSystemCol, FdwRoutine::IterateForeignScan, MemoryContextSwitchTo(), PlanState::plan, ScanState::ps, PlanState::ps_ExprContext, RelationGetRelid, ForeignScanState::ss, ScanState::ss_currentRelation, HeapTupleData::t_tableOid, and TupIsNull.

Referenced by ExecForeignScan().

    TupleTableSlot *slot;
    ForeignScan *plan = (ForeignScan *) node->ss.ps.plan;
    ExprContext *econtext = node->ss.ps.ps_ExprContext;
    MemoryContext oldcontext;

    /* Call the Iterate function in short-lived context */
    oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
    slot = node->fdwroutine->IterateForeignScan(node);

     * If any system columns are requested, we have to force the tuple into
     * physical-tuple form to avoid "cannot extract system attribute from
     * virtual tuple" errors later.  We also insert a valid value for
     * tableoid, which is the only actually-useful system column.
    if (plan->fsSystemCol && !TupIsNull(slot))
        HeapTuple   tup = ExecMaterializeSlot(slot);

        tup->t_tableOid = RelationGetRelid(node->ss.ss_currentRelation);

    return slot;

static bool ForeignRecheck ( ForeignScanState node,
TupleTableSlot slot 
) [static]

Definition at line 73 of file nodeForeignscan.c.

Referenced by ExecForeignScan().

    /* There are no access-method-specific conditions to recheck. */
    return true;