mirror of
https://github.com/postgres/postgres.git
synced 2025-11-21 00:42:43 +03:00
First pass at set-returning-functions in FROM, by Joe Conway with
some kibitzing from Tom Lane. Not everything works yet, and there's no documentation or regression test, but let's commit this so Joe doesn't need to cope with tracking changes in so many files ...
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: execnodes.h,v 1.67 2001/11/21 22:57:01 tgl Exp $
|
||||
* $Id: execnodes.h,v 1.68 2002/05/12 20:10:04 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -52,6 +52,21 @@ typedef struct IndexInfo
|
||||
bool ii_Unique;
|
||||
} IndexInfo;
|
||||
|
||||
/* ----------------
|
||||
* ExprContext_CB
|
||||
*
|
||||
* List of callbacks to be called at ExprContext shutdown.
|
||||
* ----------------
|
||||
*/
|
||||
typedef void (*ExprContextCallbackFunction) (Datum arg);
|
||||
|
||||
typedef struct ExprContext_CB
|
||||
{
|
||||
struct ExprContext_CB *next;
|
||||
ExprContextCallbackFunction function;
|
||||
Datum arg;
|
||||
} ExprContext_CB;
|
||||
|
||||
/* ----------------
|
||||
* ExprContext
|
||||
*
|
||||
@@ -77,20 +92,27 @@ typedef struct IndexInfo
|
||||
*/
|
||||
typedef struct ExprContext
|
||||
{
|
||||
NodeTag type;
|
||||
NodeTag type;
|
||||
|
||||
/* Tuples that Var nodes in expression may refer to */
|
||||
TupleTableSlot *ecxt_scantuple;
|
||||
TupleTableSlot *ecxt_innertuple;
|
||||
TupleTableSlot *ecxt_outertuple;
|
||||
|
||||
/* Memory contexts for expression evaluation --- see notes above */
|
||||
MemoryContext ecxt_per_query_memory;
|
||||
MemoryContext ecxt_per_tuple_memory;
|
||||
MemoryContext ecxt_per_query_memory;
|
||||
MemoryContext ecxt_per_tuple_memory;
|
||||
|
||||
/* Values to substitute for Param nodes in expression */
|
||||
ParamExecData *ecxt_param_exec_vals; /* for PARAM_EXEC params */
|
||||
ParamListInfo ecxt_param_list_info; /* for other param types */
|
||||
ParamExecData *ecxt_param_exec_vals; /* for PARAM_EXEC params */
|
||||
ParamListInfo ecxt_param_list_info; /* for other param types */
|
||||
|
||||
/* Values to substitute for Aggref nodes in expression */
|
||||
Datum *ecxt_aggvalues; /* precomputed values for Aggref nodes */
|
||||
bool *ecxt_aggnulls; /* null flags for Aggref nodes */
|
||||
Datum *ecxt_aggvalues; /* precomputed values for Aggref nodes */
|
||||
bool *ecxt_aggnulls; /* null flags for Aggref nodes */
|
||||
|
||||
/* Functions to call back when ExprContext is shut down */
|
||||
ExprContext_CB *ecxt_callbacks;
|
||||
} ExprContext;
|
||||
|
||||
/*
|
||||
@@ -107,7 +129,8 @@ typedef enum
|
||||
* When calling a function that might return a set (multiple rows),
|
||||
* a node of this type is passed as fcinfo->resultinfo to allow
|
||||
* return status to be passed back. A function returning set should
|
||||
* raise an error if no such resultinfo is provided.
|
||||
* raise an error if no such resultinfo is provided. The ExprContext
|
||||
* in which the function is being called is also made available.
|
||||
*
|
||||
* XXX this mechanism is a quick hack and probably needs to be redesigned.
|
||||
*/
|
||||
@@ -115,9 +138,9 @@ typedef struct ReturnSetInfo
|
||||
{
|
||||
NodeTag type;
|
||||
ExprDoneCond isDone;
|
||||
ExprContext *econtext;
|
||||
} ReturnSetInfo;
|
||||
|
||||
|
||||
/* ----------------
|
||||
* ProjectionInfo node information
|
||||
*
|
||||
@@ -481,6 +504,36 @@ typedef struct SubqueryScanState
|
||||
EState *sss_SubEState;
|
||||
} SubqueryScanState;
|
||||
|
||||
/* ----------------
|
||||
* FunctionScanState information
|
||||
*
|
||||
* Function nodes are used to scan the results of a
|
||||
* function appearing in FROM (typically a function returning set).
|
||||
*
|
||||
* functionmode function operating mode:
|
||||
* - repeated call
|
||||
* - materialize
|
||||
* - return query
|
||||
* tuplestorestate private state of tuplestore.c
|
||||
* ----------------
|
||||
*/
|
||||
typedef enum FunctionMode
|
||||
{
|
||||
PM_REPEATEDCALL,
|
||||
PM_MATERIALIZE,
|
||||
PM_QUERY
|
||||
} FunctionMode;
|
||||
|
||||
typedef struct FunctionScanState
|
||||
{
|
||||
CommonScanState csstate; /* its first field is NodeTag */
|
||||
FunctionMode functionmode;
|
||||
TupleDesc tupdesc;
|
||||
void *tuplestorestate;
|
||||
Node *funcexpr; /* function expression being evaluated */
|
||||
bool returnsTuple; /* does function return tuples? */
|
||||
} FunctionScanState;
|
||||
|
||||
/* ----------------------------------------------------------------
|
||||
* Join State Information
|
||||
* ----------------------------------------------------------------
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: nodes.h,v 1.105 2002/04/18 20:01:11 tgl Exp $
|
||||
* $Id: nodes.h,v 1.106 2002/05/12 20:10:04 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -49,6 +49,7 @@ typedef enum NodeTag
|
||||
T_SubPlan,
|
||||
T_TidScan,
|
||||
T_SubqueryScan,
|
||||
T_FunctionScan,
|
||||
|
||||
/*
|
||||
* TAGS FOR PRIMITIVE NODES (primnodes.h)
|
||||
@@ -120,6 +121,7 @@ typedef enum NodeTag
|
||||
T_SubqueryScanState,
|
||||
T_SetOpState,
|
||||
T_LimitState,
|
||||
T_FunctionScanState,
|
||||
|
||||
/*
|
||||
* TAGS FOR MEMORY NODES (memnodes.h)
|
||||
@@ -212,6 +214,7 @@ typedef enum NodeTag
|
||||
T_Alias,
|
||||
T_RangeVar,
|
||||
T_RangeSubselect,
|
||||
T_RangeFunction,
|
||||
T_TypeName,
|
||||
T_IndexElem,
|
||||
T_ColumnDef,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: parsenodes.h,v 1.175 2002/04/28 19:54:28 tgl Exp $
|
||||
* $Id: parsenodes.h,v 1.176 2002/05/12 20:10:04 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -387,6 +387,16 @@ typedef struct RangeSubselect
|
||||
Alias *alias; /* table alias & optional column aliases */
|
||||
} RangeSubselect;
|
||||
|
||||
/*
|
||||
* RangeFunction - function call appearing in a FROM clause
|
||||
*/
|
||||
typedef struct RangeFunction
|
||||
{
|
||||
NodeTag type;
|
||||
Node *funccallnode; /* untransformed function call tree */
|
||||
Alias *alias; /* table alias & optional column aliases */
|
||||
} RangeFunction;
|
||||
|
||||
/*
|
||||
* IndexElem - index parameters (used in CREATE INDEX)
|
||||
*
|
||||
@@ -482,7 +492,8 @@ typedef enum RTEKind
|
||||
RTE_RELATION, /* ordinary relation reference */
|
||||
RTE_SUBQUERY, /* subquery in FROM */
|
||||
RTE_JOIN, /* join */
|
||||
RTE_SPECIAL /* special rule relation (NEW or OLD) */
|
||||
RTE_SPECIAL, /* special rule relation (NEW or OLD) */
|
||||
RTE_FUNCTION /* function in FROM */
|
||||
} RTEKind;
|
||||
|
||||
typedef struct RangeTblEntry
|
||||
@@ -507,6 +518,11 @@ typedef struct RangeTblEntry
|
||||
*/
|
||||
Query *subquery; /* the sub-query */
|
||||
|
||||
/*
|
||||
* Fields valid for a function RTE (else NULL):
|
||||
*/
|
||||
Node *funcexpr; /* expression tree for func call */
|
||||
|
||||
/*
|
||||
* Fields valid for a join RTE (else NULL/zero):
|
||||
*
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: plannodes.h,v 1.55 2002/04/28 19:54:28 tgl Exp $
|
||||
* $Id: plannodes.h,v 1.56 2002/05/12 20:10:05 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -32,6 +32,7 @@
|
||||
* Scan *** CommonScanState scanstate;
|
||||
* IndexScan IndexScanState indxstate;
|
||||
* SubqueryScan SubqueryScanState subquerystate;
|
||||
* FunctionScan FunctionScanState functionstate;
|
||||
*
|
||||
* (*** nodes which inherit Scan also inherit scanstate)
|
||||
*
|
||||
@@ -242,6 +243,17 @@ typedef struct SubqueryScan
|
||||
Plan *subplan;
|
||||
} SubqueryScan;
|
||||
|
||||
/* ----------------
|
||||
* FunctionScan node
|
||||
* ----------------
|
||||
*/
|
||||
typedef struct FunctionScan
|
||||
{
|
||||
Scan scan;
|
||||
/* no other fields needed at present */
|
||||
/* scan.scanstate actually points at a FunctionScanState node */
|
||||
} FunctionScan;
|
||||
|
||||
/*
|
||||
* ==========
|
||||
* Join nodes
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: primnodes.h,v 1.61 2002/04/11 20:00:15 tgl Exp $
|
||||
* $Id: primnodes.h,v 1.62 2002/05/12 20:10:05 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -514,10 +514,11 @@ typedef struct RelabelType
|
||||
* rows.) If all joins are inner joins then all the qual positions are
|
||||
* semantically interchangeable.
|
||||
*
|
||||
* NOTE: in the raw output of gram.y, a join tree contains RangeVar and
|
||||
* RangeSubselect nodes, which are both replaced by RangeTblRef nodes
|
||||
* during the parse analysis phase. Also, the top-level FromExpr is added
|
||||
* during parse analysis; the grammar regards FROM and WHERE as separate.
|
||||
* NOTE: in the raw output of gram.y, a join tree contains RangeVar,
|
||||
* RangeSubselect, and RangeFunction nodes, which are all replaced by
|
||||
* RangeTblRef nodes during the parse analysis phase. Also, the top-level
|
||||
* FromExpr is added during parse analysis; the grammar regards FROM and
|
||||
* WHERE as separate.
|
||||
* ----------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: relation.h,v 1.63 2002/03/12 00:52:02 tgl Exp $
|
||||
* $Id: relation.h,v 1.64 2002/05/12 20:10:05 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -92,12 +92,12 @@ typedef enum CostSelector
|
||||
*
|
||||
* If the relation is a base relation it will have these fields set:
|
||||
*
|
||||
* issubquery - true if baserel is a subquery RTE rather than a table
|
||||
* rtekind - distinguishes plain relation, subquery, or function RTE
|
||||
* indexlist - list of IndexOptInfo nodes for relation's indexes
|
||||
* (always NIL if it's a subquery)
|
||||
* pages - number of disk pages in relation (zero if a subquery)
|
||||
* (always NIL if it's not a table)
|
||||
* pages - number of disk pages in relation (zero if not a table)
|
||||
* tuples - number of tuples in relation (not considering restrictions)
|
||||
* subplan - plan for subquery (NULL if it's a plain table)
|
||||
* subplan - plan for subquery (NULL if it's not a subquery)
|
||||
*
|
||||
* Note: for a subquery, tuples and subplan are not set immediately
|
||||
* upon creation of the RelOptInfo object; they are filled in when
|
||||
@@ -184,11 +184,11 @@ typedef struct RelOptInfo
|
||||
bool pruneable;
|
||||
|
||||
/* information about a base rel (not set for join rels!) */
|
||||
bool issubquery;
|
||||
RTEKind rtekind; /* RELATION, SUBQUERY, or FUNCTION */
|
||||
List *indexlist;
|
||||
long pages;
|
||||
double tuples;
|
||||
struct Plan *subplan;
|
||||
struct Plan *subplan; /* if subquery */
|
||||
|
||||
/* information about a join rel (not set for base rels!) */
|
||||
Index joinrti;
|
||||
|
||||
Reference in New Issue
Block a user