1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

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.
This commit is contained in:
Vicențiu Ciorbaru
2017-02-15 08:43:39 +02:00
parent 88ddb1ea4e
commit d06a44e027
3 changed files with 142 additions and 1 deletions

View File

@ -2958,3 +2958,94 @@ develop 2 4000 4000.0000
sales 3 6000 5500.0000
sales 4 5000 5500.0000
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;

View File

@ -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;
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;

View File

@ -2699,10 +2699,20 @@ bool Window_func_runner::add_function_to_run(Item_window_func *win_func)
{
/* Distinct is not yet supported. */
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:
my_error(ER_NOT_SUPPORTED_YET, MYF(0),
"SUM(DISTINCT) aggregate as window function");
return true;
case Item_sum::AVG_DISTINCT_FUNC:
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;
default:
break;