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

Commitfd31563

Browse files
committed
Aggregate functions didn't work on subscripted array references.
Things are better now.
1 parent970583a commitfd31563

File tree

2 files changed

+25
-70
lines changed

2 files changed

+25
-70
lines changed

‎src/backend/executor/nodeAgg.c

Lines changed: 23 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -275,34 +275,21 @@ ExecAgg(Agg *node)
275275
foreach(alist,node->aggs)
276276
{
277277
Aggref*aggref=lfirst(alist);
278-
AttrNumberattnum;
279-
DatumnewVal= (Datum)NULL;
280278
AggFuncInfo*aggfns=&aggFuncInfo[++aggno];
279+
DatumnewVal;
281280
Datumargs[2];
282-
Node*tagnode=NULL;
283281

284-
switch (nodeTag(aggref->target))
282+
/* Do we really need the special case for Var here? */
283+
if (IsA(aggref->target,Var))
285284
{
286-
caseT_Var:
287-
tagnode=NULL;
288-
newVal=aggGetAttr(outerslot,
289-
aggref,
290-
&isNull);
291-
break;
292-
caseT_Expr:
293-
tagnode= ((Expr*)aggref->target)->oper;
294-
econtext->ecxt_scantuple=outerslot;
295-
newVal=ExecEvalExpr(aggref->target,econtext,
296-
&isNull,&isDone);
297-
break;
298-
caseT_Const:
299-
tagnode=NULL;
300-
econtext->ecxt_scantuple=outerslot;
301-
newVal=ExecEvalExpr(aggref->target,econtext,
302-
&isNull,&isDone);
303-
break;
304-
default:
305-
elog(ERROR,"ExecAgg: Bad Agg->Target for Agg %d",aggno);
285+
newVal=aggGetAttr(outerslot,aggref,
286+
&isNull);
287+
}
288+
else
289+
{
290+
econtext->ecxt_scantuple=outerslot;
291+
newVal=ExecEvalExpr(aggref->target,econtext,
292+
&isNull,&isDone);
306293
}
307294

308295
if (isNull&& !aggref->usenulls)
@@ -312,50 +299,22 @@ ExecAgg(Agg *node)
312299
{
313300
if (noInitValue[aggno])
314301
{
315-
intattlen=0;
316-
intbyVal=0;
317-
318-
/*
319-
* value1 and value2 has not been initialized.
320-
* This is the first non-NULL value. We use it as
321-
* the initial value.
322-
*/
323-
324302
/*
325-
* but we can't just use it straight, we have to
303+
* value1 has not been initialized.
304+
* This is the first non-NULL input value.
305+
* We use it as the initial value for value1.
306+
*
307+
* But we can't just use it straight, we have to
326308
* make a copy of it since the tuple from which it
327309
* came will be freed on the next iteration of the
328-
* scan
310+
* scan. This requires finding out how to copy
311+
* the Datum. We assume the datum is of the agg's
312+
* basetype, or at least binary compatible with it.
329313
*/
330-
switch (nodeTag(aggref->target))
331-
{
332-
caseT_Var:
333-
attnum= ((Var*)aggref->target)->varattno;
334-
attlen=outerslot->ttc_tupleDescriptor->attrs[attnum-1]->attlen;
335-
byVal=outerslot->ttc_tupleDescriptor->attrs[attnum-1]->attbyval;
336-
break;
337-
338-
caseT_Expr:
339-
{
340-
FunctionCachePtrfcache_ptr;
341-
342-
if (nodeTag(tagnode)==T_Func)
343-
fcache_ptr= ((Func*)tagnode)->func_fcache;
344-
else
345-
fcache_ptr= ((Oper*)tagnode)->op_fcache;
346-
attlen=fcache_ptr->typlen;
347-
byVal=fcache_ptr->typbyval;
348-
break;
349-
350-
}
351-
caseT_Const:
352-
attlen= ((Const*)aggref->target)->constlen;
353-
byVal= ((Const*)aggref->target)->constbyval;
354-
355-
break;
356-
default:
357-
elog(ERROR,"ExecAgg: Bad Agg->Target for Agg %d",aggno);
358-
}
314+
TypeaggBaseType=typeidType(aggref->basetype);
315+
intattlen=typeLen(aggBaseType);
316+
boolbyVal=typeByVal(aggBaseType);
317+
359318
if (byVal)
360319
value1[aggno]=newVal;
361320
else

‎src/backend/parser/parse_agg.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_agg.c,v 1.17 1999/02/13 23:17:06 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_agg.c,v 1.18 1999/04/29 01:13:13 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -305,11 +305,7 @@ ParseAgg(ParseState *pstate, char *aggname, Oid basetype,
305305
if (OidIsValid(xfn1))
306306
{
307307
basetype=aggform->aggbasetype;
308-
if (nodeTag(lfirst(target))==T_Var)
309-
vartype= ((Var*)lfirst(target))->vartype;
310-
else
311-
vartype= ((Expr*)lfirst(target))->typeOid;
312-
308+
vartype=exprType(lfirst(target));
313309
if ((basetype!=vartype)
314310
&& (!IS_BINARY_COMPATIBLE(basetype,vartype)))
315311
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp