Skip to content

Commit 62e29fe

Browse files
committed
Remove 'func_tlist' from Func expression nodes, likewise 'param_tlist'
from Param nodes, per discussion a few days ago on pghackers. Add new expression node type FieldSelect that implements the functionality where it's actually needed. Clean up some other unused fields in Func nodes as well. NOTE: initdb forced due to change in stored expression trees for rules.
1 parent 8fc3237 commit 62e29fe

31 files changed

+378
-476
lines changed

src/backend/executor/execQual.c

Lines changed: 37 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.76 2000/07/23 01:35:58 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.77 2000/08/08 15:41:22 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -294,8 +294,6 @@ ExecEvalVar(Var *variable, ExprContext *econtext, bool *isNull)
294294
AttrNumber attnum;
295295
HeapTuple heapTuple;
296296
TupleDesc tuple_type;
297-
bool byval;
298-
int16 len;
299297

300298
/*
301299
* get the slot we want
@@ -363,36 +361,6 @@ ExecEvalVar(Var *variable, ExprContext *econtext, bool *isNull)
363361
tuple_type, /* tuple descriptor of tuple */
364362
isNull); /* return: is attribute null? */
365363

366-
/*
367-
* return null if att is null
368-
*/
369-
if (*isNull)
370-
return (Datum) 0;
371-
372-
/*
373-
* get length and type information.. ??? what should we do about
374-
* variable length attributes - variable length attributes have their
375-
* length stored in the first 4 bytes of the memory pointed to by the
376-
* returned value.. If we can determine that the type is a variable
377-
* length type, we can do the right thing. -cim 9/15/89
378-
*/
379-
if (attnum < 0)
380-
{
381-
382-
/*
383-
* If this is a pseudo-att, we get the type and fake the length.
384-
* There ought to be a routine to return the real lengths, so
385-
* we'll mark this one ... XXX -mao
386-
*/
387-
len = heap_sysattrlen(attnum); /* XXX see -mao above */
388-
byval = heap_sysattrbyval(attnum); /* XXX see -mao above */
389-
}
390-
else
391-
{
392-
len = tuple_type->attrs[attnum - 1]->attlen;
393-
byval = tuple_type->attrs[attnum - 1]->attbyval ? true : false;
394-
}
395-
396364
return result;
397365
}
398366

@@ -519,25 +487,7 @@ ExecEvalParam(Param *expression, ExprContext *econtext, bool *isNull)
519487
/*
520488
* return the value.
521489
*/
522-
if (paramList->isnull)
523-
{
524-
*isNull = true;
525-
return (Datum) 0;
526-
}
527-
528-
if (expression->param_tlist != NIL)
529-
{
530-
HeapTuple tup;
531-
Datum value;
532-
List *tlist = expression->param_tlist;
533-
TargetEntry *tle = (TargetEntry *) lfirst(tlist);
534-
TupleTableSlot *slot = (TupleTableSlot *) paramList->value;
535-
536-
tup = slot->val;
537-
value = ProjectAttribute(slot->ttc_tupleDescriptor,
538-
tle, tup, isNull);
539-
return value;
540-
}
490+
*isNull = paramList->isnull;
541491
return paramList->value;
542492
}
543493

