From b11123b675d9317f771d2bc44f72594de329098d Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 17 May 2007 19:35:08 +0000 Subject: Fix parameter recalculation for Limit nodes: during a ReScan call we must recompute the limit/offset immediately, so that the updated values are available when the child's ReScan function is invoked. Add a regression test for this, too. Bug is new in HEAD (due to the bounded-sorting patch) so no need for back-patch. I did not do anything about merging this signaling with chgParam processing, but if we were to do that we'd still need to compute the updated values at this point rather than during the first ProcNode call. Per observation and test case from Greg Stark, though I didn't use his patch. --- src/backend/executor/nodeSubplan.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/backend/executor/nodeSubplan.c') diff --git a/src/backend/executor/nodeSubplan.c b/src/backend/executor/nodeSubplan.c index a66f51c26a6..ac91ed1be64 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 - * $PostgreSQL: pgsql/src/backend/executor/nodeSubplan.c,v 1.88 2007/04/26 23:24:44 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/nodeSubplan.c,v 1.89 2007/05/17 19:35:08 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -242,6 +242,9 @@ ExecScanSubPlan(SubPlanState *node, planstate->chgParam = bms_add_member(planstate->chgParam, paramid); } + /* + * Now that we've set up its parameters, we can reset the subplan. + */ ExecReScan(planstate, NULL); /* @@ -901,6 +904,10 @@ ExecSetParamPlan(SubPlanState *node, ExprContext *econtext) subLinkType == ALL_SUBLINK) elog(ERROR, "ANY/ALL subselect unsupported as initplan"); + /* + * By definition, an initplan has no parameters from our query level, + * but it could have some from an outer level. Rescan it if needed. + */ if (planstate->chgParam != NULL) ExecReScan(planstate, NULL); -- cgit v1.2.3