diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-03-10 23:21:26 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-03-10 23:21:26 +0000 |
commit | 595ed2a8550e34c0abe64569a104d92ad077ec08 (patch) | |
tree | 004764220f537256d96637d5a119fd2086ed40ec /src/backend/rewrite/rewriteHandler.c | |
parent | 609e32b929cf8684f8ae3a2b9f1655b372fb8b85 (diff) | |
download | postgresql-595ed2a8550e34c0abe64569a104d92ad077ec08.tar.gz postgresql-595ed2a8550e34c0abe64569a104d92ad077ec08.zip |
Make the behavior of HAVING without GROUP BY conform to the SQL spec.
Formerly, if such a clause contained no aggregate functions we mistakenly
treated it as equivalent to WHERE. Per spec it must cause the query to
be treated as a grouped query of a single group, the same as appearance
of aggregate functions would do. Also, the HAVING filter must execute
after aggregate function computation even if it itself contains no
aggregate functions.
Diffstat (limited to 'src/backend/rewrite/rewriteHandler.c')
-rw-r--r-- | src/backend/rewrite/rewriteHandler.c | 31 |
1 files changed, 1 insertions, 30 deletions
diff --git a/src/backend/rewrite/rewriteHandler.c b/src/backend/rewrite/rewriteHandler.c index 4bc66db0bc0..cc26e8eb766 100644 --- a/src/backend/rewrite/rewriteHandler.c +++ b/src/backend/rewrite/rewriteHandler.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/rewrite/rewriteHandler.c,v 1.147 2004/12/31 22:00:45 pgsql Exp $ + * $PostgreSQL: pgsql/src/backend/rewrite/rewriteHandler.c,v 1.148 2005/03/10 23:21:24 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -182,18 +182,6 @@ rewriteRuleAction(Query *parsetree, } /* - * We copy the qualifications of the parsetree to the action and vice - * versa. So force hasSubLinks if one of them has it. If this is not - * right, the flag will get cleared later, but we mustn't risk having - * it not set when it needs to be. (XXX this should probably be - * handled by AddQual and friends, not here...) - */ - if (parsetree->hasSubLinks) - sub_action->hasSubLinks = TRUE; - else if (sub_action->hasSubLinks) - parsetree->hasSubLinks = TRUE; - - /* * Event Qualification forces copying of parsetree and splitting into * two queries one w/rule_qual, one w/NOT rule_qual. Also add user * query qual onto rule action @@ -996,23 +984,6 @@ fireRIRrules(Query *parsetree, List *activeRIRs) query_tree_walker(parsetree, fireRIRonSubLink, (void *) activeRIRs, QTW_IGNORE_RT_SUBQUERIES); - /* - * If the query was marked having aggregates, check if this is still - * true after rewriting. Ditto for sublinks. Note there should be no - * aggs in the qual at this point. (Does this code still do anything - * useful? The view-becomes-subselect-in-FROM approach doesn't look - * like it could remove aggs or sublinks...) - */ - if (parsetree->hasAggs) - { - parsetree->hasAggs = checkExprHasAggs((Node *) parsetree); - if (parsetree->hasAggs) - if (checkExprHasAggs((Node *) parsetree->jointree)) - elog(ERROR, "failed to remove aggregates from qual"); - } - if (parsetree->hasSubLinks) - parsetree->hasSubLinks = checkExprHasSubLink((Node *) parsetree); - return parsetree; } |