diff --git a/mysql-test/r/win.result b/mysql-test/r/win.result index e4b2d223a02..aef9b613433 100644 --- a/mysql-test/r/win.result +++ b/mysql-test/r/win.result @@ -3314,3 +3314,15 @@ COUNT(DISTINCT t2.a2) rank() OVER (ORDER BY t2.b1) 1 2 1 3 DROP TABLE t1,t2; +# +# MDEV-16990: server crashes in base_list_iterator::next +# +CREATE TABLE t1(i int); +insert into t1 values (1),(2); +SELECT DISTINCT row_number() OVER (), MAX(1) FROM t1; +row_number() OVER () MAX(1) +1 1 +SELECT DISTINCT BIT_AND(0) OVER (), MAX(1) FROM t1; +BIT_AND(0) OVER () MAX(1) +0 1 +drop table t1; diff --git a/mysql-test/t/win.test b/mysql-test/t/win.test index f47237ee59e..1617e85caf4 100644 --- a/mysql-test/t/win.test +++ b/mysql-test/t/win.test @@ -2082,3 +2082,13 @@ SELECT COUNT(DISTINCT t2.a2), rank() OVER (ORDER BY t2.b1) FROM t2 ,t1 GROUP BY t2.b1 ORDER BY t1.a1; DROP TABLE t1,t2; + +--echo # +--echo # MDEV-16990: server crashes in base_list_iterator::next +--echo # + +CREATE TABLE t1(i int); +insert into t1 values (1),(2); +SELECT DISTINCT row_number() OVER (), MAX(1) FROM t1; +SELECT DISTINCT BIT_AND(0) OVER (), MAX(1) FROM t1; +drop table t1; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 6f98bab32d3..a9adbd168a6 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -2731,7 +2731,7 @@ bool JOIN::make_aggr_tables_info() remove_duplicates() assumes there is a preceding computation step (and in the degenerate join, there's none) */ - if (top_join_tab_count) + if (top_join_tab_count && tables_list) curr_tab->distinct= true; having= NULL;