#include "postgres.h"
#include "access/htup_details.h"
#include "executor/execdebug.h"
#include "executor/nodeAgg.h"
#include "executor/nodeAppend.h"
#include "executor/nodeBitmapAnd.h"
#include "executor/nodeBitmapHeapscan.h"
#include "executor/nodeBitmapIndexscan.h"
#include "executor/nodeBitmapOr.h"
#include "executor/nodeCtescan.h"
#include "executor/nodeForeignscan.h"
#include "executor/nodeFunctionscan.h"
#include "executor/nodeGroup.h"
#include "executor/nodeHash.h"
#include "executor/nodeHashjoin.h"
#include "executor/nodeIndexonlyscan.h"
#include "executor/nodeIndexscan.h"
#include "executor/nodeLimit.h"
#include "executor/nodeLockRows.h"
#include "executor/nodeMaterial.h"
#include "executor/nodeMergeAppend.h"
#include "executor/nodeMergejoin.h"
#include "executor/nodeModifyTable.h"
#include "executor/nodeNestloop.h"
#include "executor/nodeRecursiveunion.h"
#include "executor/nodeResult.h"
#include "executor/nodeSeqscan.h"
#include "executor/nodeSetOp.h"
#include "executor/nodeSort.h"
#include "executor/nodeSubplan.h"
#include "executor/nodeSubqueryscan.h"
#include "executor/nodeTidscan.h"
#include "executor/nodeUnique.h"
#include "executor/nodeValuesscan.h"
#include "executor/nodeWindowAgg.h"
#include "executor/nodeWorktablescan.h"
#include "nodes/nodeFuncs.h"
#include "utils/rel.h"
#include "utils/syscache.h"
Go to the source code of this file.
Functions | |
static bool | TargetListSupportsBackwardScan (List *targetlist) |
static bool | IndexSupportsBackwardScan (Oid indexid) |
void | ExecReScan (PlanState *node) |
void | ExecMarkPos (PlanState *node) |
void | ExecRestrPos (PlanState *node) |
bool | ExecSupportsMarkRestore (NodeTag plantype) |
bool | ExecSupportsBackwardScan (Plan *node) |
bool | ExecMaterializesOutput (NodeTag plantype) |
void ExecMarkPos | ( | PlanState * | node | ) |
Definition at line 270 of file execAmi.c.
References DEBUG2, elog, ExecIndexMarkPos(), ExecIndexOnlyMarkPos(), ExecMaterialMarkPos(), ExecResultMarkPos(), ExecSeqMarkPos(), ExecSortMarkPos(), ExecTidMarkPos(), ExecValuesMarkPos(), nodeTag, T_IndexOnlyScanState, T_IndexScanState, T_MaterialState, T_ResultState, T_SeqScanState, T_SortState, T_TidScanState, and T_ValuesScanState.
Referenced by ExecMergeJoin(), and ExecResultMarkPos().
{ switch (nodeTag(node)) { case T_SeqScanState: ExecSeqMarkPos((SeqScanState *) node); break; case T_IndexScanState: ExecIndexMarkPos((IndexScanState *) node); break; case T_IndexOnlyScanState: ExecIndexOnlyMarkPos((IndexOnlyScanState *) node); break; case T_TidScanState: ExecTidMarkPos((TidScanState *) node); break; case T_ValuesScanState: ExecValuesMarkPos((ValuesScanState *) node); break; case T_MaterialState: ExecMaterialMarkPos((MaterialState *) node); break; case T_SortState: ExecSortMarkPos((SortState *) node); break; case T_ResultState: ExecResultMarkPos((ResultState *) node); break; default: /* don't make hard error unless caller asks to restore... */ elog(DEBUG2, "unrecognized node type: %d", (int) nodeTag(node)); break; } }
Definition at line 538 of file execAmi.c.
References T_CteScan, T_FunctionScan, T_Material, T_Sort, and T_WorkTableScan.
Referenced by build_subplan(), cost_subplan(), and match_unsorted_outer().
{ switch (plantype) { case T_Material: case T_FunctionScan: case T_CteScan: case T_WorkTableScan: case T_Sort: return true; default: break; } return false; }
void ExecReScan | ( | PlanState * | node | ) |
Definition at line 68 of file execAmi.c.
References bms_free(), PlanState::chgParam, elog, ERROR, ExecReScanAgg(), ExecReScanAppend(), ExecReScanBitmapAnd(), ExecReScanBitmapHeapScan(), ExecReScanBitmapIndexScan(), ExecReScanBitmapOr(), ExecReScanCteScan(), ExecReScanForeignScan(), ExecReScanFunctionScan(), ExecReScanGroup(), ExecReScanHash(), ExecReScanHashJoin(), ExecReScanIndexOnlyScan(), ExecReScanIndexScan(), ExecReScanLimit(), ExecReScanLockRows(), ExecReScanMaterial(), ExecReScanMergeAppend(), ExecReScanMergeJoin(), ExecReScanModifyTable(), ExecReScanNestLoop(), ExecReScanRecursiveUnion(), ExecReScanResult(), ExecReScanSeqScan(), ExecReScanSetOp(), ExecReScanSetParamPlan(), ExecReScanSort(), ExecReScanSubqueryScan(), ExecReScanTidScan(), ExecReScanUnique(), ExecReScanValuesScan(), ExecReScanWindowAgg(), ExecReScanWorkTableScan(), Plan::extParam, PlanState::initPlan, InstrEndLoop(), PlanState::instrument, PlanState::lefttree, lfirst, nodeTag, NULL, PlanState::plan, SubPlanState::planstate, PlanState::ps_ExprContext, ReScanExprContext(), PlanState::righttree, splan, PlanState::subPlan, T_AggState, T_AppendState, T_BitmapAndState, T_BitmapHeapScanState, T_BitmapIndexScanState, T_BitmapOrState, T_CteScanState, T_ForeignScanState, T_FunctionScanState, T_GroupState, T_HashJoinState, T_HashState, T_IndexOnlyScanState, T_IndexScanState, T_LimitState, T_LockRowsState, T_MaterialState, T_MergeAppendState, T_MergeJoinState, T_ModifyTableState, T_NestLoopState, T_RecursiveUnionState, T_ResultState, T_SeqScanState, T_SetOpState, T_SortState, T_SubqueryScanState, T_TidScanState, T_UniqueState, T_ValuesScanState, T_WindowAggState, T_WorkTableScanState, and UpdateChangedParamSet().
Referenced by buildSubPlanHash(), ExecIndexOnlyScan(), ExecIndexScan(), ExecNestLoop(), ExecProcNode(), ExecReScanAgg(), ExecReScanAppend(), ExecReScanBitmapAnd(), ExecReScanBitmapHeapScan(), ExecReScanBitmapOr(), ExecReScanGroup(), ExecReScanHash(), ExecReScanHashJoin(), ExecReScanLimit(), ExecReScanLockRows(), ExecReScanMaterial(), ExecReScanMergeAppend(), ExecReScanMergeJoin(), ExecReScanNestLoop(), ExecReScanRecursiveUnion(), ExecReScanResult(), ExecReScanSetOp(), ExecReScanSort(), ExecReScanSubqueryScan(), ExecReScanUnique(), ExecReScanWindowAgg(), ExecScanSubPlan(), ExecutorRewind(), MultiExecBitmapIndexScan(), and MultiExecProcNode().
{ /* If collecting timing stats, update them */ if (node->instrument) InstrEndLoop(node->instrument); /* * If we have changed parameters, propagate that info. * * Note: ExecReScanSetParamPlan() can add bits to node->chgParam, * corresponding to the output param(s) that the InitPlan will update. * Since we make only one pass over the list, that means that an InitPlan * can depend on the output param(s) of a sibling InitPlan only if that * sibling appears earlier in the list. This is workable for now given * the limited ways in which one InitPlan could depend on another, but * eventually we might need to work harder (or else make the planner * enlarge the extParam/allParam sets to include the params of depended-on * InitPlans). */ if (node->chgParam != NULL) { ListCell *l; foreach(l, node->initPlan) { SubPlanState *sstate = (SubPlanState *) lfirst(l); PlanState *splan = sstate->planstate; if (splan->plan->extParam != NULL) /* don't care about child * local Params */ UpdateChangedParamSet(splan, node->chgParam); if (splan->chgParam != NULL) ExecReScanSetParamPlan(sstate, node); } foreach(l, node->subPlan) { SubPlanState *sstate = (SubPlanState *) lfirst(l); PlanState *splan = sstate->planstate; if (splan->plan->extParam != NULL) UpdateChangedParamSet(splan, node->chgParam); } /* Well. Now set chgParam for left/right trees. */ if (node->lefttree != NULL) UpdateChangedParamSet(node->lefttree, node->chgParam); if (node->righttree != NULL) UpdateChangedParamSet(node->righttree, node->chgParam); } /* Shut down any SRFs in the plan node's targetlist */ if (node->ps_ExprContext) ReScanExprContext(node->ps_ExprContext); /* And do node-type-specific processing */ switch (nodeTag(node)) { case T_ResultState: ExecReScanResult((ResultState *) node); break; case T_ModifyTableState: ExecReScanModifyTable((ModifyTableState *) node); break; case T_AppendState: ExecReScanAppend((AppendState *) node); break; case T_MergeAppendState: ExecReScanMergeAppend((MergeAppendState *) node); break; case T_RecursiveUnionState: ExecReScanRecursiveUnion((RecursiveUnionState *) node); break; case T_BitmapAndState: ExecReScanBitmapAnd((BitmapAndState *) node); break; case T_BitmapOrState: ExecReScanBitmapOr((BitmapOrState *) node); break; case T_SeqScanState: ExecReScanSeqScan((SeqScanState *) node); break; case T_IndexScanState: ExecReScanIndexScan((IndexScanState *) node); break; case T_IndexOnlyScanState: ExecReScanIndexOnlyScan((IndexOnlyScanState *) node); break; case T_BitmapIndexScanState: ExecReScanBitmapIndexScan((BitmapIndexScanState *) node); break; case T_BitmapHeapScanState: ExecReScanBitmapHeapScan((BitmapHeapScanState *) node); break; case T_TidScanState: ExecReScanTidScan((TidScanState *) node); break; case T_SubqueryScanState: ExecReScanSubqueryScan((SubqueryScanState *) node); break; case T_FunctionScanState: ExecReScanFunctionScan((FunctionScanState *) node); break; case T_ValuesScanState: ExecReScanValuesScan((ValuesScanState *) node); break; case T_CteScanState: ExecReScanCteScan((CteScanState *) node); break; case T_WorkTableScanState: ExecReScanWorkTableScan((WorkTableScanState *) node); break; case T_ForeignScanState: ExecReScanForeignScan((ForeignScanState *) node); break; case T_NestLoopState: ExecReScanNestLoop((NestLoopState *) node); break; case T_MergeJoinState: ExecReScanMergeJoin((MergeJoinState *) node); break; case T_HashJoinState: ExecReScanHashJoin((HashJoinState *) node); break; case T_MaterialState: ExecReScanMaterial((MaterialState *) node); break; case T_SortState: ExecReScanSort((SortState *) node); break; case T_GroupState: ExecReScanGroup((GroupState *) node); break; case T_AggState: ExecReScanAgg((AggState *) node); break; case T_WindowAggState: ExecReScanWindowAgg((WindowAggState *) node); break; case T_UniqueState: ExecReScanUnique((UniqueState *) node); break; case T_HashState: ExecReScanHash((HashState *) node); break; case T_SetOpState: ExecReScanSetOp((SetOpState *) node); break; case T_LockRowsState: ExecReScanLockRows((LockRowsState *) node); break; case T_LimitState: ExecReScanLimit((LimitState *) node); break; default: elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node)); break; } if (node->chgParam != NULL) { bms_free(node->chgParam); node->chgParam = NULL; } }
void ExecRestrPos | ( | PlanState * | node | ) |
Definition at line 327 of file execAmi.c.
References elog, ERROR, ExecIndexOnlyRestrPos(), ExecIndexRestrPos(), ExecMaterialRestrPos(), ExecResultRestrPos(), ExecSeqRestrPos(), ExecSortRestrPos(), ExecTidRestrPos(), ExecValuesRestrPos(), nodeTag, T_IndexOnlyScanState, T_IndexScanState, T_MaterialState, T_ResultState, T_SeqScanState, T_SortState, T_TidScanState, and T_ValuesScanState.
Referenced by ExecMergeJoin(), and ExecResultRestrPos().
{ switch (nodeTag(node)) { case T_SeqScanState: ExecSeqRestrPos((SeqScanState *) node); break; case T_IndexScanState: ExecIndexRestrPos((IndexScanState *) node); break; case T_IndexOnlyScanState: ExecIndexOnlyRestrPos((IndexOnlyScanState *) node); break; case T_TidScanState: ExecTidRestrPos((TidScanState *) node); break; case T_ValuesScanState: ExecValuesRestrPos((ValuesScanState *) node); break; case T_MaterialState: ExecMaterialRestrPos((MaterialState *) node); break; case T_SortState: ExecSortRestrPos((SortState *) node); break; case T_ResultState: ExecResultRestrPos((ResultState *) node); break; default: elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node)); break; } }
Definition at line 422 of file execAmi.c.
References ExecSupportsBackwardScan(), IndexSupportsBackwardScan(), lfirst, nodeTag, NULL, outerPlan, T_Append, T_CteScan, T_FunctionScan, T_IndexOnlyScan, T_IndexScan, T_Limit, T_LockRows, T_Material, T_Result, T_SeqScan, T_Sort, T_SubqueryScan, T_TidScan, T_ValuesScan, Plan::targetlist, and TargetListSupportsBackwardScan().
Referenced by ExecSupportsBackwardScan(), PerformCursorOpen(), SPI_cursor_open_internal(), and standard_planner().
{ if (node == NULL) return false; switch (nodeTag(node)) { case T_Result: if (outerPlan(node) != NULL) return ExecSupportsBackwardScan(outerPlan(node)) && TargetListSupportsBackwardScan(node->targetlist); else return false; case T_Append: { ListCell *l; foreach(l, ((Append *) node)->appendplans) { if (!ExecSupportsBackwardScan((Plan *) lfirst(l))) return false; } /* need not check tlist because Append doesn't evaluate it */ return true; } case T_SeqScan: case T_TidScan: case T_FunctionScan: case T_ValuesScan: case T_CteScan: return TargetListSupportsBackwardScan(node->targetlist); case T_IndexScan: return IndexSupportsBackwardScan(((IndexScan *) node)->indexid) && TargetListSupportsBackwardScan(node->targetlist); case T_IndexOnlyScan: return IndexSupportsBackwardScan(((IndexOnlyScan *) node)->indexid) && TargetListSupportsBackwardScan(node->targetlist); case T_SubqueryScan: return ExecSupportsBackwardScan(((SubqueryScan *) node)->subplan) && TargetListSupportsBackwardScan(node->targetlist); case T_Material: case T_Sort: /* these don't evaluate tlist */ return true; case T_LockRows: case T_Limit: /* these don't evaluate tlist */ return ExecSupportsBackwardScan(outerPlan(node)); default: return false; } }
Definition at line 382 of file execAmi.c.
References T_IndexOnlyScan, T_IndexScan, T_Material, T_Result, T_SeqScan, T_Sort, T_TidScan, and T_ValuesScan.
Referenced by final_cost_mergejoin().
{ switch (plantype) { case T_SeqScan: case T_IndexScan: case T_IndexOnlyScan: case T_TidScan: case T_ValuesScan: case T_Material: case T_Sort: return true; case T_Result: /* * T_Result only supports mark/restore if it has a child plan that * does, so we do not have enough information to give a really * correct answer. However, for current uses it's enough to * always say "false", because this routine is not asked about * gating Result plans, only base-case Results. */ return false; default: break; } return false; }
Definition at line 500 of file execAmi.c.
References AMOID, elog, ERROR, GETSTRUCT, HeapTupleIsValid, ObjectIdGetDatum, ReleaseSysCache(), RELOID, and SearchSysCache1.
Referenced by ExecSupportsBackwardScan().
{ bool result; HeapTuple ht_idxrel; HeapTuple ht_am; Form_pg_class idxrelrec; Form_pg_am amrec; /* Fetch the pg_class tuple of the index relation */ ht_idxrel = SearchSysCache1(RELOID, ObjectIdGetDatum(indexid)); if (!HeapTupleIsValid(ht_idxrel)) elog(ERROR, "cache lookup failed for relation %u", indexid); idxrelrec = (Form_pg_class) GETSTRUCT(ht_idxrel); /* Fetch the pg_am tuple of the index' access method */ ht_am = SearchSysCache1(AMOID, ObjectIdGetDatum(idxrelrec->relam)); if (!HeapTupleIsValid(ht_am)) elog(ERROR, "cache lookup failed for access method %u", idxrelrec->relam); amrec = (Form_pg_am) GETSTRUCT(ht_am); result = amrec->amcanbackward; ReleaseSysCache(ht_idxrel); ReleaseSysCache(ht_am); return result; }
Definition at line 488 of file execAmi.c.
References expression_returns_set().
Referenced by ExecSupportsBackwardScan().
{ if (expression_returns_set((Node *) targetlist)) return false; return true; }