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

Commit9a2949e

Browse files
committed
Fix using GroupBy/non-GroupBy expressions in HAVING.
1 parent04abb54 commit9a2949e

File tree

3 files changed

+6
-54
lines changed

3 files changed

+6
-54
lines changed

‎src/backend/optimizer/plan/planner.c

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.34 1998/09/08 02:50:20 vadim Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.35 1998/09/09 03:48:01 vadim Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -185,9 +185,6 @@ union_planner(Query *parse)
185185
*/
186186
if (parse->hasAggs)
187187
{
188-
intold_length=0,
189-
new_length=0;
190-
191188
result_plan= (Plan*)make_agg(tlist,result_plan);
192189

193190
/*
@@ -256,31 +253,10 @@ union_planner(Query *parse)
256253
*/
257254
foreach(clause, ((Agg*)result_plan)->plan.qual)
258255
{
259-
260-
/*
261-
* Make sure there are aggregates in the havingQual if so,
262-
* the list must be longer after
263-
* check_having_qual_for_aggs
264-
*/
265-
old_length=length(((Agg*)result_plan)->aggs);
266-
267256
((Agg*)result_plan)->aggs=nconc(((Agg*)result_plan)->aggs,
268257
check_having_qual_for_aggs((Node*)lfirst(clause),
269258
((Agg*)result_plan)->plan.lefttree->targetlist,
270259
((List*)parse->groupClause)));
271-
272-
/*
273-
* Have a look at the length of the returned list. If
274-
* there is no difference, no aggregates have been found
275-
* and that means, that the Qual belongs to the where
276-
* clause
277-
*/
278-
if (((new_length=length(((Agg*)result_plan)->aggs))==old_length)||
279-
(new_length==0))
280-
{
281-
elog(ERROR,"This could have been done in a where clause!!");
282-
return (Plan*)NIL;
283-
}
284260
}
285261
PlannerVarParam=lnext(PlannerVarParam);
286262
if (vpm!=NULL)

‎src/backend/optimizer/plan/setrefs.c

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.26 1998/09/01 04:29:54 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.27 1998/09/09 03:48:02 vadim Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1045,36 +1045,15 @@ check_having_qual_for_aggs(Node *clause, List *subplanTargetList, List *groupCla
10451045
elseif (is_funcclause(clause)||not_clause(clause)||
10461046
or_clause(clause)||and_clause(clause))
10471047
{
1048-
intnew_length=0,
1049-
old_length=0;
1050-
10511048
/*
10521049
* This is a function. Recursively call this routine for its
10531050
* arguments... (i.e. for AND, OR, ... clauses!)
10541051
*/
10551052
foreach(t, ((Expr*)clause)->args)
10561053
{
1057-
old_length=length((List*)agg_list);
1058-
10591054
agg_list=nconc(agg_list,
10601055
check_having_qual_for_aggs(lfirst(t),subplanTargetList,
10611056
groupClause));
1062-
1063-
/*
1064-
* The arguments of OR or AND clauses are comparisons or
1065-
* relations and because we are in the havingQual there must
1066-
* be at least one operand using an aggregate function. If so,
1067-
* we will find it and the lenght of the agg_list will be
1068-
* increased after the above call to
1069-
* check_having_qual_for_aggs. If there are no aggregates
1070-
* used, the query could have been formulated using the
1071-
* 'where' clause
1072-
*/
1073-
if (((new_length=length((List*)agg_list))==old_length)|| (new_length==0))
1074-
{
1075-
elog(ERROR,"This could have been done in a where clause!!");
1076-
returnNIL;
1077-
}
10781057
}
10791058
returnagg_list;
10801059
}
@@ -1199,7 +1178,6 @@ check_having_qual_for_aggs(Node *clause, List *subplanTargetList, List *groupCla
11991178
}
12001179
else
12011180
{
1202-
12031181
/*
12041182
* Ooops! we can not handle that!
12051183
*/

‎src/backend/parser/parse_agg.c

Lines changed: 4 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.13 1998/09/01 04:30:26 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_agg.c,v 1.14 1998/09/09 03:48:17 vadim Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -104,7 +104,8 @@ exprIsAggOrGroupCol(Node *expr, List *groupClause)
104104
List*gl;
105105

106106
if (expr==NULL||IsA(expr,Const)||
107-
IsA(expr,Param)||IsA(expr,Aggreg))
107+
IsA(expr,Param)||IsA(expr,Aggreg)||
108+
IsA(expr,SubLink))/* can't handle currently !!! */
108109
return TRUE;
109110

110111
foreach(gl,groupClause)
@@ -207,13 +208,10 @@ parseCheckAggregates(ParseState *pstate, Query *qry)
207208
* the expression specified in the HAVING clause has the same
208209
* restriction as those in the target list.
209210
*/
210-
/*
211-
* Need to change here when we get HAVING works. Currently
212-
* qry->havingQual is NULL.- vadim 04/05/97
211+
213212
if (!exprIsAggOrGroupCol(qry->havingQual,qry->groupClause))
214213
elog(ERROR,
215214
"parser: illegal use of aggregates or non-group column in HAVING clause");
216-
*/
217215
return;
218216
}
219217

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp