fix for aggregates
This commit is contained in:
parent
2ae5d51668
commit
d611ccb874
@ -129,7 +129,7 @@ ExecAgg(Agg *node)
|
|||||||
econtext = aggstate->csstate.cstate.cs_ExprContext;
|
econtext = aggstate->csstate.cstate.cs_ExprContext;
|
||||||
|
|
||||||
nagg = length(node->aggs);
|
nagg = length(node->aggs);
|
||||||
|
|
||||||
value1 = node->aggstate->csstate.cstate.cs_ExprContext->ecxt_values;
|
value1 = node->aggstate->csstate.cstate.cs_ExprContext->ecxt_values;
|
||||||
nulls = node->aggstate->csstate.cstate.cs_ExprContext->ecxt_nulls;
|
nulls = node->aggstate->csstate.cstate.cs_ExprContext->ecxt_nulls;
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ ExecAgg(Agg *node)
|
|||||||
xfn2_oid,
|
xfn2_oid,
|
||||||
finalfn_oid;
|
finalfn_oid;
|
||||||
|
|
||||||
aggno++;
|
aggref->aggno = ++aggno;
|
||||||
|
|
||||||
/* ---------------------
|
/* ---------------------
|
||||||
* find transfer functions of all the aggregates and initialize
|
* find transfer functions of all the aggregates and initialize
|
||||||
@ -252,14 +252,15 @@ ExecAgg(Agg *node)
|
|||||||
TupleDesc tupType;
|
TupleDesc tupType;
|
||||||
Datum *tupValue;
|
Datum *tupValue;
|
||||||
char *null_array;
|
char *null_array;
|
||||||
|
AttrNumber attnum;
|
||||||
|
|
||||||
tupType = aggstate->csstate.css_ScanTupleSlot->ttc_tupleDescriptor;
|
tupType = aggstate->csstate.css_ScanTupleSlot->ttc_tupleDescriptor;
|
||||||
tupValue = projInfo->pi_tupValue;
|
tupValue = projInfo->pi_tupValue;
|
||||||
|
|
||||||
/* initially, set all the values to NULL */
|
/* initially, set all the values to NULL */
|
||||||
null_array = palloc(sizeof(char) * tupType->natts);
|
null_array = palloc(sizeof(char) * tupType->natts);
|
||||||
for (aggno = 0; aggno < tupType->natts; aggno++)
|
for (attnum = 0; attnum < tupType->natts; attnum++)
|
||||||
null_array[aggno] = 'n';
|
null_array[attnum] = 'n';
|
||||||
oneTuple = heap_formtuple(tupType, tupValue, null_array);
|
oneTuple = heap_formtuple(tupType, tupValue, null_array);
|
||||||
pfree(null_array);
|
pfree(null_array);
|
||||||
}
|
}
|
||||||
@ -328,8 +329,8 @@ ExecAgg(Agg *node)
|
|||||||
attnum = ((Var *) aggref->target)->varattno;
|
attnum = ((Var *) aggref->target)->varattno;
|
||||||
attlen = outerslot->ttc_tupleDescriptor->attrs[attnum - 1]->attlen;
|
attlen = outerslot->ttc_tupleDescriptor->attrs[attnum - 1]->attlen;
|
||||||
byVal = outerslot->ttc_tupleDescriptor->attrs[attnum - 1]->attbyval;
|
byVal = outerslot->ttc_tupleDescriptor->attrs[attnum - 1]->attbyval;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case T_Expr:
|
case T_Expr:
|
||||||
{
|
{
|
||||||
FunctionCachePtr fcache_ptr;
|
FunctionCachePtr fcache_ptr;
|
||||||
@ -340,8 +341,8 @@ ExecAgg(Agg *node)
|
|||||||
fcache_ptr = ((Oper *) tagnode)->op_fcache;
|
fcache_ptr = ((Oper *) tagnode)->op_fcache;
|
||||||
attlen = fcache_ptr->typlen;
|
attlen = fcache_ptr->typlen;
|
||||||
byVal = fcache_ptr->typbyval;
|
byVal = fcache_ptr->typbyval;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
case T_Const:
|
case T_Const:
|
||||||
attlen = ((Const *) aggref->target)->constlen;
|
attlen = ((Const *) aggref->target)->constlen;
|
||||||
@ -371,10 +372,8 @@ ExecAgg(Agg *node)
|
|||||||
*/
|
*/
|
||||||
args[0] = value1[aggno];
|
args[0] = value1[aggno];
|
||||||
args[1] = newVal;
|
args[1] = newVal;
|
||||||
value1[aggno] =
|
value1[aggno] = (Datum) fmgr_c(&aggfns->xfn1,
|
||||||
(Datum) fmgr_c(&aggfns->xfn1,
|
(FmgrValues *) args, &isNull1);
|
||||||
(FmgrValues *) args,
|
|
||||||
&isNull1);
|
|
||||||
Assert(!isNull1);
|
Assert(!isNull1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -383,8 +382,7 @@ ExecAgg(Agg *node)
|
|||||||
{
|
{
|
||||||
Datum xfn2_val = value2[aggno];
|
Datum xfn2_val = value2[aggno];
|
||||||
|
|
||||||
value2[aggno] =
|
value2[aggno] = (Datum) fmgr_c(&aggfns->xfn2,
|
||||||
(Datum) fmgr_c(&aggfns->xfn2,
|
|
||||||
(FmgrValues *) &xfn2_val, &isNull2);
|
(FmgrValues *) &xfn2_val, &isNull2);
|
||||||
Assert(!isNull2);
|
Assert(!isNull2);
|
||||||
}
|
}
|
||||||
@ -481,9 +479,8 @@ ExecAgg(Agg *node)
|
|||||||
* As long as the retrieved group does not match the
|
* As long as the retrieved group does not match the
|
||||||
* qualifications it is ignored and the next group is fetched
|
* qualifications it is ignored and the next group is fetched
|
||||||
*/
|
*/
|
||||||
if(node->plan.qual != NULL){
|
if(node->plan.qual != NULL)
|
||||||
qual_result = ExecQual(fix_opids(node->plan.qual), econtext);
|
qual_result = ExecQual(fix_opids(node->plan.qual), econtext);
|
||||||
}
|
|
||||||
else qual_result = false;
|
else qual_result = false;
|
||||||
|
|
||||||
if (oneTuple)
|
if (oneTuple)
|
||||||
@ -523,8 +520,7 @@ ExecInitAgg(Agg *node, EState *estate, Plan *parent)
|
|||||||
/*
|
/*
|
||||||
* assign node's base id and create expression context
|
* assign node's base id and create expression context
|
||||||
*/
|
*/
|
||||||
ExecAssignNodeBaseInfo(estate, &aggstate->csstate.cstate,
|
ExecAssignNodeBaseInfo(estate, &aggstate->csstate.cstate, (Plan *) parent);
|
||||||
(Plan *) parent);
|
|
||||||
ExecAssignExprContext(estate, &aggstate->csstate.cstate);
|
ExecAssignExprContext(estate, &aggstate->csstate.cstate);
|
||||||
|
|
||||||
#define AGG_NSLOTS 2
|
#define AGG_NSLOTS 2
|
||||||
@ -536,8 +532,7 @@ ExecInitAgg(Agg *node, EState *estate, Plan *parent)
|
|||||||
ExecInitResultTupleSlot(estate, &aggstate->csstate.cstate);
|
ExecInitResultTupleSlot(estate, &aggstate->csstate.cstate);
|
||||||
|
|
||||||
econtext = aggstate->csstate.cstate.cs_ExprContext;
|
econtext = aggstate->csstate.cstate.cs_ExprContext;
|
||||||
econtext->ecxt_values =
|
econtext->ecxt_values = (Datum *) palloc(sizeof(Datum) * length(node->aggs));
|
||||||
(Datum *) palloc(sizeof(Datum) * length(node->aggs));
|
|
||||||
MemSet(econtext->ecxt_values, 0, sizeof(Datum) * length(node->aggs));
|
MemSet(econtext->ecxt_values, 0, sizeof(Datum) * length(node->aggs));
|
||||||
econtext->ecxt_nulls = (char *) palloc(sizeof(char) * length(node->aggs));
|
econtext->ecxt_nulls = (char *) palloc(sizeof(char) * length(node->aggs));
|
||||||
MemSet(econtext->ecxt_nulls, 0, sizeof(char) * length(node->aggs));
|
MemSet(econtext->ecxt_nulls, 0, sizeof(char) * length(node->aggs));
|
||||||
@ -665,8 +660,7 @@ aggGetAttr(TupleTableSlot *slot,
|
|||||||
return (Datum) tempSlot;
|
return (Datum) tempSlot;
|
||||||
}
|
}
|
||||||
|
|
||||||
result =
|
result = heap_getattr(heapTuple, /* tuple containing attribute */
|
||||||
heap_getattr(heapTuple, /* tuple containing attribute */
|
|
||||||
attnum, /* attribute number of desired attribute */
|
attnum, /* attribute number of desired attribute */
|
||||||
tuple_type,/* tuple descriptor of tuple */
|
tuple_type,/* tuple descriptor of tuple */
|
||||||
isNull); /* return: is attribute null? */
|
isNull); /* return: is attribute null? */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user