Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
9a2949e5
Commit
9a2949e5
authored
26 years ago
by
Vadim B. Mikheev
Browse files
Options
Downloads
Patches
Plain Diff
Fix using GroupBy/non-GroupBy expressions in HAVING.
parent
04abb541
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/backend/optimizer/plan/planner.c
+1
-25
1 addition, 25 deletions
src/backend/optimizer/plan/planner.c
src/backend/optimizer/plan/setrefs.c
+1
-23
1 addition, 23 deletions
src/backend/optimizer/plan/setrefs.c
src/backend/parser/parse_agg.c
+4
-6
4 additions, 6 deletions
src/backend/parser/parse_agg.c
with
6 additions
and
54 deletions
src/backend/optimizer/plan/planner.c
+
1
−
25
View file @
9a2949e5
...
...
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.3
4
1998/09/0
8
0
2:50:20
vadim Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.3
5
1998/09/0
9
0
3:48:01
vadim Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -185,9 +185,6 @@ union_planner(Query *parse)
*/
if
(
parse
->
hasAggs
)
{
int
old_length
=
0
,
new_length
=
0
;
result_plan
=
(
Plan
*
)
make_agg
(
tlist
,
result_plan
);
/*
...
...
@@ -256,31 +253,10 @@ union_planner(Query *parse)
*/
foreach
(
clause
,
((
Agg
*
)
result_plan
)
->
plan
.
qual
)
{
/*
* Make sure there are aggregates in the havingQual if so,
* the list must be longer after
* check_having_qual_for_aggs
*/
old_length
=
length
(((
Agg
*
)
result_plan
)
->
aggs
);
((
Agg
*
)
result_plan
)
->
aggs
=
nconc
(((
Agg
*
)
result_plan
)
->
aggs
,
check_having_qual_for_aggs
((
Node
*
)
lfirst
(
clause
),
((
Agg
*
)
result_plan
)
->
plan
.
lefttree
->
targetlist
,
((
List
*
)
parse
->
groupClause
)));
/*
* Have a look at the length of the returned list. If
* there is no difference, no aggregates have been found
* and that means, that the Qual belongs to the where
* clause
*/
if
(((
new_length
=
length
(((
Agg
*
)
result_plan
)
->
aggs
))
==
old_length
)
||
(
new_length
==
0
))
{
elog
(
ERROR
,
"This could have been done in a where clause!!"
);
return
(
Plan
*
)
NIL
;
}
}
PlannerVarParam
=
lnext
(
PlannerVarParam
);
if
(
vpm
!=
NULL
)
...
...
This diff is collapsed.
Click to expand it.
src/backend/optimizer/plan/setrefs.c
+
1
−
23
View file @
9a2949e5
...
...
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.2
6
1998/09/0
1
0
4:29:54 momjian
Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.2
7
1998/09/0
9
0
3:48:02 vadim
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -1045,36 +1045,15 @@ check_having_qual_for_aggs(Node *clause, List *subplanTargetList, List *groupCla
else
if
(
is_funcclause
(
clause
)
||
not_clause
(
clause
)
||
or_clause
(
clause
)
||
and_clause
(
clause
))
{
int
new_length
=
0
,
old_length
=
0
;
/*
* This is a function. Recursively call this routine for its
* arguments... (i.e. for AND, OR, ... clauses!)
*/
foreach
(
t
,
((
Expr
*
)
clause
)
->
args
)
{
old_length
=
length
((
List
*
)
agg_list
);
agg_list
=
nconc
(
agg_list
,
check_having_qual_for_aggs
(
lfirst
(
t
),
subplanTargetList
,
groupClause
));
/*
* The arguments of OR or AND clauses are comparisons or
* relations and because we are in the havingQual there must
* be at least one operand using an aggregate function. If so,
* we will find it and the lenght of the agg_list will be
* increased after the above call to
* check_having_qual_for_aggs. If there are no aggregates
* used, the query could have been formulated using the
* 'where' clause
*/
if
(((
new_length
=
length
((
List
*
)
agg_list
))
==
old_length
)
||
(
new_length
==
0
))
{
elog
(
ERROR
,
"This could have been done in a where clause!!"
);
return
NIL
;
}
}
return
agg_list
;
}
...
...
@@ -1199,7 +1178,6 @@ check_having_qual_for_aggs(Node *clause, List *subplanTargetList, List *groupCla
}
else
{
/*
* Ooops! we can not handle that!
*/
...
...
This diff is collapsed.
Click to expand it.
src/backend/parser/parse_agg.c
+
4
−
6
View file @
9a2949e5
...
...
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_agg.c,v 1.1
3
1998/09/0
1
0
4:30:26 momjian
Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/parse_agg.c,v 1.1
4
1998/09/0
9
0
3:48:17 vadim
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -104,7 +104,8 @@ exprIsAggOrGroupCol(Node *expr, List *groupClause)
List
*
gl
;
if
(
expr
==
NULL
||
IsA
(
expr
,
Const
)
||
IsA
(
expr
,
Param
)
||
IsA
(
expr
,
Aggreg
))
IsA
(
expr
,
Param
)
||
IsA
(
expr
,
Aggreg
)
||
IsA
(
expr
,
SubLink
))
/* can't handle currently !!! */
return
TRUE
;
foreach
(
gl
,
groupClause
)
...
...
@@ -207,13 +208,10 @@ parseCheckAggregates(ParseState *pstate, Query *qry)
* the expression specified in the HAVING clause has the same
* restriction as those in the target list.
*/
/*
* Need to change here when we get HAVING works. Currently
* qry->havingQual is NULL. - vadim 04/05/97
if
(
!
exprIsAggOrGroupCol
(
qry
->
havingQual
,
qry
->
groupClause
))
elog
(
ERROR
,
"parser: illegal use of aggregates or non-group column in HAVING clause"
);
*/
return
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment