revision-id: bba7cc26ef9485c74ee399488e9fe3aad98b96f3 (mariadb-10.2.16-126-gbba7cc26ef9) parent(s): 4d991abd4fc7f60e758ec46301b0dd2bee71245c author: Varun committer: Varun timestamp: 2018-09-10 13:29:54 +0530 message: MDEV-16990:server crashes in base_list_iterator::next When we have a query which has implicit_grouping then we are sure that we would end up with only one row so there is no point to do DISTINCT computation. --- mysql-test/r/win.result | 12 ++++++++++++ mysql-test/t/win.test | 10 ++++++++++ sql/sql_select.cc | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) 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 0124a782de0..9770d5a34f0 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 && const_tables != top_join_tab_count) curr_tab->distinct= true; having= NULL;