aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/executor')
-rw-r--r--src/backend/executor/execFlatten.c13
-rw-r--r--src/backend/executor/execQual.c671
-rw-r--r--src/backend/executor/execScan.c60
-rw-r--r--src/backend/executor/functions.c238
-rw-r--r--src/backend/executor/nodeAgg.c8
-rw-r--r--src/backend/executor/nodeGroup.c8
-rw-r--r--src/backend/executor/nodeHash.c6
-rw-r--r--src/backend/executor/nodeHashjoin.c33
-rw-r--r--src/backend/executor/nodeIndexscan.c9
-rw-r--r--src/backend/executor/nodeMergejoin.c41
-rw-r--r--src/backend/executor/nodeNestloop.c35
-rw-r--r--src/backend/executor/nodeResult.c39
-rw-r--r--src/backend/executor/nodeSubplan.c11
-rw-r--r--src/backend/executor/nodeTidscan.c7
14 files changed, 650 insertions, 529 deletions
diff --git a/src/backend/executor/execFlatten.c b/src/backend/executor/execFlatten.c
index bb45e63a8a5..e94a43f3cf4 100644
--- a/src/backend/executor/execFlatten.c
+++ b/src/backend/executor/execFlatten.c
@@ -9,7 +9,7 @@
*
*
* 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,
#endif
+
Datum
ExecEvalIter(Iter *iterNode,
ExprContext *econtext,
- bool *resultIsNull,
- bool *iterIsDone)
+ bool *isNull,
+ ExprDoneCond *isDone)
{
Node *expression;
@@ -52,14 +53,14 @@ ExecEvalIter(Iter *iterNode,
* only worrying about postquel functions, c functions will come
* later.
*/
- return ExecEvalExpr(expression, econtext, resultIsNull, iterIsDone);
+ return ExecEvalExpr(expression, econtext, isNull, isDone);
}
void
ExecEvalFjoin(TargetEntry *tlist,
ExprContext *econtext,
bool *isNullVect,
- bool *fj_isDone)
+ ExprDoneCond *fj_isDone)
{
#ifdef SETS_FIXED
@@ -72,7 +73,7 @@ ExecEvalFjoin(TargetEntry *tlist,
BoolPtr alwaysDone = fjNode->fj_alwaysDone;
if (fj_isDone)
- *fj_isDone = false;
+ *fj_isDone = ExprMultipleResult;
/*
* For the next tuple produced by the plan, we need to re-initialize
diff --git a/src/backend/executor/execQual.c b/src/backend/executor/execQual.c
index 83117d836eb..3929c8782a9 100644
--- a/src/backend/executor/execQual.c
+++ b/src/backend/executor/execQual.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.78 2000/08/21 20:55:30 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.79 2000/08/24 03:29:03 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -35,34 +35,34 @@
#include "postgres.h"
#include "access/heapam.h"
-#include "catalog/pg_language.h"
#include "executor/execFlatten.h"
#include "executor/execdebug.h"
#include "executor/functions.h"
#include "executor/nodeSubplan.h"
#include "utils/array.h"
#include "utils/builtins.h"
-#include "utils/fmgroids.h"
-#include "utils/fcache2.h"
+#include "utils/fcache.h"
/* static function decls */
-static Datum ExecEvalAggref(Aggref *aggref, ExprContext *econtext, bool *isNull);
+static Datum ExecEvalAggref(Aggref *aggref, ExprContext *econtext,
+ bool *isNull);
static Datum ExecEvalArrayRef(ArrayRef *arrayRef, ExprContext *econtext,
- bool *isNull, bool *isDone);
+ bool *isNull, ExprDoneCond *isDone);
+static Datum ExecEvalVar(Var *variable, ExprContext *econtext, bool *isNull);
static Datum ExecEvalOper(Expr *opClause, ExprContext *econtext,
- bool *isNull);
+ bool *isNull, ExprDoneCond *isDone);
static Datum ExecEvalFunc(Expr *funcClause, ExprContext *econtext,
- bool *isNull, bool *isDone);
-static void ExecEvalFuncArgs(FunctionCachePtr fcache, ExprContext *econtext,
- List *argList, FunctionCallInfo fcinfo,
- bool *argIsDone);
+ bool *isNull, ExprDoneCond *isDone);
+static ExprDoneCond ExecEvalFuncArgs(FunctionCachePtr fcache,
+ List *argList,
+ ExprContext *econtext);
static Datum ExecEvalNot(Expr *notclause, ExprContext *econtext, bool *isNull);
static Datum ExecEvalAnd(Expr *andExpr, ExprContext *econtext, bool *isNull);
static Datum ExecEvalOr(Expr *orExpr, ExprContext *econtext, bool *isNull);
-static Datum ExecEvalVar(Var *variable, ExprContext *econtext, bool *isNull);
-static Datum ExecMakeFunctionResult(Node *node, List *arguments,
- ExprContext *econtext, bool *isNull, bool *isDone);
+static Datum ExecEvalCase(CaseExpr *caseExpr, ExprContext *econtext,
+ bool *isNull, ExprDoneCond *isDone);
+
/*----------
* ExecEvalArrayRef
@@ -93,7 +93,7 @@ static Datum
ExecEvalArrayRef(ArrayRef *arrayRef,
ExprContext *econtext,
bool *isNull,
- bool *isDone)
+ ExprDoneCond *isDone)
{
ArrayType *array_source;
ArrayType *resultArray;
@@ -104,9 +104,6 @@ ExecEvalArrayRef(ArrayRef *arrayRef,
IntArray upper,
lower;
int *lIndex;
- bool dummy;
-
- *isNull = false;
if (arrayRef->refexpr != NULL)
{
@@ -146,7 +143,7 @@ ExecEvalArrayRef(ArrayRef *arrayRef,
upper.indx[i++] = DatumGetInt32(ExecEvalExpr((Node *) lfirst(elt),
econtext,
isNull,
- &dummy));
+ NULL));
/* If any index expr yields NULL, result is NULL or source array */
if (*isNull)
{
@@ -168,7 +165,7 @@ ExecEvalArrayRef(ArrayRef *arrayRef,
lower.indx[j++] = DatumGetInt32(ExecEvalExpr((Node *) lfirst(elt),
econtext,
isNull,
- &dummy));
+ NULL));
/* If any index expr yields NULL, result is NULL or source array */
if (*isNull)
{
@@ -191,7 +188,7 @@ ExecEvalArrayRef(ArrayRef *arrayRef,
Datum sourceData = ExecEvalExpr(arrayRef->refassgnexpr,
econtext,
isNull,
- &dummy);
+ NULL);
/*
* For now, can't cope with inserting NULL into an array,
* so make it a no-op per discussion above...
@@ -588,162 +585,109 @@ GetAttributeByName(TupleTableSlot *slot, char *attname, bool *isNull)
return (char *) retval;
}
-
-static void
+/*
+ * Evaluate arguments for a function.
+ */
+static ExprDoneCond
ExecEvalFuncArgs(FunctionCachePtr fcache,
- ExprContext *econtext,
List *argList,
- FunctionCallInfo fcinfo,
- bool *argIsDone)
+ ExprContext *econtext)
{
+ ExprDoneCond argIsDone;
int i;
List *arg;
+ argIsDone = ExprSingleResult; /* default assumption */
+
i = 0;
foreach(arg, argList)
{
+ ExprDoneCond thisArgIsDone;
- /*
- * evaluate the expression, in general functions cannot take sets
- * as arguments but we make an exception in the case of nested dot
- * expressions. We have to watch out for this case here.
- */
- fcinfo->arg[i] = ExecEvalExpr((Node *) lfirst(arg),
- econtext,
- &fcinfo->argnull[i],
- argIsDone);
+ fcache->fcinfo.arg[i] = ExecEvalExpr((Node *) lfirst(arg),
+ econtext,
+ &fcache->fcinfo.argnull[i],
+ &thisArgIsDone);
- if (!(*argIsDone))
+ if (thisArgIsDone != ExprSingleResult)
{
- if (i != 0)
- elog(ERROR, "functions can only take sets in their first argument");
- fcache->setArg = fcinfo->arg[0];
+ /*
+ * We allow only one argument to have a set value; we'd need
+ * much more complexity to keep track of multiple set arguments
+ * (cf. ExecTargetList) and it doesn't seem worth it.
+ */
+ if (argIsDone != ExprSingleResult)
+ elog(ERROR, "Functions and operators can take only one set argument");
fcache->hasSetArg = true;
+ argIsDone = thisArgIsDone;
}
i++;
}
+
+ return argIsDone;
}
/*
* ExecMakeFunctionResult
+ *
+ * Evaluate the arguments to a function and then the function itself.
+ *
+ * NOTE: econtext is used only for evaluating the argument expressions;
+ * it is not passed to the function itself.
*/
-static Datum
-ExecMakeFunctionResult(Node *node,
+Datum
+ExecMakeFunctionResult(FunctionCachePtr fcache,
List *arguments,
ExprContext *econtext,
bool *isNull,
- bool *isDone)
+ ExprDoneCond *isDone)
{
- FunctionCallInfoData fcinfo;
- FunctionCachePtr fcache;
- bool funcisset;
- Datum result;
- bool argDone;
-
- MemSet(&fcinfo, 0, sizeof(fcinfo));
-
- /*
- * This is kind of ugly, Func nodes now have targetlists so that we
- * know when and what to project out from postquel function results.
- * ExecMakeFunctionResult becomes a little bit more of a dual personality
- * as a result.
- */
- if (IsA(node, Func))
- {
- fcache = ((Func *) node)->func_fcache;
- funcisset = (((Func *) node)->funcid == F_SETEVAL);
- }
- else
- {
- fcache = ((Oper *) node)->op_fcache;
- funcisset = false;
- }
-
- fcinfo.flinfo = &fcache->func;
- fcinfo.nargs = fcache->nargs;
+ Datum result;
+ ExprDoneCond argDone;
+ int i;
/*
* arguments is a list of expressions to evaluate before passing to
- * the function manager. We collect the results of evaluating the
- * expressions into the FunctionCallInfo struct. Note we assume that
- * fcache->nargs is the correct length of the arguments list!
+ * the function manager. We skip the evaluation if it was already
+ * done in the previous call (ie, we are continuing the evaluation
+ * of a set-valued function). Otherwise, collect the current argument
+ * values into fcache->fcinfo.
*/
- if (fcache->nargs > 0)
+ if (fcache->fcinfo.nargs > 0 && !fcache->argsValid)
{
- if (fcache->nargs > FUNC_MAX_ARGS)
- elog(ERROR, "ExecMakeFunctionResult: too many arguments");
-
- /*
- * If the setArg in the fcache is set we have an argument
- * returning a set of tuples (i.e. a nested dot expression). We
- * don't want to evaluate the arguments again until the function
- * is done. hasSetArg will always be false until we eval the args
- * for the first time.
- */
- if (fcache->hasSetArg && fcache->setArg != (Datum) 0)
- {
- fcinfo.arg[0] = fcache->setArg;
- argDone = false;
- }
- else
- ExecEvalFuncArgs(fcache, econtext, arguments, &fcinfo, &argDone);
-
- if (fcache->hasSetArg && argDone)
+ argDone = ExecEvalFuncArgs(fcache, arguments, econtext);
+ if (argDone == ExprEndResult)
{
- /* can only get here if input is an empty set. */
+ /* input is an empty set, so return an empty set. */
*isNull = true;
- *isDone = true;
+ if (isDone)
+ *isDone = ExprEndResult;
+ else
+ elog(ERROR, "Set-valued function called in context that cannot accept a set");
return (Datum) 0;
}
}
/*
- * If this function is really a set, we have to diddle with things. If
- * the function has already been called at least once, then the setArg
- * field of the fcache holds the OID of this set in pg_proc. (This is
- * not quite legit, since the setArg field is really for functions
- * which take sets of tuples as input - set functions take no inputs
- * at all. But it's a nice place to stash this value, for now.)
- *
- * If this is the first call of the set's function, then the call to
- * ExecEvalFuncArgs above just returned the OID of the pg_proc tuple
- * which defines this set. So replace the existing funcid in the
- * funcnode with the set's OID. Also, we want a new fcache which
- * points to the right function, so get that, now that we have the
- * right OID. Also zero out fcinfo.arg, since the real set doesn't take
- * any arguments.
- */
- if (funcisset)
- {
- if (fcache->setArg)
- {
- ((Func *) node)->funcid = DatumGetObjectId(fcache->setArg);
- }
- else
- {
- ((Func *) node)->funcid = DatumGetObjectId(fcinfo.arg[0]);
- setFcache(node, DatumGetObjectId(fcinfo.arg[0]), NIL, econtext);
- fcache = ((Func *) node)->func_fcache;
- fcache->setArg = fcinfo.arg[0];
- }
- fcinfo.arg[0] = (Datum) 0;
- }
-
- /*
* now return the value gotten by calling the function manager,
* passing the function the evaluated parameter values.
*/
- if (fcache->language == SQLlanguageId)
+ if (fcache->func.fn_retset || fcache->hasSetArg)
{
- /*--------------------
- * This loop handles the situation where we are iterating through
- * all results in a nested dot function (whose argument function
- * returns a set of tuples) and the current function finally
- * finishes. We need to get the next argument in the set and start
- * the function all over again. We might have to do it more than
- * once, if the function produces no results for a particular argument.
- * This is getting unclean.
- *--------------------
+ /*
+ * We need to return a set result. Complain if caller not ready
+ * to accept one.
+ */
+ if (isDone == NULL)
+ elog(ERROR, "Set-valued function called in context that cannot accept a set");
+
+ /*
+ * This loop handles the situation where we have both a set argument
+ * and a set-valued function. Once we have exhausted the function's
+ * value(s) for a particular argument value, we have to get the next
+ * argument value and start the function over again. We might have
+ * to do it more than once, if the function produces an empty result
+ * set for a particular input value.
*/
for (;;)
{
@@ -753,13 +697,11 @@ ExecMakeFunctionResult(Node *node,
*/
bool callit = true;
- if (fcinfo.flinfo->fn_strict)
+ if (fcache->func.fn_strict)
{
- int i;
-
- for (i = 0; i < fcinfo.nargs; i++)
+ for (i = 0; i < fcache->fcinfo.nargs; i++)
{
- if (fcinfo.argnull[i])
+ if (fcache->fcinfo.argnull[i])
{
callit = false;
break;
@@ -769,35 +711,55 @@ ExecMakeFunctionResult(Node *node,
if (callit)
{
- result = postquel_function(&fcinfo, fcache, isDone);
- *isNull = fcinfo.isnull;
+ fcache->fcinfo.isnull = false;
+ fcache->rsinfo.isDone = ExprSingleResult;
+ result = FunctionCallInvoke(&fcache->fcinfo);
+ *isNull = fcache->fcinfo.isnull;
+ *isDone = fcache->rsinfo.isDone;
}
else
{
result = (Datum) 0;
*isNull = true;
- *isDone = true;
+ *isDone = ExprEndResult;
+ }
+
+ if (*isDone != ExprEndResult)
+ {
+ /*
+ * Got a result from current argument. If function itself
+ * returns set, flag that we want to reuse current argument
+ * values on next call.
+ */
+ if (fcache->func.fn_retset)
+ fcache->argsValid = true;
+ /*
+ * Make sure we say we are returning a set, even if the
+ * function itself doesn't return sets.
+ */
+ *isDone = ExprMultipleResult;
+ break;
}
- if (!*isDone)
- break; /* got a result from current argument */
+ /* Else, done with this argument */
+ fcache->argsValid = false;
+
if (!fcache->hasSetArg)
break; /* input not a set, so done */
- /* OK, get the next argument... */
- ExecEvalFuncArgs(fcache, econtext, arguments, &fcinfo, &argDone);
+ /* Re-eval args to get the next element of the input set */
+ argDone = ExecEvalFuncArgs(fcache, arguments, econtext);
- if (argDone)
+ if (argDone != ExprMultipleResult)
{
/*
- * End of arguments, so reset the setArg flag and say
+ * End of arguments, so reset the hasSetArg flag and say
* "Done"
*/
- fcache->setArg = (Datum) 0;
fcache->hasSetArg = false;
- *isDone = true;
*isNull = true;
+ *isDone = ExprEndResult;
result = (Datum) 0;
break;
}
@@ -807,50 +769,29 @@ ExecMakeFunctionResult(Node *node,
* new argument.
*/
}
-
- if (funcisset)
- {
-
- /*
- * reset the funcid so that next call to this routine will
- * still recognize this func as a set. Note that for now we
- * assume that the set function in pg_proc must be a Postquel
- * function - the funcid is not reset below for C functions.
- */
- ((Func *) node)->funcid = F_SETEVAL;
-
- /*
- * If we're done with the results of this function, get rid of
- * its func cache.
- */
- if (*isDone)
- ((Func *) node)->func_fcache = NULL;
- }
}
else
{
- /* A non-SQL function cannot return a set, at present. */
- *isDone = true;
-
/*
+ * Non-set case: much easier.
+ *
* If function is strict, and there are any NULL arguments,
* skip calling the function and return NULL.
*/
- if (fcinfo.flinfo->fn_strict)
+ if (fcache->func.fn_strict)
{
- int i;
-
- for (i = 0; i < fcinfo.nargs; i++)
+ for (i = 0; i < fcache->fcinfo.nargs; i++)
{
- if (fcinfo.argnull[i])
+ if (fcache->fcinfo.argnull[i])
{
*isNull = true;
return (Datum) 0;
}
}
}
- result = FunctionCallInvoke(&fcinfo);
- *isNull = fcinfo.isnull;
+ fcache->fcinfo.isnull = false;
+ result = FunctionCallInvoke(&fcache->fcinfo);
+ *isNull = fcache->fcinfo.isnull;
}
return result;
@@ -871,12 +812,14 @@ ExecMakeFunctionResult(Node *node,
* ----------------------------------------------------------------
*/
static Datum
-ExecEvalOper(Expr *opClause, ExprContext *econtext, bool *isNull)
+ExecEvalOper(Expr *opClause,
+ ExprContext *econtext,
+ bool *isNull,
+ ExprDoneCond *isDone)
{
Oper *op;
List *argList;
FunctionCachePtr fcache;
- bool isDone;
/*
* we extract the oid of the function associated with the op and then
@@ -894,16 +837,13 @@ ExecEvalOper(Expr *opClause, ExprContext *econtext, bool *isNull)
fcache = op->op_fcache;
if (fcache == NULL)
{
- setFcache((Node *) op, op->opid, argList, econtext);
- fcache = op->op_fcache;
+ fcache = init_fcache(op->opid, length(argList),
+ econtext->ecxt_per_query_memory);
+ op->op_fcache = fcache;
}
- /*
- * call ExecMakeFunctionResult() with a dummy isDone that we ignore.
- * We don't have operator whose arguments are sets.
- */
- return ExecMakeFunctionResult((Node *) op, argList, econtext,
- isNull, &isDone);
+ return ExecMakeFunctionResult(fcache, argList, econtext,
+ isNull, isDone);
}
/* ----------------------------------------------------------------
@@ -915,7 +855,7 @@ static Datum
ExecEvalFunc(Expr *funcClause,
ExprContext *econtext,
bool *isNull,
- bool *isDone)
+ ExprDoneCond *isDone)
{
Func *func;
List *argList;
@@ -939,11 +879,12 @@ ExecEvalFunc(Expr *funcClause,
fcache = func->func_fcache;
if (fcache == NULL)
{
- setFcache((Node *) func, func->funcid, argList, econtext);
- fcache = func->func_fcache;
+ fcache = init_fcache(func->funcid, length(argList),
+ econtext->ecxt_per_query_memory);
+ func->func_fcache = fcache;
}
- return ExecMakeFunctionResult((Node *) func, argList, econtext,
+ return ExecMakeFunctionResult(fcache, argList, econtext,
isNull, isDone);
}
@@ -968,15 +909,10 @@ ExecEvalNot(Expr *notclause, ExprContext *econtext, bool *isNull)
{
Node *clause;
Datum expr_value;
- bool isDone;
clause = lfirst(notclause->args);
- /*
- * We don't iterate over sets in the quals, so pass in an isDone flag,
- * but ignore it.
- */
- expr_value = ExecEvalExpr(clause, econtext, isNull, &isDone);
+ expr_value = ExecEvalExpr(clause, econtext, isNull, NULL);
/*
* if the expression evaluates to null, then we just cascade the null
@@ -1001,7 +937,6 @@ ExecEvalOr(Expr *orExpr, ExprContext *econtext, bool *isNull)
{
List *clauses;
List *clause;
- bool isDone;
bool AnyNull;
Datum clause_value;
@@ -1024,15 +959,8 @@ ExecEvalOr(Expr *orExpr, ExprContext *econtext, bool *isNull)
*/
foreach(clause, clauses)
{
-
- /*
- * We don't iterate over sets in the quals, so pass in an isDone
- * flag, but ignore it.
- */
clause_value = ExecEvalExpr((Node *) lfirst(clause),
- econtext,
- isNull,
- &isDone);
+ econtext, isNull, NULL);
/*
* if we have a non-null true result, then return it.
@@ -1057,7 +985,6 @@ ExecEvalAnd(Expr *andExpr, ExprContext *econtext, bool *isNull)
{
List *clauses;
List *clause;
- bool isDone;
bool AnyNull;
Datum clause_value;
@@ -1074,15 +1001,8 @@ ExecEvalAnd(Expr *andExpr, ExprContext *econtext, bool *isNull)
*/
foreach(clause, clauses)
{
-
- /*
- * We don't iterate over sets in the quals, so pass in an isDone
- * flag, but ignore it.
- */
clause_value = ExecEvalExpr((Node *) lfirst(clause),
- econtext,
- isNull,
- &isDone);
+ econtext, isNull, NULL);
/*
* if we have a non-null false result, then return it.
@@ -1108,12 +1028,12 @@ ExecEvalAnd(Expr *andExpr, ExprContext *econtext, bool *isNull)
* ----------------------------------------------------------------
*/
static Datum
-ExecEvalCase(CaseExpr *caseExpr, ExprContext *econtext, bool *isNull)
+ExecEvalCase(CaseExpr *caseExpr, ExprContext *econtext,
+ bool *isNull, ExprDoneCond *isDone)
{
List *clauses;
List *clause;
Datum clause_value;
- bool isDone;
clauses = caseExpr->args;
@@ -1126,14 +1046,10 @@ ExecEvalCase(CaseExpr *caseExpr, ExprContext *econtext, bool *isNull)
{
CaseWhen *wclause = lfirst(clause);
- /*
- * We don't iterate over sets in the quals, so pass in an isDone
- * flag, but ignore it.
- */
clause_value = ExecEvalExpr(wclause->expr,
econtext,
isNull,
- &isDone);
+ NULL);
/*
* if we have a true test, then we return the result, since the
@@ -1145,7 +1061,7 @@ ExecEvalCase(CaseExpr *caseExpr, ExprContext *econtext, bool *isNull)
return ExecEvalExpr(wclause->result,
econtext,
isNull,
- &isDone);
+ isDone);
}
}
@@ -1154,7 +1070,7 @@ ExecEvalCase(CaseExpr *caseExpr, ExprContext *econtext, bool *isNull)
return ExecEvalExpr(caseExpr->defresult,
econtext,
isNull,
- &isDone);
+ isDone);
}
*isNull = true;
@@ -1171,7 +1087,7 @@ static Datum
ExecEvalFieldSelect(FieldSelect *fselect,
ExprContext *econtext,
bool *isNull,
- bool *isDone)
+ ExprDoneCond *isDone)
{
Datum result;
TupleTableSlot *resSlot;
@@ -1179,7 +1095,6 @@ ExecEvalFieldSelect(FieldSelect *fselect,
result = ExecEvalExpr(fselect->arg, econtext, isNull, isDone);
if (*isNull)
return result;
- /* XXX what about isDone? */
resSlot = (TupleTableSlot *) DatumGetPointer(result);
Assert(resSlot != NULL && IsA(resSlot, TupleTableSlot));
result = heap_getattr(resSlot->val,
@@ -1194,28 +1109,52 @@ ExecEvalFieldSelect(FieldSelect *fselect,
*
* Recursively evaluate a targetlist or qualification expression.
*
- * The caller should already have switched into the temporary
- * memory context econtext->ecxt_per_tuple_memory. The convenience
- * entry point ExecEvalExprSwitchContext() is provided for callers
- * who don't prefer to do the switch in an outer loop. We do not
- * do the switch here because it'd be a waste of cycles during
- * recursive entries to ExecEvalExpr().
+ * Inputs:
+ * expression: the expression tree to evaluate
+ * econtext: evaluation context information
+ *
+ * Outputs:
+ * return value: Datum value of result
+ * *isNull: set to TRUE if result is NULL (actual return value is
+ * meaningless if so); set to FALSE if non-null result
+ * *isDone: set to indicator of set-result status
+ *
+ * A caller that can only accept a singleton (non-set) result should pass
+ * NULL for isDone; if the expression computes a set result then an elog()
+ * error will be reported. If the caller does pass an isDone pointer then
+ * *isDone is set to one of these three states:
+ * ExprSingleResult singleton result (not a set)
+ * ExprMultipleResult return value is one element of a set
+ * ExprEndResult there are no more elements in the set
+ * When ExprMultipleResult is returned, the caller should invoke
+ * ExecEvalExpr() repeatedly until ExprEndResult is returned. ExprEndResult
+ * is returned after the last real set element. For convenience isNull will
+ * always be set TRUE when ExprEndResult is returned, but this should not be
+ * taken as indicating a NULL element of the set. Note that these return
+ * conventions allow us to distinguish among a singleton NULL, a NULL element
+ * of a set, and an empty set.
*
- * This routine is an inner loop routine and must be as fast
- * as possible.
+ * The caller should already have switched into the temporary memory
+ * context econtext->ecxt_per_tuple_memory. The convenience entry point
+ * ExecEvalExprSwitchContext() is provided for callers who don't prefer to
+ * do the switch in an outer loop. We do not do the switch here because
+ * it'd be a waste of cycles during recursive entries to ExecEvalExpr().
+ *
+ * This routine is an inner loop routine and must be as fast as possible.
* ----------------------------------------------------------------
*/
Datum
ExecEvalExpr(Node *expression,
ExprContext *econtext,
bool *isNull,
- bool *isDone)
+ ExprDoneCond *isDone)
{
Datum retDatum;
/* Set default values for result flags: non-null, not a set result */
*isNull = false;
- *isDone = true;
+ if (isDone)
+ *isDone = ExprSingleResult;
/* Is this still necessary? Doubtful... */
if (expression == NULL)
@@ -1266,7 +1205,8 @@ ExecEvalExpr(Node *expression,
switch (expr->opType)
{
case OP_EXPR:
- retDatum = ExecEvalOper(expr, econtext, isNull);
+ retDatum = ExecEvalOper(expr, econtext,
+ isNull, isDone);
break;
case FUNC_EXPR:
retDatum = ExecEvalFunc(expr, econtext,
@@ -1307,7 +1247,10 @@ ExecEvalExpr(Node *expression,
isDone);
break;
case T_CaseExpr:
- retDatum = ExecEvalCase((CaseExpr *) expression, econtext, isNull);
+ retDatum = ExecEvalCase((CaseExpr *) expression,
+ econtext,
+ isNull,
+ isDone);
break;
default:
@@ -1328,7 +1271,7 @@ Datum
ExecEvalExprSwitchContext(Node *expression,
ExprContext *econtext,
bool *isNull,
- bool *isDone)
+ ExprDoneCond *isDone)
{
Datum retDatum;
MemoryContext oldContext;
@@ -1413,13 +1356,8 @@ ExecQual(List *qual, ExprContext *econtext, bool resultForNull)
Node *clause = (Node *) lfirst(qlist);
Datum expr_value;
bool isNull;
- bool isDone;
- /*
- * pass isDone, but ignore it. We don't iterate over multiple
- * returns in the qualifications.
- */
- expr_value = ExecEvalExpr(clause, econtext, &isNull, &isDone);
+ expr_value = ExecEvalExpr(clause, econtext, &isNull, NULL);
if (isNull)
{
@@ -1496,6 +1434,11 @@ ExecCleanTargetListLength(List *targetlist)
*
* Evaluates a targetlist with respect to the current
* expression context and return a tuple.
+ *
+ * As with ExecEvalExpr, the caller should pass isDone = NULL if not
+ * prepared to deal with sets of result tuples. Otherwise, a return
+ * of *isDone = ExprMultipleResult signifies a set element, and a return
+ * of *isDone = ExprEndResult signifies end of the set of tuple.
* ----------------------------------------------------------------
*/
static HeapTuple
@@ -1504,24 +1447,22 @@ ExecTargetList(List *targetlist,
TupleDesc targettype,
Datum *values,
ExprContext *econtext,
- bool *isDone)
+ ExprDoneCond *isDone)
{
MemoryContext oldContext;
- char nulls_array[64];
- bool fjNullArray[64];
- bool itemIsDoneArray[64];
- char *null_head;
+#define NPREALLOCDOMAINS 64
+ char nullsArray[NPREALLOCDOMAINS];
+ bool fjIsNullArray[NPREALLOCDOMAINS];
+ ExprDoneCond itemIsDoneArray[NPREALLOCDOMAINS];
+ char *nulls;
bool *fjIsNull;
- bool *itemIsDone;
+ ExprDoneCond *itemIsDone;
List *tl;
TargetEntry *tle;
- Node *expr;
- Resdom *resdom;
AttrNumber resind;
- Datum constvalue;
HeapTuple newTuple;
bool isNull;
- bool haveDoneIters;
+ bool haveDoneSets;
static struct tupleDesc NullTupleDesc; /* we assume this inits to
* zeroes */
@@ -1553,70 +1494,67 @@ ExecTargetList(List *targetlist,
* we have a really large targetlist. otherwise we use the stack.
*
* We also allocate a bool array that is used to hold fjoin result state,
- * and another that holds the isDone status for each targetlist item.
+ * and another array that holds the isDone status for each targetlist item.
+ * The isDone status is needed so that we can iterate, generating multiple
+ * tuples, when one or more tlist items return sets. (We expect the caller
+ * to call us again if we return *isDone = ExprMultipleResult.)
*/
- if (nodomains > 64)
+ if (nodomains > NPREALLOCDOMAINS)
{
- null_head = (char *) palloc(nodomains + 1);
- fjIsNull = (bool *) palloc(nodomains + 1);
- itemIsDone = (bool *) palloc(nodomains + 1);
+ nulls = (char *) palloc(nodomains * sizeof(char));
+ fjIsNull = (bool *) palloc(nodomains * sizeof(bool));
+ itemIsDone = (ExprDoneCond *) palloc(nodomains * sizeof(ExprDoneCond));
}
else
{
- null_head = &nulls_array[0];
- fjIsNull = &fjNullArray[0];
- itemIsDone = &itemIsDoneArray[0];
+ nulls = nullsArray;
+ fjIsNull = fjIsNullArray;
+ itemIsDone = itemIsDoneArray;
}
/*
* evaluate all the expressions in the target list
*/
- *isDone = true; /* until proven otherwise */
- haveDoneIters = false; /* any isDone Iter exprs in tlist? */
+ if (isDone)
+ *isDone = ExprSingleResult; /* until proven otherwise */
+
+ haveDoneSets = false; /* any exhausted set exprs in tlist? */
foreach(tl, targetlist)
{
-
- /*
- * remember, a target list is a list of lists:
- *
- * ((<resdom | fjoin> expr) (<resdom | fjoin> expr) ...)
- *
- * tl is a pointer to successive cdr's of the targetlist tle is a
- * pointer to the target list entry in tl
- */
tle = lfirst(tl);
if (tle->resdom != NULL)
{
- expr = tle->expr;
- resdom = tle->resdom;
- resind = resdom->resno - 1;
-
- constvalue = ExecEvalExpr(expr,
- econtext,
- &isNull,
- &itemIsDone[resind]);
+ resind = tle->resdom->resno - 1;
- values[resind] = constvalue;
+ values[resind] = ExecEvalExpr(tle->expr,
+ econtext,
+ &isNull,
+ &itemIsDone[resind]);
+ nulls[resind] = isNull ? 'n' : ' ';
- if (!isNull)
- null_head[resind] = ' ';
- else
- null_head[resind] = 'n';
-
- if (IsA(expr, Iter))
+ if (itemIsDone[resind] != ExprSingleResult)
{
- if (itemIsDone[resind])
- haveDoneIters = true;
+ /* We have a set-valued expression in the tlist */
+ if (isDone == NULL)
+ elog(ERROR, "Set-valued function called in context that cannot accept a set");
+ if (itemIsDone[resind] == ExprMultipleResult)
+ {
+ /* we have undone sets in the tlist, set flag */
+ *isDone = ExprMultipleResult;
+ }
else
- *isDone = false; /* we have undone Iters in the
- * list */
+ {
+ /* we have done sets in the tlist, set flag for that */
+ haveDoneSets = true;
+ }
}
}
else
{
+#ifdef SETS_FIXED
int curNode;
Resdom *fjRes;
List *fjTlist = (List *) tle->expr;
@@ -1626,9 +1564,12 @@ ExecTargetList(List *targetlist,
ExecEvalFjoin(tle, econtext, fjIsNull, isDone);
- /* this is probably wrong: */
- if (*isDone)
+ /* XXX this is wrong, but since fjoin code is completely broken
+ * anyway, I'm not going to worry about it now --- tgl 8/23/00
+ */
+ if (isDone && *isDone == ExprEndResult)
{
+ MemoryContextSwitchTo(oldContext);
newTuple = NULL;
goto exit;
}
@@ -1638,13 +1579,8 @@ ExecTargetList(List *targetlist,
*/
fjRes = (Resdom *) fjNode->fj_innerNode;
resind = fjRes->resno - 1;
- if (fjIsNull[0])
- null_head[resind] = 'n';
- else
- {
- null_head[resind] = ' ';
- values[resind] = results[0];
- }
+ values[resind] = results[0];
+ nulls[resind] = fjIsNull[0] ? 'n' : ' ';
/*
* Get results from all of the outer nodes
@@ -1653,32 +1589,32 @@ ExecTargetList(List *targetlist,
curNode < nNodes;
curNode++, fjTlist = lnext(fjTlist))
{
-#ifdef NOT_USED /* what is this?? */
Node *outernode = lfirst(fjTlist);
fjRes = (Resdom *) outernode->iterexpr;
-#endif
resind = fjRes->resno - 1;
- if (fjIsNull[curNode])
- null_head[resind] = 'n';
- else
- {
- null_head[resind] = ' ';
- values[resind] = results[curNode];
- }
+ values[resind] = results[curNode];
+ nulls[resind] = fjIsNull[curNode] ? 'n' : ' ';
}
+#else
+ elog(ERROR, "ExecTargetList: fjoin nodes not currently supported");
+#endif
}
}
- if (haveDoneIters)
+ if (haveDoneSets)
{
- if (*isDone)
+ /*
+ * note: can't get here unless we verified isDone != NULL
+ */
+ if (*isDone == ExprSingleResult)
{
/*
- * all Iters are done, so return a null indicating tlist set
- * expansion is complete.
+ * all sets are done, so report that tlist expansion is complete.
*/
+ *isDone = ExprEndResult;
+ MemoryContextSwitchTo(oldContext);
newTuple = NULL;
goto exit;
}
@@ -1686,22 +1622,8 @@ ExecTargetList(List *targetlist,
{
/*
- * We have some done and some undone Iters. Restart the done
+ * We have some done and some undone sets. Restart the done
* ones so that we can deliver a tuple (if possible).
- *
- * XXX this code is a crock, because it only works for Iters at
- * the top level of tlist expressions, and doesn't even work
- * right for them: you should get all possible combinations of
- * Iter results, but you won't unless the numbers of values
- * returned by each are relatively prime. Should have a
- * mechanism more like aggregate functions, where we make a
- * list of all Iters contained in the tlist and cycle through
- * their values in a methodical fashion. To do someday; can't
- * get excited about fixing a Berkeley feature that's not in
- * SQL92. (The only reason we're doing this much is that we
- * have to be sure all the Iters are run to completion, or
- * their subplan executors will have unreleased resources,
- * e.g. pinned buffers...)
*/
foreach(tl, targetlist)
{
@@ -1709,36 +1631,57 @@ ExecTargetList(List *targetlist,
if (tle->resdom != NULL)
{
- expr = tle->expr;
- resdom = tle->resdom;
- resind = resdom->resno - 1;
+ resind = tle->resdom->resno - 1;
- if (IsA(expr, Iter) &&itemIsDone[resind])
+ if (itemIsDone[resind] == ExprEndResult)
{
- constvalue = ExecEvalExpr(expr,
- econtext,
- &isNull,
- &itemIsDone[resind]);
- if (itemIsDone[resind])
+ values[resind] = ExecEvalExpr(tle->expr,
+ econtext,
+ &isNull,
+ &itemIsDone[resind]);
+ nulls[resind] = isNull ? 'n' : ' ';
+
+ if (itemIsDone[resind] == ExprEndResult)
{
/*
- * Oh dear, this Iter is returning an empty
+ * Oh dear, this item is returning an empty
* set. Guess we can't make a tuple after all.
*/
- *isDone = true;
- newTuple = NULL;
- goto exit;
+ *isDone = ExprEndResult;
+ break;
}
+ }
+ }
+ }
+ /*
+ * If we cannot make a tuple because some sets are empty,
+ * we still have to cycle the nonempty sets to completion,
+ * else resources will not be released from subplans etc.
+ */
+ if (*isDone == ExprEndResult)
+ {
+ foreach(tl, targetlist)
+ {
+ tle = lfirst(tl);
- values[resind] = constvalue;
+ if (tle->resdom != NULL)
+ {
+ resind = tle->resdom->resno - 1;
- if (!isNull)
- null_head[resind] = ' ';
- else
- null_head[resind] = 'n';
+ while (itemIsDone[resind] == ExprMultipleResult)
+ {
+ (void) ExecEvalExpr(tle->expr,
+ econtext,
+ &isNull,
+ &itemIsDone[resind]);
+ }
}
}
+
+ MemoryContextSwitchTo(oldContext);
+ newTuple = NULL;
+ goto exit;
}
}
}
@@ -1748,30 +1691,27 @@ ExecTargetList(List *targetlist,
*/
MemoryContextSwitchTo(oldContext);
- newTuple = (HeapTuple) heap_formtuple(targettype, values, null_head);
+ newTuple = (HeapTuple) heap_formtuple(targettype, values, nulls);
exit:
/*
* free the status arrays if we palloc'd them
*/
- if (nodomains > 64)
+ if (nodomains > NPREALLOCDOMAINS)
{
- pfree(null_head);
+ pfree(nulls);
pfree(fjIsNull);
pfree(itemIsDone);
}
- /* make sure we are in the right context if we did "goto exit" */
- MemoryContextSwitchTo(oldContext);
-
return newTuple;
}
/* ----------------------------------------------------------------
* ExecProject
*
- * projects a tuple based in projection info and stores
+ * projects a tuple based on projection info and stores
* it in the specified tuple table slot.
*
* Note: someday soon the executor can be extended to eliminate
@@ -1782,7 +1722,7 @@ exit:
* ----------------------------------------------------------------
*/
TupleTableSlot *
-ExecProject(ProjectionInfo *projInfo, bool *isDone)
+ExecProject(ProjectionInfo *projInfo, ExprDoneCond *isDone)
{
TupleTableSlot *slot;
List *targetlist;
@@ -1810,7 +1750,7 @@ ExecProject(ProjectionInfo *projInfo, bool *isDone)
econtext = projInfo->pi_exprContext;
/*
- * form a new (result) tuple
+ * form a new result tuple (if possible --- result can be NULL)
*/
newTuple = ExecTargetList(targetlist,
len,
@@ -1822,9 +1762,8 @@ ExecProject(ProjectionInfo *projInfo, bool *isDone)
/*
* store the tuple in the projection slot and return the slot.
*/
- return (TupleTableSlot *)
- ExecStoreTuple(newTuple,/* tuple to store */
- slot, /* slot to store in */
- InvalidBuffer, /* tuple has no buffer */
- true);
+ return ExecStoreTuple(newTuple, /* tuple to store */
+ slot, /* slot to store in */
+ InvalidBuffer, /* tuple has no buffer */
+ true);
}
diff --git a/src/backend/executor/execScan.c b/src/backend/executor/execScan.c
index a3f66d20cad..d000a4cf50a 100644
--- a/src/backend/executor/execScan.c
+++ b/src/backend/executor/execScan.c
@@ -12,7 +12,7 @@
*
*
* 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,
{
CommonScanState *scanstate;
EState *estate;
+ ExprContext *econtext;
List *qual;
- bool isDone;
+ ExprDoneCond isDone;
TupleTableSlot *resultSlot;
- ExprContext *econtext;
- ProjectionInfo *projInfo;
/* ----------------
* Fetch data from node
@@ -66,13 +65,6 @@ ExecScan(Scan *node,
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
* scan tuple (because there is a function-returning-set in the
* projection expressions). If so, try to project another one.
@@ -80,14 +72,21 @@ ExecScan(Scan *node,
*/
if (scanstate->cstate.cs_TupFromTlist)
{
- projInfo = scanstate->cstate.cs_ProjInfo;
- resultSlot = ExecProject(projInfo, &isDone);
- if (!isDone)
+ resultSlot = ExecProject(scanstate->cstate.cs_ProjInfo, &isDone);
+ if (isDone == ExprMultipleResult)
return resultSlot;
/* Done with that source tuple... */
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
* which passes the qualification.
@@ -121,8 +120,6 @@ ExecScan(Scan *node,
/* ----------------
* 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
* ExecQual() when the qual is nil ... saves only a few cycles,
@@ -130,7 +127,22 @@ ExecScan(Scan *node,
* ----------------
*/
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.
@@ -138,18 +150,4 @@ ExecScan(Scan *node,
*/
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;
}
diff --git a/src/backend/executor/functions.c b/src/backend/executor/functions.c
index 001feb267ff..58fb68a6113 100644
--- a/src/backend/executor/functions.c
+++ b/src/backend/executor/functions.c
@@ -8,22 +8,29 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/executor/functions.c,v 1.37 2000/08/08 15:41:22 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/executor/functions.c,v 1.38 2000/08/24 03:29:03 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "access/heapam.h"
+#include "catalog/pg_proc.h"
+#include "catalog/pg_type.h"
#include "executor/execdefs.h"
#include "executor/executor.h"
#include "executor/functions.h"
#include "tcop/pquery.h"
#include "tcop/tcopprot.h"
#include "tcop/utility.h"
+#include "utils/builtins.h"
#include "utils/datum.h"
+#include "utils/syscache.h"
+/*
+ * We have an execution_state record for each query in the function.
+ */
typedef enum
{
F_EXEC_START, F_EXEC_RUN, F_EXEC_DONE
@@ -39,15 +46,40 @@ typedef struct local_es
#define LAST_POSTQUEL_COMMAND(es) ((es)->next == (execution_state *) NULL)
+
+/*
+ * An SQLFunctionCache record is built during the first call,
+ * and linked to from the fn_extra field of the FmgrInfo struct.
+ */
+
+typedef struct
+{
+ 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 */
+
+ TupleTableSlot *funcSlot; /* if one result we need to copy it before
+ * we end execution of the function and
+ * free stuff */
+
+ /* head of linked list of execution_state records */
+ execution_state *func_state;
+} SQLFunctionCache;
+
+typedef SQLFunctionCache *SQLFunctionCachePtr;
+
+
/* non-export function prototypes */
+static execution_state *init_execution_state(char *src,
+ Oid *argOidVect, int nargs);
+static void init_sql_fcache(FmgrInfo *finfo);
static TupleDesc postquel_start(execution_state *es);
-static execution_state *init_execution_state(FunctionCachePtr fcache);
static TupleTableSlot *postquel_getnext(execution_state *es);
static void postquel_end(execution_state *es);
static void postquel_sub_params(execution_state *es, FunctionCallInfo fcinfo);
static Datum postquel_execute(execution_state *es,
FunctionCallInfo fcinfo,
- FunctionCachePtr fcache);
+ SQLFunctionCachePtr fcache);
static Datum
@@ -69,21 +101,19 @@ ProjectAttribute(HeapTuple tup,
}
static execution_state *
-init_execution_state(FunctionCachePtr fcache)
+init_execution_state(char *src, Oid *argOidVect, int nargs)
{
execution_state *newes;
execution_state *nextes;
execution_state *preves;
List *queryTree_list,
*qtl_item;
- int nargs = fcache->nargs;
newes = (execution_state *) palloc(sizeof(execution_state));
nextes = newes;
preves = (execution_state *) NULL;
- queryTree_list = pg_parse_and_rewrite(fcache->src,
- fcache->argOidVect, nargs);
+ queryTree_list = pg_parse_and_rewrite(src, argOidVect, nargs);
foreach(qtl_item, queryTree_list)
{
@@ -138,6 +168,134 @@ init_execution_state(FunctionCachePtr fcache)
return newes;
}
+
+static void
+init_sql_fcache(FmgrInfo *finfo)
+{
+ Oid foid = finfo->fn_oid;
+ HeapTuple procedureTuple;
+ HeapTuple typeTuple;
+ Form_pg_proc procedureStruct;
+ Form_pg_type typeStruct;
+ SQLFunctionCachePtr fcache;
+ Oid *argOidVect;
+ char *src;
+ int nargs;
+ Datum tmp;
+ bool isNull;
+
+ /* ----------------
+ * get the procedure tuple corresponding to the given function Oid
+ *
+ * NB: use SearchSysCacheTupleCopy to ensure tuple lives long enough
+ * ----------------
+ */
+ procedureTuple = SearchSysCacheTupleCopy(PROCOID,
+ ObjectIdGetDatum(foid),
+ 0, 0, 0);
+
+ if (!HeapTupleIsValid(procedureTuple))
+ elog(ERROR, "init_sql_fcache: Cache lookup failed for procedure %u",
+ foid);
+
+ procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple);
+
+ /* ----------------
+ * get the return type from the procedure tuple
+ * ----------------
+ */
+ typeTuple = SearchSysCacheTuple(TYPEOID,
+ ObjectIdGetDatum(procedureStruct->prorettype),
+ 0, 0, 0);
+
+ if (!HeapTupleIsValid(typeTuple))
+ elog(ERROR, "init_sql_fcache: Cache lookup failed for type %u",
+ procedureStruct->prorettype);
+
+ typeStruct = (Form_pg_type) GETSTRUCT(typeTuple);
+
+ fcache = (SQLFunctionCachePtr) palloc(sizeof(SQLFunctionCache));
+ MemSet(fcache, 0, sizeof(SQLFunctionCache));
+
+ /* ----------------
+ * get the type length and by-value flag from the type tuple
+ * ----------------
+ */
+ fcache->typlen = typeStruct->typlen;
+ if (typeStruct->typrelid == InvalidOid)
+ {
+ /* The return type is not a relation, so just use byval */
+ fcache->typbyval = typeStruct->typbyval;
+ fcache->returnsTuple = false;
+ }
+ else
+ {
+
+ /*
+ * 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.
+ */
+ fcache->typbyval = false;
+ fcache->returnsTuple = true;
+ }
+
+ /*
+ * 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 (!finfo->fn_retset && !fcache->typbyval)
+ {
+ TupleTableSlot *slot;
+
+ slot = makeNode(TupleTableSlot);
+ slot->val = (HeapTuple) NULL;
+ slot->ttc_shouldFree = true;
+ slot->ttc_descIsNew = true;
+ slot->ttc_tupleDescriptor = (TupleDesc) NULL;
+ slot->ttc_buffer = InvalidBuffer;
+ slot->ttc_whichplan = -1;
+
+ fcache->funcSlot = slot;
+ }
+ else
+ fcache->funcSlot = NULL;
+
+ nargs = procedureStruct->pronargs;
+
+ if (nargs > 0)
+ {
+ argOidVect = (Oid *) palloc(nargs * sizeof(Oid));
+ memcpy(argOidVect,
+ procedureStruct->proargtypes,
+ nargs * sizeof(Oid));
+ }
+ else
+ {
+ argOidVect = (Oid *) NULL;
+ }
+
+ tmp = SysCacheGetAttr(PROCOID,
+ procedureTuple,
+ Anum_pg_proc_prosrc,
+ &isNull);
+ if (isNull)
+ elog(ERROR, "init_sql_fcache: null prosrc for procedure %u",
+ foid);
+ src = DatumGetCString(DirectFunctionCall1(textout, tmp));
+
+ fcache->func_state = init_execution_state(src, argOidVect, nargs);
+
+ pfree(src);
+
+ heap_freetuple(procedureTuple);
+
+ finfo->fn_extra = (void *) fcache;
+}
+
+
static TupleDesc
postquel_start(execution_state *es)
{
@@ -208,7 +366,7 @@ postquel_sub_params(execution_state *es, FunctionCallInfo fcinfo)
}
static TupleTableSlot *
-copy_function_result(FunctionCachePtr fcache,
+copy_function_result(SQLFunctionCachePtr fcache,
TupleTableSlot *resultSlot)
{
TupleTableSlot *funcSlot;
@@ -219,10 +377,10 @@ copy_function_result(FunctionCachePtr fcache,
Assert(!TupIsNull(resultSlot));
resultTuple = resultSlot->val;
- funcSlot = (TupleTableSlot *) fcache->funcSlot;
+ funcSlot = fcache->funcSlot;
- if (funcSlot == (TupleTableSlot *) NULL)
- return resultSlot;
+ if (funcSlot == NULL)
+ return resultSlot; /* no need to copy result */
/*
* If first time through, we have to initialize the funcSlot's
@@ -243,7 +401,7 @@ copy_function_result(FunctionCachePtr fcache,
static Datum
postquel_execute(execution_state *es,
FunctionCallInfo fcinfo,
- FunctionCachePtr fcache)
+ SQLFunctionCachePtr fcache)
{
TupleTableSlot *slot;
Datum value;
@@ -319,7 +477,7 @@ postquel_execute(execution_state *es,
* If this is a single valued function we have to end the function
* execution now.
*/
- if (!fcache->returnsSet)
+ if (!fcinfo->flinfo->fn_retset)
{
postquel_end(es);
es->status = F_EXEC_DONE;
@@ -338,11 +496,10 @@ postquel_execute(execution_state *es,
}
Datum
-postquel_function(FunctionCallInfo fcinfo,
- FunctionCachePtr fcache,
- bool *isDone)
+fmgr_sql(PG_FUNCTION_ARGS)
{
MemoryContext oldcontext;
+ SQLFunctionCachePtr fcache;
execution_state *es;
Datum result = 0;
CommandId savedId;
@@ -352,7 +509,7 @@ postquel_function(FunctionCallInfo fcinfo,
* parsetrees, plans, etc, will have sufficient lifetime. The
* sub-executor is responsible for deleting per-tuple information.
*/
- oldcontext = MemoryContextSwitchTo(fcache->fcacheCxt);
+ oldcontext = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
/*
* Before we start do anything we must save CurrentScanCommandId to
@@ -362,13 +519,21 @@ postquel_function(FunctionCallInfo fcinfo,
savedId = GetScanCommandId();
SetScanCommandId(GetCurrentCommandId());
- es = (execution_state *) fcache->func_state;
- if (es == NULL)
+ /*
+ * Initialize fcache and execution state if first time through.
+ */
+ fcache = (SQLFunctionCachePtr) fcinfo->flinfo->fn_extra;
+ if (fcache == NULL)
{
- es = init_execution_state(fcache);
- fcache->func_state = (char *) es;
+ init_sql_fcache(fcinfo->flinfo);
+ fcache = (SQLFunctionCachePtr) fcinfo->flinfo->fn_extra;
}
+ es = fcache->func_state;
+ Assert(es);
+ /*
+ * Find first unfinished query in function.
+ */
while (es && es->status == F_EXEC_DONE)
es = es->next;
@@ -401,7 +566,7 @@ postquel_function(FunctionCallInfo fcinfo,
/*
* Reset the execution states to start over again
*/
- es = (execution_state *) fcache->func_state;
+ es = fcache->func_state;
while (es)
{
es->status = F_EXEC_START;
@@ -411,9 +576,21 @@ postquel_function(FunctionCallInfo fcinfo,
/*
* Let caller know we're finished.
*/
- *isDone = true;
+ if (fcinfo->flinfo->fn_retset)
+ {
+ ReturnSetInfo *rsi = (ReturnSetInfo *) fcinfo->resultinfo;
+
+ if (rsi && IsA(rsi, ReturnSetInfo))
+ rsi->isDone = ExprEndResult;
+ else
+ elog(ERROR, "Set-valued function called in context that cannot accept a set");
+ fcinfo->isnull = true;
+ result = (Datum) 0;
+ }
+
MemoryContextSwitchTo(oldcontext);
- return (fcache->returnsSet) ? (Datum) NULL : result;
+
+ return result;
}
/*
@@ -422,7 +599,18 @@ postquel_function(FunctionCallInfo fcinfo,
*/
Assert(LAST_POSTQUEL_COMMAND(es));
- *isDone = false;
+ /*
+ * Let caller know we're not finished.
+ */
+ if (fcinfo->flinfo->fn_retset)
+ {
+ ReturnSetInfo *rsi = (ReturnSetInfo *) fcinfo->resultinfo;
+
+ if (rsi && IsA(rsi, ReturnSetInfo))
+ rsi->isDone = ExprMultipleResult;
+ else
+ elog(ERROR, "Set-valued function called in context that cannot accept a set");
+ }
MemoryContextSwitchTo(oldcontext);
diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/nodeAgg.c
index 547a946b4ce..fae1a5b0d87 100644
--- a/src/backend/executor/nodeAgg.c
+++ b/src/backend/executor/nodeAgg.c
@@ -34,7 +34,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* 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)
TupleTableSlot *resultSlot;
HeapTuple inputTuple;
int aggno;
- bool isDone;
bool isNull;
/* ---------------------
@@ -523,7 +522,7 @@ ExecAgg(Agg *node)
Datum newVal;
newVal = ExecEvalExpr(aggref->target, econtext,
- &isNull, &isDone);
+ &isNull, NULL);
if (aggref->aggdistinct)
{
@@ -677,8 +676,9 @@ ExecAgg(Agg *node)
/*
* Form a projection tuple using the aggregate results and the
* 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
diff --git a/src/backend/executor/nodeGroup.c b/src/backend/executor/nodeGroup.c
index 8a445b53d41..8fc319a77f0 100644
--- a/src/backend/executor/nodeGroup.c
+++ b/src/backend/executor/nodeGroup.c
@@ -15,7 +15,7 @@
* locate group boundaries.
*
* 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)
TupleTableSlot *outerslot;
ProjectionInfo *projInfo;
TupleTableSlot *resultSlot;
- bool isDone;
/* ---------------------
* get state info from node
@@ -163,7 +162,7 @@ ExecGroupEveryTuple(Group *node)
projInfo = grpstate->csstate.cstate.cs_ProjInfo;
econtext->ecxt_scantuple = grpstate->csstate.css_ScanTupleSlot;
- resultSlot = ExecProject(projInfo, &isDone);
+ resultSlot = ExecProject(projInfo, NULL);
return resultSlot;
}
@@ -185,7 +184,6 @@ ExecGroupOneTuple(Group *node)
TupleTableSlot *outerslot;
ProjectionInfo *projInfo;
TupleTableSlot *resultSlot;
- bool isDone;
/* ---------------------
* get state info from node
@@ -258,7 +256,7 @@ ExecGroupOneTuple(Group *node)
grpstate->csstate.css_ScanTupleSlot,
InvalidBuffer, false);
econtext->ecxt_scantuple = grpstate->csstate.css_ScanTupleSlot;
- resultSlot = ExecProject(projInfo, &isDone);
+ resultSlot = ExecProject(projInfo, NULL);
/* save outerTuple if we are not done yet */
if (!grpstate->grp_done)
diff --git a/src/backend/executor/nodeHash.c b/src/backend/executor/nodeHash.c
index 682afdba4af..9cd85195cdc 100644
--- a/src/backend/executor/nodeHash.c
+++ b/src/backend/executor/nodeHash.c
@@ -7,7 +7,7 @@
* 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,
int bucketno;
Datum keyval;
bool isNull;
- bool isDone;
/* ----------------
* Get the join attribute value of the tuple
@@ -535,8 +534,7 @@ ExecHashGetBucket(HashJoinTable hashtable,
*/
ResetExprContext(econtext);
- keyval = ExecEvalExprSwitchContext(hashkey, econtext,
- &isNull, &isDone);
+ keyval = ExecEvalExprSwitchContext(hashkey, econtext, &isNull, NULL);
/* ------------------
* compute the hash function
diff --git a/src/backend/executor/nodeHashjoin.c b/src/backend/executor/nodeHashjoin.c
index 54af882db12..4b3b4a82505 100644
--- a/src/backend/executor/nodeHashjoin.c
+++ b/src/backend/executor/nodeHashjoin.c
@@ -8,7 +8,7 @@
*
*
* 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)
TupleTableSlot *inntuple;
Node *outerVar;
ExprContext *econtext;
+ ExprDoneCond isDone;
HashJoinTable hashtable;
HeapTuple curtuple;
TupleTableSlot *outerTupleSlot;
@@ -84,13 +85,6 @@ ExecHashJoin(HashJoin *node)
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
* join tuple (because there is a function-returning-set in the
* projection expressions). If so, try to project another one.
@@ -99,16 +93,23 @@ ExecHashJoin(HashJoin *node)
if (hjstate->jstate.cs_TupFromTlist)
{
TupleTableSlot *result;
- bool isDone;
result = ExecProject(hjstate->jstate.cs_ProjInfo, &isDone);
- if (!isDone)
+ if (isDone == ExprMultipleResult)
return result;
/* Done with that source tuple... */
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
* ----------------
*/
@@ -241,15 +242,15 @@ ExecHashJoin(HashJoin *node)
*/
if (ExecQual(qual, econtext, false))
{
- ProjectionInfo *projInfo;
TupleTableSlot *result;
- bool isDone;
hjstate->jstate.cs_OuterTupleSlot = outerTupleSlot;
- projInfo = hjstate->jstate.cs_ProjInfo;
- result = ExecProject(projInfo, &isDone);
- hjstate->jstate.cs_TupFromTlist = !isDone;
- return result;
+ result = ExecProject(hjstate->jstate.cs_ProjInfo, &isDone);
+ if (isDone != ExprEndResult)
+ {
+ hjstate->jstate.cs_TupFromTlist = (isDone == ExprMultipleResult);
+ return result;
+ }
}
}
diff --git a/src/backend/executor/nodeIndexscan.c b/src/backend/executor/nodeIndexscan.c
index 57770d24058..a8b29514b88 100644
--- a/src/backend/executor/nodeIndexscan.c
+++ b/src/backend/executor/nodeIndexscan.c
@@ -8,7 +8,7 @@
*
*
* 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)
Node *scanexpr;
Datum scanvalue;
bool isNull;
- bool isDone;
estate = node->scan.plan.state;
indexstate = node->indxstate;
@@ -411,14 +410,10 @@ ExecIndexReScan(IndexScan *node, ExprContext *exprCtxt, Plan *parent)
(Node *) get_rightop(clause) :
(Node *) get_leftop(clause);
- /*
- * pass in isDone but ignore it. We don't iterate in
- * quals
- */
scanvalue = ExecEvalExprSwitchContext(scanexpr,
econtext,
&isNull,
- &isDone);
+ NULL);
scan_keys[j].sk_argument = scanvalue;
if (isNull)
scan_keys[j].sk_flags |= SK_ISNULL;
diff --git a/src/backend/executor/nodeMergejoin.c b/src/backend/executor/nodeMergejoin.c
index a3f92b06901..5a2f45028a0 100644
--- a/src/backend/executor/nodeMergejoin.c
+++ b/src/backend/executor/nodeMergejoin.c
@@ -8,7 +8,7 @@
*
*
* 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)
{
Datum const_value;
bool isNull;
- bool isDone;
/* ----------------
* first test if our compare clause is satisfied.
* if so then return true.
*
* A NULL result is considered false.
- * ignore isDone, don't iterate in quals.
* ----------------
*/
const_value = ExecEvalExpr((Node *) lfirst(clause), econtext,
- &isNull, &isDone);
+ &isNull, NULL);
if (DatumGetBool(const_value) && !isNull)
{
@@ -254,7 +252,7 @@ MergeCompare(List *eqQual, List *compareQual, ExprContext *econtext)
const_value = ExecEvalExpr((Node *) lfirst(eqclause),
econtext,
&isNull,
- &isDone);
+ NULL);
if (! DatumGetBool(const_value) || isNull)
break; /* return false */
@@ -448,13 +446,6 @@ ExecMergeJoin(MergeJoin *node)
}
/* ----------------
- * 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
* join tuple (because there is a function-returning-set in the
* projection expressions). If so, try to project another one.
@@ -463,16 +454,24 @@ ExecMergeJoin(MergeJoin *node)
if (mergestate->jstate.cs_TupFromTlist)
{
TupleTableSlot *result;
- bool isDone;
+ ExprDoneCond isDone;
result = ExecProject(mergestate->jstate.cs_ProjInfo, &isDone);
- if (!isDone)
+ if (isDone == ExprMultipleResult)
return result;
/* Done with that source tuple... */
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
* ----------------
*/
@@ -599,17 +598,19 @@ ExecMergeJoin(MergeJoin *node)
* projection tuple and return the slot containing it.
* ----------------
*/
- ProjectionInfo *projInfo;
TupleTableSlot *result;
- bool isDone;
+ ExprDoneCond isDone;
MJ_printf("ExecMergeJoin: **** returning tuple ****\n");
- projInfo = mergestate->jstate.cs_ProjInfo;
+ result = ExecProject(mergestate->jstate.cs_ProjInfo,
+ &isDone);
- result = ExecProject(projInfo, &isDone);
- mergestate->jstate.cs_TupFromTlist = !isDone;
- return result;
+ if (isDone != ExprEndResult)
+ {
+ mergestate->jstate.cs_TupFromTlist = (isDone == ExprMultipleResult);
+ return result;
+ }
}
break;
diff --git a/src/backend/executor/nodeNestloop.c b/src/backend/executor/nodeNestloop.c
index f59c1b0f602..3685232c7e4 100644
--- a/src/backend/executor/nodeNestloop.c
+++ b/src/backend/executor/nodeNestloop.c
@@ -8,7 +8,7 @@
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
@@ -88,13 +88,6 @@ ExecNestLoop(NestLoop *node)
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
* join tuple (because there is a function-returning-set in the
* projection expressions). If so, try to project another one.
@@ -103,16 +96,24 @@ ExecNestLoop(NestLoop *node)
if (nlstate->jstate.cs_TupFromTlist)
{
TupleTableSlot *result;
- bool isDone;
+ ExprDoneCond isDone;
result = ExecProject(nlstate->jstate.cs_ProjInfo, &isDone);
- if (!isDone)
+ if (isDone == ExprMultipleResult)
return result;
/* Done with that source tuple... */
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
* we return a qualifying join tuple..
* ----------------
@@ -219,16 +220,18 @@ ExecNestLoop(NestLoop *node)
* using ExecProject().
* ----------------
*/
- ProjectionInfo *projInfo;
TupleTableSlot *result;
- bool isDone;
+ ExprDoneCond isDone;
ENL1_printf("qualification succeeded, projecting tuple");
- projInfo = nlstate->jstate.cs_ProjInfo;
- result = ExecProject(projInfo, &isDone);
- nlstate->jstate.cs_TupFromTlist = !isDone;
- return result;
+ result = ExecProject(nlstate->jstate.cs_ProjInfo, &isDone);
+
+ if (isDone != ExprEndResult)
+ {
+ nlstate->jstate.cs_TupFromTlist = (isDone == ExprMultipleResult);
+ return result;
+ }
}
/* ----------------
diff --git a/src/backend/executor/nodeResult.c b/src/backend/executor/nodeResult.c
index 770cc47ccc4..e36037de710 100644
--- a/src/backend/executor/nodeResult.c
+++ b/src/backend/executor/nodeResult.c
@@ -34,7 +34,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* 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)
TupleTableSlot *resultSlot;
Plan *outerPlan;
ExprContext *econtext;
- bool isDone;
- ProjectionInfo *projInfo;
+ ExprDoneCond isDone;
/* ----------------
* initialize the result node's state
@@ -78,13 +77,6 @@ ExecResult(Result *node)
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
* ----------------
*/
@@ -111,20 +103,28 @@ ExecResult(Result *node)
if (resstate->cstate.cs_TupFromTlist)
{
resultSlot = ExecProject(resstate->cstate.cs_ProjInfo, &isDone);
- if (!isDone)
+ if (isDone == ExprMultipleResult)
return resultSlot;
/* Done with that source tuple... */
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
* a constant tuple and we already did the last time ExecResult()
* was called, OR that we failed the constant qual check.
* Either way, now we are through.
* ----------------
*/
- if (!resstate->rs_done)
+ while (!resstate->rs_done)
{
outerPlan = outerPlan(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(projInfo, &isDone);
- resstate->cstate.cs_TupFromTlist = !isDone;
- return resultSlot;
+ resultSlot = ExecProject(resstate->cstate.cs_ProjInfo, &isDone);
+
+ if (isDone != ExprEndResult)
+ {
+ resstate->cstate.cs_TupFromTlist = (isDone == ExprMultipleResult);
+ return resultSlot;
+ }
}
return NULL;
diff --git a/src/backend/executor/nodeSubplan.c b/src/backend/executor/nodeSubplan.c
index 3d331c714f7..aee6911e5e4 100644
--- a/src/backend/executor/nodeSubplan.c
+++ b/src/backend/executor/nodeSubplan.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* 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)
MemoryContext oldcontext;
TupleTableSlot *slot;
Datum result;
- bool isDone;
bool found = false; /* TRUE if got at least one subplan tuple */
List *lst;
@@ -67,9 +66,7 @@ ExecSubPlan(SubPlan *node, List *pvar, ExprContext *econtext, bool *isNull)
prm->value = ExecEvalExprSwitchContext((Node *) lfirst(pvar),
econtext,
&(prm->isnull),
- &isDone);
- if (!isDone)
- elog(ERROR, "ExecSubPlan: set values not supported for params");
+ NULL);
pvar = lnext(pvar);
}
plan->chgParam = nconc(plan->chgParam, listCopy(node->parParam));
@@ -189,9 +186,7 @@ ExecSubPlan(SubPlan *node, List *pvar, ExprContext *econtext, bool *isNull)
* Now we can eval the combining operator for this column.
*/
expresult = ExecEvalExprSwitchContext((Node *) expr, econtext,
- &expnull, &isDone);
- if (!isDone)
- elog(ERROR, "ExecSubPlan: set values not supported for combining operators");
+ &expnull, NULL);
/*
* Combine the result into the row result as appropriate.
diff --git a/src/backend/executor/nodeTidscan.c b/src/backend/executor/nodeTidscan.c
index ac6511dcbfb..055d07998b9 100644
--- a/src/backend/executor/nodeTidscan.c
+++ b/src/backend/executor/nodeTidscan.c
@@ -8,7 +8,7 @@
*
*
* 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)
List *lst;
ItemPointer itemptr;
bool isNull;
- bool isDone;
int numTids = 0;
foreach(lst, evalList)
@@ -47,8 +46,8 @@ TidListCreate(List *evalList, ExprContext *econtext, ItemPointer *tidList)
DatumGetPointer(ExecEvalExprSwitchContext(lfirst(lst),
econtext,
&isNull,
- &isDone));
- if (itemptr && ItemPointerIsValid(itemptr))
+ NULL));
+ if (!isNull && itemptr && ItemPointerIsValid(itemptr))
{
tidList[numTids] = itemptr;
numTids++;