1996-08-28 03:59:28 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* plannodes.h--
|
1997-09-07 07:04:48 +02:00
|
|
|
* definitions for query plan nodes
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
1997-09-08 23:56:23 +02:00
|
|
|
* $Id: plannodes.h,v 1.10 1997/09/08 21:52:53 momjian 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
|
|
|
|
1996-11-04 13:11:44 +01:00
|
|
|
#include <nodes/execnodes.h>
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* Executor State types are used in the plannode structures
|
|
|
|
* so we have to include their definitions too.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* Node Type node information used by executor
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
* control nodes
|
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* Existential ExistentialState exstate;
|
|
|
|
* Result ResultState resstate;
|
|
|
|
* Append AppendState unionstate;
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
* scan nodes
|
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* Scan *** CommonScanState scanstate;
|
|
|
|
* IndexScan IndexScanState indxstate;
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* (*** nodes which inherit Scan also inherit scanstate)
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
* join nodes
|
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* NestLoop NestLoopState nlstate;
|
|
|
|
* MergeJoin MergeJoinState mergestate;
|
|
|
|
* HashJoin HashJoinState hashjoinstate;
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
* materialize nodes
|
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* Material MaterialState matstate;
|
|
|
|
* Sort SortState sortstate;
|
|
|
|
* Unique UniqueState uniquestate;
|
|
|
|
* Hash HashState hashstate;
|
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
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* Plan node
|
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;
|
|
|
|
Cost cost;
|
|
|
|
int plan_size;
|
|
|
|
int plan_width;
|
|
|
|
int plan_tupperpage;
|
|
|
|
EState *state; /* at execution time, state's of
|
1997-09-07 07:04:48 +02:00
|
|
|
* individual nodes point to one EState
|
|
|
|
* for the whole top-level plan */
|
1997-09-08 04:41:22 +02:00
|
|
|
List *targetlist;
|
|
|
|
List *qual; /* Node* or List* ?? */
|
|
|
|
struct Plan *lefttree;
|
|
|
|
struct Plan *righttree;
|
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
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ===============
|
|
|
|
* Top-level nodes
|
|
|
|
* ===============
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* 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 */
|
|
|
|
|
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* existential node
|
1996-08-28 03:59:28 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
typedef Plan Existential;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* result node -
|
|
|
|
* returns tuples from outer plan that satisfy the qualifications
|
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;
|
|
|
|
ResultState *resstate;
|
1997-09-08 23:56:23 +02:00
|
|
|
} Result;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* append node
|
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;
|
|
|
|
List *unionplans;
|
|
|
|
Index unionrelid;
|
|
|
|
List *unionrtentries;
|
|
|
|
AppendState *unionstate;
|
1997-09-08 22:59:27 +02:00
|
|
|
} Append;
|
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-07 07:04:48 +02:00
|
|
|
CommonScanState *scanstate;
|
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
|
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;
|
|
|
|
List *indxid;
|
|
|
|
List *indxqual;
|
1997-09-07 07:04:48 +02:00
|
|
|
IndexScanState *indxstate;
|
1997-09-08 23:56:23 +02:00
|
|
|
} IndexScan;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ==========
|
|
|
|
* Join nodes
|
|
|
|
* ==========
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* Join node
|
1996-08-28 03:59:28 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
typedef Plan 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;
|
|
|
|
NestLoopState *nlstate;
|
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
|
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;
|
|
|
|
List *mergeclauses;
|
|
|
|
Oid mergesortop;
|
|
|
|
Oid *mergerightorder;/* inner sort operator */
|
|
|
|
Oid *mergeleftorder; /* outer sort operator */
|
1997-09-07 07:04:48 +02:00
|
|
|
MergeJoinState *mergestate;
|
1997-09-08 23:56:23 +02:00
|
|
|
} MergeJoin;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* hash join (probe) 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;
|
|
|
|
Oid hashjoinop;
|
|
|
|
HashJoinState *hashjoinstate;
|
|
|
|
HashJoinTable hashjointable;
|
|
|
|
IpcMemoryKey hashjointablekey;
|
|
|
|
int hashjointablesize;
|
|
|
|
bool hashdone;
|
1997-09-08 23:56:23 +02:00
|
|
|
} HashJoin;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* ---------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* aggregate node
|
1996-08-28 03:59:28 +02:00
|
|
|
* ---------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct Agg
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Plan plan;
|
|
|
|
int numAgg;
|
|
|
|
Aggreg **aggs;
|
|
|
|
AggState *aggstate;
|
1997-09-08 22:59:27 +02:00
|
|
|
} Agg;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* ---------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* group node -
|
|
|
|
* use for queries with GROUP BY specified.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* If tuplePerGroup is true, one tuple (with group columns only) is
|
|
|
|
* returned for each group and NULL is returned when there are no more
|
|
|
|
* groups. Otherwise, all the tuples of a group are returned with a
|
|
|
|
* NULL returned at the end of each group. (see nodeGroup.c for details)
|
1996-08-28 03:59:28 +02:00
|
|
|
* ---------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct Group
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Plan plan;
|
|
|
|
bool tuplePerGroup; /* what tuples to return (see above) */
|
|
|
|
int numCols; /* number of group columns */
|
|
|
|
AttrNumber *grpColIdx; /* index into the target list */
|
|
|
|
GroupState *grpstate;
|
1997-09-08 23:56:23 +02:00
|
|
|
} Group;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ==========
|
|
|
|
* Temp nodes
|
|
|
|
* ==========
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct Temp
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Plan plan;
|
|
|
|
Oid tempid;
|
|
|
|
int keycount;
|
1997-09-08 23:56:23 +02:00
|
|
|
} Temp;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* materialization node
|
1996-08-28 03:59:28 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct Material
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Plan plan; /* temp node flattened out */
|
|
|
|
Oid tempid;
|
|
|
|
int keycount;
|
|
|
|
MaterialState *matstate;
|
1997-09-08 23:56:23 +02:00
|
|
|
} Material;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* sort node
|
1996-08-28 03:59:28 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct Sort
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Plan plan; /* temp node flattened out */
|
|
|
|
Oid tempid;
|
|
|
|
int keycount;
|
|
|
|
SortState *sortstate;
|
|
|
|
void *psortstate;
|
|
|
|
bool cleaned;
|
1997-09-08 23:56:23 +02:00
|
|
|
} Sort;
|
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
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Plan plan; /* temp node flattened out */
|
|
|
|
Oid tempid;
|
|
|
|
int keycount;
|
|
|
|
char *uniqueAttr; /* NULL if all attrs, or unique attribute
|
1997-09-07 07:04:48 +02:00
|
|
|
* name */
|
1997-09-08 04:41:22 +02:00
|
|
|
AttrNumber uniqueAttrNum; /* attribute number of attribute to select
|
|
|
|
* distinct on */
|
|
|
|
UniqueState *uniquestate;
|
1997-09-08 23:56:23 +02:00
|
|
|
} Unique;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* hash build node
|
1996-08-28 03:59:28 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct Hash
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Plan plan;
|
|
|
|
Var *hashkey;
|
|
|
|
HashState *hashstate;
|
|
|
|
HashJoinTable hashtable;
|
|
|
|
IpcMemoryKey hashtablekey;
|
|
|
|
int hashtablesize;
|
1997-09-08 23:56:23 +02:00
|
|
|
} Hash;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* ---------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* choose node
|
1996-08-28 03:59:28 +02:00
|
|
|
* ---------------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct Choose
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Plan plan;
|
|
|
|
List *chooseplanlist;
|
1997-09-08 23:56:23 +02:00
|
|
|
} Choose;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* -------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* Tee node information
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* leftParent : the left parent of this node
|
|
|
|
* rightParent: the right parent of this node
|
1996-08-28 03:59:28 +02:00
|
|
|
* -------------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct Tee
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Plan plan;
|
|
|
|
Plan *leftParent;
|
|
|
|
Plan *rightParent;
|
|
|
|
TeeState *teestate;
|
|
|
|
char *teeTableName; /* the name of the table to materialize
|
|
|
|
* the tee into */
|
|
|
|
List *rtentries; /* the range table for the plan below the
|
1997-09-07 07:04:48 +02:00
|
|
|
* Tee may be different than the parent
|
|
|
|
* plans */
|
1997-09-08 23:56:23 +02:00
|
|
|
} Tee;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
#endif /* PLANNODES_H */
|