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

Commit62e29fe

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 newexpression node type FieldSelect that implements the functionality whereit's actually needed. Clean up some other unused fields in Func nodesas well.NOTE: initdb forced due to change in stored expression trees for rules.
1 parent8fc3237 commit62e29fe

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
AttrNumberattnum;
295295
HeapTupleheapTuple;
296296
TupleDesctuple_type;
297-
boolbyval;
298-
int16len;
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
returnresult;
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-
HeapTupletup;
531-
Datumvalue;
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-
returnvalue;
540-
}
490+
*isNull=paramList->isnull;
541491
returnparamList->value;
542492
}
543493

@@ -686,7 +636,6 @@ ExecMakeFunctionResult(Node *node,
686636
{
687637
FunctionCallInfoDatafcinfo;
688638
FunctionCachePtrfcache;
689-
List*ftlist;
690639
boolfuncisset;
691640
Datumresult;
692641
boolargDone;
@@ -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+
staticDatum
1171+
ExecEvalFieldSelect(FieldSelect*fselect,
1172+
ExprContext*econtext,
1173+
bool*isNull,
1174+
bool*isDone)
1175+
{
1176+
Datumresult;
1177+
TupleTableSlot*resSlot;
1178+
1179+
result=ExecEvalExpr(fselect->arg,econtext,isNull,isDone);
1180+
if (*isNull)
1181+
returnresult;
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+
returnresult;
1190+
}
1191+
12171192
/* ----------------------------------------------------------------
12181193
*ExecEvalExpr
12191194
*
@@ -1319,6 +1294,12 @@ ExecEvalExpr(Node *expression,
13191294
}
13201295
break;
13211296
}
1297+
caseT_FieldSelect:
1298+
retDatum=ExecEvalFieldSelect((FieldSelect*)expression,
1299+
econtext,
1300+
isNull,
1301+
isDone);
1302+
break;
13221303
caseT_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
staticvoidpostquel_sub_params(execution_state*es,FunctionCallInfofcinfo);
4848
staticDatumpostquel_execute(execution_state*es,
4949
FunctionCallInfofcinfo,
50-
FunctionCachePtrfcache,
51-
List*func_tlist);
50+
FunctionCachePtrfcache);
5251

5352

54-
Datum
55-
ProjectAttribute(TupleDescTD,
56-
TargetEntry*tlist,
57-
HeapTupletup,
53+
staticDatum
54+
ProjectAttribute(HeapTupletup,
55+
AttrNumberattrno,
56+
TupleDescTD,
5857
bool*isnullP)
5958
{
6059
Datumval;
61-
Var*attrVar= (Var*)tlist->expr;
62-
AttrNumberattrno=attrVar->varattno;
6360

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

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

6966
returndatumCopy(val,
7067
TD->attrs[attrno-1]->attbyval,
@@ -216,48 +213,37 @@ copy_function_result(FunctionCachePtr fcache,
216213
{
217214
TupleTableSlot*funcSlot;
218215
TupleDescresultTd;
216+
HeapTupleresultTuple;
219217
HeapTuplenewTuple;
220-
HeapTupleoldTuple;
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
returnresultSlot;
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-
inti=0;
239-
TupleDescfuncTd=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
returnExecStoreTuple(newTuple,funcSlot,InvalidBuffer, true);
254241
}
255242

256243
staticDatum
257244
postquel_execute(execution_state*es,
258245
FunctionCallInfofcinfo,
259-
FunctionCachePtrfcache,
260-
List*func_tlist)
246+
FunctionCachePtrfcache)
261247
{
262248
TupleTableSlot*slot;
263249
Datumvalue;
@@ -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(FunctionCallInfofcinfo,
348342
FunctionCachePtrfcache,
349-
List*func_tlist,
350343
bool*isDone)
351344
{
352345
MemoryContextoldcontext;
@@ -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)

[8]ページ先頭

©2009-2025 Movatter.jp