Skip to content

Commit 54840ec

Browse files
committed
Use a shutdown callback to clear setArgsValid in a FuncExprState that is
evaluating a set-valued function. This fixes some additional problems with rescanning partially-evaluated SRFs.
1 parent ed8e514 commit 54840ec

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/backend/executor/execQual.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.151 2003/11/29 19:51:48 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.152 2003/12/18 22:23:42 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -636,9 +636,26 @@ init_fcache(Oid foid, FuncExprState *fcache, MemoryContext fcacheCxt)
636636

637637
/* Initialize additional info */
638638
fcache->setArgsValid = false;
639+
fcache->shutdown_reg = false;
639640
fcache->func.fn_expr = (Node *) fcache->xprstate.expr;
640641
}
641642

643+
/*
644+
* callback function in case a FuncExpr returning a set needs to be shut down
645+
* before it has been run to completion
646+
*/
647+
static void
648+
ShutdownFuncExpr(Datum arg)
649+
{
650+
FuncExprState *fcache = (FuncExprState *) DatumGetPointer(arg);
651+
652+
/* Clear any active set-argument state */
653+
fcache->setArgsValid = false;
654+
655+
/* execUtils will deregister the callback... */
656+
fcache->shutdown_reg = false;
657+
}
658+
642659
/*
643660
* Evaluate arguments for a function.
644661
*/
@@ -827,6 +844,14 @@ ExecMakeFunctionResult(FuncExprState *fcache,
827844
memcpy(&fcache->setArgs, &fcinfo, sizeof(fcinfo));
828845
fcache->setHasSetArg = hasSetArg;
829846
fcache->setArgsValid = true;
847+
/* Register cleanup callback if we didn't already */
848+
if (!fcache->shutdown_reg)
849+
{
850+
RegisterExprContextCallback(econtext,
851+
ShutdownFuncExpr,
852+
PointerGetDatum(fcache));
853+
fcache->shutdown_reg = true;
854+
}
830855
}
831856

832857
/*

src/include/nodes/execnodes.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.108 2003/11/29 22:41:06 pgsql Exp $
10+
* $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.109 2003/12/18 22:23:42 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -481,6 +481,13 @@ typedef struct FuncExprState
481481
*/
482482
bool setHasSetArg; /* some argument returns a set */
483483

484+
/*
485+
* Flag to remember whether we have registered a shutdown callback for
486+
* this FuncExprState. We do so only if setArgsValid has been true at
487+
* least once (since all the callback is for is to clear setArgsValid).
488+
*/
489+
bool shutdown_reg; /* a shutdown callback is registered */
490+
484491
/*
485492
* Current argument data for a set-valued function; contains valid
486493
* data only if setArgsValid is true.

0 commit comments

Comments
 (0)