]> granicus.if.org Git - postgresql/blobdiff - src/backend/executor/nodeTidscan.c
Make some small planner API cleanups.
[postgresql] / src / backend / executor / nodeTidscan.c
index 96af2d21d9dfb7cf22fb20bda9a96bcc062d5891..8daf09c785a5e30fce6d69ee113bdb953f253f4a 100644 (file)
@@ -3,7 +3,7 @@
  * nodeTidscan.c
  *       Routines to support direct tid scans of relations
  *
- * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
  */
 #include "postgres.h"
 
+#include "access/heapam.h"
 #include "access/sysattr.h"
 #include "catalog/pg_type.h"
 #include "executor/execdebug.h"
 #include "executor/nodeTidscan.h"
-#include "optimizer/clauses.h"
+#include "miscadmin.h"
+#include "nodes/nodeFuncs.h"
 #include "storage/bufmgr.h"
 #include "utils/array.h"
 #include "utils/rel.h"
@@ -376,20 +378,18 @@ TidNext(TidScanState *node)
                if (heap_fetch(heapRelation, snapshot, tuple, &buffer, false, NULL))
                {
                        /*
-                        * store the scanned tuple in the scan tuple slot of the scan
+                        * Store the scanned tuple in the scan tuple slot of the scan
                         * state.  Eventually we will only do this and not return a tuple.
-                        * Note: we pass 'false' because tuples returned by amgetnext are
-                        * pointers onto disk pages and were not created with palloc() and
-                        * so should not be pfree()'d.
                         */
-                       ExecStoreTuple(tuple,   /* tuple to store */
-                                                  slot,        /* slot to store in */
-                                                  buffer,      /* buffer associated with tuple  */
-                                                  false);      /* don't pfree */
+                       ExecStoreBufferHeapTuple(tuple, /* tuple to store */
+                                                                        slot,  /* slot to store in */
+                                                                        buffer);       /* buffer associated with
+                                                                                                * tuple */
 
                        /*
                         * At this point we have an extra pin on the buffer, because
-                        * ExecStoreTuple incremented the pin count. Drop our local pin.
+                        * ExecStoreHeapTuple incremented the pin count. Drop our local
+                        * pin.
                         */
                        ReleaseBuffer(buffer);
 
@@ -400,6 +400,8 @@ TidNext(TidScanState *node)
                        node->tss_TidPtr--;
                else
                        node->tss_TidPtr++;
+
+               CHECK_FOR_INTERRUPTS();
        }
 
        /*
@@ -442,9 +444,11 @@ TidRecheck(TidScanState *node, TupleTableSlot *slot)
  *               -- tidPtr is -1.
  * ----------------------------------------------------------------
  */
-TupleTableSlot *
-ExecTidScan(TidScanState *node)
+static TupleTableSlot *
+ExecTidScan(PlanState *pstate)
 {
+       TidScanState *node = castNode(TidScanState, pstate);
+
        return ExecScan(&node->ss,
                                        (ExecScanAccessMtd) TidNext,
                                        (ExecScanRecheckMtd) TidRecheck);
@@ -484,13 +488,9 @@ ExecEndTidScan(TidScanState *node)
        /*
         * clear out tuple table slots
         */
-       ExecClearTuple(node->ss.ps.ps_ResultTupleSlot);
+       if (node->ss.ps.ps_ResultTupleSlot)
+               ExecClearTuple(node->ss.ps.ps_ResultTupleSlot);
        ExecClearTuple(node->ss.ss_ScanTupleSlot);
-
-       /*
-        * close the heap relation.
-        */
-       ExecCloseScanRelation(node->ss.ss_currentRelation);
 }
 
 /* ----------------------------------------------------------------
@@ -516,6 +516,7 @@ ExecInitTidScan(TidScan *node, EState *estate, int eflags)
        tidstate = makeNode(TidScanState);
        tidstate->ss.ps.plan = (Plan *) node;
        tidstate->ss.ps.state = estate;
+       tidstate->ss.ps.ExecProcNode = ExecTidScan;
 
        /*
         * Miscellaneous initialization
@@ -524,20 +525,6 @@ ExecInitTidScan(TidScan *node, EState *estate, int eflags)
         */
        ExecAssignExprContext(estate, &tidstate->ss.ps);
 
-       /*
-        * initialize child expressions
-        */
-       tidstate->ss.ps.qual =
-               ExecInitQual(node->scan.plan.qual, (PlanState *) tidstate);
-
-       TidExprListCreate(tidstate);
-
-       /*
-        * tuple table initialization
-        */
-       ExecInitResultTupleSlot(estate, &tidstate->ss.ps);
-       ExecInitScanTupleSlot(estate, &tidstate->ss);
-
        /*
         * mark tid list as not computed yet
         */
@@ -546,7 +533,7 @@ ExecInitTidScan(TidScan *node, EState *estate, int eflags)
        tidstate->tss_TidPtr = -1;
 
        /*
-        * open the base relation and acquire appropriate lock on it.
+        * open the scan relation
         */
        currentRelation = ExecOpenScanRelation(estate, node->scan.scanrelid, eflags);
 
@@ -556,14 +543,24 @@ ExecInitTidScan(TidScan *node, EState *estate, int eflags)
        /*
         * get the scan type from the relation descriptor.
         */
-       ExecAssignScanType(&tidstate->ss, RelationGetDescr(currentRelation));
+       ExecInitScanTupleSlot(estate, &tidstate->ss,
+                                                 RelationGetDescr(currentRelation),
+                                                 &TTSOpsBufferHeapTuple);
 
        /*
-        * Initialize result tuple type and projection info.
+        * Initialize result type and projection.
         */
-       ExecAssignResultTypeFromTL(&tidstate->ss.ps);
+       ExecInitResultTypeTL(&tidstate->ss.ps);
        ExecAssignScanProjectionInfo(&tidstate->ss);
 
+       /*
+        * initialize child expressions
+        */
+       tidstate->ss.ps.qual =
+               ExecInitQual(node->scan.plan.qual, (PlanState *) tidstate);
+
+       TidExprListCreate(tidstate);
+
        /*
         * all done.
         */