mirror of
https://github.com/postgres/postgres.git
synced 2025-07-09 22:41:56 +03:00
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.
This commit is contained in:
@ -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 $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -181,18 +181,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
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user