Commit 782c16c6 authored by Tom Lane's avatar Tom Lane

SQL-language functions are now callable in ordinary fmgr contexts ...

for example, an SQL function can be used in a functional index.  (I make
no promises about speed, but it'll work ;-).)  Clean up and simplify
handling of functions returning sets.
parent 87523ab8
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/Attic/execFlatten.c,v 1.12 2000/01/26 05:56:21 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/Attic/execFlatten.c,v 1.13 2000/08/24 03:29:03 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -36,11 +36,12 @@ static bool FjoinBumpOuterNodes(TargetEntry *tlist, ExprContext *econtext, ...@@ -36,11 +36,12 @@ static bool FjoinBumpOuterNodes(TargetEntry *tlist, ExprContext *econtext,
#endif #endif
Datum Datum
ExecEvalIter(Iter *iterNode, ExecEvalIter(Iter *iterNode,
ExprContext *econtext, ExprContext *econtext,
bool *resultIsNull, bool *isNull,
bool *iterIsDone) ExprDoneCond *isDone)
{ {
Node *expression; Node *expression;
...@@ -52,14 +53,14 @@ ExecEvalIter(Iter *iterNode, ...@@ -52,14 +53,14 @@ ExecEvalIter(Iter *iterNode,
* only worrying about postquel functions, c functions will come * only worrying about postquel functions, c functions will come
* later. * later.
*/ */
return ExecEvalExpr(expression, econtext, resultIsNull, iterIsDone); return ExecEvalExpr(expression, econtext, isNull, isDone);
} }
void void
ExecEvalFjoin(TargetEntry *tlist, ExecEvalFjoin(TargetEntry *tlist,
ExprContext *econtext, ExprContext *econtext,
bool *isNullVect, bool *isNullVect,
bool *fj_isDone) ExprDoneCond *fj_isDone)
{ {
#ifdef SETS_FIXED #ifdef SETS_FIXED
...@@ -72,7 +73,7 @@ ExecEvalFjoin(TargetEntry *tlist, ...@@ -72,7 +73,7 @@ ExecEvalFjoin(TargetEntry *tlist,
BoolPtr alwaysDone = fjNode->fj_alwaysDone; BoolPtr alwaysDone = fjNode->fj_alwaysDone;
if (fj_isDone) if (fj_isDone)
*fj_isDone = false; *fj_isDone = ExprMultipleResult;
/* /*
* For the next tuple produced by the plan, we need to re-initialize * For the next tuple produced by the plan, we need to re-initialize
......
This diff is collapsed.
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execScan.c,v 1.13 2000/07/17 03:04:53 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/execScan.c,v 1.14 2000/08/24 03:29:03 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -50,11 +50,10 @@ ExecScan(Scan *node, ...@@ -50,11 +50,10 @@ ExecScan(Scan *node,
{ {
CommonScanState *scanstate; CommonScanState *scanstate;
EState *estate; EState *estate;
ExprContext *econtext;
List *qual; List *qual;
bool isDone; ExprDoneCond isDone;
TupleTableSlot *resultSlot; TupleTableSlot *resultSlot;
ExprContext *econtext;
ProjectionInfo *projInfo;
/* ---------------- /* ----------------
* Fetch data from node * Fetch data from node
...@@ -65,13 +64,6 @@ ExecScan(Scan *node, ...@@ -65,13 +64,6 @@ ExecScan(Scan *node,
econtext = scanstate->cstate.cs_ExprContext; econtext = scanstate->cstate.cs_ExprContext;
qual = node->plan.qual; qual = node->plan.qual;
/* ----------------
* Reset per-tuple memory context to free any expression evaluation
* storage allocated in the previous tuple cycle.
* ----------------
*/
ResetExprContext(econtext);
/* ---------------- /* ----------------
* Check to see if we're still projecting out tuples from a previous * Check to see if we're still projecting out tuples from a previous
* scan tuple (because there is a function-returning-set in the * scan tuple (because there is a function-returning-set in the
...@@ -80,14 +72,21 @@ ExecScan(Scan *node, ...@@ -80,14 +72,21 @@ ExecScan(Scan *node,
*/ */
if (scanstate->cstate.cs_TupFromTlist) if (scanstate->cstate.cs_TupFromTlist)
{ {
projInfo = scanstate->cstate.cs_ProjInfo; resultSlot = ExecProject(scanstate->cstate.cs_ProjInfo, &isDone);
resultSlot = ExecProject(projInfo, &isDone); if (isDone == ExprMultipleResult)
if (!isDone)
return resultSlot; return resultSlot;
/* Done with that source tuple... */ /* Done with that source tuple... */
scanstate->cstate.cs_TupFromTlist = false; scanstate->cstate.cs_TupFromTlist = false;
} }
/* ----------------
* Reset per-tuple memory context to free any expression evaluation
* storage allocated in the previous tuple cycle. Note this can't
* happen until we're done projecting out tuples from a scan tuple.
* ----------------
*/
ResetExprContext(econtext);
/* /*
* get a tuple from the access method loop until we obtain a tuple * get a tuple from the access method loop until we obtain a tuple
* which passes the qualification. * which passes the qualification.
...@@ -121,8 +120,6 @@ ExecScan(Scan *node, ...@@ -121,8 +120,6 @@ ExecScan(Scan *node,
/* ---------------- /* ----------------
* check that the current tuple satisfies the qual-clause * check that the current tuple satisfies the qual-clause
* if our qualification succeeds then we may
* leave the loop.
* *
* check for non-nil qual here to avoid a function call to * check for non-nil qual here to avoid a function call to
* ExecQual() when the qual is nil ... saves only a few cycles, * ExecQual() when the qual is nil ... saves only a few cycles,
...@@ -130,7 +127,22 @@ ExecScan(Scan *node, ...@@ -130,7 +127,22 @@ ExecScan(Scan *node,
* ---------------- * ----------------
*/ */
if (!qual || ExecQual(qual, econtext, false)) if (!qual || ExecQual(qual, econtext, false))
break; {
/* ----------------
* Found a satisfactory scan tuple.
*
* Form a projection tuple, store it in the result tuple
* slot and return it --- unless we find we can project no
* tuples from this scan tuple, in which case continue scan.
* ----------------
*/
resultSlot = ExecProject(scanstate->cstate.cs_ProjInfo, &isDone);
if (isDone != ExprEndResult)
{
scanstate->cstate.cs_TupFromTlist = (isDone == ExprMultipleResult);
return resultSlot;
}
}
/* ---------------- /* ----------------
* Tuple fails qual, so free per-tuple memory and try again. * Tuple fails qual, so free per-tuple memory and try again.
...@@ -138,18 +150,4 @@ ExecScan(Scan *node, ...@@ -138,18 +150,4 @@ ExecScan(Scan *node,
*/ */
ResetExprContext(econtext); ResetExprContext(econtext);
} }
/* ----------------
* Found a satisfactory scan tuple.
*
* Form a projection tuple, store it in the result tuple
* slot and return it.
* ----------------
*/
projInfo = scanstate->cstate.cs_ProjInfo;
resultSlot = ExecProject(projInfo, &isDone);
scanstate->cstate.cs_TupFromTlist = !isDone;
return resultSlot;
} }
This diff is collapsed.
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeAgg.c,v 1.70 2000/07/17 03:04:53 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/nodeAgg.c,v 1.71 2000/08/24 03:29:03 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -451,7 +451,6 @@ ExecAgg(Agg *node) ...@@ -451,7 +451,6 @@ ExecAgg(Agg *node)
TupleTableSlot *resultSlot; TupleTableSlot *resultSlot;
HeapTuple inputTuple; HeapTuple inputTuple;
int aggno; int aggno;
bool isDone;
bool isNull; bool isNull;
/* --------------------- /* ---------------------
...@@ -523,7 +522,7 @@ ExecAgg(Agg *node) ...@@ -523,7 +522,7 @@ ExecAgg(Agg *node)
Datum newVal; Datum newVal;
newVal = ExecEvalExpr(aggref->target, econtext, newVal = ExecEvalExpr(aggref->target, econtext,
&isNull, &isDone); &isNull, NULL);
if (aggref->aggdistinct) if (aggref->aggdistinct)
{ {
...@@ -677,8 +676,9 @@ ExecAgg(Agg *node) ...@@ -677,8 +676,9 @@ ExecAgg(Agg *node)
/* /*
* Form a projection tuple using the aggregate results and the * Form a projection tuple using the aggregate results and the
* representative input tuple. Store it in the result tuple slot. * representative input tuple. Store it in the result tuple slot.
* Note we do not support aggregates returning sets ...
*/ */
resultSlot = ExecProject(projInfo, &isDone); resultSlot = ExecProject(projInfo, NULL);
/* /*
* If the completed tuple does not match the qualifications, it is * If the completed tuple does not match the qualifications, it is
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* locate group boundaries. * locate group boundaries.
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeGroup.c,v 1.37 2000/07/12 02:37:03 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/nodeGroup.c,v 1.38 2000/08/24 03:29:03 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -73,7 +73,6 @@ ExecGroupEveryTuple(Group *node) ...@@ -73,7 +73,6 @@ ExecGroupEveryTuple(Group *node)
TupleTableSlot *outerslot; TupleTableSlot *outerslot;
ProjectionInfo *projInfo; ProjectionInfo *projInfo;
TupleTableSlot *resultSlot; TupleTableSlot *resultSlot;
bool isDone;
/* --------------------- /* ---------------------
* get state info from node * get state info from node
...@@ -163,7 +162,7 @@ ExecGroupEveryTuple(Group *node) ...@@ -163,7 +162,7 @@ ExecGroupEveryTuple(Group *node)
projInfo = grpstate->csstate.cstate.cs_ProjInfo; projInfo = grpstate->csstate.cstate.cs_ProjInfo;
econtext->ecxt_scantuple = grpstate->csstate.css_ScanTupleSlot; econtext->ecxt_scantuple = grpstate->csstate.css_ScanTupleSlot;
resultSlot = ExecProject(projInfo, &isDone); resultSlot = ExecProject(projInfo, NULL);
return resultSlot; return resultSlot;
} }
...@@ -185,7 +184,6 @@ ExecGroupOneTuple(Group *node) ...@@ -185,7 +184,6 @@ ExecGroupOneTuple(Group *node)
TupleTableSlot *outerslot; TupleTableSlot *outerslot;
ProjectionInfo *projInfo; ProjectionInfo *projInfo;
TupleTableSlot *resultSlot; TupleTableSlot *resultSlot;
bool isDone;
/* --------------------- /* ---------------------
* get state info from node * get state info from node
...@@ -258,7 +256,7 @@ ExecGroupOneTuple(Group *node) ...@@ -258,7 +256,7 @@ ExecGroupOneTuple(Group *node)
grpstate->csstate.css_ScanTupleSlot, grpstate->csstate.css_ScanTupleSlot,
InvalidBuffer, false); InvalidBuffer, false);
econtext->ecxt_scantuple = grpstate->csstate.css_ScanTupleSlot; econtext->ecxt_scantuple = grpstate->csstate.css_ScanTupleSlot;
resultSlot = ExecProject(projInfo, &isDone); resultSlot = ExecProject(projInfo, NULL);
/* save outerTuple if we are not done yet */ /* save outerTuple if we are not done yet */
if (!grpstate->grp_done) if (!grpstate->grp_done)
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* *
* $Id: nodeHash.c,v 1.51 2000/08/22 04:06:19 tgl Exp $ * $Id: nodeHash.c,v 1.52 2000/08/24 03:29:03 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -524,7 +524,6 @@ ExecHashGetBucket(HashJoinTable hashtable, ...@@ -524,7 +524,6 @@ ExecHashGetBucket(HashJoinTable hashtable,
int bucketno; int bucketno;
Datum keyval; Datum keyval;
bool isNull; bool isNull;
bool isDone;
/* ---------------- /* ----------------
* Get the join attribute value of the tuple * Get the join attribute value of the tuple
...@@ -535,8 +534,7 @@ ExecHashGetBucket(HashJoinTable hashtable, ...@@ -535,8 +534,7 @@ ExecHashGetBucket(HashJoinTable hashtable,
*/ */
ResetExprContext(econtext); ResetExprContext(econtext);
keyval = ExecEvalExprSwitchContext(hashkey, econtext, keyval = ExecEvalExprSwitchContext(hashkey, econtext, &isNull, NULL);
&isNull, &isDone);
/* ------------------ /* ------------------
* compute the hash function * compute the hash function
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeHashjoin.c,v 1.32 2000/07/17 03:04:53 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/nodeHashjoin.c,v 1.33 2000/08/24 03:29:03 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -55,6 +55,7 @@ ExecHashJoin(HashJoin *node) ...@@ -55,6 +55,7 @@ ExecHashJoin(HashJoin *node)
TupleTableSlot *inntuple; TupleTableSlot *inntuple;
Node *outerVar; Node *outerVar;
ExprContext *econtext; ExprContext *econtext;
ExprDoneCond isDone;
HashJoinTable hashtable; HashJoinTable hashtable;
HeapTuple curtuple; HeapTuple curtuple;
TupleTableSlot *outerTupleSlot; TupleTableSlot *outerTupleSlot;
...@@ -83,13 +84,6 @@ ExecHashJoin(HashJoin *node) ...@@ -83,13 +84,6 @@ ExecHashJoin(HashJoin *node)
hashtable = hjstate->hj_HashTable; hashtable = hjstate->hj_HashTable;
econtext = hjstate->jstate.cs_ExprContext; econtext = hjstate->jstate.cs_ExprContext;
/* ----------------
* Reset per-tuple memory context to free any expression evaluation
* storage allocated in the previous tuple cycle.
* ----------------
*/
ResetExprContext(econtext);
/* ---------------- /* ----------------
* Check to see if we're still projecting out tuples from a previous * Check to see if we're still projecting out tuples from a previous
* join tuple (because there is a function-returning-set in the * join tuple (because there is a function-returning-set in the
...@@ -99,15 +93,22 @@ ExecHashJoin(HashJoin *node) ...@@ -99,15 +93,22 @@ ExecHashJoin(HashJoin *node)
if (hjstate->jstate.cs_TupFromTlist) if (hjstate->jstate.cs_TupFromTlist)
{ {
TupleTableSlot *result; TupleTableSlot *result;
bool isDone;
result = ExecProject(hjstate->jstate.cs_ProjInfo, &isDone); result = ExecProject(hjstate->jstate.cs_ProjInfo, &isDone);
if (!isDone) if (isDone == ExprMultipleResult)
return result; return result;
/* Done with that source tuple... */ /* Done with that source tuple... */
hjstate->jstate.cs_TupFromTlist = false; hjstate->jstate.cs_TupFromTlist = false;
} }
/* ----------------
* Reset per-tuple memory context to free any expression evaluation
* storage allocated in the previous tuple cycle. Note this can't
* happen until we're done projecting out tuples from a join tuple.
* ----------------
*/
ResetExprContext(econtext);
/* ---------------- /* ----------------
* if this is the first call, build the hash table for inner relation * if this is the first call, build the hash table for inner relation
* ---------------- * ----------------
...@@ -241,15 +242,15 @@ ExecHashJoin(HashJoin *node) ...@@ -241,15 +242,15 @@ ExecHashJoin(HashJoin *node)
*/ */
if (ExecQual(qual, econtext, false)) if (ExecQual(qual, econtext, false))
{ {
ProjectionInfo *projInfo;
TupleTableSlot *result; TupleTableSlot *result;
bool isDone;
hjstate->jstate.cs_OuterTupleSlot = outerTupleSlot; hjstate->jstate.cs_OuterTupleSlot = outerTupleSlot;
projInfo = hjstate->jstate.cs_ProjInfo; result = ExecProject(hjstate->jstate.cs_ProjInfo, &isDone);
result = ExecProject(projInfo, &isDone); if (isDone != ExprEndResult)
hjstate->jstate.cs_TupFromTlist = !isDone; {
return result; hjstate->jstate.cs_TupFromTlist = (isDone == ExprMultipleResult);
return result;
}
} }
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeIndexscan.c,v 1.53 2000/08/13 02:50:03 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/nodeIndexscan.c,v 1.54 2000/08/24 03:29:03 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -334,7 +334,6 @@ ExecIndexReScan(IndexScan *node, ExprContext *exprCtxt, Plan *parent) ...@@ -334,7 +334,6 @@ ExecIndexReScan(IndexScan *node, ExprContext *exprCtxt, Plan *parent)
Node *scanexpr; Node *scanexpr;
Datum scanvalue; Datum scanvalue;
bool isNull; bool isNull;
bool isDone;
estate = node->scan.plan.state; estate = node->scan.plan.state;
indexstate = node->indxstate; indexstate = node->indxstate;
...@@ -411,14 +410,10 @@ ExecIndexReScan(IndexScan *node, ExprContext *exprCtxt, Plan *parent) ...@@ -411,14 +410,10 @@ ExecIndexReScan(IndexScan *node, ExprContext *exprCtxt, Plan *parent)
(Node *) get_rightop(clause) : (Node *) get_rightop(clause) :
(Node *) get_leftop(clause); (Node *) get_leftop(clause);
/*
* pass in isDone but ignore it. We don't iterate in
* quals
*/
scanvalue = ExecEvalExprSwitchContext(scanexpr, scanvalue = ExecEvalExprSwitchContext(scanexpr,
econtext, econtext,
&isNull, &isNull,
&isDone); NULL);
scan_keys[j].sk_argument = scanvalue; scan_keys[j].sk_argument = scanvalue;
if (isNull) if (isNull)
scan_keys[j].sk_flags |= SK_ISNULL; scan_keys[j].sk_flags |= SK_ISNULL;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeMergejoin.c,v 1.36 2000/07/12 02:37:03 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/nodeMergejoin.c,v 1.37 2000/08/24 03:29:03 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -226,18 +226,16 @@ MergeCompare(List *eqQual, List *compareQual, ExprContext *econtext) ...@@ -226,18 +226,16 @@ MergeCompare(List *eqQual, List *compareQual, ExprContext *econtext)
{ {
Datum const_value; Datum const_value;
bool isNull; bool isNull;
bool isDone;
/* ---------------- /* ----------------
* first test if our compare clause is satisfied. * first test if our compare clause is satisfied.
* if so then return true. * if so then return true.
* *
* A NULL result is considered false. * A NULL result is considered false.
* ignore isDone, don't iterate in quals.
* ---------------- * ----------------
*/ */
const_value = ExecEvalExpr((Node *) lfirst(clause), econtext, const_value = ExecEvalExpr((Node *) lfirst(clause), econtext,
&isNull, &isDone); &isNull, NULL);
if (DatumGetBool(const_value) && !isNull) if (DatumGetBool(const_value) && !isNull)
{ {
...@@ -254,7 +252,7 @@ MergeCompare(List *eqQual, List *compareQual, ExprContext *econtext) ...@@ -254,7 +252,7 @@ MergeCompare(List *eqQual, List *compareQual, ExprContext *econtext)
const_value = ExecEvalExpr((Node *) lfirst(eqclause), const_value = ExecEvalExpr((Node *) lfirst(eqclause),
econtext, econtext,
&isNull, &isNull,
&isDone); NULL);
if (! DatumGetBool(const_value) || isNull) if (! DatumGetBool(const_value) || isNull)
break; /* return false */ break; /* return false */
...@@ -447,13 +445,6 @@ ExecMergeJoin(MergeJoin *node) ...@@ -447,13 +445,6 @@ ExecMergeJoin(MergeJoin *node)
innerSkipQual = mergestate->mj_OuterSkipQual; innerSkipQual = mergestate->mj_OuterSkipQual;
} }
/* ----------------
* Reset per-tuple memory context to free any expression evaluation
* storage allocated in the previous tuple cycle.
* ----------------
*/
ResetExprContext(econtext);
/* ---------------- /* ----------------
* Check to see if we're still projecting out tuples from a previous * Check to see if we're still projecting out tuples from a previous
* join tuple (because there is a function-returning-set in the * join tuple (because there is a function-returning-set in the
...@@ -463,15 +454,23 @@ ExecMergeJoin(MergeJoin *node) ...@@ -463,15 +454,23 @@ ExecMergeJoin(MergeJoin *node)
if (mergestate->jstate.cs_TupFromTlist) if (mergestate->jstate.cs_TupFromTlist)
{ {
TupleTableSlot *result; TupleTableSlot *result;
bool isDone; ExprDoneCond isDone;
result = ExecProject(mergestate->jstate.cs_ProjInfo, &isDone); result = ExecProject(mergestate->jstate.cs_ProjInfo, &isDone);
if (!isDone) if (isDone == ExprMultipleResult)
return result; return result;
/* Done with that source tuple... */ /* Done with that source tuple... */
mergestate->jstate.cs_TupFromTlist = false; mergestate->jstate.cs_TupFromTlist = false;
} }
/* ----------------
* Reset per-tuple memory context to free any expression evaluation
* storage allocated in the previous tuple cycle. Note this can't
* happen until we're done projecting out tuples from a join tuple.
* ----------------
*/
ResetExprContext(econtext);
/* ---------------- /* ----------------
* ok, everything is setup.. let's go to work * ok, everything is setup.. let's go to work
* ---------------- * ----------------
...@@ -599,17 +598,19 @@ ExecMergeJoin(MergeJoin *node) ...@@ -599,17 +598,19 @@ ExecMergeJoin(MergeJoin *node)
* projection tuple and return the slot containing it. * projection tuple and return the slot containing it.
* ---------------- * ----------------
*/ */
ProjectionInfo *projInfo;
TupleTableSlot *result; TupleTableSlot *result;
bool isDone; ExprDoneCond isDone;
MJ_printf("ExecMergeJoin: **** returning tuple ****\n"); MJ_printf("ExecMergeJoin: **** returning tuple ****\n");
projInfo = mergestate->jstate.cs_ProjInfo; result = ExecProject(mergestate->jstate.cs_ProjInfo,
&isDone);
result = ExecProject(projInfo, &isDone); if (isDone != ExprEndResult)
mergestate->jstate.cs_TupFromTlist = !isDone; {
return result; mergestate->jstate.cs_TupFromTlist = (isDone == ExprMultipleResult);
return result;
}
} }
break; break;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeNestloop.c,v 1.19 2000/08/13 02:50:03 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/nodeNestloop.c,v 1.20 2000/08/24 03:29:03 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -87,13 +87,6 @@ ExecNestLoop(NestLoop *node) ...@@ -87,13 +87,6 @@ ExecNestLoop(NestLoop *node)
outerTupleSlot = nlstate->jstate.cs_OuterTupleSlot; outerTupleSlot = nlstate->jstate.cs_OuterTupleSlot;
econtext->ecxt_outertuple = outerTupleSlot; econtext->ecxt_outertuple = outerTupleSlot;
/* ----------------
* Reset per-tuple memory context to free any expression evaluation
* storage allocated in the previous tuple cycle.
* ----------------
*/
ResetExprContext(econtext);
/* ---------------- /* ----------------
* Check to see if we're still projecting out tuples from a previous * Check to see if we're still projecting out tuples from a previous
* join tuple (because there is a function-returning-set in the * join tuple (because there is a function-returning-set in the
...@@ -103,15 +96,23 @@ ExecNestLoop(NestLoop *node) ...@@ -103,15 +96,23 @@ ExecNestLoop(NestLoop *node)
if (nlstate->jstate.cs_TupFromTlist) if (nlstate->jstate.cs_TupFromTlist)
{ {
TupleTableSlot *result; TupleTableSlot *result;
bool isDone; ExprDoneCond isDone;
result = ExecProject(nlstate->jstate.cs_ProjInfo, &isDone); result = ExecProject(nlstate->jstate.cs_ProjInfo, &isDone);
if (!isDone) if (isDone == ExprMultipleResult)
return result; return result;
/* Done with that source tuple... */ /* Done with that source tuple... */
nlstate->jstate.cs_TupFromTlist = false; nlstate->jstate.cs_TupFromTlist = false;
} }
/* ----------------
* Reset per-tuple memory context to free any expression evaluation
* storage allocated in the previous tuple cycle. Note this can't
* happen until we're done projecting out tuples from a join tuple.
* ----------------
*/
ResetExprContext(econtext);
/* ---------------- /* ----------------
* Ok, everything is setup for the join so now loop until * Ok, everything is setup for the join so now loop until
* we return a qualifying join tuple.. * we return a qualifying join tuple..
...@@ -219,16 +220,18 @@ ExecNestLoop(NestLoop *node) ...@@ -219,16 +220,18 @@ ExecNestLoop(NestLoop *node)
* using ExecProject(). * using ExecProject().
* ---------------- * ----------------
*/ */
ProjectionInfo *projInfo;
TupleTableSlot *result; TupleTableSlot *result;
bool isDone; ExprDoneCond isDone;
ENL1_printf("qualification succeeded, projecting tuple"); ENL1_printf("qualification succeeded, projecting tuple");
projInfo = nlstate->jstate.cs_ProjInfo; result = ExecProject(nlstate->jstate.cs_ProjInfo, &isDone);
result = ExecProject(projInfo, &isDone);
nlstate->jstate.cs_TupFromTlist = !isDone; if (isDone != ExprEndResult)
return result; {
nlstate->jstate.cs_TupFromTlist = (isDone == ExprMultipleResult);
return result;
}
} }
/* ---------------- /* ----------------
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeResult.c,v 1.15 2000/07/17 03:04:53 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/nodeResult.c,v 1.16 2000/08/24 03:29:03 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -67,8 +67,7 @@ ExecResult(Result *node) ...@@ -67,8 +67,7 @@ ExecResult(Result *node)
TupleTableSlot *resultSlot; TupleTableSlot *resultSlot;
Plan *outerPlan; Plan *outerPlan;
ExprContext *econtext; ExprContext *econtext;
bool isDone; ExprDoneCond isDone;
ProjectionInfo *projInfo;
/* ---------------- /* ----------------
* initialize the result node's state * initialize the result node's state
...@@ -77,13 +76,6 @@ ExecResult(Result *node) ...@@ -77,13 +76,6 @@ ExecResult(Result *node)
resstate = node->resstate; resstate = node->resstate;
econtext = resstate->cstate.cs_ExprContext; econtext = resstate->cstate.cs_ExprContext;
/* ----------------
* Reset per-tuple memory context to free any expression evaluation
* storage allocated in the previous tuple cycle.
* ----------------
*/
ResetExprContext(econtext);
/* ---------------- /* ----------------
* check constant qualifications like (2 > 1), if not already done * check constant qualifications like (2 > 1), if not already done
* ---------------- * ----------------
...@@ -111,12 +103,20 @@ ExecResult(Result *node) ...@@ -111,12 +103,20 @@ ExecResult(Result *node)
if (resstate->cstate.cs_TupFromTlist) if (resstate->cstate.cs_TupFromTlist)
{ {
resultSlot = ExecProject(resstate->cstate.cs_ProjInfo, &isDone); resultSlot = ExecProject(resstate->cstate.cs_ProjInfo, &isDone);
if (!isDone) if (isDone == ExprMultipleResult)
return resultSlot; return resultSlot;
/* Done with that source tuple... */ /* Done with that source tuple... */
resstate->cstate.cs_TupFromTlist = false; resstate->cstate.cs_TupFromTlist = false;
} }
/* ----------------
* Reset per-tuple memory context to free any expression evaluation
* storage allocated in the previous tuple cycle. Note this can't
* happen until we're done projecting out tuples from a scan tuple.
* ----------------
*/
ResetExprContext(econtext);
/* ---------------- /* ----------------
* if rs_done is true then it means that we were asked to return * if rs_done is true then it means that we were asked to return
* a constant tuple and we already did the last time ExecResult() * a constant tuple and we already did the last time ExecResult()
...@@ -124,7 +124,7 @@ ExecResult(Result *node) ...@@ -124,7 +124,7 @@ ExecResult(Result *node)
* Either way, now we are through. * Either way, now we are through.
* ---------------- * ----------------
*/ */
if (!resstate->rs_done) while (!resstate->rs_done)
{ {
outerPlan = outerPlan(node); outerPlan = outerPlan(node);
...@@ -159,13 +159,18 @@ ExecResult(Result *node) ...@@ -159,13 +159,18 @@ ExecResult(Result *node)
} }
/* ---------------- /* ----------------
* form the result tuple using ExecProject(), and return it. * form the result tuple using ExecProject(), and return it
* --- unless the projection produces an empty set, in which case
* we must loop back to see if there are more outerPlan tuples.
* ---------------- * ----------------
*/ */
projInfo = resstate->cstate.cs_ProjInfo; resultSlot = ExecProject(resstate->cstate.cs_ProjInfo, &isDone);
resultSlot = ExecProject(projInfo, &isDone);
resstate->cstate.cs_TupFromTlist = !isDone; if (isDone != ExprEndResult)
return resultSlot; {
resstate->cstate.cs_TupFromTlist = (isDone == ExprMultipleResult);
return resultSlot;
}
} }
return NULL; return NULL;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeSubplan.c,v 1.26 2000/07/12 02:37:04 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/nodeSubplan.c,v 1.27 2000/08/24 03:29:03 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -40,7 +40,6 @@ ExecSubPlan(SubPlan *node, List *pvar, ExprContext *econtext, bool *isNull) ...@@ -40,7 +40,6 @@ ExecSubPlan(SubPlan *node, List *pvar, ExprContext *econtext, bool *isNull)
MemoryContext oldcontext; MemoryContext oldcontext;
TupleTableSlot *slot; TupleTableSlot *slot;
Datum result; Datum result;
bool isDone;
bool found = false; /* TRUE if got at least one subplan tuple */ bool found = false; /* TRUE if got at least one subplan tuple */
List *lst; List *lst;
...@@ -67,9 +66,7 @@ ExecSubPlan(SubPlan *node, List *pvar, ExprContext *econtext, bool *isNull) ...@@ -67,9 +66,7 @@ ExecSubPlan(SubPlan *node, List *pvar, ExprContext *econtext, bool *isNull)
prm->value = ExecEvalExprSwitchContext((Node *) lfirst(pvar), prm->value = ExecEvalExprSwitchContext((Node *) lfirst(pvar),
econtext, econtext,
&(prm->isnull), &(prm->isnull),
&isDone); NULL);
if (!isDone)
elog(ERROR, "ExecSubPlan: set values not supported for params");
pvar = lnext(pvar); pvar = lnext(pvar);
} }
plan->chgParam = nconc(plan->chgParam, listCopy(node->parParam)); plan->chgParam = nconc(plan->chgParam, listCopy(node->parParam));
...@@ -189,9 +186,7 @@ ExecSubPlan(SubPlan *node, List *pvar, ExprContext *econtext, bool *isNull) ...@@ -189,9 +186,7 @@ ExecSubPlan(SubPlan *node, List *pvar, ExprContext *econtext, bool *isNull)
* Now we can eval the combining operator for this column. * Now we can eval the combining operator for this column.
*/ */
expresult = ExecEvalExprSwitchContext((Node *) expr, econtext, expresult = ExecEvalExprSwitchContext((Node *) expr, econtext,
&expnull, &isDone); &expnull, NULL);
if (!isDone)
elog(ERROR, "ExecSubPlan: set values not supported for combining operators");
/* /*
* Combine the result into the row result as appropriate. * Combine the result into the row result as appropriate.
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeTidscan.c,v 1.11 2000/08/03 19:19:30 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/nodeTidscan.c,v 1.12 2000/08/24 03:29:03 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -38,7 +38,6 @@ TidListCreate(List *evalList, ExprContext *econtext, ItemPointer *tidList) ...@@ -38,7 +38,6 @@ TidListCreate(List *evalList, ExprContext *econtext, ItemPointer *tidList)
List *lst; List *lst;
ItemPointer itemptr; ItemPointer itemptr;
bool isNull; bool isNull;
bool isDone;
int numTids = 0; int numTids = 0;
foreach(lst, evalList) foreach(lst, evalList)
...@@ -47,8 +46,8 @@ TidListCreate(List *evalList, ExprContext *econtext, ItemPointer *tidList) ...@@ -47,8 +46,8 @@ TidListCreate(List *evalList, ExprContext *econtext, ItemPointer *tidList)
DatumGetPointer(ExecEvalExprSwitchContext(lfirst(lst), DatumGetPointer(ExecEvalExprSwitchContext(lfirst(lst),
econtext, econtext,
&isNull, &isNull,
&isDone)); NULL));
if (itemptr && ItemPointerIsValid(itemptr)) if (!isNull && itemptr && ItemPointerIsValid(itemptr))
{ {
tidList[numTids] = itemptr; tidList[numTids] = itemptr;
numTids++; numTids++;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.93 2000/08/13 02:50:04 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.94 2000/08/24 03:29:04 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1380,9 +1380,8 @@ clause_pred_clause_test(Expr *predicate, Node *clause) ...@@ -1380,9 +1380,8 @@ clause_pred_clause_test(Expr *predicate, Node *clause)
copyObject(clause_const), copyObject(clause_const),
copyObject(pred_const)); copyObject(pred_const));
#ifndef OMIT_PARTIAL_INDEX
test_result = ExecEvalExpr((Node *) test_expr, NULL, &isNull, NULL); test_result = ExecEvalExpr((Node *) test_expr, NULL, &isNull, NULL);
#endif /* OMIT_PARTIAL_INDEX */
if (isNull) if (isNull)
{ {
elog(DEBUG, "clause_pred_clause_test: null test result"); elog(DEBUG, "clause_pred_clause_test: null test result");
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.72 2000/08/21 17:22:34 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.73 2000/08/24 03:29:05 tgl Exp $
* *
* HISTORY * HISTORY
* AUTHOR DATE MAJOR EVENT * AUTHOR DATE MAJOR EVENT
...@@ -1447,7 +1447,6 @@ simplify_op_or_func(Expr *expr, List *args) ...@@ -1447,7 +1447,6 @@ simplify_op_or_func(Expr *expr, List *args)
bool has_nonconst_input = false; bool has_nonconst_input = false;
bool has_null_input = false; bool has_null_input = false;
bool const_is_null; bool const_is_null;
bool isDone;
/* /*
* Check for constant inputs and especially constant-NULL inputs. * Check for constant inputs and especially constant-NULL inputs.
...@@ -1566,8 +1565,7 @@ simplify_op_or_func(Expr *expr, List *args) ...@@ -1566,8 +1565,7 @@ simplify_op_or_func(Expr *expr, List *args)
econtext = MakeExprContext(NULL, CurrentMemoryContext); econtext = MakeExprContext(NULL, CurrentMemoryContext);
const_val = ExecEvalExprSwitchContext((Node *) newexpr, econtext, const_val = ExecEvalExprSwitchContext((Node *) newexpr, econtext,
&const_is_null, &isDone); &const_is_null, NULL);
Assert(isDone); /* if this isn't set, we blew it... */
/* Must copy result out of sub-context used by expression eval */ /* Must copy result out of sub-context used by expression eval */
const_val = datumCopy(const_val, resultTypByVal, resultTypLen); const_val = datumCopy(const_val, resultTypByVal, resultTypLen);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.88 2000/08/20 00:44:18 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.89 2000/08/24 03:29:05 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -560,13 +560,13 @@ ParseFuncOrColumn(ParseState *pstate, char *funcname, List *fargs, ...@@ -560,13 +560,13 @@ ParseFuncOrColumn(ParseState *pstate, char *funcname, List *fargs,
{ /* we know all of these fields already */ { /* we know all of these fields already */
/* /*
* We create a funcnode with a placeholder function SetEval. * We create a funcnode with a placeholder function seteval().
* SetEval() never actually gets executed. When the function * At runtime, seteval() will execute the function identified
* evaluation routines see it, they use the funcid projected out * by the funcid it receives as parameter.
* from the relation as the actual function to call. Example: *
* retrieve (emp.mgr.name) The plan for this will scan the emp * Example: retrieve (emp.mgr.name). The plan for this will scan the
* relation, projecting out the mgr attribute, which is a funcid. * emp relation, projecting out the mgr attribute, which is a funcid.
* This function is then called (instead of SetEval) and "name" is * This function is then called (via seteval()) and "name" is
* projected from its result. * projected from its result.
*/ */
funcid = F_SETEVAL; funcid = F_SETEVAL;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.44 2000/08/08 15:42:04 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.45 2000/08/24 03:29:05 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
#include "utils/syscache.h" #include "utils/syscache.h"
static void disallow_setop(char *op, Type optype, Node *operand);
static bool fitsInFloat(Value *value); static bool fitsInFloat(Value *value);
...@@ -71,7 +70,6 @@ make_operand(char *opname, ...@@ -71,7 +70,6 @@ make_operand(char *opname,
if (tree != NULL) if (tree != NULL)
{ {
disallow_setop(opname, target_type, tree);
/* must coerce? */ /* must coerce? */
if (target_typeId != orig_typeId) if (target_typeId != orig_typeId)
result = coerce_type(NULL, tree, orig_typeId, target_typeId, -1); result = coerce_type(NULL, tree, orig_typeId, target_typeId, -1);
...@@ -96,21 +94,6 @@ make_operand(char *opname, ...@@ -96,21 +94,6 @@ make_operand(char *opname,
} /* make_operand() */ } /* make_operand() */
static void
disallow_setop(char *op, Type optype, Node *operand)
{
if (operand == NULL)
return;
if (nodeTag(operand) == T_Iter)
{
elog(ERROR, "An operand to the '%s' operator returns a set of %s,"
"\n\tbut '%s' takes single values, not sets.",
op, typeTypeName(optype), op);
}
}
/* make_op() /* make_op()
* Operator construction. * Operator construction.
* *
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.32 2000/06/09 01:11:09 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.33 2000/08/24 03:29:06 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
#include "catalog/catname.h" #include "catalog/catname.h"
#include "catalog/indexing.h" #include "catalog/indexing.h"
#include "catalog/pg_proc.h" #include "catalog/pg_proc.h"
#include "executor/executor.h"
#include "utils/fcache.h"
#include "utils/sets.h" #include "utils/sets.h"
#include "utils/syscache.h" #include "utils/syscache.h"
...@@ -30,9 +32,9 @@ extern CommandDest whereToSendOutput; /* defined in tcop/postgres.c */ ...@@ -30,9 +32,9 @@ extern CommandDest whereToSendOutput; /* defined in tcop/postgres.c */
/* /*
* SetDefine - converts query string defining set to an oid * SetDefine - converts query string defining set to an oid
* *
* The query string is used to store the set as a function in * We create an SQL function having the given querystring as its body.
* pg_proc. The name of the function is then changed to use the * The name of the function is then changed to use the OID of its tuple
* OID of its tuple in pg_proc. * in pg_proc.
*/ */
Oid Oid
SetDefine(char *querystr, char *typename) SetDefine(char *querystr, char *typename)
...@@ -57,11 +59,11 @@ SetDefine(char *querystr, char *typename) ...@@ -57,11 +59,11 @@ SetDefine(char *querystr, char *typename)
querystr, /* sourceCode */ querystr, /* sourceCode */
fileName, /* fileName */ fileName, /* fileName */
true, /* trusted */ true, /* trusted */
false, /* canCache XXX appropriate? */ false, /* canCache (assume unsafe) */
false, /* isStrict XXX appropriate? */ false, /* isStrict (irrelevant, no args) */
100, /* byte_pct */ 100, /* byte_pct */
0, /* perbyte_cpu */ 0, /* perbyte_cpu */
0, /* percall_cpu */ 0, /* percall_cpu */
100, /* outin_ratio */ 100, /* outin_ratio */
NIL, /* argList */ NIL, /* argList */
whereToSendOutput); whereToSendOutput);
...@@ -74,11 +76,12 @@ SetDefine(char *querystr, char *typename) ...@@ -74,11 +76,12 @@ SetDefine(char *querystr, char *typename)
* until you start the next command.) * until you start the next command.)
*/ */
CommandCounterIncrement(); CommandCounterIncrement();
tup = SearchSysCacheTuple(PROCOID, tup = SearchSysCacheTuple(PROCOID,
ObjectIdGetDatum(setoid), ObjectIdGetDatum(setoid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(tup)) if (!HeapTupleIsValid(tup))
elog(ERROR, "setin: unable to define set %s", querystr); elog(ERROR, "SetDefine: unable to define set %s", querystr);
/* /*
* We can tell whether the set was already defined by checking the * We can tell whether the set was already defined by checking the
...@@ -86,7 +89,7 @@ SetDefine(char *querystr, char *typename) ...@@ -86,7 +89,7 @@ SetDefine(char *querystr, char *typename)
* oid>" it's already defined. * oid>" it's already defined.
*/ */
proc = (Form_pg_proc) GETSTRUCT(tup); proc = (Form_pg_proc) GETSTRUCT(tup);
if (!strcmp((char *) procname, (char *) &(proc->proname))) if (strcmp(procname, NameStr(proc->proname)) == 0)
{ {
/* make the real proc name */ /* make the real proc name */
sprintf(realprocname, "set%u", setoid); sprintf(realprocname, "set%u", setoid);
...@@ -120,7 +123,7 @@ SetDefine(char *querystr, char *typename) ...@@ -120,7 +123,7 @@ SetDefine(char *querystr, char *typename)
setoid = newtup->t_data->t_oid; setoid = newtup->t_data->t_oid;
} }
else else
elog(ERROR, "setin: could not find new set oid tuple"); elog(ERROR, "SetDefine: could not find new set oid tuple");
if (RelationGetForm(procrel)->relhasindex) if (RelationGetForm(procrel)->relhasindex)
{ {
...@@ -132,20 +135,79 @@ SetDefine(char *querystr, char *typename) ...@@ -132,20 +135,79 @@ SetDefine(char *querystr, char *typename)
} }
heap_close(procrel, RowExclusiveLock); heap_close(procrel, RowExclusiveLock);
} }
return setoid; return setoid;
} }
/* This function is a placeholder. The parser uses the OID of this /*
* function to fill in the :funcid field of a set. This routine is * This function executes set evaluation. The parser sets up a set reference
* never executed. At runtime, the OID of the actual set is substituted * as a call to this function with the OID of the set to evaluate as argument.
* into the :funcid. *
* We build a new fcache for execution of the set's function and run the
* function until it says "no mas". The fn_extra field of the call's
* FmgrInfo record is a handy place to hold onto the fcache. (Since this
* is a built-in function, there is no competing use of fn_extra.)
*/ */
Datum Datum
seteval(PG_FUNCTION_ARGS) seteval(PG_FUNCTION_ARGS)
{ {
Oid funcoid = PG_GETARG_OID(0); Oid funcoid = PG_GETARG_OID(0);
FunctionCachePtr fcache;
Datum result;
bool isNull;
ExprDoneCond isDone;
/*
* If this is the first call, we need to set up the fcache for the
* target set's function.
*/
fcache = (FunctionCachePtr) fcinfo->flinfo->fn_extra;
if (fcache == NULL)
{
fcache = init_fcache(funcoid, 0, fcinfo->flinfo->fn_mcxt);
fcinfo->flinfo->fn_extra = (void *) fcache;
}
/*
* Evaluate the function. NOTE: we need no econtext because there
* are no arguments to evaluate.
*/
/* ExecMakeFunctionResult assumes these are initialized at call: */
isNull = false;
isDone = ExprSingleResult;
elog(ERROR, "seteval called for OID %u", funcoid); result = ExecMakeFunctionResult(fcache,
NIL,
NULL, /* no econtext, see above */
&isNull,
&isDone);
/*
* If we're done with the results of this set function, get rid of
* its func cache so that we will start from the top next time.
* (Can you say "memory leak"? This feature is a crock anyway...)
*/
if (isDone != ExprMultipleResult)
{
pfree(fcache);
fcinfo->flinfo->fn_extra = NULL;
}
/*
* Return isNull/isDone status.
*/
fcinfo->isnull = isNull;
if (isDone != ExprSingleResult)
{
ReturnSetInfo *rsi = (ReturnSetInfo *) fcinfo->resultinfo;
if (rsi && IsA(rsi, ReturnSetInfo))
rsi->isDone = isDone;
else
elog(ERROR, "Set-valued function called in context that cannot accept a set");
}
PG_RETURN_INT32(0); /* keep compiler happy */ PG_RETURN_DATUM(result);
} }
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* fcache.c * fcache.c
* Code for the 'function cache' used in Oper and Func nodes.... * Code for the 'function cache' used in Oper and Func nodes.
*
* *
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
*
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/fcache.c,v 1.36 2000/08/11 18:35:50 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/fcache.c,v 1.37 2000/08/24 03:29:07 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "postgres.h" #include "postgres.h"
#include "access/heapam.h" #include "utils/fcache.h"
#include "catalog/pg_language.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_type.h"
#include "parser/parsetree.h"
#include "utils/builtins.h"
#include "utils/fcache2.h"
#include "utils/syscache.h"
static Oid GetDynamicFuncArgType(Var *arg, ExprContext *econtext);
static FunctionCachePtr init_fcache(Oid foid,
List *argList,
ExprContext *econtext);
#define FuncArgTypeIsDynamic(arg) \
(IsA(arg,Var) && ((Var*)arg)->varattno == InvalidAttrNumber)
static Oid
GetDynamicFuncArgType(Var *arg, ExprContext *econtext)
{
char *relname;
int rtid;
HeapTuple tup;
Assert(IsA(arg, Var));
rtid = ((Var *) arg)->varno;
relname = (char *) getrelname(rtid, econtext->ecxt_range_table);
tup = SearchSysCacheTuple(TYPENAME,
PointerGetDatum(relname),
0, 0, 0);
if (!tup)
elog(ERROR, "Lookup failed on type tuple for class %s",
relname);
return tup->t_data->t_oid;
}
/*----------------------------------------------------------------- /*-----------------------------------------------------------------
* *
* Initialize a 'FunctionCache' struct given the PG_PROC oid. * Build a 'FunctionCache' struct given the PG_PROC oid.
* *
*----------------------------------------------------------------- *-----------------------------------------------------------------
*/ */
static FunctionCachePtr FunctionCachePtr
init_fcache(Oid foid, init_fcache(Oid foid, int nargs, MemoryContext fcacheCxt)
List *argList,
ExprContext *econtext)
{ {
HeapTuple procedureTuple; MemoryContext oldcontext;
HeapTuple typeTuple;
Form_pg_proc procedureStruct;
Form_pg_type typeStruct;
FunctionCachePtr retval; FunctionCachePtr retval;
int nargs;
Datum tmp; /* Switch to a context long-lived enough for the fcache entry */
bool isNull; oldcontext = MemoryContextSwitchTo(fcacheCxt);
retval = (FunctionCachePtr) palloc(sizeof(FunctionCache)); retval = (FunctionCachePtr) palloc(sizeof(FunctionCache));
MemSet(retval, 0, sizeof(FunctionCache)); MemSet(retval, 0, sizeof(FunctionCache));
retval->fcacheCxt = CurrentMemoryContext;
/* ----------------
* get the procedure tuple corresponding to the given functionOid
*
* NB: use SearchSysCacheTupleCopy to ensure tuple lives long enough
* ----------------
*/
procedureTuple = SearchSysCacheTupleCopy(PROCOID,
ObjectIdGetDatum(foid),
0, 0, 0);
if (!HeapTupleIsValid(procedureTuple)) /* Set up the primary fmgr lookup information */
elog(ERROR, "init_fcache: Cache lookup failed for procedure %u", fmgr_info(foid, &(retval->func));
foid);
procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple); /* Initialize unvarying fields of per-call info block */
retval->fcinfo.flinfo = &(retval->func);
retval->fcinfo.nargs = nargs;
/* ---------------- if (nargs > FUNC_MAX_ARGS)
* get the return type from the procedure tuple elog(ERROR, "init_fcache: too many arguments");
* ----------------
*/
typeTuple = SearchSysCacheTuple(TYPEOID,
ObjectIdGetDatum(procedureStruct->prorettype),
0, 0, 0);
if (!HeapTupleIsValid(typeTuple)) /* If function returns set, prepare a resultinfo node for communication */
elog(ERROR, "init_fcache: Cache lookup failed for type %u", if (retval->func.fn_retset)
procedureStruct->prorettype);
typeStruct = (Form_pg_type) GETSTRUCT(typeTuple);
/* ----------------
* get the type length and by-value flag from the type tuple
* ----------------
*/
retval->typlen = typeStruct->typlen;
if (typeStruct->typrelid == InvalidOid)
{ {
/* The return type is not a relation, so just use byval */ retval->fcinfo.resultinfo = (Node *) &(retval->rsinfo);
retval->typbyval = typeStruct->typbyval; retval->rsinfo.type = T_ReturnSetInfo;
retval->returnsTuple = false;
} }
else
{
/* retval->argsValid = false;
* This is a hack. We assume here that any function returning a
* tuple returns it by reference. This needs to be fixed, since
* actually the mechanism isn't quite like return-by-reference.
*/
retval->typbyval = false;
retval->returnsTuple = true;
}
retval->foid = foid;
retval->language = procedureStruct->prolang;
retval->returnsSet = procedureStruct->proretset;
retval->hasSetArg = false; retval->hasSetArg = false;
retval->func_state = (char *) NULL;
retval->setArg = (Datum) 0;
/*
* If we are returning exactly one result then we have to copy tuples
* and by reference results because we have to end the execution
* before we return the results. When you do this everything
* allocated by the executor (i.e. slots and tuples) is freed.
*/
if ((retval->language == SQLlanguageId) &&
!retval->returnsSet &&
!retval->typbyval)
{
TupleTableSlot *slot;
slot = makeNode(TupleTableSlot);
slot->ttc_shouldFree = true;
slot->ttc_descIsNew = true;
slot->ttc_tupleDescriptor = (TupleDesc) NULL;
slot->ttc_buffer = InvalidBuffer;
slot->ttc_whichplan = -1;
retval->funcSlot = (Pointer) slot;
}
else
retval->funcSlot = (Pointer) NULL;
nargs = procedureStruct->pronargs;
retval->nargs = nargs;
if (nargs > 0)
{
Oid *argTypes;
if (retval->language == SQLlanguageId)
{
int i;
List *oneArg;
retval->argOidVect = (Oid *) palloc(retval->nargs * sizeof(Oid));
argTypes = procedureStruct->proargtypes;
memmove(retval->argOidVect,
argTypes,
(retval->nargs) * sizeof(Oid));
for (i = 0; MemoryContextSwitchTo(oldcontext);
argList;
i++, argList = lnext(argList))
{
oneArg = lfirst(argList);
if (FuncArgTypeIsDynamic(oneArg))
retval->argOidVect[i] = GetDynamicFuncArgType((Var *) oneArg,
econtext);
}
}
else
retval->argOidVect = (Oid *) NULL;
}
else
{
retval->argOidVect = (Oid *) NULL;
}
if (procedureStruct->prolang == SQLlanguageId)
{
tmp = SysCacheGetAttr(PROCOID,
procedureTuple,
Anum_pg_proc_prosrc,
&isNull);
if (isNull)
elog(ERROR, "init_fcache: null prosrc for procedure %u",
foid);
retval->src = DatumGetCString(DirectFunctionCall1(textout, tmp));
retval->bin = (char *) NULL;
}
else
{
retval->src = (char *) NULL;
if (procedureStruct->proistrusted)
retval->bin = (char *) NULL;
else
{
tmp = SysCacheGetAttr(PROCOID,
procedureTuple,
Anum_pg_proc_probin,
&isNull);
if (isNull)
elog(ERROR, "init_fcache: null probin for procedure %u",
foid);
retval->bin = DatumGetCString(DirectFunctionCall1(textout, tmp));
}
}
if (retval->language != SQLlanguageId)
{
fmgr_info(foid, &(retval->func));
retval->nargs = retval->func.fn_nargs;
}
else
retval->func.fn_addr = (PGFunction) NULL;
heap_freetuple(procedureTuple);
return retval; return retval;
} }
void
setFcache(Node *node, Oid foid, List *argList, ExprContext *econtext)
{
MemoryContext oldcontext;
FunctionCachePtr fcache;
/* Switch to a context long-lived enough for the fcache entry */
oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
fcache = init_fcache(foid, argList, econtext);
if (IsA(node, Oper))
{
Oper *onode = (Oper *) node;
onode->op_fcache = fcache;
}
else if (IsA(node, Func))
{
Func *fnode = (Func *) node;
fnode->func_fcache = fcache;
}
else
elog(ERROR, "init_fcache: node must be Oper or Func!");
MemoryContextSwitchTo(oldcontext);
}
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/fmgr/fmgr.c,v 1.45 2000/07/06 05:48:13 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/fmgr/fmgr.c,v 1.46 2000/08/24 03:29:07 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "catalog/pg_language.h" #include "catalog/pg_language.h"
#include "catalog/pg_proc.h" #include "catalog/pg_proc.h"
#include "executor/functions.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/fmgrtab.h" #include "utils/fmgrtab.h"
#include "utils/syscache.h" #include "utils/syscache.h"
...@@ -44,7 +45,6 @@ typedef char *((*func_ptr) ()); ...@@ -44,7 +45,6 @@ typedef char *((*func_ptr) ());
static Datum fmgr_oldstyle(PG_FUNCTION_ARGS); static Datum fmgr_oldstyle(PG_FUNCTION_ARGS);
static Datum fmgr_untrusted(PG_FUNCTION_ARGS); static Datum fmgr_untrusted(PG_FUNCTION_ARGS);
static Datum fmgr_sql(PG_FUNCTION_ARGS);
/* /*
...@@ -111,6 +111,7 @@ fmgr_info(Oid functionId, FmgrInfo *finfo) ...@@ -111,6 +111,7 @@ fmgr_info(Oid functionId, FmgrInfo *finfo)
finfo->fn_oid = functionId; finfo->fn_oid = functionId;
finfo->fn_extra = NULL; finfo->fn_extra = NULL;
finfo->fn_mcxt = CurrentMemoryContext;
if ((fbp = fmgr_isbuiltin(functionId)) != NULL) if ((fbp = fmgr_isbuiltin(functionId)) != NULL)
{ {
...@@ -119,6 +120,7 @@ fmgr_info(Oid functionId, FmgrInfo *finfo) ...@@ -119,6 +120,7 @@ fmgr_info(Oid functionId, FmgrInfo *finfo)
*/ */
finfo->fn_nargs = fbp->nargs; finfo->fn_nargs = fbp->nargs;
finfo->fn_strict = fbp->strict; finfo->fn_strict = fbp->strict;
finfo->fn_retset = false; /* assume no builtins return sets! */
if (fbp->oldstyle) if (fbp->oldstyle)
{ {
finfo->fn_addr = fmgr_oldstyle; finfo->fn_addr = fmgr_oldstyle;
...@@ -142,6 +144,7 @@ fmgr_info(Oid functionId, FmgrInfo *finfo) ...@@ -142,6 +144,7 @@ fmgr_info(Oid functionId, FmgrInfo *finfo)
finfo->fn_nargs = procedureStruct->pronargs; finfo->fn_nargs = procedureStruct->pronargs;
finfo->fn_strict = procedureStruct->proisstrict; finfo->fn_strict = procedureStruct->proisstrict;
finfo->fn_retset = procedureStruct->proretset;
if (!procedureStruct->proistrusted) if (!procedureStruct->proistrusted)
{ {
...@@ -427,21 +430,6 @@ fmgr_untrusted(PG_FUNCTION_ARGS) ...@@ -427,21 +430,6 @@ fmgr_untrusted(PG_FUNCTION_ARGS)
return 0; /* keep compiler happy */ return 0; /* keep compiler happy */
} }
/*
* Handler for SQL-language functions
*/
static Datum
fmgr_sql(PG_FUNCTION_ARGS)
{
/*
* XXX It'd be really nice to support SQL functions anywhere that
* builtins are supported. What would we have to do? What pitfalls
* are there?
*/
elog(ERROR, "SQL-language function not supported in this context");
return 0; /* keep compiler happy */
}
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* Support routines for callers of fmgr-compatible functions * Support routines for callers of fmgr-compatible functions
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: pg_proc.h,v 1.163 2000/08/23 06:04:44 thomas Exp $ * $Id: pg_proc.h,v 1.164 2000/08/24 03:29:08 tgl Exp $
* *
* NOTES * NOTES
* The script catalog/genbki.sh reads this file and generates .bki * The script catalog/genbki.sh reads this file and generates .bki
...@@ -1266,8 +1266,8 @@ DATA(insert OID = 1036 ( aclremove PGUID 12 f t f t 2 f 1034 "1034 1033" 10 ...@@ -1266,8 +1266,8 @@ DATA(insert OID = 1036 ( aclremove PGUID 12 f t f t 2 f 1034 "1034 1033" 10
DESCR("remove ACL item"); DESCR("remove ACL item");
DATA(insert OID = 1037 ( aclcontains PGUID 12 f t f t 2 f 16 "1034 1033" 100 0 0 100 aclcontains - )); DATA(insert OID = 1037 ( aclcontains PGUID 12 f t f t 2 f 16 "1034 1033" 100 0 0 100 aclcontains - ));
DESCR("does ACL contain item?"); DESCR("does ACL contain item?");
DATA(insert OID = 1038 ( seteval PGUID 12 f t f t 1 f 23 "26" 100 0 0 100 seteval - )); DATA(insert OID = 1038 ( seteval PGUID 12 f t f t 1 t 23 "26" 100 0 0 100 seteval - ));
DESCR(""); DESCR("internal function supporting PostQuel-style sets");
DATA(insert OID = 1044 ( bpcharin PGUID 12 f t t t 3 f 1042 "0 26 23" 100 0 0 100 bpcharin - )); DATA(insert OID = 1044 ( bpcharin PGUID 12 f t t t 3 f 1042 "0 26 23" 100 0 0 100 bpcharin - ));
DESCR("(internal)"); DESCR("(internal)");
DATA(insert OID = 1045 ( bpcharout PGUID 12 f t t t 1 f 23 "0" 100 0 0 100 bpcharout - )); DATA(insert OID = 1045 ( bpcharout PGUID 12 f t t t 1 f 23 "0" 100 0 0 100 bpcharout - ));
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: defrem.h,v 1.19 2000/02/18 09:29:49 inoue Exp $ * $Id: defrem.h,v 1.20 2000/08/24 03:29:09 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -44,7 +44,6 @@ extern void CreateFunction(ProcedureStmt *stmt, CommandDest dest); ...@@ -44,7 +44,6 @@ extern void CreateFunction(ProcedureStmt *stmt, CommandDest dest);
extern void DefineOperator(char *name, List *parameters); extern void DefineOperator(char *name, List *parameters);
extern void DefineAggregate(char *name, List *parameters); extern void DefineAggregate(char *name, List *parameters);
extern void DefineType(char *name, List *parameters); extern void DefineType(char *name, List *parameters);
extern void CreateFunction(ProcedureStmt *stmt, CommandDest dest);
/* /*
* prototypes in remove.c * prototypes in remove.c
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: execFlatten.h,v 1.11 2000/01/26 05:58:05 momjian Exp $ * $Id: execFlatten.h,v 1.12 2000/08/24 03:29:10 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -15,11 +15,14 @@ ...@@ -15,11 +15,14 @@
#define EXECFLATTEN_H #define EXECFLATTEN_H
#include "nodes/execnodes.h" #include "nodes/execnodes.h"
#include "nodes/relation.h" #include "nodes/parsenodes.h"
extern Datum ExecEvalIter(Iter *iterNode, ExprContext *econtext, bool *resultIsNull, bool *iterIsDone);
extern void ExecEvalFjoin(TargetEntry *tlist, ExprContext *econtext, bool *isNullVect, bool *fj_isDone); extern Datum ExecEvalIter(Iter *iterNode, ExprContext *econtext,
bool *isNull, ExprDoneCond *isDone);
extern void ExecEvalFjoin(TargetEntry *tlist, ExprContext *econtext,
bool *isNullVect, ExprDoneCond *fj_isDone);
#endif /* EXECFLATTEN_H */ #endif /* EXECFLATTEN_H */
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: executor.h,v 1.48 2000/08/21 20:55:29 tgl Exp $ * $Id: executor.h,v 1.49 2000/08/24 03:29:10 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -78,14 +78,20 @@ extern char *GetAttributeByNum(TupleTableSlot *slot, AttrNumber attrno, ...@@ -78,14 +78,20 @@ extern char *GetAttributeByNum(TupleTableSlot *slot, AttrNumber attrno,
bool *isNull); bool *isNull);
extern char *GetAttributeByName(TupleTableSlot *slot, char *attname, extern char *GetAttributeByName(TupleTableSlot *slot, char *attname,
bool *isNull); bool *isNull);
extern Datum ExecMakeFunctionResult(FunctionCachePtr fcache,
List *arguments,
ExprContext *econtext,
bool *isNull,
ExprDoneCond *isDone);
extern Datum ExecEvalExpr(Node *expression, ExprContext *econtext, extern Datum ExecEvalExpr(Node *expression, ExprContext *econtext,
bool *isNull, bool *isDone); bool *isNull, ExprDoneCond *isDone);
extern Datum ExecEvalExprSwitchContext(Node *expression, ExprContext *econtext, extern Datum ExecEvalExprSwitchContext(Node *expression, ExprContext *econtext,
bool *isNull, bool *isDone); bool *isNull, ExprDoneCond *isDone);
extern bool ExecQual(List *qual, ExprContext *econtext, bool resultForNull); extern bool ExecQual(List *qual, ExprContext *econtext, bool resultForNull);
extern int ExecTargetListLength(List *targetlist); extern int ExecTargetListLength(List *targetlist);
extern int ExecCleanTargetListLength(List *targetlist); extern int ExecCleanTargetListLength(List *targetlist);
extern TupleTableSlot *ExecProject(ProjectionInfo *projInfo, bool *isDone); extern TupleTableSlot *ExecProject(ProjectionInfo *projInfo,
ExprDoneCond *isDone);
/* /*
* prototypes from functions in execScan.c * prototypes from functions in execScan.c
......
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* functions.h * functions.h
* * Declarations for execution of SQL-language functions.
* *
* *
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: functions.h,v 1.13 2000/08/08 15:42:39 tgl Exp $ * $Id: functions.h,v 1.14 2000/08/24 03:29:10 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#ifndef FUNCTIONS_H #ifndef FUNCTIONS_H
#define FUNCTIONS_H #define FUNCTIONS_H
#include "nodes/parsenodes.h" #include "fmgr.h"
#include "utils/syscache.h"
extern Datum postquel_function(FunctionCallInfo fcinfo, extern Datum fmgr_sql(PG_FUNCTION_ARGS);
FunctionCachePtr fcache,
bool *isDone);
#endif /* FUNCTIONS_H */ #endif /* FUNCTIONS_H */
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: fmgr.h,v 1.9 2000/07/29 03:26:47 tgl Exp $ * $Id: fmgr.h,v 1.10 2000/08/24 03:29:11 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -41,7 +41,9 @@ typedef struct ...@@ -41,7 +41,9 @@ typedef struct
Oid fn_oid; /* OID of function (NOT of handler, if any) */ Oid fn_oid; /* OID of function (NOT of handler, if any) */
short fn_nargs; /* 0..FUNC_MAX_ARGS, or -1 if variable arg count */ short fn_nargs; /* 0..FUNC_MAX_ARGS, or -1 if variable arg count */
bool fn_strict; /* function is "strict" (NULL in => NULL out) */ bool fn_strict; /* function is "strict" (NULL in => NULL out) */
bool fn_retset; /* function returns a set (over multiple calls) */
void *fn_extra; /* extra space for use by handler */ void *fn_extra; /* extra space for use by handler */
MemoryContext fn_mcxt; /* memory context to store fn_extra in */
} FmgrInfo; } FmgrInfo;
/* /*
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: execnodes.h,v 1.47 2000/08/22 04:06:22 tgl Exp $ * $Id: execnodes.h,v 1.48 2000/08/24 03:29:13 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -120,6 +120,31 @@ typedef struct ExprContext ...@@ -120,6 +120,31 @@ typedef struct ExprContext
List *ecxt_range_table; List *ecxt_range_table;
} ExprContext; } ExprContext;
/*
* Set-result status returned by ExecEvalExpr()
*/
typedef enum
{
ExprSingleResult, /* expression does not return a set */
ExprMultipleResult, /* this result is an element of a set */
ExprEndResult /* there are no more elements in the set */
} ExprDoneCond;
/*
* 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.
*
* XXX this mechanism is a quick hack and probably needs to be redesigned.
*/
typedef struct ReturnSetInfo
{
NodeTag type;
ExprDoneCond isDone;
} ReturnSetInfo;
/* ---------------- /* ----------------
* ProjectionInfo node information * ProjectionInfo node information
* *
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: nodes.h,v 1.74 2000/08/11 23:46:54 tgl Exp $ * $Id: nodes.h,v 1.75 2000/08/24 03:29:13 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -227,7 +227,9 @@ typedef enum NodeTag ...@@ -227,7 +227,9 @@ typedef enum NodeTag
* TAGS FOR FUNCTION-CALL CONTEXT AND RESULTINFO NODES (cf. fmgr.h) * TAGS FOR FUNCTION-CALL CONTEXT AND RESULTINFO NODES (cf. fmgr.h)
*--------------------- *---------------------
*/ */
T_TriggerData = 800 /* in commands/trigger.h */ T_TriggerData = 800, /* in commands/trigger.h */
T_ReturnSetInfo /* in nodes/execnodes.h */
} NodeTag; } NodeTag;
/* /*
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: primnodes.h,v 1.46 2000/08/08 15:42:59 tgl Exp $ * $Id: primnodes.h,v 1.47 2000/08/24 03:29:13 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -16,7 +16,10 @@ ...@@ -16,7 +16,10 @@
#include "access/attnum.h" #include "access/attnum.h"
#include "nodes/pg_list.h" #include "nodes/pg_list.h"
#include "utils/fcache.h"
/* FunctionCache is declared in utils/fcache.h */
typedef struct FunctionCache *FunctionCachePtr;
/* ---------------------------------------------------------------- /* ----------------------------------------------------------------
* node definitions * node definitions
......
...@@ -7,13 +7,14 @@ ...@@ -7,13 +7,14 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: builtins.h,v 1.133 2000/08/23 06:04:49 thomas Exp $ * $Id: builtins.h,v 1.134 2000/08/24 03:29:14 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#ifndef BUILTINS_H #ifndef BUILTINS_H
#define BUILTINS_H #define BUILTINS_H
#include "fmgr.h"
#include "nodes/relation.h" /* for amcostestimate parameters */ #include "nodes/relation.h" /* for amcostestimate parameters */
#include "storage/itemptr.h" #include "storage/itemptr.h"
#include "utils/numeric.h" #include "utils/numeric.h"
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: fcache.h,v 1.13 2000/08/08 15:43:12 tgl Exp $ * $Id: fcache.h,v 1.14 2000/08/24 03:29:14 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -19,45 +19,50 @@ ...@@ -19,45 +19,50 @@
#define FCACHE_H #define FCACHE_H
#include "fmgr.h" #include "fmgr.h"
#include "nodes/execnodes.h"
/*
* A FunctionCache record is built for all functions regardless of language.
*
* We store the fmgr lookup info to avoid recomputing it on each call.
* We also store a prebuilt FunctionCallInfo struct. When evaluating a
* function-returning-set, fcinfo holds the argument values across calls
* so that we need not re-evaluate the arguments for each call. Even for
* non-set functions, fcinfo saves a few cycles per call by allowing us to
* avoid redundant setup of its fields.
*/
typedef struct typedef struct FunctionCache
{ {
FmgrInfo func; /* info for fmgr call mechanism */ /*
Oid foid; /* oid of the function in pg_proc */ * Function manager's lookup info for the target function.
Oid language; /* oid of the language in pg_language */
int typlen; /* length of the return type */
bool typbyval; /* true if return type is pass by value */
bool returnsTuple; /* true if return type is a tuple */
bool returnsSet; /* true if func returns a set (multi rows) */
bool hasSetArg; /* true if func is part of a nested dot
* expr whose argument is func returning a
* set ugh! */
/* If additional info is added to an existing fcache, be sure to
* allocate it in the fcacheCxt.
*/ */
MemoryContext fcacheCxt; /* context the fcache lives in */ FmgrInfo func;
/*
int nargs; /* actual number of arguments */ * Per-call info for calling the target function. Unvarying fields
Oid *argOidVect; /* oids of all the argument types */ * are set up by init_fcache(). Argument values are filled in as needed.
*/
char *src; /* source code of the function */ FunctionCallInfoData fcinfo;
char *bin; /* binary object code ?? */ /*
char *func_state; /* function_state struct for execution */ * "Resultinfo" node --- used only if target function returns a set.
*/
Pointer funcSlot; /* if one result we need to copy it before ReturnSetInfo rsinfo;
* we end execution of the function and /*
* free stuff */ * argsValid is true when we are evaluating a set-valued function and
* we are in the middle of a call series; we want to pass the same
Datum setArg; /* current argument for nested dot * argument values to the function again (and again, until it returns
* execution Nested dot expressions mean * ExprEndResult).
* we have funcs whose argument is a set */
* of tuples */ bool argsValid; /* TRUE if fcinfo contains valid arguments */
/*
* hasSetArg is true if we found a set-valued argument to the function.
* This causes the function result to be a set as well.
*/
bool hasSetArg; /* some argument returns a set */
} FunctionCache; } FunctionCache;
typedef FunctionCache *FunctionCachePtr;
extern FunctionCachePtr init_fcache(Oid foid, int nargs,
MemoryContext fcacheCxt);
#endif /* FCACHE_H */ #endif /* FCACHE_H */
/*-------------------------------------------------------------------------
*
* fcache2.h
*
*
*
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: fcache2.h,v 1.10 2000/01/26 05:58:38 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef FCACHE2_H
#define FCACHE2_H
#include "nodes/execnodes.h"
extern void setFcache(Node *node, Oid foid, List *argList, ExprContext *econtext);
#endif /* FCACHE2_H */
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: sets.h,v 1.7 2000/06/09 01:11:15 tgl Exp $ * $Id: sets.h,v 1.8 2000/08/24 03:29:14 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -17,10 +17,11 @@ ...@@ -17,10 +17,11 @@
#include "fmgr.h" #include "fmgr.h"
/* Temporary name of set, before SetDefine changes it. */ /* Temporary name of a set function, before SetDefine changes it. */
#define GENERICSETNAME "zyxset" #define GENERICSETNAME "ZYX#Set#ZYX"
extern Oid SetDefine(char *querystr, char *typename); extern Oid SetDefine(char *querystr, char *typename);
extern Datum seteval(PG_FUNCTION_ARGS); extern Datum seteval(PG_FUNCTION_ARGS);
#endif /* SETS_H */ #endif /* SETS_H */
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* procedural language * procedural language
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.27 2000/08/13 02:50:35 tgl Exp $ * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.28 2000/08/24 03:29:15 tgl Exp $
* *
* This software is copyrighted by Jan Wieck - Hamburg. * This software is copyrighted by Jan Wieck - Hamburg.
* *
...@@ -2200,7 +2200,6 @@ exec_eval_simple_expr(PLpgSQL_execstate * estate, ...@@ -2200,7 +2200,6 @@ exec_eval_simple_expr(PLpgSQL_execstate * estate,
int fno; int fno;
int i; int i;
bool isnull; bool isnull;
bool isdone;
ExprContext *econtext; ExprContext *econtext;
ParamListInfo paramLI; ParamListInfo paramLI;
...@@ -2274,9 +2273,7 @@ exec_eval_simple_expr(PLpgSQL_execstate * estate, ...@@ -2274,9 +2273,7 @@ exec_eval_simple_expr(PLpgSQL_execstate * estate,
* Initialize things * Initialize things
* ---------- * ----------
*/ */
*isNull = FALSE;
*rettype = expr->plan_simple_type; *rettype = expr->plan_simple_type;
isdone = FALSE;
/* ---------- /* ----------
* Clear the function cache * Clear the function cache
...@@ -2292,14 +2289,17 @@ exec_eval_simple_expr(PLpgSQL_execstate * estate, ...@@ -2292,14 +2289,17 @@ exec_eval_simple_expr(PLpgSQL_execstate * estate,
retval = ExecEvalExprSwitchContext(expr->plan_simple_expr, retval = ExecEvalExprSwitchContext(expr->plan_simple_expr,
econtext, econtext,
isNull, isNull,
&isdone); NULL);
SPI_pop(); SPI_pop();
/* /*
* Copy the result out of the expression-evaluation memory context, * Copy the result out of the expression-evaluation memory context,
* so that we can free the expression context. * so that we can free the expression context.
*/ */
retval = datumCopy(retval, get_typbyval(*rettype), get_typlen(*rettype)); if (! *isNull)
retval = datumCopy(retval,
get_typbyval(*rettype),
get_typlen(*rettype));
FreeExprContext(econtext); FreeExprContext(econtext);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment