Skip to content

Commit 8e90978

Browse files
committed
Fixing bug in INDEXSCAN_PATCH:
ExecInitIndexScan now works with operands of Param type and (!!!) postquel_execute() now substitutes param values before calling postquel_start().
1 parent 6850a96 commit 8e90978

File tree

3 files changed

+53
-6
lines changed

3 files changed

+53
-6
lines changed

src/backend/executor/execMain.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
*
2828
* IDENTIFICATION
29-
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.9 1996/11/13 20:48:28 scrappy Exp $
29+
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.10 1997/01/22 05:26:27 vadim Exp $
3030
*
3131
*-------------------------------------------------------------------------
3232
*/
@@ -170,6 +170,11 @@ ExecutorRun(QueryDesc *queryDesc, EState *estate, int feature, int count)
170170
dest = queryDesc->dest;
171171
destination = (void (*)()) DestToFunction(dest);
172172

173+
#if 0
174+
/*
175+
* It doesn't work in common case (i.g. if function has a aggregate).
176+
* Now we store parameter values before ExecutorStart. - vadim 01/22/97
177+
*/
173178
#ifdef INDEXSCAN_PATCH
174179
/*
175180
* If the plan is an index scan and some of the scan key are
@@ -182,6 +187,7 @@ ExecutorRun(QueryDesc *queryDesc, EState *estate, int feature, int count)
182187
econtext = ((IndexScan *)plan)->scan.scanstate->cstate.cs_ExprContext;
183188
ExecIndexReScan((IndexScan *)plan, econtext, plan);
184189
}
190+
#endif
185191
#endif
186192

187193
switch(feature) {

src/backend/executor/functions.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/executor/functions.c,v 1.4 1996/11/06 06:47:36 scrappy Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/executor/functions.c,v 1.5 1997/01/22 05:26:37 vadim Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -281,15 +281,26 @@ postquel_execute(execution_state *es,
281281
{
282282
TupleTableSlot *slot;
283283
Datum value;
284+
285+
#ifdef INDEXSCAN_PATCH
286+
/*
287+
* It's more right place to do it (before postquel_start->ExecutorStart).
288+
* Now ExecutorStart->ExecInitIndexScan->ExecEvalParam works ok.
289+
* (But note: I HOPE we can do it here). - vadim 01/22/97
290+
*/
291+
if (fcache->nargs > 0)
292+
postquel_sub_params(es, fcache->nargs, args, fcache->nullVect);
293+
#endif
284294

285295
if (es->status == F_EXEC_START)
286296
{
287297
(void) postquel_start(es);
288298
es->status = F_EXEC_RUN;
289299
}
290-
300+
#ifndef INDEXSCAN_PATCH
291301
if (fcache->nargs > 0)
292302
postquel_sub_params(es, fcache->nargs, args, fcache->nullVect);
303+
#endif
293304

294305
slot = postquel_getnext(es);
295306

src/backend/executor/nodeIndexscan.c

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/executor/nodeIndexscan.c,v 1.5 1996/11/08 00:45:57 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/executor/nodeIndexscan.c,v 1.6 1997/01/22 05:26:50 vadim Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -609,6 +609,7 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
609609
Oper *op; /* operator used in scan.. */
610610
Node *leftop; /* expr on lhs of operator */
611611
Node *rightop; /* expr on rhs ... */
612+
bits16 flags = 0;
612613

613614
int scanvar; /* which var identifies varattno */
614615
AttrNumber varattno = 0; /* att number used in scan */
@@ -675,6 +676,21 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
675676
*/
676677
run_keys[ j ] = NO_OP;
677678
scanvalue = ((Const*) leftop)->constvalue;
679+
#ifdef INDEXSCAN_PATCH
680+
} else if (IsA(leftop,Param)) {
681+
bool isnull;
682+
/* ----------------
683+
* if the leftop is a Param node then it means
684+
* it identifies the value to place in our scan key.
685+
* ----------------
686+
*/
687+
run_keys[ j ] = NO_OP;
688+
scanvalue = ExecEvalParam((Param*) leftop,
689+
scanstate->cstate.cs_ExprContext,
690+
&isnull);
691+
if ( isnull )
692+
flags |= SK_ISNULL;
693+
#endif
678694
} else if (leftop != NULL &&
679695
is_funcclause(leftop) &&
680696
var_is_rel(lfirst(((Expr*)leftop)->args))) {
@@ -733,7 +749,21 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
733749
*/
734750
run_keys[ j ] = NO_OP;
735751
scanvalue = ((Const*) rightop)->constvalue;
736-
752+
#ifdef INDEXSCAN_PATCH
753+
} else if (IsA(rightop,Param)) {
754+
bool isnull;
755+
/* ----------------
756+
* if the rightop is a Param node then it means
757+
* it identifies the value to place in our scan key.
758+
* ----------------
759+
*/
760+
run_keys[ j ] = NO_OP;
761+
scanvalue = ExecEvalParam((Param*) rightop,
762+
scanstate->cstate.cs_ExprContext,
763+
&isnull);
764+
if ( isnull )
765+
flags |= SK_ISNULL;
766+
#endif
737767
} else if (rightop!=NULL &&
738768
is_funcclause(rightop) &&
739769
var_is_rel(lfirst(((Expr*)rightop)->args))) {
@@ -777,7 +807,7 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
777807
* ----------------
778808
*/
779809
ScanKeyEntryInitialize(&scan_keys[j],
780-
0,
810+
flags,
781811
varattno, /* attribute number to scan */
782812
(RegProcedure) opid, /* reg proc to use */
783813
(Datum) scanvalue); /* constant */

0 commit comments

Comments
 (0)