Index: src/backend/executor/nodeResult.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/executor/nodeResult.c,v retrieving revision 1.34.2.3 diff -c -r1.34.2.3 nodeResult.c *** src/backend/executor/nodeResult.c 15 Feb 2007 03:07:21 -0000 1.34.2.3 --- src/backend/executor/nodeResult.c 16 Feb 2007 03:34:49 -0000 *************** *** 309,318 **** node->rs_checkqual = (node->resconstantqual == NULL) ? false : true; /* ! * if chgParam of subnode is not null then plan will be re-scanned by ! * first ExecProcNode. */ ! if (((PlanState *) node)->lefttree && ! ((PlanState *) node)->lefttree->chgParam == NULL) ! ExecReScan(((PlanState *) node)->lefttree, exprCtxt); } --- 309,320 ---- node->rs_checkqual = (node->resconstantqual == NULL) ? false : true; /* ! * If chgParam of subnode is not null then plan will be re-scanned by ! * first ExecProcNode. However, if caller is passing us an exprCtxt ! * then forcibly rescan the subnode now, so that we can pass the ! * exprCtxt down to the subnode (needed for gated indexscan). */ ! if (node->ps.lefttree && ! (node->ps.lefttree->chgParam == NULL || exprCtxt != NULL)) ! ExecReScan(node->ps.lefttree, exprCtxt); } Index: src/backend/optimizer/plan/setrefs.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v retrieving revision 1.126 diff -c -r1.126 setrefs.c *** src/backend/optimizer/plan/setrefs.c 4 Oct 2006 00:29:54 -0000 1.126 --- src/backend/optimizer/plan/setrefs.c 16 Feb 2007 03:34:49 -0000 *************** *** 937,942 **** --- 937,950 ---- outer_itlist); } } + else if (IsA(inner_plan, Result)) + { + /* Recurse through a gating Result node (similar to Append case) */ + Result *result = (Result *) inner_plan; + + if (result->plan.lefttree) + set_inner_join_references(result->plan.lefttree, outer_itlist); + } else if (IsA(inner_plan, TidScan)) { TidScan *innerscan = (TidScan *) inner_plan;