@@ -686,7 +636,6 @@ ExecMakeFunctionResult(Node *node,
686636
{
687637
FunctionCallInfoData fcinfo;
688638
FunctionCachePtr fcache;
689-
List *ftlist;
690639
bool funcisset;
691640
Datum result;
692641
bool argDone;
@@ -702,13 +651,11 @@ ExecMakeFunctionResult(Node *node,
702651
if (IsA(node, Func))
703652
{
704653
fcache = ((Func *) node)->func_fcache;
705-
ftlist = ((Func *) node)->func_tlist;
706654
funcisset = (((Func *) node)->funcid == F_SETEVAL);
707655
}
708656
else
709657
{
710658
fcache = ((Oper *) node)->op_fcache;
711-
ftlist = NIL;
712659
funcisset = false;
713660
}
714661

@@ -822,7 +769,7 @@ ExecMakeFunctionResult(Node *node,
822769

823770
if (callit)
824771
{
825-
result = postquel_function(&fcinfo, fcache, ftlist, isDone);
772+
result = postquel_function(&fcinfo, fcache, isDone);
826773
*isNull = fcinfo.isnull;
827774
}
828775
else
@@ -1214,6 +1161,34 @@ ExecEvalCase(CaseExpr *caseExpr, ExprContext *econtext, bool *isNull)
12141161
return (Datum) 0;
12151162
}
12161163

1164+
/* ----------------------------------------------------------------
1165+
* ExecEvalFieldSelect
1166+
*
1167+
* Evaluate a FieldSelect node.
1168+
* ----------------------------------------------------------------
1169+
*/
1170+
static Datum
1171+
ExecEvalFieldSelect(FieldSelect *fselect,
1172+
ExprContext *econtext,
1173+
bool *isNull,
1174+
bool *isDone)
1175+
{
1176+
Datum result;
1177+
TupleTableSlot *resSlot;
1178+
1179+
result = ExecEvalExpr(fselect->arg, econtext, isNull, isDone);
1180+
if (*isNull)
1181+
return result;
1182+
/* XXX what about isDone? */
1183+
resSlot = (TupleTableSlot *) DatumGetPointer(result);
1184+
Assert(resSlot != NULL && IsA(resSlot, TupleTableSlot));
1185+
result = heap_getattr(resSlot->val,
1186+
fselect->fieldnum,
1187+
resSlot->ttc_tupleDescriptor,
1188+
isNull);
1189+
return result;
1190+
}
1191+
12171192
/* ----------------------------------------------------------------
12181193
* ExecEvalExpr
12191194
*
@@ -1319,6 +1294,12 @@ ExecEvalExpr(Node *expression,
13191294
}
13201295
break;
13211296
}
1297+
case T_FieldSelect:
1298+
retDatum = ExecEvalFieldSelect((FieldSelect *) expression,
1299+
econtext,
1300+
isNull,
1301+
isDone);
1302+
break;
13221303
case T_RelabelType:
13231304
retDatum = ExecEvalExpr(((RelabelType *) expression)->arg,
13241305
econtext,

src/backend/executor/functions.c

Lines changed: 36 additions & 46 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.36 2000/07/12 02:37:03 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/executor/functions.c,v 1.37 2000/08/08 15:41:22 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -47,24 +47,21 @@ static void postquel_end(execution_state *es);
4747
static void postquel_sub_params(execution_state *es, FunctionCallInfo fcinfo);
4848
static Datum postquel_execute(execution_state *es,
4949
FunctionCallInfo fcinfo,
50-
FunctionCachePtr fcache,
51-
List *func_tlist);
50+
FunctionCachePtr fcache);
5251

5352

54-
Datum
55-
ProjectAttribute(TupleDesc TD,
56-
TargetEntry *tlist,
57-
HeapTuple tup,
53+
static Datum
54+
ProjectAttribute(HeapTuple tup,
55+
AttrNumber attrno,
56+
TupleDesc TD,
5857
bool *isnullP)
5958
{
6059
Datum val;
61-
Var *attrVar = (Var *) tlist->expr;
62-
AttrNumber attrno = attrVar->varattno;
6360

6461
val = heap_getattr(tup, attrno, TD, isnullP);
6562

6663
if (*isnullP)
67-
return (Datum) 0;
64+
return val;
6865

6966
return datumCopy(val,
7067
TD->attrs[attrno - 1]->attbyval,
@@ -216,48 +213,37 @@ copy_function_result(FunctionCachePtr fcache,
216213
{
217214
TupleTableSlot *funcSlot;
218215
TupleDesc resultTd;
216+
HeapTuple resultTuple;
219217
HeapTuple newTuple;
220-
HeapTuple oldTuple;
221218

222219
Assert(!TupIsNull(resultSlot));
223-
oldTuple = resultSlot->val;
220+
resultTuple = resultSlot->val;
224221

225222
funcSlot = (TupleTableSlot *) fcache->funcSlot;
226223

227224
if (funcSlot == (TupleTableSlot *) NULL)
228225
return resultSlot;
229226

230-
resultTd = resultSlot->ttc_tupleDescriptor;
231-
232227
/*
233-
* When the funcSlot is NULL we have to initialize the funcSlot's
228+
* If first time through, we have to initialize the funcSlot's
234229
* tuple descriptor.
235230
*/
236231
if (TupIsNull(funcSlot))
237232
{
238-
int i = 0;
239-
TupleDesc funcTd = funcSlot->ttc_tupleDescriptor;
240-
241-
while (i < oldTuple->t_data->t_natts)
242-
{
243-
funcTd->attrs[i] = (Form_pg_attribute) palloc(ATTRIBUTE_TUPLE_SIZE);
244-
memmove(funcTd->attrs[i],
245-
resultTd->attrs[i],
246-
ATTRIBUTE_TUPLE_SIZE);
247-
i++;
248-
}
233+
resultTd = resultSlot->ttc_tupleDescriptor;
234+
funcSlot->ttc_tupleDescriptor = CreateTupleDescCopy(resultTd);
235+
funcSlot->ttc_descIsNew = true;
249236
}
250237

251-
newTuple = heap_copytuple(oldTuple);
238+
newTuple = heap_copytuple(resultTuple);
252239

253240
return ExecStoreTuple(newTuple, funcSlot, InvalidBuffer, true);
254241
}
255242

256243
static Datum
257244
postquel_execute(execution_state *es,
258245
FunctionCallInfo fcinfo,
259-
FunctionCachePtr fcache,
260-
List *func_tlist)
246+
FunctionCachePtr fcache)
261247
{
262248
TupleTableSlot *slot;
263249
Datum value;
@@ -305,27 +291,35 @@ postquel_execute(execution_state *es,
305291
* logic and code redundancy here.
306292
*/
307293
resSlot = copy_function_result(fcache, slot);
308-
if (func_tlist != NIL)
309-
{
310-
TargetEntry *tle = lfirst(func_tlist);
311294

312-
value = ProjectAttribute(resSlot->ttc_tupleDescriptor,
313-
tle,
314-
resSlot->val,
315-
&fcinfo->isnull);
316-
}
317-
else
295+
/*
296+
* If we are supposed to return a tuple, we return the tuple slot
297+
* pointer converted to Datum. If we are supposed to return a simple
298+
* value, then project out the first attribute of the result tuple
299+
* (ie, take the first result column of the final SELECT).
300+
*/
301+
if (fcache->returnsTuple)
318302
{
319-
/* XXX is this right? Return whole tuple slot?? */
303+
/*
304+
* XXX do we need to remove junk attrs from the result tuple?
305+
* Probably OK to leave them, as long as they are at the end.
306+
*/
320307
value = PointerGetDatum(resSlot);
321308
fcinfo->isnull = false;
322309
}
310+
else
311+
{
312+
value = ProjectAttribute(resSlot->val,
313+
1,
314+
resSlot->ttc_tupleDescriptor,
315+
&fcinfo->isnull);
316+
}
323317

324318
/*
325319
* If this is a single valued function we have to end the function
326320
* execution now.
327321
*/
328-
if (fcache->oneResult)
322+
if (!fcache->returnsSet)
329323
{
330324
postquel_end(es);
331325
es->status = F_EXEC_DONE;
@@ -346,7 +340,6 @@ postquel_execute(execution_state *es,
346340
Datum
347341
postquel_function(FunctionCallInfo fcinfo,
348342
FunctionCachePtr fcache,
349-
List *func_tlist,
350343
bool *isDone)
351344
{
352345
MemoryContext oldcontext;
@@ -388,10 +381,7 @@ postquel_function(FunctionCallInfo fcinfo,
388381
*/
389382
while (es != (execution_state *) NULL)
390383
{
391-
result = postquel_execute(es,
392-
fcinfo,
393-
fcache,
394-
func_tlist);
384+
result = postquel_execute(es, fcinfo, fcache);
395385
if (es->status != F_EXEC_DONE)
396386
break;
397387
es = es->next;
@@ -423,7 +413,7 @@ postquel_function(FunctionCallInfo fcinfo,
423413
*/
424414
*isDone = true;
425415
MemoryContextSwitchTo(oldcontext);
426-
return (fcache->oneResult) ? result : (Datum) NULL;
416+
return (fcache->returnsSet) ? (Datum) NULL : result;
427417
}
428418

429419
/*

0 commit comments

Comments
 (0)