LCOV - code coverage report
Current view: top level - src/backend/executor - execAmi.c (source / functions) Hit Total Coverage
Test: PostgreSQL 13beta1 Lines: 222 282 78.7 %
Date: 2020-06-05 18:07:03 Functions: 7 7 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*-------------------------------------------------------------------------
       2             :  *
       3             :  * execAmi.c
       4             :  *    miscellaneous executor access method routines
       5             :  *
       6             :  * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
       7             :  * Portions Copyright (c) 1994, Regents of the University of California
       8             :  *
       9             :  *  src/backend/executor/execAmi.c
      10             :  *
      11             :  *-------------------------------------------------------------------------
      12             :  */
      13             : #include "postgres.h"
      14             : 
      15             : #include "access/amapi.h"
      16             : #include "access/htup_details.h"
      17             : #include "executor/execdebug.h"
      18             : #include "executor/nodeAgg.h"
      19             : #include "executor/nodeAppend.h"
      20             : #include "executor/nodeBitmapAnd.h"
      21             : #include "executor/nodeBitmapHeapscan.h"
      22             : #include "executor/nodeBitmapIndexscan.h"
      23             : #include "executor/nodeBitmapOr.h"
      24             : #include "executor/nodeCtescan.h"
      25             : #include "executor/nodeCustom.h"
      26             : #include "executor/nodeForeignscan.h"
      27             : #include "executor/nodeFunctionscan.h"
      28             : #include "executor/nodeGather.h"
      29             : #include "executor/nodeGatherMerge.h"
      30             : #include "executor/nodeGroup.h"
      31             : #include "executor/nodeHash.h"
      32             : #include "executor/nodeHashjoin.h"
      33             : #include "executor/nodeIncrementalSort.h"
      34             : #include "executor/nodeIndexonlyscan.h"
      35             : #include "executor/nodeIndexscan.h"
      36             : #include "executor/nodeLimit.h"
      37             : #include "executor/nodeLockRows.h"
      38             : #include "executor/nodeMaterial.h"
      39             : #include "executor/nodeMergeAppend.h"
      40             : #include "executor/nodeMergejoin.h"
      41             : #include "executor/nodeModifyTable.h"
      42             : #include "executor/nodeNamedtuplestorescan.h"
      43             : #include "executor/nodeNestloop.h"
      44             : #include "executor/nodeProjectSet.h"
      45             : #include "executor/nodeRecursiveunion.h"
      46             : #include "executor/nodeResult.h"
      47             : #include "executor/nodeSamplescan.h"
      48             : #include "executor/nodeSeqscan.h"
      49             : #include "executor/nodeSetOp.h"
      50             : #include "executor/nodeSort.h"
      51             : #include "executor/nodeSubplan.h"
      52             : #include "executor/nodeSubqueryscan.h"
      53             : #include "executor/nodeTableFuncscan.h"
      54             : #include "executor/nodeTidscan.h"
      55             : #include "executor/nodeUnique.h"
      56             : #include "executor/nodeValuesscan.h"
      57             : #include "executor/nodeWindowAgg.h"
      58             : #include "executor/nodeWorktablescan.h"
      59             : #include "nodes/extensible.h"
      60             : #include "nodes/nodeFuncs.h"
      61             : #include "nodes/pathnodes.h"
      62             : #include "utils/rel.h"
      63             : #include "utils/syscache.h"
      64             : 
      65             : static bool IndexSupportsBackwardScan(Oid indexid);
      66             : 
      67             : 
      68             : /*
      69             :  * ExecReScan
      70             :  *      Reset a plan node so that its output can be re-scanned.
      71             :  *
      72             :  * Note that if the plan node has parameters that have changed value,
      73             :  * the output might be different from last time.
      74             :  */
      75             : void
      76     6100238 : ExecReScan(PlanState *node)
      77             : {
      78             :     /* If collecting timing stats, update them */
      79     6100238 :     if (node->instrument)
      80        2504 :         InstrEndLoop(node->instrument);
      81             : 
      82             :     /*
      83             :      * If we have changed parameters, propagate that info.
      84             :      *
      85             :      * Note: ExecReScanSetParamPlan() can add bits to node->chgParam,
      86             :      * corresponding to the output param(s) that the InitPlan will update.
      87             :      * Since we make only one pass over the list, that means that an InitPlan
      88             :      * can depend on the output param(s) of a sibling InitPlan only if that
      89             :      * sibling appears earlier in the list.  This is workable for now given
      90             :      * the limited ways in which one InitPlan could depend on another, but
      91             :      * eventually we might need to work harder (or else make the planner
      92             :      * enlarge the extParam/allParam sets to include the params of depended-on
      93             :      * InitPlans).
      94             :      */
      95     6100238 :     if (node->chgParam != NULL)
      96             :     {
      97             :         ListCell   *l;
      98             : 
      99     5277510 :         foreach(l, node->initPlan)
     100             :         {
     101        1130 :             SubPlanState *sstate = (SubPlanState *) lfirst(l);
     102        1130 :             PlanState  *splan = sstate->planstate;
     103             : 
     104        1130 :             if (splan->plan->extParam != NULL)    /* don't care about child
     105             :                                                  * local Params */
     106        1032 :                 UpdateChangedParamSet(splan, node->chgParam);
     107        1130 :             if (splan->chgParam != NULL)
     108         872 :                 ExecReScanSetParamPlan(sstate, node);
     109             :         }
     110     5361044 :         foreach(l, node->subPlan)
     111             :         {
     112       84664 :             SubPlanState *sstate = (SubPlanState *) lfirst(l);
     113       84664 :             PlanState  *splan = sstate->planstate;
     114             : 
     115       84664 :             if (splan->plan->extParam != NULL)
     116       84652 :                 UpdateChangedParamSet(splan, node->chgParam);
     117             :         }
     118             :         /* Well. Now set chgParam for left/right trees. */
     119     5276380 :         if (node->lefttree != NULL)
     120     2679414 :             UpdateChangedParamSet(node->lefttree, node->chgParam);
     121     5276380 :         if (node->righttree != NULL)
     122     1137056 :             UpdateChangedParamSet(node->righttree, node->chgParam);
     123             :     }
     124             : 
     125             :     /* Call expression callbacks */
     126     6100238 :     if (node->ps_ExprContext)
     127     5289356 :         ReScanExprContext(node->ps_ExprContext);
     128             : 
     129             :     /* And do node-type-specific processing */
     130     6100238 :     switch (nodeTag(node))
     131             :     {
     132       94182 :         case T_ResultState:
     133       94182 :             ExecReScanResult((ResultState *) node);
     134       94182 :             break;
     135             : 
     136       44540 :         case T_ProjectSetState:
     137       44540 :             ExecReScanProjectSet((ProjectSetState *) node);
     138       44540 :             break;
     139             : 
     140           0 :         case T_ModifyTableState:
     141           0 :             ExecReScanModifyTable((ModifyTableState *) node);
     142           0 :             break;
     143             : 
     144       47520 :         case T_AppendState:
     145       47520 :             ExecReScanAppend((AppendState *) node);
     146       47520 :             break;
     147             : 
     148          12 :         case T_MergeAppendState:
     149          12 :             ExecReScanMergeAppend((MergeAppendState *) node);
     150          12 :             break;
     151             : 
     152         400 :         case T_RecursiveUnionState:
     153         400 :             ExecReScanRecursiveUnion((RecursiveUnionState *) node);
     154         400 :             break;
     155             : 
     156          28 :         case T_BitmapAndState:
     157          28 :             ExecReScanBitmapAnd((BitmapAndState *) node);
     158          28 :             break;
     159             : 
     160          22 :         case T_BitmapOrState:
     161          22 :             ExecReScanBitmapOr((BitmapOrState *) node);
     162          22 :             break;
     163             : 
     164      873202 :         case T_SeqScanState:
     165      873202 :             ExecReScanSeqScan((SeqScanState *) node);
     166      873202 :             break;
     167             : 
     168          50 :         case T_SampleScanState:
     169          50 :             ExecReScanSampleScan((SampleScanState *) node);
     170          50 :             break;
     171             : 
     172         200 :         case T_GatherState:
     173         200 :             ExecReScanGather((GatherState *) node);
     174         200 :             break;
     175             : 
     176          32 :         case T_GatherMergeState:
     177          32 :             ExecReScanGatherMerge((GatherMergeState *) node);
     178          32 :             break;
     179             : 
     180      212322 :         case T_IndexScanState:
     181      212322 :             ExecReScanIndexScan((IndexScanState *) node);
     182      212318 :             break;
     183             : 
     184        9076 :         case T_IndexOnlyScanState:
     185        9076 :             ExecReScanIndexOnlyScan((IndexOnlyScanState *) node);
     186        9076 :             break;
     187             : 
     188        3280 :         case T_BitmapIndexScanState:
     189        3280 :             ExecReScanBitmapIndexScan((BitmapIndexScanState *) node);
     190        3280 :             break;
     191             : 
     192        2788 :         case T_BitmapHeapScanState:
     193        2788 :             ExecReScanBitmapHeapScan((BitmapHeapScanState *) node);
     194        2788 :             break;
     195             : 
     196          12 :         case T_TidScanState:
     197          12 :             ExecReScanTidScan((TidScanState *) node);
     198          12 :             break;
     199             : 
     200        1462 :         case T_SubqueryScanState:
     201        1462 :             ExecReScanSubqueryScan((SubqueryScanState *) node);
     202        1462 :             break;
     203             : 
     204     1426530 :         case T_FunctionScanState:
     205     1426530 :             ExecReScanFunctionScan((FunctionScanState *) node);
     206     1426530 :             break;
     207             : 
     208         128 :         case T_TableFuncScanState:
     209         128 :             ExecReScanTableFuncScan((TableFuncScanState *) node);
     210         128 :             break;
     211             : 
     212       40250 :         case T_ValuesScanState:
     213       40250 :             ExecReScanValuesScan((ValuesScanState *) node);
     214       40250 :             break;
     215             : 
     216         722 :         case T_CteScanState:
     217         722 :             ExecReScanCteScan((CteScanState *) node);
     218         722 :             break;
     219             : 
     220           0 :         case T_NamedTuplestoreScanState:
     221           0 :             ExecReScanNamedTuplestoreScan((NamedTuplestoreScanState *) node);
     222           0 :             break;
     223             : 
     224        7312 :         case T_WorkTableScanState:
     225        7312 :             ExecReScanWorkTableScan((WorkTableScanState *) node);
     226        7312 :             break;
     227             : 
     228         738 :         case T_ForeignScanState:
     229         738 :             ExecReScanForeignScan((ForeignScanState *) node);
     230         738 :             break;
     231             : 
     232           0 :         case T_CustomScanState:
     233           0 :             ExecReScanCustomScan((CustomScanState *) node);
     234           0 :             break;
     235             : 
     236       43244 :         case T_NestLoopState:
     237       43244 :             ExecReScanNestLoop((NestLoopState *) node);
     238       43244 :             break;
     239             : 
     240          48 :         case T_MergeJoinState:
     241          48 :             ExecReScanMergeJoin((MergeJoinState *) node);
     242          48 :             break;
     243             : 
     244     1094146 :         case T_HashJoinState:
     245     1094146 :             ExecReScanHashJoin((HashJoinState *) node);
     246     1094146 :             break;
     247             : 
     248      740954 :         case T_MaterialState:
     249      740954 :             ExecReScanMaterial((MaterialState *) node);
     250      740954 :             break;
     251             : 
     252       20818 :         case T_SortState:
     253       20818 :             ExecReScanSort((SortState *) node);
     254       20818 :             break;
     255             : 
     256           8 :         case T_IncrementalSortState:
     257           8 :             ExecReScanIncrementalSort((IncrementalSortState *) node);
     258           8 :             break;
     259             : 
     260          12 :         case T_GroupState:
     261          12 :             ExecReScanGroup((GroupState *) node);
     262          12 :             break;
     263             : 
     264     1183070 :         case T_AggState:
     265     1183070 :             ExecReScanAgg((AggState *) node);
     266     1183070 :             break;
     267             : 
     268          52 :         case T_WindowAggState:
     269          52 :             ExecReScanWindowAgg((WindowAggState *) node);
     270          52 :             break;
     271             : 
     272           0 :         case T_UniqueState:
     273           0 :             ExecReScanUnique((UniqueState *) node);
     274           0 :             break;
     275             : 
     276      252174 :         case T_HashState:
     277      252174 :             ExecReScanHash((HashState *) node);
     278      252174 :             break;
     279             : 
     280         400 :         case T_SetOpState:
     281         400 :             ExecReScanSetOp((SetOpState *) node);
     282         400 :             break;
     283             : 
     284          16 :         case T_LockRowsState:
     285          16 :             ExecReScanLockRows((LockRowsState *) node);
     286          16 :             break;
     287             : 
     288         488 :         case T_LimitState:
     289         488 :             ExecReScanLimit((LimitState *) node);
     290         488 :             break;
     291             : 
     292           0 :         default:
     293           0 :             elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node));
     294             :             break;
     295             :     }
     296             : 
     297     6100234 :     if (node->chgParam != NULL)
     298             :     {
     299     5276380 :         bms_free(node->chgParam);
     300     5276380 :         node->chgParam = NULL;
     301             :     }
     302     6100234 : }
     303             : 
     304             : /*
     305             :  * ExecMarkPos
     306             :  *
     307             :  * Marks the current scan position.
     308             :  *
     309             :  * NOTE: mark/restore capability is currently needed only for plan nodes
     310             :  * that are the immediate inner child of a MergeJoin node.  Since MergeJoin
     311             :  * requires sorted input, there is never any need to support mark/restore in
     312             :  * node types that cannot produce sorted output.  There are some cases in
     313             :  * which a node can pass through sorted data from its child; if we don't
     314             :  * implement mark/restore for such a node type, the planner compensates by
     315             :  * inserting a Material node above that node.
     316             :  */
     317             : void
     318      438632 : ExecMarkPos(PlanState *node)
     319             : {
     320      438632 :     switch (nodeTag(node))
     321             :     {
     322        4030 :         case T_IndexScanState:
     323        4030 :             ExecIndexMarkPos((IndexScanState *) node);
     324        4030 :             break;
     325             : 
     326       84008 :         case T_IndexOnlyScanState:
     327       84008 :             ExecIndexOnlyMarkPos((IndexOnlyScanState *) node);
     328       84008 :             break;
     329             : 
     330           0 :         case T_CustomScanState:
     331           0 :             ExecCustomMarkPos((CustomScanState *) node);
     332           0 :             break;
     333             : 
     334        4240 :         case T_MaterialState:
     335        4240 :             ExecMaterialMarkPos((MaterialState *) node);
     336        4240 :             break;
     337             : 
     338      346354 :         case T_SortState:
     339      346354 :             ExecSortMarkPos((SortState *) node);
     340      346354 :             break;
     341             : 
     342           0 :         case T_ResultState:
     343           0 :             ExecResultMarkPos((ResultState *) node);
     344           0 :             break;
     345             : 
     346           0 :         default:
     347             :             /* don't make hard error unless caller asks to restore... */
     348           0 :             elog(DEBUG2, "unrecognized node type: %d", (int) nodeTag(node));
     349           0 :             break;
     350             :     }
     351      438632 : }
     352             : 
     353             : /*
     354             :  * ExecRestrPos
     355             :  *
     356             :  * restores the scan position previously saved with ExecMarkPos()
     357             :  *
     358             :  * NOTE: the semantics of this are that the first ExecProcNode following
     359             :  * the restore operation will yield the same tuple as the first one following
     360             :  * the mark operation.  It is unspecified what happens to the plan node's
     361             :  * result TupleTableSlot.  (In most cases the result slot is unchanged by
     362             :  * a restore, but the node may choose to clear it or to load it with the
     363             :  * restored-to tuple.)  Hence the caller should discard any previously
     364             :  * returned TupleTableSlot after doing a restore.
     365             :  */
     366             : void
     367       88126 : ExecRestrPos(PlanState *node)
     368             : {
     369       88126 :     switch (nodeTag(node))
     370             :     {
     371       36008 :         case T_IndexScanState:
     372       36008 :             ExecIndexRestrPos((IndexScanState *) node);
     373       36008 :             break;
     374             : 
     375           4 :         case T_IndexOnlyScanState:
     376           4 :             ExecIndexOnlyRestrPos((IndexOnlyScanState *) node);
     377           4 :             break;
     378             : 
     379           0 :         case T_CustomScanState:
     380           0 :             ExecCustomRestrPos((CustomScanState *) node);
     381           0 :             break;
     382             : 
     383       36024 :         case T_MaterialState:
     384       36024 :             ExecMaterialRestrPos((MaterialState *) node);
     385       36024 :             break;
     386             : 
     387       16090 :         case T_SortState:
     388       16090 :             ExecSortRestrPos((SortState *) node);
     389       16090 :             break;
     390             : 
     391           0 :         case T_ResultState:
     392           0 :             ExecResultRestrPos((ResultState *) node);
     393           0 :             break;
     394             : 
     395           0 :         default:
     396           0 :             elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node));
     397             :             break;
     398             :     }
     399       88126 : }
     400             : 
     401             : /*
     402             :  * ExecSupportsMarkRestore - does a Path support mark/restore?
     403             :  *
     404             :  * This is used during planning and so must accept a Path, not a Plan.
     405             :  * We keep it here to be adjacent to the routines above, which also must
     406             :  * know which plan types support mark/restore.
     407             :  */
     408             : bool
     409        3074 : ExecSupportsMarkRestore(Path *pathnode)
     410             : {
     411             :     /*
     412             :      * For consistency with the routines above, we do not examine the nodeTag
     413             :      * but rather the pathtype, which is the Plan node type the Path would
     414             :      * produce.
     415             :      */
     416        3074 :     switch (pathnode->pathtype)
     417             :     {
     418        2258 :         case T_IndexScan:
     419             :         case T_IndexOnlyScan:
     420             :         case T_Material:
     421             :         case T_Sort:
     422        2258 :             return true;
     423             : 
     424           0 :         case T_CustomScan:
     425             :             {
     426           0 :                 CustomPath *customPath = castNode(CustomPath, pathnode);
     427             : 
     428           0 :                 if (customPath->flags & CUSTOMPATH_SUPPORT_MARK_RESTORE)
     429           0 :                     return true;
     430           0 :                 return false;
     431             :             }
     432           0 :         case T_Result:
     433             : 
     434             :             /*
     435             :              * Result supports mark/restore iff it has a child plan that does.
     436             :              *
     437             :              * We have to be careful here because there is more than one Path
     438             :              * type that can produce a Result plan node.
     439             :              */
     440           0 :             if (IsA(pathnode, ProjectionPath))
     441           0 :                 return ExecSupportsMarkRestore(((ProjectionPath *) pathnode)->subpath);
     442           0 :             else if (IsA(pathnode, MinMaxAggPath))
     443           0 :                 return false;   /* childless Result */
     444           0 :             else if (IsA(pathnode, GroupResultPath))
     445           0 :                 return false;   /* childless Result */
     446             :             else
     447             :             {
     448             :                 /* Simple RTE_RESULT base relation */
     449             :                 Assert(IsA(pathnode, Path));
     450           0 :                 return false;   /* childless Result */
     451             :             }
     452             : 
     453          80 :         case T_Append:
     454             :             {
     455          80 :                 AppendPath *appendPath = castNode(AppendPath, pathnode);
     456             : 
     457             :                 /*
     458             :                  * If there's exactly one child, then there will be no Append
     459             :                  * in the final plan, so we can handle mark/restore if the
     460             :                  * child plan node can.
     461             :                  */
     462          80 :                 if (list_length(appendPath->subpaths) == 1)
     463           0 :                     return ExecSupportsMarkRestore((Path *) linitial(appendPath->subpaths));
     464             :                 /* Otherwise, Append can't handle it */
     465          80 :                 return false;
     466             :             }
     467             : 
     468          40 :         case T_MergeAppend:
     469             :             {
     470          40 :                 MergeAppendPath *mapath = castNode(MergeAppendPath, pathnode);
     471             : 
     472             :                 /*
     473             :                  * Like the Append case above, single-subpath MergeAppends
     474             :                  * won't be in the final plan, so just return the child's
     475             :                  * mark/restore ability.
     476             :                  */
     477          40 :                 if (list_length(mapath->subpaths) == 1)
     478           0 :                     return ExecSupportsMarkRestore((Path *) linitial(mapath->subpaths));
     479             :                 /* Otherwise, MergeAppend can't handle it */
     480          40 :                 return false;
     481             :             }
     482             : 
     483         696 :         default:
     484         696 :             break;
     485             :     }
     486             : 
     487         696 :     return false;
     488             : }
     489             : 
     490             : /*
     491             :  * ExecSupportsBackwardScan - does a plan type support backwards scanning?
     492             :  *
     493             :  * Ideally, all plan types would support backwards scan, but that seems
     494             :  * unlikely to happen soon.  In some cases, a plan node passes the backwards
     495             :  * scan down to its children, and so supports backwards scan only if its
     496             :  * children do.  Therefore, this routine must be passed a complete plan tree.
     497             :  */
     498             : bool
     499        4498 : ExecSupportsBackwardScan(Plan *node)
     500             : {
     501        4498 :     if (node == NULL)
     502           0 :         return false;
     503             : 
     504             :     /*
     505             :      * Parallel-aware nodes return a subset of the tuples in each worker, and
     506             :      * in general we can't expect to have enough bookkeeping state to know
     507             :      * which ones we returned in this worker as opposed to some other worker.
     508             :      */
     509        4498 :     if (node->parallel_aware)
     510           0 :         return false;
     511             : 
     512        4498 :     switch (nodeTag(node))
     513             :     {
     514         740 :         case T_Result:
     515         740 :             if (outerPlan(node) != NULL)
     516           0 :                 return ExecSupportsBackwardScan(outerPlan(node));
     517             :             else
     518         740 :                 return false;
     519             : 
     520          22 :         case T_Append:
     521             :             {
     522             :                 ListCell   *l;
     523             : 
     524          76 :                 foreach(l, ((Append *) node)->appendplans)
     525             :                 {
     526          56 :                     if (!ExecSupportsBackwardScan((Plan *) lfirst(l)))
     527           2 :                         return false;
     528             :                 }
     529             :                 /* need not check tlist because Append doesn't evaluate it */
     530          20 :                 return true;
     531             :             }
     532             : 
     533           4 :         case T_SampleScan:
     534             :             /* Simplify life for tablesample methods by disallowing this */
     535           4 :             return false;
     536             : 
     537           0 :         case T_Gather:
     538           0 :             return false;
     539             : 
     540         342 :         case T_IndexScan:
     541         342 :             return IndexSupportsBackwardScan(((IndexScan *) node)->indexid);
     542             : 
     543          82 :         case T_IndexOnlyScan:
     544          82 :             return IndexSupportsBackwardScan(((IndexOnlyScan *) node)->indexid);
     545             : 
     546           0 :         case T_SubqueryScan:
     547           0 :             return ExecSupportsBackwardScan(((SubqueryScan *) node)->subplan);
     548             : 
     549           0 :         case T_CustomScan:
     550           0 :             {
     551           0 :                 uint32      flags = ((CustomScan *) node)->flags;
     552             : 
     553           0 :                 if (flags & CUSTOMPATH_SUPPORT_BACKWARD_SCAN)
     554           0 :                     return true;
     555             :             }
     556           0 :             return false;
     557             : 
     558        2052 :         case T_SeqScan:
     559             :         case T_TidScan:
     560             :         case T_FunctionScan:
     561             :         case T_ValuesScan:
     562             :         case T_CteScan:
     563             :         case T_Material:
     564             :         case T_Sort:
     565             :             /* these don't evaluate tlist */
     566        2052 :             return true;
     567             : 
     568           4 :         case T_IncrementalSort:
     569             : 
     570             :             /*
     571             :              * Unlike full sort, incremental sort keeps only a single group of
     572             :              * tuples in memory, so it can't scan backwards.
     573             :              */
     574           4 :             return false;
     575             : 
     576          98 :         case T_LockRows:
     577             :         case T_Limit:
     578          98 :             return ExecSupportsBackwardScan(outerPlan(node));
     579             : 
     580        1154 :         default:
     581        1154 :             return false;
     582             :     }
     583             : }
     584             : 
     585             : /*
     586             :  * An IndexScan or IndexOnlyScan node supports backward scan only if the
     587             :  * index's AM does.
     588             :  */
     589             : static bool
     590         424 : IndexSupportsBackwardScan(Oid indexid)
     591             : {
     592             :     bool        result;
     593             :     HeapTuple   ht_idxrel;
     594             :     Form_pg_class idxrelrec;
     595             :     IndexAmRoutine *amroutine;
     596             : 
     597             :     /* Fetch the pg_class tuple of the index relation */
     598         424 :     ht_idxrel = SearchSysCache1(RELOID, ObjectIdGetDatum(indexid));
     599         424 :     if (!HeapTupleIsValid(ht_idxrel))
     600           0 :         elog(ERROR, "cache lookup failed for relation %u", indexid);
     601         424 :     idxrelrec = (Form_pg_class) GETSTRUCT(ht_idxrel);
     602             : 
     603             :     /* Fetch the index AM's API struct */
     604         424 :     amroutine = GetIndexAmRoutineByAmId(idxrelrec->relam, false);
     605             : 
     606         424 :     result = amroutine->amcanbackward;
     607             : 
     608         424 :     pfree(amroutine);
     609         424 :     ReleaseSysCache(ht_idxrel);
     610             : 
     611         424 :     return result;
     612             : }
     613             : 
     614             : /*
     615             :  * ExecMaterializesOutput - does a plan type materialize its output?
     616             :  *
     617             :  * Returns true if the plan node type is one that automatically materializes
     618             :  * its output (typically by keeping it in a tuplestore).  For such plans,
     619             :  * a rescan without any parameter change will have zero startup cost and
     620             :  * very low per-tuple cost.
     621             :  */
     622             : bool
     623      251448 : ExecMaterializesOutput(NodeTag plantype)
     624             : {
     625      251448 :     switch (plantype)
     626             :     {
     627       10492 :         case T_Material:
     628             :         case T_FunctionScan:
     629             :         case T_TableFuncScan:
     630             :         case T_CteScan:
     631             :         case T_NamedTuplestoreScan:
     632             :         case T_WorkTableScan:
     633             :         case T_Sort:
     634       10492 :             return true;
     635             : 
     636      240956 :         default:
     637      240956 :             break;
     638             :     }
     639             : 
     640      240956 :     return false;
     641             : }

Generated by: LCOV version 1.13