mirror of
https://github.com/postgres/postgres.git
synced 2025-05-02 11:44:50 +03:00
as determined by include-what-you-use (IWYU) While IWYU also suggests to *add* a bunch of #include's (which is its main purpose), this patch does not do that. In some cases, a more specific #include replaces another less specific one. Some manual adjustments of the automatic result: - IWYU currently doesn't know about includes that provide global variable declarations (like -Wmissing-variable-declarations), so those includes are being kept manually. - All includes for port(ability) headers are being kept for now, to play it safe. - No changes of catalog/pg_foo.h to catalog/pg_foo_d.h, to keep the patch from exploding in size. Note that this patch touches just *.c files, so nothing declared in header files changes in hidden ways. As a small example, in src/backend/access/transam/rmgr.c, some IWYU pragma annotations are added to handle a special case there. Discussion: https://www.postgresql.org/message-id/flat/af837490-6b2f-46df-ba05-37ea6a6653fc%40eisentraut.org
202 lines
5.6 KiB
C
202 lines
5.6 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* nodeSubqueryscan.c
|
|
* Support routines for scanning subqueries (subselects in rangetable).
|
|
*
|
|
* This is just enough different from sublinks (nodeSubplan.c) to mean that
|
|
* we need two sets of code. Ought to look at trying to unify the cases.
|
|
*
|
|
*
|
|
* Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
*
|
|
* IDENTIFICATION
|
|
* src/backend/executor/nodeSubqueryscan.c
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
/*
|
|
* INTERFACE ROUTINES
|
|
* ExecSubqueryScan scans a subquery.
|
|
* ExecSubqueryNext retrieve next tuple in sequential order.
|
|
* ExecInitSubqueryScan creates and initializes a subqueryscan node.
|
|
* ExecEndSubqueryScan releases any storage allocated.
|
|
* ExecReScanSubqueryScan rescans the relation
|
|
*
|
|
*/
|
|
#include "postgres.h"
|
|
|
|
#include "executor/executor.h"
|
|
#include "executor/nodeSubqueryscan.h"
|
|
|
|
static TupleTableSlot *SubqueryNext(SubqueryScanState *node);
|
|
|
|
/* ----------------------------------------------------------------
|
|
* Scan Support
|
|
* ----------------------------------------------------------------
|
|
*/
|
|
/* ----------------------------------------------------------------
|
|
* SubqueryNext
|
|
*
|
|
* This is a workhorse for ExecSubqueryScan
|
|
* ----------------------------------------------------------------
|
|
*/
|
|
static TupleTableSlot *
|
|
SubqueryNext(SubqueryScanState *node)
|
|
{
|
|
TupleTableSlot *slot;
|
|
|
|
/*
|
|
* Get the next tuple from the sub-query.
|
|
*/
|
|
slot = ExecProcNode(node->subplan);
|
|
|
|
/*
|
|
* We just return the subplan's result slot, rather than expending extra
|
|
* cycles for ExecCopySlot(). (Our own ScanTupleSlot is used only for
|
|
* EvalPlanQual rechecks.)
|
|
*/
|
|
return slot;
|
|
}
|
|
|
|
/*
|
|
* SubqueryRecheck -- access method routine to recheck a tuple in EvalPlanQual
|
|
*/
|
|
static bool
|
|
SubqueryRecheck(SubqueryScanState *node, TupleTableSlot *slot)
|
|
{
|
|
/* nothing to check */
|
|
return true;
|
|
}
|
|
|
|
/* ----------------------------------------------------------------
|
|
* ExecSubqueryScan(node)
|
|
*
|
|
* Scans the subquery sequentially and returns the next qualifying
|
|
* tuple.
|
|
* We call the ExecScan() routine and pass it the appropriate
|
|
* access method functions.
|
|
* ----------------------------------------------------------------
|
|
*/
|
|
static TupleTableSlot *
|
|
ExecSubqueryScan(PlanState *pstate)
|
|
{
|
|
SubqueryScanState *node = castNode(SubqueryScanState, pstate);
|
|
|
|
return ExecScan(&node->ss,
|
|
(ExecScanAccessMtd) SubqueryNext,
|
|
(ExecScanRecheckMtd) SubqueryRecheck);
|
|
}
|
|
|
|
/* ----------------------------------------------------------------
|
|
* ExecInitSubqueryScan
|
|
* ----------------------------------------------------------------
|
|
*/
|
|
SubqueryScanState *
|
|
ExecInitSubqueryScan(SubqueryScan *node, EState *estate, int eflags)
|
|
{
|
|
SubqueryScanState *subquerystate;
|
|
|
|
/* check for unsupported flags */
|
|
Assert(!(eflags & EXEC_FLAG_MARK));
|
|
|
|
/* SubqueryScan should not have any "normal" children */
|
|
Assert(outerPlan(node) == NULL);
|
|
Assert(innerPlan(node) == NULL);
|
|
|
|
/*
|
|
* create state structure
|
|
*/
|
|
subquerystate = makeNode(SubqueryScanState);
|
|
subquerystate->ss.ps.plan = (Plan *) node;
|
|
subquerystate->ss.ps.state = estate;
|
|
subquerystate->ss.ps.ExecProcNode = ExecSubqueryScan;
|
|
|
|
/*
|
|
* Miscellaneous initialization
|
|
*
|
|
* create expression context for node
|
|
*/
|
|
ExecAssignExprContext(estate, &subquerystate->ss.ps);
|
|
|
|
/*
|
|
* initialize subquery
|
|
*/
|
|
subquerystate->subplan = ExecInitNode(node->subplan, estate, eflags);
|
|
|
|
/*
|
|
* Initialize scan slot and type (needed by ExecAssignScanProjectionInfo)
|
|
*/
|
|
ExecInitScanTupleSlot(estate, &subquerystate->ss,
|
|
ExecGetResultType(subquerystate->subplan),
|
|
ExecGetResultSlotOps(subquerystate->subplan, NULL));
|
|
|
|
/*
|
|
* The slot used as the scantuple isn't the slot above (outside of EPQ),
|
|
* but the one from the node below.
|
|
*/
|
|
subquerystate->ss.ps.scanopsset = true;
|
|
subquerystate->ss.ps.scanops = ExecGetResultSlotOps(subquerystate->subplan,
|
|
&subquerystate->ss.ps.scanopsfixed);
|
|
subquerystate->ss.ps.resultopsset = true;
|
|
subquerystate->ss.ps.resultops = subquerystate->ss.ps.scanops;
|
|
subquerystate->ss.ps.resultopsfixed = subquerystate->ss.ps.scanopsfixed;
|
|
|
|
/*
|
|
* Initialize result type and projection.
|
|
*/
|
|
ExecInitResultTypeTL(&subquerystate->ss.ps);
|
|
ExecAssignScanProjectionInfo(&subquerystate->ss);
|
|
|
|
/*
|
|
* initialize child expressions
|
|
*/
|
|
subquerystate->ss.ps.qual =
|
|
ExecInitQual(node->scan.plan.qual, (PlanState *) subquerystate);
|
|
|
|
return subquerystate;
|
|
}
|
|
|
|
/* ----------------------------------------------------------------
|
|
* ExecEndSubqueryScan
|
|
*
|
|
* frees any storage allocated through C routines.
|
|
* ----------------------------------------------------------------
|
|
*/
|
|
void
|
|
ExecEndSubqueryScan(SubqueryScanState *node)
|
|
{
|
|
/*
|
|
* close down subquery
|
|
*/
|
|
ExecEndNode(node->subplan);
|
|
}
|
|
|
|
/* ----------------------------------------------------------------
|
|
* ExecReScanSubqueryScan
|
|
*
|
|
* Rescans the relation.
|
|
* ----------------------------------------------------------------
|
|
*/
|
|
void
|
|
ExecReScanSubqueryScan(SubqueryScanState *node)
|
|
{
|
|
ExecScanReScan(&node->ss);
|
|
|
|
/*
|
|
* ExecReScan doesn't know about my subplan, so I have to do
|
|
* changed-parameter signaling myself. This is just as well, because the
|
|
* subplan has its own memory context in which its chgParam state lives.
|
|
*/
|
|
if (node->ss.ps.chgParam != NULL)
|
|
UpdateChangedParamSet(node->subplan, node->ss.ps.chgParam);
|
|
|
|
/*
|
|
* if chgParam of subnode is not null then plan will be re-scanned by
|
|
* first ExecProcNode.
|
|
*/
|
|
if (node->subplan->chgParam == NULL)
|
|
ExecReScan(node->subplan);
|
|
}
|