1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

Recognize GROUPING() as a aggregate expression.

Previously GROUPING() was not recognized as a aggregate expression,
erroneously allowing the planner to move it from HAVING to WHERE.

Author: Jeevan Chalke
Reviewed-By: Andrew Gierth
Discussion: CAM2+6=WG9omG5rFOMAYBweJxmpTaapvVp5pCeMrE6BfpCwr4Og@mail.gmail.com
Backpatch: 9.5, where grouping sets were introduced
This commit is contained in:
Andres Freund
2015-07-26 15:34:29 +02:00
parent 65b86c1767
commit 3500d1cc78
3 changed files with 85 additions and 1 deletions

View File

@@ -390,7 +390,7 @@ make_ands_implicit(Expr *clause)
/*
* contain_agg_clause
* Recursively search for Aggref nodes within a clause.
* Recursively search for Aggref/GroupingFunc nodes within a clause.
*
* Returns true if any aggregate found.
*
@@ -417,6 +417,11 @@ contain_agg_clause_walker(Node *node, void *context)
Assert(((Aggref *) node)->agglevelsup == 0);
return true; /* abort the tree traversal and return true */
}
if (IsA(node, GroupingFunc))
{
Assert(((GroupingFunc *) node)->agglevelsup == 0);
return true; /* abort the tree traversal and return true */
}
Assert(!IsA(node, SubLink));
return expression_tree_walker(node, contain_agg_clause_walker, context);
}