1996-08-28 03:59:28 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* plannodes.h
|
1997-09-07 07:04:48 +02:00
|
|
|
* definitions for query plan nodes
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*
|
2009-01-01 18:24:05 +01:00
|
|
|
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
Re-implement EvalPlanQual processing to improve its performance and eliminate
a lot of strange behaviors that occurred in join cases. We now identify the
"current" row for every joined relation in UPDATE, DELETE, and SELECT FOR
UPDATE/SHARE queries. If an EvalPlanQual recheck is necessary, we jam the
appropriate row into each scan node in the rechecking plan, forcing it to emit
only that one row. The former behavior could rescan the whole of each joined
relation for each recheck, which was terrible for performance, and what's much
worse could result in duplicated output tuples.
Also, the original implementation of EvalPlanQual could not re-use the recheck
execution tree --- it had to go through a full executor init and shutdown for
every row to be tested. To avoid this overhead, I've associated a special
runtime Param with each LockRows or ModifyTable plan node, and arranged to
make every scan node below such a node depend on that Param. Thus, by
signaling a change in that Param, the EPQ machinery can just rescan the
already-built test plan.
This patch also adds a prohibition on set-returning functions in the
targetlist of SELECT FOR UPDATE/SHARE. This is needed to avoid the
duplicate-output-tuple problem. It seems fairly reasonable since the
other restrictions on SELECT FOR UPDATE are meant to ensure that there
is a unique correspondence between source tuples and result tuples,
which an output SRF destroys as much as anything else does.
2009-10-26 03:26:45 +01:00
|
|
|
* $PostgreSQL: pgsql/src/include/nodes/plannodes.h,v 1.113 2009/10/26 02:26:42 tgl Exp $
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef PLANNODES_H
|
1997-09-07 07:04:48 +02:00
|
|
|
#define PLANNODES_H
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
#include "access/sdir.h"
|
2003-02-09 01:30:41 +01:00
|
|
|
#include "nodes/bitmapset.h"
|
2002-12-05 16:50:39 +01:00
|
|
|
#include "nodes/primnodes.h"
|
2008-09-09 20:58:09 +02:00
|
|
|
#include "storage/itemptr.h"
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* node definitions
|
1996-08-28 03:59:28 +02:00
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2007-02-20 18:32:18 +01:00
|
|
|
/* ----------------
|
|
|
|
* PlannedStmt node
|
|
|
|
*
|
|
|
|
* The output of the planner is a Plan tree headed by a PlannedStmt node.
|
|
|
|
* PlannedStmt holds the "one time" information needed by the executor.
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
typedef struct PlannedStmt
|
|
|
|
{
|
|
|
|
NodeTag type;
|
|
|
|
|
|
|
|
CmdType commandType; /* select|insert|update|delete */
|
|
|
|
|
2009-10-10 03:43:50 +02:00
|
|
|
bool hasReturning; /* is it insert|update|delete RETURNING? */
|
|
|
|
|
2007-02-20 18:32:18 +01:00
|
|
|
bool canSetTag; /* do I set the command result tag? */
|
|
|
|
|
2007-09-20 19:56:33 +02:00
|
|
|
bool transientPlan; /* redo plan when TransactionXmin changes? */
|
|
|
|
|
2007-02-20 18:32:18 +01:00
|
|
|
struct Plan *planTree; /* tree of Plan nodes */
|
|
|
|
|
|
|
|
List *rtable; /* list of RangeTblEntry nodes */
|
|
|
|
|
|
|
|
/* rtable indexes of target relations for INSERT/UPDATE/DELETE */
|
|
|
|
List *resultRelations; /* integer list of RT indexes, or NIL */
|
|
|
|
|
2007-04-28 00:05:49 +02:00
|
|
|
Node *utilityStmt; /* non-null if this is DECLARE CURSOR */
|
|
|
|
|
|
|
|
IntoClause *intoClause; /* target for SELECT INTO / CREATE TABLE AS */
|
2007-02-20 18:32:18 +01:00
|
|
|
|
2007-02-22 23:00:26 +01:00
|
|
|
List *subplans; /* Plan trees for SubPlan expressions */
|
|
|
|
|
2007-02-27 02:11:26 +01:00
|
|
|
Bitmapset *rewindPlanIDs; /* indices of subplans that require REWIND */
|
|
|
|
|
Re-implement EvalPlanQual processing to improve its performance and eliminate
a lot of strange behaviors that occurred in join cases. We now identify the
"current" row for every joined relation in UPDATE, DELETE, and SELECT FOR
UPDATE/SHARE queries. If an EvalPlanQual recheck is necessary, we jam the
appropriate row into each scan node in the rechecking plan, forcing it to emit
only that one row. The former behavior could rescan the whole of each joined
relation for each recheck, which was terrible for performance, and what's much
worse could result in duplicated output tuples.
Also, the original implementation of EvalPlanQual could not re-use the recheck
execution tree --- it had to go through a full executor init and shutdown for
every row to be tested. To avoid this overhead, I've associated a special
runtime Param with each LockRows or ModifyTable plan node, and arranged to
make every scan node below such a node depend on that Param. Thus, by
signaling a change in that Param, the EPQ machinery can just rescan the
already-built test plan.
This patch also adds a prohibition on set-returning functions in the
targetlist of SELECT FOR UPDATE/SHARE. This is needed to avoid the
duplicate-output-tuple problem. It seems fairly reasonable since the
other restrictions on SELECT FOR UPDATE are meant to ensure that there
is a unique correspondence between source tuples and result tuples,
which an output SRF destroys as much as anything else does.
2009-10-26 03:26:45 +01:00
|
|
|
List *rowMarks; /* a list of PlanRowMark's */
|
2007-02-20 18:32:18 +01:00
|
|
|
|
2007-10-11 20:05:27 +02:00
|
|
|
List *relationOids; /* OIDs of relations the plan depends on */
|
|
|
|
|
2008-09-09 20:58:09 +02:00
|
|
|
List *invalItems; /* other dependencies, as PlanInvalItems */
|
|
|
|
|
2007-02-20 18:32:18 +01:00
|
|
|
int nParamExec; /* number of PARAM_EXEC Params used */
|
2007-11-15 23:25:18 +01:00
|
|
|
} PlannedStmt;
|
2007-02-20 18:32:18 +01:00
|
|
|
|
2007-02-22 23:00:26 +01:00
|
|
|
/* macro for fetching the Plan associated with a SubPlan node */
|
|
|
|
#define exec_subplan_get_plan(plannedstmt, subplan) \
|
|
|
|
((Plan *) list_nth((plannedstmt)->subplans, (subplan)->plan_id - 1))
|
|
|
|
|
2007-02-20 18:32:18 +01:00
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* Plan node
|
2002-12-05 16:50:39 +01:00
|
|
|
*
|
|
|
|
* All plan nodes "derive" from the Plan structure by having the
|
|
|
|
* Plan structure as the first field. This ensures that everything works
|
|
|
|
* when nodes are cast to Plan's. (node pointers are frequently cast to Plan*
|
|
|
|
* when passed around generically in the executor)
|
|
|
|
*
|
|
|
|
* We never actually instantiate any Plan nodes; this is just the common
|
|
|
|
* abstract superclass for all Plan-type nodes.
|
1996-08-28 03:59:28 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct Plan
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
NodeTag type;
|
2000-01-09 01:26:47 +01:00
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
/*
|
|
|
|
* estimated execution costs for plan (see costsize.c for more info)
|
|
|
|
*/
|
2005-10-15 04:49:52 +02:00
|
|
|
Cost startup_cost; /* cost expended before fetching any tuples */
|
|
|
|
Cost total_cost; /* total cost (assuming all tuples fetched) */
|
2000-02-15 21:49:31 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
/*
|
2002-12-05 16:50:39 +01:00
|
|
|
* planner's estimate of result size of this plan step
|
2000-02-15 21:49:31 +01:00
|
|
|
*/
|
|
|
|
double plan_rows; /* number of rows plan is expected to emit */
|
|
|
|
int plan_width; /* average row width in bytes */
|
2000-01-09 01:26:47 +01:00
|
|
|
|
2001-09-18 03:59:07 +02:00
|
|
|
/*
|
2002-12-05 16:50:39 +01:00
|
|
|
* Common structural data for all Plan types.
|
2001-09-18 03:59:07 +02:00
|
|
|
*/
|
2002-12-05 16:50:39 +01:00
|
|
|
List *targetlist; /* target list to be computed at this node */
|
|
|
|
List *qual; /* implicitly-ANDed qual conditions */
|
|
|
|
struct Plan *lefttree; /* input plan tree(s) */
|
|
|
|
struct Plan *righttree;
|
|
|
|
List *initPlan; /* Init Plan nodes (un-correlated expr
|
|
|
|
* subselects) */
|
2001-09-18 03:59:07 +02:00
|
|
|
|
|
|
|
/*
|
2002-12-05 16:50:39 +01:00
|
|
|
* Information for management of parameter-change-driven rescanning
|
2003-02-09 01:30:41 +01:00
|
|
|
*
|
2005-11-22 19:17:34 +01:00
|
|
|
* extParam includes the paramIDs of all external PARAM_EXEC params
|
|
|
|
* affecting this plan node or its children. setParam params from the
|
|
|
|
* node's initPlans are not included, but their extParams are.
|
2003-02-09 01:30:41 +01:00
|
|
|
*
|
2005-11-22 19:17:34 +01:00
|
|
|
* allParam includes all the extParam paramIDs, plus the IDs of local
|
|
|
|
* params that affect the node (i.e., the setParams of its initplans).
|
|
|
|
* These are _all_ the PARAM_EXEC params that affect this node.
|
2001-09-18 03:59:07 +02:00
|
|
|
*/
|
2003-02-09 01:30:41 +01:00
|
|
|
Bitmapset *extParam;
|
|
|
|
Bitmapset *allParam;
|
1997-09-08 23:56:23 +02:00
|
|
|
} Plan;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* these are are defined to avoid confusion problems with "left"
|
|
|
|
* and "right" and "inner" and "outer". The convention is that
|
|
|
|
* the "left" plan is the "outer" plan and the "right" plan is
|
|
|
|
* the inner plan, but these make the code more readable.
|
1996-08-28 03:59:28 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#define innerPlan(node) (((Plan *)(node))->righttree)
|
|
|
|
#define outerPlan(node) (((Plan *)(node))->lefttree)
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* ----------------
|
2000-11-12 01:37:02 +01:00
|
|
|
* Result node -
|
|
|
|
* If no outer plan, evaluate a variable-free targetlist.
|
2002-11-06 01:00:45 +01:00
|
|
|
* If outer plan, return tuples from outer plan (after a level of
|
|
|
|
* projection as shown by targetlist).
|
|
|
|
*
|
|
|
|
* If resconstantqual isn't NULL, it represents a one-time qualification
|
|
|
|
* test (i.e., one that doesn't depend on any variables from the outer plan,
|
|
|
|
* so needs to be evaluated only once).
|
1996-08-28 03:59:28 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct Result
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Plan plan;
|
|
|
|
Node *resconstantqual;
|
1997-09-08 23:56:23 +02:00
|
|
|
} Result;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2009-10-10 03:43:50 +02:00
|
|
|
/* ----------------
|
|
|
|
* ModifyTable node -
|
|
|
|
* Apply rows produced by subplan(s) to result table(s),
|
|
|
|
* by inserting, updating, or deleting.
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
typedef struct ModifyTable
|
|
|
|
{
|
|
|
|
Plan plan;
|
|
|
|
CmdType operation; /* INSERT, UPDATE, or DELETE */
|
|
|
|
List *resultRelations; /* integer list of RT indexes */
|
|
|
|
List *plans; /* plan(s) producing source data */
|
|
|
|
List *returningLists; /* per-target-table RETURNING tlists */
|
Re-implement EvalPlanQual processing to improve its performance and eliminate
a lot of strange behaviors that occurred in join cases. We now identify the
"current" row for every joined relation in UPDATE, DELETE, and SELECT FOR
UPDATE/SHARE queries. If an EvalPlanQual recheck is necessary, we jam the
appropriate row into each scan node in the rechecking plan, forcing it to emit
only that one row. The former behavior could rescan the whole of each joined
relation for each recheck, which was terrible for performance, and what's much
worse could result in duplicated output tuples.
Also, the original implementation of EvalPlanQual could not re-use the recheck
execution tree --- it had to go through a full executor init and shutdown for
every row to be tested. To avoid this overhead, I've associated a special
runtime Param with each LockRows or ModifyTable plan node, and arranged to
make every scan node below such a node depend on that Param. Thus, by
signaling a change in that Param, the EPQ machinery can just rescan the
already-built test plan.
This patch also adds a prohibition on set-returning functions in the
targetlist of SELECT FOR UPDATE/SHARE. This is needed to avoid the
duplicate-output-tuple problem. It seems fairly reasonable since the
other restrictions on SELECT FOR UPDATE are meant to ensure that there
is a unique correspondence between source tuples and result tuples,
which an output SRF destroys as much as anything else does.
2009-10-26 03:26:45 +01:00
|
|
|
List *rowMarks; /* PlanRowMarks (non-locking only) */
|
|
|
|
int epqParam; /* ID of Param for EvalPlanQual re-eval */
|
2009-10-10 03:43:50 +02:00
|
|
|
} ModifyTable;
|
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
/* ----------------
|
2000-11-12 01:37:02 +01:00
|
|
|
* Append node -
|
|
|
|
* Generate the concatenation of the results of sub-plans.
|
1996-08-28 03:59:28 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct Append
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Plan plan;
|
1998-07-15 16:54:39 +02:00
|
|
|
List *appendplans;
|
1997-09-08 22:59:27 +02:00
|
|
|
} Append;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2008-10-04 23:56:55 +02:00
|
|
|
/* ----------------
|
|
|
|
* RecursiveUnion node -
|
|
|
|
* Generate a recursive union of two subplans.
|
|
|
|
*
|
|
|
|
* The "outer" subplan is always the non-recursive term, and the "inner"
|
|
|
|
* subplan is the recursive term.
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
typedef struct RecursiveUnion
|
|
|
|
{
|
|
|
|
Plan plan;
|
|
|
|
int wtParam; /* ID of Param representing work table */
|
2008-10-07 21:27:04 +02:00
|
|
|
/* Remaining fields are zero/null in UNION ALL case */
|
|
|
|
int numCols; /* number of columns to check for
|
|
|
|
* duplicate-ness */
|
|
|
|
AttrNumber *dupColIdx; /* their indexes in the target list */
|
|
|
|
Oid *dupOperators; /* equality operators to compare with */
|
|
|
|
long numGroups; /* estimated number of groups in input */
|
2008-10-04 23:56:55 +02:00
|
|
|
} RecursiveUnion;
|
|
|
|
|
2005-04-20 00:35:18 +02:00
|
|
|
/* ----------------
|
|
|
|
* BitmapAnd node -
|
|
|
|
* Generate the intersection of the results of sub-plans.
|
|
|
|
*
|
2005-10-15 04:49:52 +02:00
|
|
|
* The subplans must be of types that yield tuple bitmaps. The targetlist
|
2005-04-20 00:35:18 +02:00
|
|
|
* and qual fields of the plan are unused and are always NIL.
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
typedef struct BitmapAnd
|
|
|
|
{
|
|
|
|
Plan plan;
|
|
|
|
List *bitmapplans;
|
|
|
|
} BitmapAnd;
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* BitmapOr node -
|
|
|
|
* Generate the union of the results of sub-plans.
|
|
|
|
*
|
2005-10-15 04:49:52 +02:00
|
|
|
* The subplans must be of types that yield tuple bitmaps. The targetlist
|
2005-04-20 00:35:18 +02:00
|
|
|
* and qual fields of the plan are unused and are always NIL.
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
typedef struct BitmapOr
|
|
|
|
{
|
|
|
|
Plan plan;
|
|
|
|
List *bitmapplans;
|
|
|
|
} BitmapOr;
|
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
/*
|
|
|
|
* ==========
|
|
|
|
* Scan nodes
|
|
|
|
* ==========
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct Scan
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Plan plan;
|
|
|
|
Index scanrelid; /* relid is index into the range table */
|
1997-09-08 23:56:23 +02:00
|
|
|
} Scan;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* sequential scan node
|
1996-08-28 03:59:28 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
typedef Scan SeqScan;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* index scan node
|
2003-11-09 22:30:38 +01:00
|
|
|
*
|
2005-04-25 03:30:14 +02:00
|
|
|
* indexqualorig is an implicitly-ANDed list of index qual expressions, each
|
|
|
|
* in the same form it appeared in the query WHERE condition. Each should
|
|
|
|
* be of the form (indexkey OP comparisonval) or (comparisonval OP indexkey).
|
|
|
|
* The indexkey is a Var or expression referencing column(s) of the index's
|
2005-10-15 04:49:52 +02:00
|
|
|
* base table. The comparisonval might be any expression, but it won't use
|
2005-04-25 03:30:14 +02:00
|
|
|
* any columns of the base table.
|
|
|
|
*
|
|
|
|
* indexqual has the same form, but the expressions have been commuted if
|
|
|
|
* necessary to put the indexkeys on the left, and the indexkeys are replaced
|
|
|
|
* by Var nodes identifying the index columns (varattno is the index column
|
|
|
|
* position, not the base table's column, even though varno is for the base
|
2005-10-15 04:49:52 +02:00
|
|
|
* table). This is a bit hokey ... would be cleaner to use a special-purpose
|
|
|
|
* node type that could not be mistaken for a regular Var. But it will do
|
2005-04-25 03:30:14 +02:00
|
|
|
* for now.
|
1996-08-28 03:59:28 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct IndexScan
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Scan scan;
|
2005-10-15 04:49:52 +02:00
|
|
|
Oid indexid; /* OID of index to scan */
|
|
|
|
List *indexqual; /* list of index quals (OpExprs) */
|
|
|
|
List *indexqualorig; /* the same in original form */
|
2005-04-25 03:30:14 +02:00
|
|
|
ScanDirection indexorderdir; /* forward or backward or don't care */
|
1997-09-08 23:56:23 +02:00
|
|
|
} IndexScan;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1999-11-23 21:07:06 +01:00
|
|
|
/* ----------------
|
2005-04-20 00:35:18 +02:00
|
|
|
* bitmap index scan node
|
|
|
|
*
|
|
|
|
* BitmapIndexScan delivers a bitmap of potential tuple locations;
|
2005-10-15 04:49:52 +02:00
|
|
|
* it does not access the heap itself. The bitmap is used by an
|
2005-04-20 00:35:18 +02:00
|
|
|
* ancestor BitmapHeapScan node, possibly after passing through
|
|
|
|
* intermediate BitmapAnd and/or BitmapOr nodes to combine it with
|
|
|
|
* the results of other BitmapIndexScans.
|
|
|
|
*
|
2005-04-25 03:30:14 +02:00
|
|
|
* The fields have the same meanings as for IndexScan, except we don't
|
|
|
|
* store a direction flag because direction is uninteresting.
|
|
|
|
*
|
2005-04-20 00:35:18 +02:00
|
|
|
* In a BitmapIndexScan plan node, the targetlist and qual fields are
|
2005-04-25 03:30:14 +02:00
|
|
|
* not used and are always NIL. The indexqualorig field is unused at
|
2005-04-20 00:35:18 +02:00
|
|
|
* run time too, but is saved for the benefit of EXPLAIN.
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
typedef struct BitmapIndexScan
|
|
|
|
{
|
|
|
|
Scan scan;
|
2005-10-15 04:49:52 +02:00
|
|
|
Oid indexid; /* OID of index to scan */
|
|
|
|
List *indexqual; /* list of index quals (OpExprs) */
|
|
|
|
List *indexqualorig; /* the same in original form */
|
2005-04-20 00:35:18 +02:00
|
|
|
} BitmapIndexScan;
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* bitmap sequential scan node
|
|
|
|
*
|
|
|
|
* This needs a copy of the qual conditions being used by the input index
|
|
|
|
* scans because there are various cases where we need to recheck the quals;
|
|
|
|
* for example, when the bitmap is lossy about the specific rows on a page
|
|
|
|
* that meet the index condition.
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
typedef struct BitmapHeapScan
|
|
|
|
{
|
|
|
|
Scan scan;
|
2005-10-15 04:49:52 +02:00
|
|
|
List *bitmapqualorig; /* index quals, in standard expr form */
|
2005-04-20 00:35:18 +02:00
|
|
|
} BitmapHeapScan;
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* tid scan node
|
2005-11-26 23:14:57 +01:00
|
|
|
*
|
|
|
|
* tidquals is an implicitly OR'ed list of qual expressions of the form
|
|
|
|
* "CTID = pseudoconstant" or "CTID = ANY(pseudoconstant_array)".
|
1999-11-23 21:07:06 +01:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
typedef struct TidScan
|
|
|
|
{
|
2000-01-09 01:26:47 +01:00
|
|
|
Scan scan;
|
2005-11-26 23:14:57 +01:00
|
|
|
List *tidquals; /* qual(s) involving CTID = something */
|
1999-11-23 21:07:06 +01:00
|
|
|
} TidScan;
|
|
|
|
|
2000-09-29 20:21:41 +02:00
|
|
|
/* ----------------
|
|
|
|
* subquery scan node
|
|
|
|
*
|
|
|
|
* SubqueryScan is for scanning the output of a sub-query in the range table.
|
2007-02-19 03:23:12 +01:00
|
|
|
* We often need an extra plan node above the sub-query's plan to perform
|
|
|
|
* expression evaluations (which we can't push into the sub-query without
|
|
|
|
* risking changing its semantics). Although we are not scanning a physical
|
|
|
|
* relation, we make this a descendant of Scan anyway for code-sharing
|
|
|
|
* purposes.
|
2000-09-29 20:21:41 +02:00
|
|
|
*
|
|
|
|
* Note: we store the sub-plan in the type-specific subplan field, not in
|
2001-03-22 05:01:46 +01:00
|
|
|
* the generic lefttree field as you might expect. This is because we do
|
2000-09-29 20:21:41 +02:00
|
|
|
* not want plan-tree-traversal routines to recurse into the subplan without
|
|
|
|
* knowing that they are changing Query contexts.
|
2007-02-22 23:00:26 +01:00
|
|
|
*
|
|
|
|
* Note: subrtable is used just to carry the subquery rangetable from
|
|
|
|
* createplan.c to setrefs.c; it should always be NIL by the time the
|
2009-10-12 20:10:51 +02:00
|
|
|
* executor sees the plan. Similarly for subrowmark.
|
2000-09-29 20:21:41 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
typedef struct SubqueryScan
|
|
|
|
{
|
|
|
|
Scan scan;
|
|
|
|
Plan *subplan;
|
2007-02-22 23:00:26 +01:00
|
|
|
List *subrtable; /* temporary workspace for planner */
|
2009-10-12 20:10:51 +02:00
|
|
|
List *subrowmark; /* temporary workspace for planner */
|
2000-09-29 20:21:41 +02:00
|
|
|
} SubqueryScan;
|
|
|
|
|
2002-05-12 22:10:05 +02:00
|
|
|
/* ----------------
|
|
|
|
* FunctionScan node
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
typedef struct FunctionScan
|
|
|
|
{
|
2002-09-04 22:31:48 +02:00
|
|
|
Scan scan;
|
2007-02-19 03:23:12 +01:00
|
|
|
Node *funcexpr; /* expression tree for func call */
|
|
|
|
List *funccolnames; /* output column names (string Value nodes) */
|
|
|
|
List *funccoltypes; /* OID list of column type OIDs */
|
|
|
|
List *funccoltypmods; /* integer list of column typmods */
|
2002-05-12 22:10:05 +02:00
|
|
|
} FunctionScan;
|
|
|
|
|
2006-08-02 03:59:48 +02:00
|
|
|
/* ----------------
|
|
|
|
* ValuesScan node
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
typedef struct ValuesScan
|
|
|
|
{
|
|
|
|
Scan scan;
|
2007-02-19 03:23:12 +01:00
|
|
|
List *values_lists; /* list of expression lists */
|
2006-08-02 03:59:48 +02:00
|
|
|
} ValuesScan;
|
|
|
|
|
2008-10-04 23:56:55 +02:00
|
|
|
/* ----------------
|
|
|
|
* CteScan node
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
typedef struct CteScan
|
|
|
|
{
|
|
|
|
Scan scan;
|
|
|
|
int ctePlanId; /* ID of init SubPlan for CTE */
|
|
|
|
int cteParam; /* ID of Param representing CTE output */
|
|
|
|
} CteScan;
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* WorkTableScan node
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
typedef struct WorkTableScan
|
|
|
|
{
|
|
|
|
Scan scan;
|
|
|
|
int wtParam; /* ID of Param representing work table */
|
|
|
|
} WorkTableScan;
|
|
|
|
|
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
/*
|
1996-08-28 03:59:28 +02:00
|
|
|
* ==========
|
|
|
|
* Join nodes
|
|
|
|
* ==========
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* Join node
|
2000-09-12 23:07:18 +02:00
|
|
|
*
|
|
|
|
* jointype: rule for joining tuples from left and right subtrees
|
|
|
|
* joinqual: qual conditions that came from JOIN/ON or JOIN/USING
|
|
|
|
* (plan.qual contains conditions that came from WHERE)
|
|
|
|
*
|
|
|
|
* When jointype is INNER, joinqual and plan.qual are semantically
|
|
|
|
* interchangeable. For OUTER jointypes, the two are *not* interchangeable;
|
|
|
|
* only joinqual is used to determine whether a match has been found for
|
|
|
|
* the purpose of deciding whether to generate null-extended tuples.
|
|
|
|
* (But plan.qual is still applied before actually returning a tuple.)
|
|
|
|
* For an outer join, only joinquals are allowed to be used as the merge
|
|
|
|
* or hash condition of a merge or hash join.
|
1996-08-28 03:59:28 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
2000-09-12 23:07:18 +02:00
|
|
|
typedef struct Join
|
|
|
|
{
|
|
|
|
Plan plan;
|
|
|
|
JoinType jointype;
|
|
|
|
List *joinqual; /* JOIN quals (in addition to plan.qual) */
|
|
|
|
} Join;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* nest loop join node
|
1996-08-28 03:59:28 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct NestLoop
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Join join;
|
1997-09-08 23:56:23 +02:00
|
|
|
} NestLoop;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* merge join node
|
2007-01-10 19:06:05 +01:00
|
|
|
*
|
|
|
|
* The expected ordering of each mergeable column is described by a btree
|
|
|
|
* opfamily OID, a direction (BTLessStrategyNumber or BTGreaterStrategyNumber)
|
2007-11-15 22:14:46 +01:00
|
|
|
* and a nulls-first flag. Note that the two sides of each mergeclause may
|
2007-01-10 19:06:05 +01:00
|
|
|
* be of different datatypes, but they are ordered the same way according to
|
|
|
|
* the common opfamily. The operator in each mergeclause must be an equality
|
|
|
|
* operator of the indicated opfamily.
|
1996-08-28 03:59:28 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct MergeJoin
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Join join;
|
2007-11-15 22:14:46 +01:00
|
|
|
List *mergeclauses; /* mergeclauses as expression trees */
|
2007-01-10 19:06:05 +01:00
|
|
|
/* these are arrays, but have the same length as the mergeclauses list: */
|
2007-11-15 22:14:46 +01:00
|
|
|
Oid *mergeFamilies; /* per-clause OIDs of btree opfamilies */
|
2007-01-10 19:06:05 +01:00
|
|
|
int *mergeStrategies; /* per-clause ordering (ASC or DESC) */
|
|
|
|
bool *mergeNullsFirst; /* per-clause nulls ordering */
|
1997-09-08 23:56:23 +02:00
|
|
|
} MergeJoin;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* ----------------
|
2009-03-21 01:04:40 +01:00
|
|
|
* hash join node
|
1996-08-28 03:59:28 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct HashJoin
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Join join;
|
|
|
|
List *hashclauses;
|
1997-09-08 23:56:23 +02:00
|
|
|
} HashJoin;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
/* ----------------
|
|
|
|
* materialization node
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
typedef struct Material
|
|
|
|
{
|
|
|
|
Plan plan;
|
|
|
|
} Material;
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* sort node
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
typedef struct Sort
|
|
|
|
{
|
|
|
|
Plan plan;
|
2003-05-06 02:20:33 +02:00
|
|
|
int numCols; /* number of sort-key columns */
|
|
|
|
AttrNumber *sortColIdx; /* their indexes in the target list */
|
|
|
|
Oid *sortOperators; /* OIDs of operators to sort them by */
|
2007-01-09 03:14:16 +01:00
|
|
|
bool *nullsFirst; /* NULLS FIRST/LAST directions */
|
2002-12-05 16:50:39 +01:00
|
|
|
} Sort;
|
|
|
|
|
|
|
|
/* ---------------
|
|
|
|
* group node -
|
|
|
|
* Used for queries with GROUP BY (but no aggregates) specified.
|
|
|
|
* The input must be presorted according to the grouping columns.
|
|
|
|
* ---------------
|
|
|
|
*/
|
|
|
|
typedef struct Group
|
|
|
|
{
|
|
|
|
Plan plan;
|
|
|
|
int numCols; /* number of grouping columns */
|
|
|
|
AttrNumber *grpColIdx; /* their indexes in the target list */
|
2007-01-10 19:06:05 +01:00
|
|
|
Oid *grpOperators; /* equality operators to compare with */
|
2002-12-05 16:50:39 +01:00
|
|
|
} Group;
|
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
/* ---------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* aggregate node
|
2002-11-06 01:00:45 +01:00
|
|
|
*
|
|
|
|
* An Agg node implements plain or grouped aggregation. For grouped
|
|
|
|
* aggregation, we can work with presorted input or unsorted input;
|
|
|
|
* the latter strategy uses an internal hashtable.
|
|
|
|
*
|
|
|
|
* Notice the lack of any direct info about the aggregate functions to be
|
|
|
|
* computed. They are found by scanning the node's tlist and quals during
|
|
|
|
* executor startup. (It is possible that there are no aggregate functions;
|
|
|
|
* this could happen if they get optimized away by constant-folding, or if
|
|
|
|
* we are using the Agg node to implement hash-based grouping.)
|
1996-08-28 03:59:28 +02:00
|
|
|
* ---------------
|
|
|
|
*/
|
2002-11-06 01:00:45 +01:00
|
|
|
typedef enum AggStrategy
|
|
|
|
{
|
|
|
|
AGG_PLAIN, /* simple agg across all input rows */
|
|
|
|
AGG_SORTED, /* grouped agg, input must be sorted */
|
|
|
|
AGG_HASHED /* grouped agg, use internal hashtable */
|
2003-08-08 23:42:59 +02:00
|
|
|
} AggStrategy;
|
2002-11-06 01:00:45 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct Agg
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Plan plan;
|
2003-08-04 02:43:34 +02:00
|
|
|
AggStrategy aggstrategy;
|
2002-11-06 01:00:45 +01:00
|
|
|
int numCols; /* number of grouping columns */
|
|
|
|
AttrNumber *grpColIdx; /* their indexes in the target list */
|
2007-01-10 19:06:05 +01:00
|
|
|
Oid *grpOperators; /* equality operators to compare with */
|
2002-11-06 23:31:24 +01:00
|
|
|
long numGroups; /* estimated number of groups in input */
|
1997-09-08 22:59:27 +02:00
|
|
|
} Agg;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2008-12-28 19:54:01 +01:00
|
|
|
/* ----------------
|
|
|
|
* window aggregate node
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
typedef struct WindowAgg
|
|
|
|
{
|
|
|
|
Plan plan;
|
2008-12-31 01:08:39 +01:00
|
|
|
Index winref; /* ID referenced by window functions */
|
2008-12-28 19:54:01 +01:00
|
|
|
int partNumCols; /* number of columns in partition clause */
|
|
|
|
AttrNumber *partColIdx; /* their indexes in the target list */
|
|
|
|
Oid *partOperators; /* equality operators for partition columns */
|
|
|
|
int ordNumCols; /* number of columns in ordering clause */
|
|
|
|
AttrNumber *ordColIdx; /* their indexes in the target list */
|
|
|
|
Oid *ordOperators; /* equality operators for ordering columns */
|
2008-12-31 01:08:39 +01:00
|
|
|
int frameOptions; /* frame_clause options, see WindowDef */
|
2008-12-28 19:54:01 +01:00
|
|
|
} WindowAgg;
|
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* unique node
|
1996-08-28 03:59:28 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct Unique
|
|
|
|
{
|
2000-06-19 00:44:35 +02:00
|
|
|
Plan plan;
|
2005-10-15 04:49:52 +02:00
|
|
|
int numCols; /* number of columns to check for uniqueness */
|
2007-01-10 19:06:05 +01:00
|
|
|
AttrNumber *uniqColIdx; /* their indexes in the target list */
|
|
|
|
Oid *uniqOperators; /* equality operators to compare with */
|
1997-09-08 23:56:23 +02:00
|
|
|
} Unique;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
/* ----------------
|
|
|
|
* hash build node
|
2009-03-21 01:04:40 +01:00
|
|
|
*
|
|
|
|
* If the executor is supposed to try to apply skew join optimization, then
|
|
|
|
* skewTable/skewColumn identify the outer relation's join key column, from
|
|
|
|
* which the relevant MCV statistics can be fetched. Also, its type
|
|
|
|
* information is provided to save a lookup.
|
2002-12-05 16:50:39 +01:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
typedef struct Hash
|
|
|
|
{
|
|
|
|
Plan plan;
|
2009-03-21 01:04:40 +01:00
|
|
|
Oid skewTable; /* outer join key's table OID, or InvalidOid */
|
|
|
|
AttrNumber skewColumn; /* outer join key's column #, or zero */
|
|
|
|
Oid skewColType; /* datatype of the outer key column */
|
|
|
|
int32 skewColTypmod; /* typmod of the outer key column */
|
2003-11-25 22:00:54 +01:00
|
|
|
/* all other info is in the parent HashJoin node */
|
2002-12-05 16:50:39 +01:00
|
|
|
} Hash;
|
|
|
|
|
2000-10-05 21:11:39 +02:00
|
|
|
/* ----------------
|
|
|
|
* setop node
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
typedef enum SetOpCmd
|
|
|
|
{
|
2001-10-28 07:26:15 +01:00
|
|
|
SETOPCMD_INTERSECT,
|
|
|
|
SETOPCMD_INTERSECT_ALL,
|
|
|
|
SETOPCMD_EXCEPT,
|
|
|
|
SETOPCMD_EXCEPT_ALL
|
2000-10-05 21:11:39 +02:00
|
|
|
} SetOpCmd;
|
|
|
|
|
2008-08-07 05:04:04 +02:00
|
|
|
typedef enum SetOpStrategy
|
|
|
|
{
|
|
|
|
SETOP_SORTED, /* input must be sorted */
|
|
|
|
SETOP_HASHED /* use internal hashtable */
|
|
|
|
} SetOpStrategy;
|
|
|
|
|
2000-10-05 21:11:39 +02:00
|
|
|
typedef struct SetOp
|
|
|
|
{
|
|
|
|
Plan plan;
|
|
|
|
SetOpCmd cmd; /* what to do */
|
2008-08-07 05:04:04 +02:00
|
|
|
SetOpStrategy strategy; /* how to do it */
|
2000-10-05 21:11:39 +02:00
|
|
|
int numCols; /* number of columns to check for
|
|
|
|
* duplicate-ness */
|
2007-01-10 19:06:05 +01:00
|
|
|
AttrNumber *dupColIdx; /* their indexes in the target list */
|
|
|
|
Oid *dupOperators; /* equality operators to compare with */
|
|
|
|
AttrNumber flagColIdx; /* where is the flag column, if any */
|
2008-08-07 21:35:02 +02:00
|
|
|
int firstFlag; /* flag value for first input relation */
|
2008-08-07 05:04:04 +02:00
|
|
|
long numGroups; /* estimated number of groups in input */
|
2000-10-05 21:11:39 +02:00
|
|
|
} SetOp;
|
|
|
|
|
2009-10-12 20:10:51 +02:00
|
|
|
/* ----------------
|
|
|
|
* lock-rows node
|
|
|
|
*
|
|
|
|
* rowMarks identifies the rels to be locked by this node; it should be
|
|
|
|
* a subset of the rowMarks listed in the top-level PlannedStmt.
|
Re-implement EvalPlanQual processing to improve its performance and eliminate
a lot of strange behaviors that occurred in join cases. We now identify the
"current" row for every joined relation in UPDATE, DELETE, and SELECT FOR
UPDATE/SHARE queries. If an EvalPlanQual recheck is necessary, we jam the
appropriate row into each scan node in the rechecking plan, forcing it to emit
only that one row. The former behavior could rescan the whole of each joined
relation for each recheck, which was terrible for performance, and what's much
worse could result in duplicated output tuples.
Also, the original implementation of EvalPlanQual could not re-use the recheck
execution tree --- it had to go through a full executor init and shutdown for
every row to be tested. To avoid this overhead, I've associated a special
runtime Param with each LockRows or ModifyTable plan node, and arranged to
make every scan node below such a node depend on that Param. Thus, by
signaling a change in that Param, the EPQ machinery can just rescan the
already-built test plan.
This patch also adds a prohibition on set-returning functions in the
targetlist of SELECT FOR UPDATE/SHARE. This is needed to avoid the
duplicate-output-tuple problem. It seems fairly reasonable since the
other restrictions on SELECT FOR UPDATE are meant to ensure that there
is a unique correspondence between source tuples and result tuples,
which an output SRF destroys as much as anything else does.
2009-10-26 03:26:45 +01:00
|
|
|
* epqParam is a Param that all scan nodes below this one must depend on.
|
|
|
|
* It is used to force re-evaluation of the plan during EvalPlanQual.
|
2009-10-12 20:10:51 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
typedef struct LockRows
|
|
|
|
{
|
|
|
|
Plan plan;
|
Re-implement EvalPlanQual processing to improve its performance and eliminate
a lot of strange behaviors that occurred in join cases. We now identify the
"current" row for every joined relation in UPDATE, DELETE, and SELECT FOR
UPDATE/SHARE queries. If an EvalPlanQual recheck is necessary, we jam the
appropriate row into each scan node in the rechecking plan, forcing it to emit
only that one row. The former behavior could rescan the whole of each joined
relation for each recheck, which was terrible for performance, and what's much
worse could result in duplicated output tuples.
Also, the original implementation of EvalPlanQual could not re-use the recheck
execution tree --- it had to go through a full executor init and shutdown for
every row to be tested. To avoid this overhead, I've associated a special
runtime Param with each LockRows or ModifyTable plan node, and arranged to
make every scan node below such a node depend on that Param. Thus, by
signaling a change in that Param, the EPQ machinery can just rescan the
already-built test plan.
This patch also adds a prohibition on set-returning functions in the
targetlist of SELECT FOR UPDATE/SHARE. This is needed to avoid the
duplicate-output-tuple problem. It seems fairly reasonable since the
other restrictions on SELECT FOR UPDATE are meant to ensure that there
is a unique correspondence between source tuples and result tuples,
which an output SRF destroys as much as anything else does.
2009-10-26 03:26:45 +01:00
|
|
|
List *rowMarks; /* a list of PlanRowMark's */
|
|
|
|
int epqParam; /* ID of Param for EvalPlanQual re-eval */
|
2009-10-12 20:10:51 +02:00
|
|
|
} LockRows;
|
|
|
|
|
2000-10-26 23:38:24 +02:00
|
|
|
/* ----------------
|
|
|
|
* limit node
|
2006-07-26 21:31:51 +02:00
|
|
|
*
|
|
|
|
* Note: as of Postgres 8.2, the offset and count expressions are expected
|
|
|
|
* to yield int8, rather than int4 as before.
|
2000-10-26 23:38:24 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
typedef struct Limit
|
|
|
|
{
|
|
|
|
Plan plan;
|
|
|
|
Node *limitOffset; /* OFFSET parameter, or NULL if none */
|
|
|
|
Node *limitCount; /* COUNT parameter, or NULL if none */
|
|
|
|
} Limit;
|
|
|
|
|
2008-09-09 20:58:09 +02:00
|
|
|
|
Re-implement EvalPlanQual processing to improve its performance and eliminate
a lot of strange behaviors that occurred in join cases. We now identify the
"current" row for every joined relation in UPDATE, DELETE, and SELECT FOR
UPDATE/SHARE queries. If an EvalPlanQual recheck is necessary, we jam the
appropriate row into each scan node in the rechecking plan, forcing it to emit
only that one row. The former behavior could rescan the whole of each joined
relation for each recheck, which was terrible for performance, and what's much
worse could result in duplicated output tuples.
Also, the original implementation of EvalPlanQual could not re-use the recheck
execution tree --- it had to go through a full executor init and shutdown for
every row to be tested. To avoid this overhead, I've associated a special
runtime Param with each LockRows or ModifyTable plan node, and arranged to
make every scan node below such a node depend on that Param. Thus, by
signaling a change in that Param, the EPQ machinery can just rescan the
already-built test plan.
This patch also adds a prohibition on set-returning functions in the
targetlist of SELECT FOR UPDATE/SHARE. This is needed to avoid the
duplicate-output-tuple problem. It seems fairly reasonable since the
other restrictions on SELECT FOR UPDATE are meant to ensure that there
is a unique correspondence between source tuples and result tuples,
which an output SRF destroys as much as anything else does.
2009-10-26 03:26:45 +01:00
|
|
|
/*
|
|
|
|
* RowMarkType -
|
|
|
|
* enums for types of row-marking operations
|
|
|
|
*
|
|
|
|
* When doing UPDATE, DELETE, or SELECT FOR UPDATE/SHARE, we have to uniquely
|
|
|
|
* identify all the source rows, not only those from the target relations, so
|
|
|
|
* that we can perform EvalPlanQual rechecking at need. For plain tables we
|
|
|
|
* can just fetch the TID, the same as for a target relation. Otherwise (for
|
|
|
|
* example for VALUES or FUNCTION scans) we have to copy the whole row value.
|
|
|
|
* The latter is pretty inefficient but fortunately the case is not
|
|
|
|
* performance-critical in practice.
|
|
|
|
*/
|
|
|
|
typedef enum RowMarkType
|
|
|
|
{
|
|
|
|
ROW_MARK_EXCLUSIVE, /* obtain exclusive tuple lock */
|
|
|
|
ROW_MARK_SHARE, /* obtain shared tuple lock */
|
|
|
|
ROW_MARK_REFERENCE, /* just fetch the TID */
|
|
|
|
ROW_MARK_COPY /* physically copy the row value */
|
|
|
|
} RowMarkType;
|
|
|
|
|
|
|
|
#define RowMarkRequiresRowShareLock(marktype) ((marktype) <= ROW_MARK_SHARE)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PlanRowMark -
|
|
|
|
* plan-time representation of FOR UPDATE/SHARE clauses
|
|
|
|
*
|
|
|
|
* When doing UPDATE, DELETE, or SELECT FOR UPDATE/SHARE, we create a separate
|
|
|
|
* PlanRowMark node for each non-target relation in the query. Relations that
|
|
|
|
* are not specified as FOR UPDATE/SHARE are marked ROW_MARK_REFERENCE (if
|
|
|
|
* real tables) or ROW_MARK_COPY (if not).
|
|
|
|
*
|
|
|
|
* Initially all PlanRowMarks have rti == prti and isParent == false.
|
|
|
|
* When the planner discovers that a relation is the root of an inheritance
|
|
|
|
* tree, it sets isParent true, and adds an additional PlanRowMark to the
|
|
|
|
* list for each child relation (including the target rel itself in its role
|
|
|
|
* as a child). The child entries have rti == child rel's RT index and
|
|
|
|
* prti == parent's RT index, and can therefore be recognized as children by
|
|
|
|
* the fact that prti != rti.
|
|
|
|
*
|
|
|
|
* The AttrNumbers are filled in during preprocess_targetlist. We use
|
|
|
|
* different subsets of them for plain relations, inheritance children,
|
|
|
|
* and non-table relations.
|
|
|
|
*/
|
|
|
|
typedef struct PlanRowMark
|
|
|
|
{
|
|
|
|
NodeTag type;
|
|
|
|
Index rti; /* range table index of markable relation */
|
|
|
|
Index prti; /* range table index of parent relation */
|
|
|
|
RowMarkType markType; /* see enum above */
|
|
|
|
bool noWait; /* NOWAIT option */
|
|
|
|
bool isParent; /* true if this is a "dummy" parent entry */
|
|
|
|
AttrNumber ctidAttNo; /* resno of ctid junk attribute, if any */
|
|
|
|
AttrNumber toidAttNo; /* resno of tableoid junk attribute, if any */
|
|
|
|
AttrNumber wholeAttNo; /* resno of whole-row junk attribute, if any */
|
|
|
|
} PlanRowMark;
|
|
|
|
|
|
|
|
|
2008-09-09 20:58:09 +02:00
|
|
|
/*
|
|
|
|
* Plan invalidation info
|
|
|
|
*
|
|
|
|
* We track the objects on which a PlannedStmt depends in two ways:
|
|
|
|
* relations are recorded as a simple list of OIDs, and everything else
|
2009-06-11 16:49:15 +02:00
|
|
|
* is represented as a list of PlanInvalItems. A PlanInvalItem is designed
|
2008-09-09 20:58:09 +02:00
|
|
|
* to be used with the syscache invalidation mechanism, so it identifies a
|
|
|
|
* system catalog entry by cache ID and tuple TID.
|
|
|
|
*/
|
|
|
|
typedef struct PlanInvalItem
|
|
|
|
{
|
|
|
|
NodeTag type;
|
|
|
|
int cacheId; /* a syscache ID, see utils/syscache.h */
|
|
|
|
ItemPointerData tupleId; /* TID of the object's catalog tuple */
|
|
|
|
} PlanInvalItem;
|
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* PLANNODES_H */
|