1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-10 17:42:29 +03:00

Replaced targetlist entry in GroupClause by reference number

in Resdom and GroupClause so changing of resno's doesn't confuse
the grouping any more.

Jan
This commit is contained in:
Jan Wieck
1999-05-12 15:02:39 +00:00
parent 1a87c14c9c
commit 79c2576f77
22 changed files with 242 additions and 199 deletions

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_agg.c,v 1.18 1999/04/29 01:13:13 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/parse_agg.c,v 1.19 1999/05/12 15:01:48 wieck Exp $
*
*-------------------------------------------------------------------------
*/
@@ -32,8 +32,9 @@
#include "utils/lsyscache.h"
static bool contain_agg_clause(Node *clause);
static bool exprIsAggOrGroupCol(Node *expr, List *groupClause);
static bool tleIsAggOrGroupCol(TargetEntry *tle, List *groupClause);
static bool exprIsAggOrGroupCol(Node *expr, List *groupClause, List *tlist);
static bool tleIsAggOrGroupCol(TargetEntry *tle, List *groupClause,
List *tlist);
/*
* contain_agg_clause
@@ -100,7 +101,7 @@ contain_agg_clause(Node *clause)
* returns true if the expression does not contain non-group columns.
*/
static bool
exprIsAggOrGroupCol(Node *expr, List *groupClause)
exprIsAggOrGroupCol(Node *expr, List *groupClause, List *tlist)
{
List *gl;
@@ -113,7 +114,7 @@ exprIsAggOrGroupCol(Node *expr, List *groupClause)
{
GroupClause *grpcl = lfirst(gl);
if (equal(expr, grpcl->entry->expr))
if (equal(expr, get_groupclause_expr(grpcl, tlist)))
return TRUE;
}
@@ -122,7 +123,7 @@ exprIsAggOrGroupCol(Node *expr, List *groupClause)
List *temp;
foreach(temp, ((Expr *) expr)->args)
if (!exprIsAggOrGroupCol(lfirst(temp), groupClause))
if (!exprIsAggOrGroupCol(lfirst(temp), groupClause, tlist))
return FALSE;
return TRUE;
}
@@ -135,7 +136,7 @@ exprIsAggOrGroupCol(Node *expr, List *groupClause)
* returns true if the TargetEntry is Agg or GroupCol.
*/
static bool
tleIsAggOrGroupCol(TargetEntry *tle, List *groupClause)
tleIsAggOrGroupCol(TargetEntry *tle, List *groupClause, List *tlist)
{
Node *expr = tle->expr;
List *gl;
@@ -147,7 +148,7 @@ tleIsAggOrGroupCol(TargetEntry *tle, List *groupClause)
{
GroupClause *grpcl = lfirst(gl);
if (tle->resdom->resno == grpcl->entry->resdom->resno)
if (tle->resdom->resgroupref == grpcl->tleGroupref)
{
if (contain_agg_clause((Node *) expr))
elog(ERROR, "Aggregates not allowed in GROUP BY clause");
@@ -163,7 +164,7 @@ tleIsAggOrGroupCol(TargetEntry *tle, List *groupClause)
List *temp;
foreach(temp, ((Expr *) expr)->args)
if (!exprIsAggOrGroupCol(lfirst(temp), groupClause))
if (!exprIsAggOrGroupCol(lfirst(temp), groupClause, tlist))
return FALSE;
return TRUE;
}
@@ -200,7 +201,7 @@ parseCheckAggregates(ParseState *pstate, Query *qry)
{
TargetEntry *tle = lfirst(tl);
if (!tleIsAggOrGroupCol(tle, qry->groupClause))
if (!tleIsAggOrGroupCol(tle, qry->groupClause, qry->targetList))
elog(ERROR,
"Illegal use of aggregates or non-group column in target list");
}
@@ -210,7 +211,7 @@ parseCheckAggregates(ParseState *pstate, Query *qry)
* restriction as those in the target list.
*/
if (!exprIsAggOrGroupCol(qry->havingQual, qry->groupClause))
if (!exprIsAggOrGroupCol(qry->havingQual, qry->groupClause, qry->targetList))
elog(ERROR,
"Illegal use of aggregates or non-group column in HAVING clause");
return;

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.29 1999/02/23 07:46:42 thomas Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.30 1999/05/12 15:01:50 wieck Exp $
*
*-------------------------------------------------------------------------
*/
@@ -550,13 +550,19 @@ transformGroupClause(ParseState *pstate, List *grouplist, List *targetlist)
restarget = findTargetlistEntry(pstate, lfirst(grouplist), targetlist, GROUP_CLAUSE);
grpcl->entry = restarget;
resdom = restarget->resdom;
grpcl->grpOpoid = oprid(oper("<",
resdom->restype,
resdom->restype, false));
if (glist == NIL)
{
int groupref = length(glist) + 1;
restarget->resdom->resgroupref = groupref;
grpcl->tleGroupref = groupref;
gl = glist = lcons(grpcl, NIL);
}
else
{
List *i;
@@ -565,11 +571,17 @@ transformGroupClause(ParseState *pstate, List *grouplist, List *targetlist)
{
GroupClause *gcl = (GroupClause *) lfirst(i);
if (gcl->entry == grpcl->entry)
if (equal(get_groupclause_expr(gcl, targetlist),
restarget->expr))
break;
}
if (i == NIL) /* not in grouplist already */
{
int groupref = length(glist) + 1;
restarget->resdom->resgroupref = groupref;
grpcl->tleGroupref = groupref;
lnext(gl) = lcons(grpcl, NIL);
gl = lnext(gl);
}