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

Commit31a0f1d

Browse files
committed
Fix oversight in check_ungrouped_columns optimization that avoids
unnecessary checks for complex grouping expressions: we cannot checkwhether the expressions are simple Vars until after we applyflatten_join_alias_vars, because in the case of FULL JOIN that routinecan introduce non-Var expressions. Per example from Joel Knight.
1 parent4405b3e commit31a0f1d

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

‎src/backend/parser/parse_agg.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/parser/parse_agg.c,v 1.60 2003/11/29 19:51:51 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/parser/parse_agg.c,v 1.61 2004/01/28 07:46:44 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -98,7 +98,7 @@ void
9898
parseCheckAggregates(ParseState*pstate,Query*qry)
9999
{
100100
List*groupClauses=NIL;
101-
boolhave_non_var_grouping= false;
101+
boolhave_non_var_grouping;
102102
List*lst;
103103
boolhasJoinRTEs;
104104
Node*clause;
@@ -127,9 +127,7 @@ parseCheckAggregates(ParseState *pstate, Query *qry)
127127
* No aggregates allowed in GROUP BY clauses, either.
128128
*
129129
* While we are at it, build a list of the acceptable GROUP BY
130-
* expressions for use by check_ungrouped_columns() (this avoids
131-
* repeated scans of the targetlist within the recursive routine...).
132-
* And detect whether any of the expressions aren't simple Vars.
130+
* expressions for use by check_ungrouped_columns().
133131
*/
134132
foreach(lst,qry->groupClause)
135133
{
@@ -144,8 +142,6 @@ parseCheckAggregates(ParseState *pstate, Query *qry)
144142
(errcode(ERRCODE_GROUPING_ERROR),
145143
errmsg("aggregates not allowed in GROUP BY clause")));
146144
groupClauses=lcons(expr,groupClauses);
147-
if (!IsA(expr,Var))
148-
have_non_var_grouping= true;
149145
}
150146

151147
/*
@@ -170,6 +166,21 @@ parseCheckAggregates(ParseState *pstate, Query *qry)
170166
groupClauses= (List*)flatten_join_alias_vars(qry,
171167
(Node*)groupClauses);
172168

169+
/*
170+
* Detect whether any of the grouping expressions aren't simple Vars;
171+
* if they're all Vars then we don't have to work so hard in the
172+
* recursive scans. (Note we have to flatten aliases before this.)
173+
*/
174+
have_non_var_grouping= false;
175+
foreach(lst,groupClauses)
176+
{
177+
if (!IsA((Node*)lfirst(lst),Var))
178+
{
179+
have_non_var_grouping= true;
180+
break;
181+
}
182+
}
183+
173184
/*
174185
* Check the targetlist and HAVING clause for ungrouped variables.
175186
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp