Skip to content

Commit 1d98333

Browse files
committed
MDEV-15894 Error, while using aggregated functions/window functions in anchor part
Usage of aggregate/window functions in non-recursive parts of recursive CTEs is allowed. Error messages complaining about this were reported by mistake.
1 parent e34d318 commit 1d98333

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

mysql-test/r/cte_recursive.result

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3179,3 +3179,22 @@ p1 k2 p2 k1
31793179
10 10 10 10
31803180
DROP PROCEDURE getNums;
31813181
DROP TABLE t1;
3182+
#
3183+
# MDEV-15894: aggregate/winfow functions in non-recorsive part
3184+
#
3185+
create table t1(b int);
3186+
insert into t1 values(10),(20),(10);
3187+
with recursive qn as
3188+
(select max(b) as a from t1 union
3189+
select a from qn)
3190+
select * from qn;
3191+
a
3192+
20
3193+
with recursive qn as
3194+
(select rank() over (order by b) as a from t1 union
3195+
select a from qn)
3196+
select * from qn;
3197+
a
3198+
1
3199+
3
3200+
drop table t1;

mysql-test/t/cte_recursive.test

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,3 +2190,22 @@ call getNums();
21902190

21912191
DROP PROCEDURE getNums;
21922192
DROP TABLE t1;
2193+
2194+
--echo #
2195+
--echo # MDEV-15894: aggregate/winfow functions in non-recorsive part
2196+
--echo #
2197+
2198+
create table t1(b int);
2199+
insert into t1 values(10),(20),(10);
2200+
2201+
with recursive qn as
2202+
(select max(b) as a from t1 union
2203+
select a from qn)
2204+
select * from qn;
2205+
2206+
with recursive qn as
2207+
(select rank() over (order by b) as a from t1 union
2208+
select a from qn)
2209+
select * from qn;
2210+
2211+
drop table t1;

sql/sql_cte.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ bool st_select_lex::check_unrestricted_recursive(bool only_standard_compliant)
11731173

11741174

11751175
/* Check conditions 3-4 for restricted specification*/
1176-
if (with_sum_func ||
1176+
if ((with_sum_func && !with_elem->is_anchor(this)) ||
11771177
(with_elem->contains_sq_with_recursive_reference()))
11781178
with_elem->get_owner()->add_unrestricted(
11791179
with_elem->get_mutually_recursive());

0 commit comments

Comments
 (0)