提交 756241e2 编写于 作者: H Heikki Linnakangas

Revert contain_vars_of_level() to match the upstream.

The function was rewritten in GPDB, and its behaviour was changed to also
return 'true' if the expression contains an Aggref of the given level.
That change in behaviour was made back in 2006, as part of a commit
containing a lot of subquery optimization changes. I could not find an
explanation for that particular change, and all the regression tests pass
without so I assume that it has become obsolete at some point over they
years.

This smoothens the way for future merges with upstream, by reducing the
diff in both code and behaviour. Also, you get a more accurate error
message in a few cases, as seen by the changes to expected output.
上级 26330731
......@@ -52,6 +52,7 @@ typedef struct
} flatten_join_alias_vars_context;
static bool contain_var_clause_walker(Node *node, void *context);
static bool contain_vars_of_level_walker(Node *node, int *sublevels_up);
static bool pull_var_clause_walker(Node *node,
pull_var_clause_context *context);
static Node *flatten_join_alias_vars_mutator(Node *node,
......@@ -273,38 +274,50 @@ contain_var_clause_walker(Node *node, void *context)
*
* Will recurse into sublinks. Also, may be invoked directly on a Query.
*/
static bool
contain_vars_of_level_cbVar(Var *var, void *unused, int sublevelsup)
{
if ((int)var->varlevelsup == sublevelsup)
return true; /* abort tree traversal and return true */
return false;
}
static bool
contain_vars_of_level_cbAggref(Aggref *aggref, void *unused, int sublevelsup)
bool
contain_vars_of_level(Node *node, int levelsup)
{
if ((int)aggref->agglevelsup == sublevelsup)
return true;
int sublevels_up = levelsup;
/* visit aggregate's args */
return cdb_walk_vars((Node *)aggref->args,
contain_vars_of_level_cbVar,
contain_vars_of_level_cbAggref,
NULL,
NULL,
sublevelsup);
return query_or_expression_tree_walker(node,
contain_vars_of_level_walker,
(void *) &sublevels_up,
0);
}
bool
contain_vars_of_level(Node *node, int levelsup)
static bool
contain_vars_of_level_walker(Node *node, int *sublevels_up)
{
return cdb_walk_vars(node,
contain_vars_of_level_cbVar,
contain_vars_of_level_cbAggref,
NULL,
NULL,
levelsup);
if (node == NULL)
return false;
if (IsA(node, Var))
{
if (((Var *) node)->varlevelsup == *sublevels_up)
return true; /* abort tree traversal and return true */
return false;
}
if (IsA(node, CurrentOfExpr))
{
if (*sublevels_up == 0)
return true;
return false;
}
if (IsA(node, Query))
{
/* Recurse into subselects */
bool result;
(*sublevels_up)++;
result = query_tree_walker((Query *) node,
contain_vars_of_level_walker,
(void *) sublevels_up,
0);
(*sublevels_up)--;
return result;
}
return expression_tree_walker(node,
contain_vars_of_level_walker,
(void *) sublevels_up);
}
/*
......
......@@ -75,3 +75,12 @@ SELECT dkey, substring(tval from 1 for 2) as str from (SELECT * from mksort_lim
(3 rows)
DROP TABLE mksort_limit_test_table;
-- Check invalid things in LIMIT
select * from generate_series(1,10) g limit g;
ERROR: argument of LIMIT must not contain variables
LINE 1: select * from generate_series(1,10) g limit g;
^
select * from generate_series(1,10) g limit count(*);
ERROR: argument of LIMIT must not contain aggregates
LINE 1: select * from generate_series(1,10) g limit count(*);
^
......@@ -1006,7 +1006,7 @@ select b, percentile_disc(0.1) within group (order by a) from perct;
ERROR: column "perct.b" must appear in the GROUP BY clause or be used in an aggregate function
-- nested aggregate
select percentile_cont(count(*)) within group (order by a) from perct;
ERROR: argument of percentile function must not contain variables
ERROR: argument of percentile function must not contain aggregates
LINE 1: select percentile_cont(count(*)) within group (order by a) f...
^
select sum(percentile_cont(0.22) within group (order by a)) from perct;
......
......@@ -27,3 +27,8 @@ SELECT dkey, substring(tval from 1 for 2) as str from (SELECT * from mksort_limi
SELECT dkey, substring(tval from 1 for 2) as str from (SELECT * from mksort_limit_test_table ORDER BY dkey DESC LIMIT 5000) as temp ORDER BY jkey DESC LIMIT 3;
DROP TABLE mksort_limit_test_table;
-- Check invalid things in LIMIT
select * from generate_series(1,10) g limit g;
select * from generate_series(1,10) g limit count(*);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册