LCOV - code coverage report
Current view: top level - src/backend/executor - execScan.c (source / functions) Coverage Total Hit
Test: Code coverage Lines: 60.9 % 46 28
Test Date: 2026-01-26 10:56:24 Functions: 100.0 % 4 4
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 6.2 % 16 1

             Branch data     Line data    Source code
       1                 :             : /*-------------------------------------------------------------------------
       2                 :             :  *
       3                 :             :  * execScan.c
       4                 :             :  *        This code provides support for generalized relation scans. ExecScan
       5                 :             :  *        is passed a node and a pointer to a function to "do the right thing"
       6                 :             :  *        and return a tuple from the relation. ExecScan then does the tedious
       7                 :             :  *        stuff - checking the qualification and projecting the tuple
       8                 :             :  *        appropriately.
       9                 :             :  *
      10                 :             :  * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
      11                 :             :  * Portions Copyright (c) 1994, Regents of the University of California
      12                 :             :  *
      13                 :             :  *
      14                 :             :  * IDENTIFICATION
      15                 :             :  *        src/backend/executor/execScan.c
      16                 :             :  *
      17                 :             :  *-------------------------------------------------------------------------
      18                 :             :  */
      19                 :             : #include "postgres.h"
      20                 :             : 
      21                 :             : #include "executor/executor.h"
      22                 :             : #include "executor/execScan.h"
      23                 :             : #include "miscadmin.h"
      24                 :             : 
      25                 :             : /* ----------------------------------------------------------------
      26                 :             :  *              ExecScan
      27                 :             :  *
      28                 :             :  *              Scans the relation using the 'access method' indicated and
      29                 :             :  *              returns the next qualifying tuple.
      30                 :             :  *              The access method returns the next tuple and ExecScan() is
      31                 :             :  *              responsible for checking the tuple returned against the qual-clause.
      32                 :             :  *
      33                 :             :  *              A 'recheck method' must also be provided that can check an
      34                 :             :  *              arbitrary tuple of the relation against any qual conditions
      35                 :             :  *              that are implemented internal to the access method.
      36                 :             :  *
      37                 :             :  *              Conditions:
      38                 :             :  *                -- the "cursor" maintained by the AMI is positioned at the tuple
      39                 :             :  *                       returned previously.
      40                 :             :  *
      41                 :             :  *              Initial States:
      42                 :             :  *                -- the relation indicated is opened for scanning so that the
      43                 :             :  *                       "cursor" is positioned before the first qualifying tuple.
      44                 :             :  * ----------------------------------------------------------------
      45                 :             :  */
      46                 :             : TupleTableSlot *
      47                 :     3638931 : ExecScan(ScanState *node,
      48                 :             :                  ExecScanAccessMtd accessMtd,   /* function returning a tuple */
      49                 :             :                  ExecScanRecheckMtd recheckMtd)
      50                 :             : {
      51                 :     3638931 :         EPQState   *epqstate;
      52                 :     3638931 :         ExprState  *qual;
      53                 :     3638931 :         ProjectionInfo *projInfo;
      54                 :             : 
      55                 :     3638931 :         epqstate = node->ps.state->es_epq_active;
      56                 :     3638931 :         qual = node->ps.qual;
      57                 :     3638931 :         projInfo = node->ps.ps_ProjInfo;
      58                 :             : 
      59                 :    10916793 :         return ExecScanExtended(node,
      60                 :     3638931 :                                                         accessMtd,
      61                 :     3638931 :                                                         recheckMtd,
      62                 :     3638931 :                                                         epqstate,
      63                 :     3638931 :                                                         qual,
      64                 :     3638931 :                                                         projInfo);
      65                 :     3638931 : }
      66                 :             : 
      67                 :             : /*
      68                 :             :  * ExecAssignScanProjectionInfo
      69                 :             :  *              Set up projection info for a scan node, if necessary.
      70                 :             :  *
      71                 :             :  * We can avoid a projection step if the requested tlist exactly matches
      72                 :             :  * the underlying tuple type.  If so, we just set ps_ProjInfo to NULL.
      73                 :             :  * Note that this case occurs not only for simple "SELECT * FROM ...", but
      74                 :             :  * also in most cases where there are joins or other processing nodes above
      75                 :             :  * the scan node, because the planner will preferentially generate a matching
      76                 :             :  * tlist.
      77                 :             :  *
      78                 :             :  * The scan slot's descriptor must have been set already.
      79                 :             :  */
      80                 :             : void
      81                 :      453248 : ExecAssignScanProjectionInfo(ScanState *node)
      82                 :             : {
      83                 :      453248 :         Scan       *scan = (Scan *) node->ps.plan;
      84                 :      453248 :         TupleDesc       tupdesc = node->ss_ScanTupleSlot->tts_tupleDescriptor;
      85                 :             : 
      86                 :      453248 :         ExecConditionalAssignProjectionInfo(&node->ps, tupdesc, scan->scanrelid);
      87                 :      453248 : }
      88                 :             : 
      89                 :             : /*
      90                 :             :  * ExecAssignScanProjectionInfoWithVarno
      91                 :             :  *              As above, but caller can specify varno expected in Vars in the tlist.
      92                 :             :  */
      93                 :             : void
      94                 :        1965 : ExecAssignScanProjectionInfoWithVarno(ScanState *node, int varno)
      95                 :             : {
      96                 :        1965 :         TupleDesc       tupdesc = node->ss_ScanTupleSlot->tts_tupleDescriptor;
      97                 :             : 
      98                 :        1965 :         ExecConditionalAssignProjectionInfo(&node->ps, tupdesc, varno);
      99                 :        1965 : }
     100                 :             : 
     101                 :             : /*
     102                 :             :  * ExecScanReScan
     103                 :             :  *
     104                 :             :  * This must be called within the ReScan function of any plan node type
     105                 :             :  * that uses ExecScan().
     106                 :             :  */
     107                 :             : void
     108                 :      184832 : ExecScanReScan(ScanState *node)
     109                 :             : {
     110                 :      184832 :         EState     *estate = node->ps.state;
     111                 :             : 
     112                 :             :         /*
     113                 :             :          * We must clear the scan tuple so that observers (e.g., execCurrent.c)
     114                 :             :          * can tell that this plan node is not positioned on a tuple.
     115                 :             :          */
     116                 :      184832 :         ExecClearTuple(node->ss_ScanTupleSlot);
     117                 :             : 
     118                 :             :         /*
     119                 :             :          * Rescan EvalPlanQual tuple(s) if we're inside an EvalPlanQual recheck.
     120                 :             :          * But don't lose the "blocked" status of blocked target relations.
     121                 :             :          */
     122         [ +  - ]:      184832 :         if (estate->es_epq_active != NULL)
     123                 :             :         {
     124                 :           0 :                 EPQState   *epqstate = estate->es_epq_active;
     125                 :           0 :                 Index           scanrelid = ((Scan *) node->ps.plan)->scanrelid;
     126                 :             : 
     127         [ #  # ]:           0 :                 if (scanrelid > 0)
     128                 :           0 :                         epqstate->relsubs_done[scanrelid - 1] =
     129                 :           0 :                                 epqstate->relsubs_blocked[scanrelid - 1];
     130                 :             :                 else
     131                 :             :                 {
     132                 :           0 :                         Bitmapset  *relids;
     133                 :           0 :                         int                     rtindex = -1;
     134                 :             : 
     135                 :             :                         /*
     136                 :             :                          * If an FDW or custom scan provider has replaced the join with a
     137                 :             :                          * scan, there are multiple RTIs; reset the relsubs_done flag for
     138                 :             :                          * all of them.
     139                 :             :                          */
     140         [ #  # ]:           0 :                         if (IsA(node->ps.plan, ForeignScan))
     141                 :           0 :                                 relids = ((ForeignScan *) node->ps.plan)->fs_base_relids;
     142         [ #  # ]:           0 :                         else if (IsA(node->ps.plan, CustomScan))
     143                 :           0 :                                 relids = ((CustomScan *) node->ps.plan)->custom_relids;
     144                 :             :                         else
     145   [ #  #  #  # ]:           0 :                                 elog(ERROR, "unexpected scan node: %d",
     146                 :             :                                          (int) nodeTag(node->ps.plan));
     147                 :             : 
     148         [ #  # ]:           0 :                         while ((rtindex = bms_next_member(relids, rtindex)) >= 0)
     149                 :             :                         {
     150         [ #  # ]:           0 :                                 Assert(rtindex > 0);
     151                 :           0 :                                 epqstate->relsubs_done[rtindex - 1] =
     152                 :           0 :                                         epqstate->relsubs_blocked[rtindex - 1];
     153                 :             :                         }
     154                 :           0 :                 }
     155                 :           0 :         }
     156                 :      184832 : }
        

Generated by: LCOV version 2.3.2-1