Commit d06a44e0 authored by Vicențiu Ciorbaru's avatar Vicențiu Ciorbaru

MDEV-11868: min ( distinct ) over ( ) returns wrong value

The bug was not visible in current HEAD. Introduced test case to catch
regressions. Also improve error messages regarding distinct usage in
window functions.
parent 88ddb1ea
...@@ -2958,3 +2958,94 @@ develop 2 4000 4000.0000 ...@@ -2958,3 +2958,94 @@ develop 2 4000 4000.0000
sales 3 6000 5500.0000 sales 3 6000 5500.0000
sales 4 5000 5500.0000 sales 4 5000 5500.0000
drop table empsalary; drop table empsalary;
#
# MDEV-11868: min(distinct) over () returns wrong value
#
create table TDEC (CDEC int, RNUM int);
create view VDEC as select * from TDEC;
insert into TDEC (CDEC) values (null),(-1),(0),(1),(0),(10);
select TDEC.CDEC, min(TDEC.CDEC) over () from TDEC;
CDEC min(TDEC.CDEC) over ()
NULL -1
-1 -1
0 -1
1 -1
0 -1
10 -1
select VDEC.CDEC, min(VDEC.CDEC) over () from VDEC;
CDEC min(VDEC.CDEC) over ()
NULL -1
-1 -1
0 -1
1 -1
0 -1
10 -1
select TDEC.CDEC, max(TDEC.CDEC) over () from TDEC;
CDEC max(TDEC.CDEC) over ()
NULL 10
-1 10
0 10
1 10
0 10
10 10
select VDEC.CDEC, max(VDEC.CDEC) over () from VDEC;
CDEC max(VDEC.CDEC) over ()
NULL 10
-1 10
0 10
1 10
0 10
10 10
select TDEC.CDEC, min(distinct TDEC.CDEC) over () from TDEC;
CDEC min(distinct TDEC.CDEC) over ()
NULL -1
-1 -1
0 -1
1 -1
0 -1
10 -1
select VDEC.CDEC, min(distinct VDEC.CDEC) over () from VDEC;
CDEC min(distinct VDEC.CDEC) over ()
NULL -1
-1 -1
0 -1
1 -1
0 -1
10 -1
select TDEC.CDEC, max(distinct TDEC.CDEC) over () from TDEC;
CDEC max(distinct TDEC.CDEC) over ()
NULL 10
-1 10
0 10
1 10
0 10
10 10
select VDEC.CDEC, max(distinct VDEC.CDEC) over () from VDEC;
CDEC max(distinct VDEC.CDEC) over ()
NULL 10
-1 10
0 10
1 10
0 10
10 10
#
# These should be removed once support for them is added.
#
select TDEC.CDEC, count(distinct TDEC.CDEC) over () from TDEC;
ERROR 42000: This version of MariaDB doesn't yet support 'COUNT(DISTINCT) aggregate as window function'
select VDEC.CDEC, count(distinct VDEC.CDEC) over () from VDEC;
ERROR 42000: This version of MariaDB doesn't yet support 'COUNT(DISTINCT) aggregate as window function'
select TDEC.CDEC, sum(distinct TDEC.CDEC) over () from TDEC;
ERROR 42000: This version of MariaDB doesn't yet support 'SUM(DISTINCT) aggregate as window function'
select VDEC.CDEC, sum(distinct VDEC.CDEC) over () from VDEC;
ERROR 42000: This version of MariaDB doesn't yet support 'SUM(DISTINCT) aggregate as window function'
select TDEC.CDEC, avg(distinct TDEC.CDEC) over () from TDEC;
ERROR 42000: This version of MariaDB doesn't yet support 'AVG(DISTINCT) aggregate as window function'
select VDEC.CDEC, avg(distinct VDEC.CDEC) over () from VDEC;
ERROR 42000: This version of MariaDB doesn't yet support 'AVG(DISTINCT) aggregate as window function'
select TDEC.CDEC, GROUP_CONCAT(TDEC.CDEC) over () from TDEC;
ERROR 42000: This version of MariaDB doesn't yet support 'GROUP_CONCAT() aggregate as window function'
select VDEC.CDEC, GROUP_CONCAT(distinct VDEC.CDEC) over () from VDEC;
ERROR 42000: This version of MariaDB doesn't yet support 'GROUP_CONCAT() aggregate as window function'
drop table TDEC;
drop view VDEC;
...@@ -1734,3 +1734,43 @@ SELECT depname, empno, salary, avg(salary) OVER (PARTITION BY depname) FROM emps ...@@ -1734,3 +1734,43 @@ SELECT depname, empno, salary, avg(salary) OVER (PARTITION BY depname) FROM emps
SELECT depname, empno, salary, avg(salary) OVER (PARTITION BY depname) FROM empsalary HAVING empno > 1 ORDER BY depname; SELECT depname, empno, salary, avg(salary) OVER (PARTITION BY depname) FROM empsalary HAVING empno > 1 ORDER BY depname;
drop table empsalary; drop table empsalary;
--echo #
--echo # MDEV-11868: min(distinct) over () returns wrong value
--echo #
create table TDEC (CDEC int, RNUM int);
create view VDEC as select * from TDEC;
insert into TDEC (CDEC) values (null),(-1),(0),(1),(0),(10);
select TDEC.CDEC, min(TDEC.CDEC) over () from TDEC;
select VDEC.CDEC, min(VDEC.CDEC) over () from VDEC;
select TDEC.CDEC, max(TDEC.CDEC) over () from TDEC;
select VDEC.CDEC, max(VDEC.CDEC) over () from VDEC;
select TDEC.CDEC, min(distinct TDEC.CDEC) over () from TDEC;
select VDEC.CDEC, min(distinct VDEC.CDEC) over () from VDEC;
select TDEC.CDEC, max(distinct TDEC.CDEC) over () from TDEC;
select VDEC.CDEC, max(distinct VDEC.CDEC) over () from VDEC;
--echo #
--echo # These should be removed once support for them is added.
--echo #
--error ER_NOT_SUPPORTED_YET
select TDEC.CDEC, count(distinct TDEC.CDEC) over () from TDEC;
--error ER_NOT_SUPPORTED_YET
select VDEC.CDEC, count(distinct VDEC.CDEC) over () from VDEC;
--error ER_NOT_SUPPORTED_YET
select TDEC.CDEC, sum(distinct TDEC.CDEC) over () from TDEC;
--error ER_NOT_SUPPORTED_YET
select VDEC.CDEC, sum(distinct VDEC.CDEC) over () from VDEC;
--error ER_NOT_SUPPORTED_YET
select TDEC.CDEC, avg(distinct TDEC.CDEC) over () from TDEC;
--error ER_NOT_SUPPORTED_YET
select VDEC.CDEC, avg(distinct VDEC.CDEC) over () from VDEC;
--error ER_NOT_SUPPORTED_YET
select TDEC.CDEC, GROUP_CONCAT(TDEC.CDEC) over () from TDEC;
--error ER_NOT_SUPPORTED_YET
select VDEC.CDEC, GROUP_CONCAT(distinct VDEC.CDEC) over () from VDEC;
drop table TDEC;
drop view VDEC;
...@@ -2699,10 +2699,20 @@ bool Window_func_runner::add_function_to_run(Item_window_func *win_func) ...@@ -2699,10 +2699,20 @@ bool Window_func_runner::add_function_to_run(Item_window_func *win_func)
{ {
/* Distinct is not yet supported. */ /* Distinct is not yet supported. */
case Item_sum::GROUP_CONCAT_FUNC: case Item_sum::GROUP_CONCAT_FUNC:
my_error(ER_NOT_SUPPORTED_YET, MYF(0),
"GROUP_CONCAT() aggregate as window function");
return true;
case Item_sum::SUM_DISTINCT_FUNC: case Item_sum::SUM_DISTINCT_FUNC:
my_error(ER_NOT_SUPPORTED_YET, MYF(0),
"SUM(DISTINCT) aggregate as window function");
return true;
case Item_sum::AVG_DISTINCT_FUNC: case Item_sum::AVG_DISTINCT_FUNC:
my_error(ER_NOT_SUPPORTED_YET, MYF(0), my_error(ER_NOT_SUPPORTED_YET, MYF(0),
"This aggregate as window function"); "AVG(DISTINCT) aggregate as window function");
return true;
case Item_sum::COUNT_DISTINCT_FUNC:
my_error(ER_NOT_SUPPORTED_YET, MYF(0),
"COUNT(DISTINCT) aggregate as window function");
return true; return true;
default: default:
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment