Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3842323

Browse files
committed
Ensure set-returning functions in the targetlist of a plan node will be
shut down cleanly if the plan node is ReScanned before the SRFs are runto completion. This fixes the problem for SQL-language functions, butstill need work on functions using the SRF_XXX() macros.
1 parent125d69c commit3842323

File tree

3 files changed

+41
-9
lines changed

3 files changed

+41
-9
lines changed

‎src/backend/executor/execAmi.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
*$PostgreSQL: pgsql/src/backend/executor/execAmi.c,v 1.76 2003/11/29 19:51:48 pgsql Exp $
9+
*$PostgreSQL: pgsql/src/backend/executor/execAmi.c,v 1.77 2003/12/18 20:21:37 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -39,13 +39,20 @@
3939
#include"executor/nodeUnique.h"
4040

4141

42-
/* ----------------------------------------------------------------
43-
*ExecReScan
42+
/*
43+
* ExecReScan
44+
*Reset a plan node so that its output can be re-scanned.
45+
*
46+
* Note that if the plan node has parameters that have changed value,
47+
* the output might be different from last time.
4448
*
45-
*takes the new expression context as an argument, so that
46-
*index scans needn't have their scan keys updated separately
47-
*- marcel 09/20/94
48-
* ----------------------------------------------------------------
49+
* The second parameter is currently only used to pass a NestLoop plan's
50+
* econtext down to its inner child plan, in case that is an indexscan that
51+
* needs access to variables of the current outer tuple. (The handling of
52+
* this parameter is currently pretty inconsistent: some callers pass NULL
53+
* and some pass down their parent's value; so don't rely on it in other
54+
* situations. It'd probably be better to remove the whole thing and use
55+
* the generalized parameter mechanism instead.)
4956
*/
5057
void
5158
ExecReScan(PlanState*node,ExprContext*exprCtxt)
@@ -85,6 +92,11 @@ ExecReScan(PlanState *node, ExprContext *exprCtxt)
8592
UpdateChangedParamSet(node->righttree,node->chgParam);
8693
}
8794

95+
/* Shut down any SRFs in the plan node's targetlist */
96+
if (node->ps_ExprContext)
97+
ReScanExprContext(node->ps_ExprContext);
98+
99+
/* And do node-type-specific processing */
88100
switch (nodeTag(node))
89101
{
90102
caseT_ResultState:

‎src/backend/executor/execUtils.c

Lines changed: 20 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/execUtils.c,v 1.107 2003/11/29 19:51:48 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/execUtils.c,v 1.108 2003/12/18 20:21:37 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -18,6 +18,7 @@
1818
*FreeExecutorState
1919
*CreateExprContext
2020
*FreeExprContext
21+
*ReScanExprContext
2122
*
2223
*ExecAssignExprContextCommon code for plan node init routines.
2324
*ExecAssignResultType
@@ -352,6 +353,24 @@ FreeExprContext(ExprContext *econtext)
352353
pfree(econtext);
353354
}
354355

356+
/*
357+
* ReScanExprContext
358+
*
359+
*Reset an expression context in preparation for a rescan of its
360+
*plan node. This requires calling any registered shutdown callbacks,
361+
*since any partially complete set-returning-functions must be canceled.
362+
*
363+
* Note we make no assumption about the caller's memory context.
364+
*/
365+
void
366+
ReScanExprContext(ExprContext*econtext)
367+
{
368+
/* Call any registered callbacks */
369+
ShutdownExprContext(econtext);
370+
/* And clean up the memory used */
371+
MemoryContextReset(econtext->ecxt_per_tuple_memory);
372+
}
373+
355374
/*
356375
* Build a per-output-tuple ExprContext for an EState.
357376
*

‎src/include/executor/executor.h

Lines changed: 2 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/executor/executor.h,v 1.103 2003/11/29 22:41:01 pgsql Exp $
10+
* $PostgreSQL: pgsql/src/include/executor/executor.h,v 1.104 2003/12/18 20:21:37 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -201,6 +201,7 @@ extern EState *CreateExecutorState(void);
201201
externvoidFreeExecutorState(EState*estate);
202202
externExprContext*CreateExprContext(EState*estate);
203203
externvoidFreeExprContext(ExprContext*econtext);
204+
externvoidReScanExprContext(ExprContext*econtext);
204205

205206
#defineResetExprContext(econtext) \
206207
MemoryContextReset((econtext)->ecxt_per_tuple_memory)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp