*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.40 1999/01/24 00:28:18 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.41 1999/01/25 18:02:13 momjian Exp $
*
*-------------------------------------------------------------------------
*/
int execConstLen;
/* static functions decls */
-static Datum ExecEvalAggref(Aggref *agg, ExprContext *econtext, bool *isNull);
+static Datum ExecEvalAggref(Aggref *aggref, ExprContext *econtext, bool *isNull);
static Datum ExecEvalArrayRef(ArrayRef *arrayRef, ExprContext *econtext,
bool *isNull, bool *isDone);
static Datum ExecEvalAnd(Expr *andExpr, ExprContext *econtext, bool *isNull);
* ----------------------------------------------------------------
*/
static Datum
-ExecEvalAggref(Aggref *agg, ExprContext *econtext, bool *isNull)
+ExecEvalAggref(Aggref *aggref, ExprContext *econtext, bool *isNull)
{
- *isNull = econtext->ecxt_nulls[agg->aggno];
- return econtext->ecxt_values[agg->aggno];
+ *isNull = econtext->ecxt_nulls[aggref->aggno];
+ return econtext->ecxt_values[aggref->aggno];
}
/* ----------------------------------------------------------------
FmgrInfo finalfn;
} AggFuncInfo;
-static Datum aggGetAttr(TupleTableSlot *tuple, Aggref *agg, bool *isNull);
+static Datum aggGetAttr(TupleTableSlot *tuple, Aggref *aggref, bool *isNull);
/* ---------------------------------------
{
AggState *aggstate;
EState *estate;
- Aggref **aggregates;
Plan *outerPlan;
- int i,
+ int aggno,
nagg;
Datum *value1,
*value2;
*/
do
{
-
aggstate = node->aggstate;
if (aggstate->agg_done)
return NULL;
nagg = length(node->aggs);
- aggregates = (Aggref **) palloc(sizeof(Aggref *) * nagg);
-
- /* take List* and make it an array that can be quickly indexed */
- alist = node->aggs;
- for (i = 0; i < nagg; i++)
- {
- aggregates[i] = lfirst(alist);
- aggregates[i]->aggno = i;
- alist = lnext(alist);
- }
-
value1 = node->aggstate->csstate.cstate.cs_ExprContext->ecxt_values;
nulls = node->aggstate->csstate.cstate.cs_ExprContext->ecxt_nulls;
projInfo = aggstate->csstate.cstate.cs_ProjInfo;
- for (i = 0; i < nagg; i++)
+ aggno = 0;
+ foreach(alist, node->aggs)
{
- Aggref *agg;
+ Aggref *aggref = lfirst(alist);
char *aggname;
HeapTuple aggTuple;
Form_pg_aggregate aggp;
xfn2_oid,
finalfn_oid;
- agg = aggregates[i];
-
/* ---------------------
* find transfer functions of all the aggregates and initialize
* their initial values
* ---------------------
*/
- aggname = agg->aggname;
+ aggname = aggref->aggname;
aggTuple = SearchSysCacheTuple(AGGNAME,
PointerGetDatum(aggname),
- ObjectIdGetDatum(agg->basetype),
+ ObjectIdGetDatum(aggref->basetype),
0, 0);
if (!HeapTupleIsValid(aggTuple))
elog(ERROR, "ExecAgg: cache lookup failed for aggregate \"%s\"(%s)",
aggname,
- typeidTypeName(agg->basetype));
+ typeidTypeName(aggref->basetype));
aggp = (Form_pg_aggregate) GETSTRUCT(aggTuple);
xfn1_oid = aggp->aggtransfn1;
if (OidIsValid(finalfn_oid))
{
- fmgr_info(finalfn_oid, &aggFuncInfo[i].finalfn);
- aggFuncInfo[i].finalfn_oid = finalfn_oid;
+ fmgr_info(finalfn_oid, &aggFuncInfo[aggno].finalfn);
+ aggFuncInfo[aggno].finalfn_oid = finalfn_oid;
}
if (OidIsValid(xfn2_oid))
{
- fmgr_info(xfn2_oid, &aggFuncInfo[i].xfn2);
- aggFuncInfo[i].xfn2_oid = xfn2_oid;
- value2[i] = (Datum) AggNameGetInitVal((char *) aggname,
+ fmgr_info(xfn2_oid, &aggFuncInfo[aggno].xfn2);
+ aggFuncInfo[aggno].xfn2_oid = xfn2_oid;
+ value2[aggno] = (Datum) AggNameGetInitVal((char *) aggname,
aggp->aggbasetype,
2,
&isNull2);
if (OidIsValid(xfn1_oid))
{
- fmgr_info(xfn1_oid, &aggFuncInfo[i].xfn1);
- aggFuncInfo[i].xfn1_oid = xfn1_oid;
- value1[i] = (Datum) AggNameGetInitVal((char *) aggname,
+ fmgr_info(xfn1_oid, &aggFuncInfo[aggno].xfn1);
+ aggFuncInfo[aggno].xfn1_oid = xfn1_oid;
+ value1[aggno] = (Datum) AggNameGetInitVal((char *) aggname,
aggp->aggbasetype,
1,
&isNull1);
*/
if (isNull1)
{
- noInitValue[i] = 1;
- nulls[i] = 1;
+ noInitValue[aggno] = 1;
+ nulls[aggno] = 1;
}
}
+ aggno++;
}
/* ----------------
/* initially, set all the values to NULL */
null_array = palloc(tupType->natts);
- for (i = 0; i < tupType->natts; i++)
- null_array[i] = 'n';
+ for (aggno = 0; aggno < tupType->natts; aggno++)
+ null_array[aggno] = 'n';
oneTuple = heap_formtuple(tupType, tupValue, null_array);
pfree(null_array);
}
break;
}
- for (i = 0; i < nagg; i++)
+ aggno = 0;
+ foreach(alist, node->aggs)
{
+ Aggref *aggref = lfirst(alist);
AttrNumber attnum;
int2 attlen = 0;
Datum newVal = (Datum) NULL;
- AggFuncInfo *aggfns = &aggFuncInfo[i];
+ AggFuncInfo *aggfns = &aggFuncInfo[aggno];
Datum args[2];
Node *tagnode = NULL;
- switch (nodeTag(aggregates[i]->target))
+ switch (nodeTag(aggref->target))
{
case T_Var:
tagnode = NULL;
newVal = aggGetAttr(outerslot,
- aggregates[i],
+ aggref,
&isNull);
break;
case T_Expr:
- tagnode = ((Expr *) aggregates[i]->target)->oper;
+ tagnode = ((Expr *) aggref->target)->oper;
econtext->ecxt_scantuple = outerslot;
- newVal = ExecEvalExpr(aggregates[i]->target, econtext,
+ newVal = ExecEvalExpr(aggref->target, econtext,
&isNull, &isDone);
break;
case T_Const:
tagnode = NULL;
econtext->ecxt_scantuple = outerslot;
- newVal = ExecEvalExpr(aggregates[i]->target, econtext,
+ newVal = ExecEvalExpr(aggref->target, econtext,
&isNull, &isDone);
break;
default:
- elog(ERROR, "ExecAgg: Bad Agg->Target for Agg %d", i);
+ elog(ERROR, "ExecAgg: Bad Agg->Target for Agg %d", aggno);
}
- if (isNull && !aggregates[i]->usenulls)
+ if (isNull && !aggref->usenulls)
continue; /* ignore this tuple for this agg */
if (aggfns->xfn1.fn_addr != NULL)
{
- if (noInitValue[i])
+ if (noInitValue[aggno])
{
int byVal = 0;
* came will be freed on the next iteration of the
* scan
*/
- switch (nodeTag(aggregates[i]->target))
+ switch (nodeTag(aggref->target))
{
case T_Var:
- attnum = ((Var *) aggregates[i]->target)->varattno;
+ attnum = ((Var *) aggref->target)->varattno;
attlen = outerslot->ttc_tupleDescriptor->attrs[attnum - 1]->attlen;
byVal = outerslot->ttc_tupleDescriptor->attrs[attnum - 1]->attbyval;
break;
}
case T_Const:
- attlen = ((Const *) aggregates[i]->target)->constlen;
- byVal = ((Const *) aggregates[i]->target)->constbyval;
+ attlen = ((Const *) aggref->target)->constlen;
+ byVal = ((Const *) aggref->target)->constbyval;
break;
default:
- elog(ERROR, "ExecAgg: Bad Agg->Target for Agg %d", i);
+ elog(ERROR, "ExecAgg: Bad Agg->Target for Agg %d", aggno);
}
if (attlen == -1)
{
/* variable length */
attlen = VARSIZE((struct varlena *) newVal);
}
- value1[i] = (Datum) palloc(attlen);
+ value1[aggno] = (Datum) palloc(attlen);
if (byVal)
- value1[i] = newVal;
+ value1[aggno] = newVal;
else
- memmove((char *) (value1[i]), (char *) newVal, attlen);
- noInitValue[i] = 0;
- nulls[i] = 0;
+ memmove((char *) (value1[aggno]), (char *) newVal, attlen);
+ noInitValue[aggno] = 0;
+ nulls[aggno] = 0;
}
else
{
-
/*
* apply the transition functions.
*/
- args[0] = value1[i];
+ args[0] = value1[aggno];
args[1] = newVal;
- value1[i] =
+ value1[aggno] =
(Datum) fmgr_c(&aggfns->xfn1,
(FmgrValues *) args,
&isNull1);
if (aggfns->xfn2.fn_addr != NULL)
{
- Datum xfn2_val = value2[i];
+ Datum xfn2_val = value2[aggno];
- value2[i] =
+ value2[aggno] =
(Datum) fmgr_c(&aggfns->xfn2,
(FmgrValues *) &xfn2_val, &isNull2);
Assert(!isNull2);
}
+ aggno++;
}
/*
* finalize the aggregate (if necessary), and get the resultant value
* --------------
*/
- for (i = 0; i < nagg; i++)
+
+ aggno = 0;
+ foreach(alist, node->aggs)
{
char *args[2];
- AggFuncInfo *aggfns = &aggFuncInfo[i];
+ AggFuncInfo *aggfns = &aggFuncInfo[aggno];
- if (noInitValue[i])
+ if (noInitValue[aggno])
{
/*
{
if (aggfns->finalfn.fn_nargs > 1)
{
- args[0] = (char *) value1[i];
- args[1] = (char *) value2[i];
+ args[0] = (char *) value1[aggno];
+ args[1] = (char *) value2[aggno];
}
else if (aggfns->xfn1.fn_addr != NULL)
- args[0] = (char *) value1[i];
+ args[0] = (char *) value1[aggno];
else if (aggfns->xfn2.fn_addr != NULL)
- args[0] = (char *) value2[i];
+ args[0] = (char *) value2[aggno];
else
elog(NOTICE, "ExecAgg: no valid transition functions??");
- value1[i] = (Datum) fmgr_c(&aggfns->finalfn,
- (FmgrValues *) args, &(nulls[i]));
+ value1[aggno] = (Datum) fmgr_c(&aggfns->finalfn,
+ (FmgrValues *) args, &(nulls[aggno]));
}
else if (aggfns->xfn1.fn_addr != NULL)
{
*/
}
else if (aggfns->xfn2.fn_addr != NULL)
- value1[i] = value2[i];
+ value1[aggno] = value2[aggno];
else
elog(ERROR, "ExecAgg: no valid transition functions??");
+ aggno++;
}
/*
if(node->plan.qual != NULL){
qual_result = ExecQual(fix_opids(node->plan.qual), econtext);
}
+ else qual_result = false;
if (oneTuple)
pfree(oneTuple);
}
- while ((node->plan.qual != NULL) && (qual_result != true));
+ while (node->plan.qual != NULL && qual_result != true);
return resultSlot;
}
AggState *aggstate;
Plan *outerPlan;
ExprContext *econtext;
-
+
/*
* assign the node's execution state
*/
aggstate = makeNode(AggState);
node->aggstate = aggstate;
aggstate->agg_done = FALSE;
-
+
/*
* assign node's base id and create expression context
*/
*/
static Datum
aggGetAttr(TupleTableSlot *slot,
- Aggref *agg,
+ Aggref *aggref,
bool *isNull)
{
Datum result;
tuple_type = slot->ttc_tupleDescriptor;
buffer = slot->ttc_buffer;
- attnum = ((Var *) agg->target)->varattno;
+ attnum = ((Var *) aggref->target)->varattno;
/*
* If the attribute number is invalid, then we are supposed to return
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.54 1999/01/24 00:28:19 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.55 1999/01/25 18:02:14 momjian Exp $
*
*-------------------------------------------------------------------------
*/
CopyPlanFields((Plan *) from, (Plan *) newnode);
- newnode->aggs = set_agg_tlist_references(newnode);
+ newnode->aggs = get_agg_tlist_references(newnode);
Node_Copy(from, newnode, aggstate);
return newnode;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.37 1999/01/25 12:01:04 vadim Exp $
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.38 1999/01/25 18:02:15 momjian Exp $
*
*-------------------------------------------------------------------------
*/
{
int old_length=0, new_length=0;
- /* Create the AGG node but use 'tlist' not 'new_tlist' as target list because we
+ /* Create the Agg node but use 'tlist' not 'new_tlist' as target list because we
* don't want the additional attributes (only used for the havingQual, see above)
* to show up in the result */
result_plan = (Plan *) make_agg(tlist, result_plan);
* the result tuple of the subplans.
*/
((Agg *) result_plan)->aggs =
- set_agg_tlist_references((Agg *) result_plan);
+ get_agg_tlist_references((Agg *) result_plan);
/***S*H***/
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.32 1999/01/24 00:28:20 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.33 1999/01/25 18:02:18 momjian Exp $
*
*-------------------------------------------------------------------------
*/
/*---------------------------------------------------------
*
- * set_agg_tlist_references -
+ * get_agg_tlist_references -
* changes the target list of an Agg node so that it points to
* the tuples returned by its left tree subplan.
*
*
*/
List *
-set_agg_tlist_references(Agg *aggNode)
+get_agg_tlist_references(Agg *aggNode)
{
List *aggTargetList;
List *subplanTargetList;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/rewrite/Attic/locks.c,v 1.15 1999/01/24 00:28:30 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/rewrite/Attic/locks.c,v 1.16 1999/01/25 18:02:18 momjian Exp $
*
*-------------------------------------------------------------------------
*/
break;
case T_Aggref:
{
- Aggref *agg = (Aggref *) node;
+ Aggref *aggref = (Aggref *) node;
- return nodeThisLockWasTriggered(agg->target, varno, attnum,
+ return nodeThisLockWasTriggered(aggref->target, varno, attnum,
sublevels_up);
}
break;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.31 1999/01/25 12:01:14 vadim Exp $
+ * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.32 1999/01/25 18:02:20 momjian Exp $
*
*-------------------------------------------------------------------------
*/
case T_Aggref:
{
- Aggref *agg = (Aggref *)node;
+ Aggref *aggref = (Aggref *)node;
return rangeTableEntry_used(
- (Node *)(agg->target),
+ (Node *)(aggref->target),
rt_index,
sublevels_up);
}
case T_Aggref:
{
- Aggref *agg = (Aggref *)node;
+ Aggref *aggref = (Aggref *)node;
return attribute_used(
- (Node *)(agg->target),
+ (Node *)(aggref->target),
rt_index,
attno,
sublevels_up);
case T_Aggref:
{
- Aggref *agg = (Aggref *)node;
+ Aggref *aggref = (Aggref *)node;
modifyAggrefUplevel(
- (Node *)(agg->target));
+ (Node *)(aggref->target));
}
break;
case T_Aggref:
{
- Aggref *agg = (Aggref *)node;
+ Aggref *aggref = (Aggref *)node;
modifyAggrefChangeVarnodes(
- (Node **)(&(agg->target)),
+ (Node **)(&(aggref->target)),
rt_index,
new_index,
sublevels_up);
case T_Aggref:
{
- Aggref *agg = (Aggref *)node;
- Aggref *oagg = (Aggref *)orignode;
+ Aggref *aggref = (Aggref *)node;
+ Aggref *oaggref = (Aggref *)orignode;
modifyAggrefDropQual(
- (Node **)(&(agg->target)),
- (Node *)(oagg->target),
+ (Node **)(&(aggref->target)),
+ (Node *)(oaggref->target),
expr);
}
break;
case T_Aggref:
{
- Aggref *agg = (Aggref *)node;
+ Aggref *aggref = (Aggref *)node;
apply_RIR_adjust_sublevel(
- (Node *)(agg->target),
+ (Node *)(aggref->target),
sublevels_up);
}
break;
case T_Aggref:
{
- Aggref *agg = (Aggref *)node;
+ Aggref *aggref = (Aggref *)node;
apply_RIR_view(
- (Node **)(&(agg->target)),
+ (Node **)(&(aggref->target)),
rt_index,
rte,
tlist,
case T_Aggref:
{
- Aggref *agg = (Aggref *)node;
+ Aggref *aggref = (Aggref *)node;
fireRIRonSubselect(
- (Node *)(agg->target));
+ (Node *)(aggref->target));
}
break;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteManip.c,v 1.25 1999/01/24 00:28:31 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteManip.c,v 1.26 1999/01/25 18:02:22 momjian Exp $
*
*-------------------------------------------------------------------------
*/
case T_Aggref:
{
- Aggref *agg = (Aggref *)node;
+ Aggref *aggref = (Aggref *)node;
OffsetVarNodes(
- (Node *)(agg->target),
+ (Node *)(aggref->target),
offset,
sublevels_up);
}
case T_Aggref:
{
- Aggref *agg = (Aggref *)node;
+ Aggref *aggref = (Aggref *)node;
ChangeVarNodes(
- (Node *)(agg->target),
+ (Node *)(aggref->target),
rt_index,
new_index,
sublevels_up);
break;
case T_Aggref:
{
- Aggref *agg = (Aggref *) node;
+ Aggref *aggref = (Aggref *) node;
- nodeHandleRIRAttributeRule(&agg->target, rtable, targetlist,
+ nodeHandleRIRAttributeRule(&aggref->target, rtable, targetlist,
rt_index, attr_num, modified, badsql,
sublevels_up);
}
break;
case T_Aggref:
{
- Aggref *agg = (Aggref *) node;
+ Aggref *aggref = (Aggref *) node;
- nodeHandleViewRule(&(agg->target), rtable, targetlist,
+ nodeHandleViewRule(&(aggref->target), rtable, targetlist,
rt_index, modified, sublevels_up);
}
break;
* out of it's tuple
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.7 1999/01/24 00:28:32 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.8 1999/01/25 18:02:23 momjian Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
case T_Aggref:
{
- Aggref *agg = (Aggref *) node;
+ Aggref *aggref = (Aggref *) node;
strcat(buf, "\"");
- strcat(buf, agg->aggname);
+ strcat(buf, aggref->aggname);
strcat(buf, "\"(");
strcat(buf, get_rule_expr(qh, rt_index,
- (Node *) (agg->target), varprefix));
+ (Node *) (aggref->target), varprefix));
strcat(buf, ")");
return pstrdup(buf);
}
case T_Aggref:
{
- Aggref *agg = (Aggref *) node;
+ Aggref *aggref = (Aggref *) node;
return check_if_rte_used(rt_index,
- (Node *) (agg->target), sup);
+ (Node *) (aggref->target), sup);
}
break;
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: planmain.h,v 1.17 1998/10/08 18:30:34 momjian Exp $
+ * $Id: planmain.h,v 1.18 1999/01/25 18:02:28 momjian Exp $
*
*-------------------------------------------------------------------------
*/
List *inner_tlist);
extern List *index_outerjoin_references(List *inner_indxqual,
List *outer_tlist, Index inner_relid);
-extern List *set_agg_tlist_references(Agg *aggNode);
+extern List *get_agg_tlist_references(Agg *aggNode);
extern void set_agg_agglist_references(Agg *aggNode);
extern void del_agg_tlist_references(List *tlist);
extern List *check_having_qual_for_aggs(Node *clause,
SELECT ('current'::datetime = 'now'::datetime) as "True";
SELECT ('now'::datetime - 'current'::datetime) AS "ZeroSecs";
+SET DateStyle = 'Postgres,noneuropean';
+SELECT datetime('1994-01-01', '11:00') AS "Jan_01_1994_11am";
+
CREATE TABLE DATETIME_TBL( d1 datetime);
INSERT INTO DATETIME_TBL VALUES ('current');