diff options
author | Varun Gupta <varun.gupta@mariadb.com> | 2019-12-26 12:50:21 +0530 |
---|---|---|
committer | Varun Gupta <varun.gupta@mariadb.com> | 2019-12-26 15:18:49 +0530 |
commit | 891609b571a6c134d308bf7fb6f9683eb716f157 (patch) | |
tree | 0ba2919ede99f4dd8fd4074795dae041de45f20a /mysql-test/t/win.test | |
parent | 3dfe1ba3b85043ed3c451292c6a47950849569dd (diff) | |
download | mariadb-git-891609b571a6c134d308bf7fb6f9683eb716f157.tar.gz |
MDEV-21318: Wrong results with window functions and implicit grouping
The issue here is for degenerate joins we should execute the window
function but it is not getting executed in all the cases.
To get the window function values window function needs to be executed
always. This currently does not happen in few cases
where the join would return 0 or 1 row like
1) IMPOSSIBLE WHERE
2) MIN/MAX optimization
3) EMPTY CONST TABLE
The fix is to make sure that window functions get executed
and the temporary table is setup for the execution of window functions
Diffstat (limited to 'mysql-test/t/win.test')
-rw-r--r-- | mysql-test/t/win.test | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/mysql-test/t/win.test b/mysql-test/t/win.test index 1e302722b99..d2c0c1c9712 100644 --- a/mysql-test/t/win.test +++ b/mysql-test/t/win.test @@ -2362,5 +2362,70 @@ SELECT DISTINCT COUNT(*) OVER (), MOD(MIN(i),2) FROM t1 GROUP BY i ; drop table t1; --echo # +--echo # MDEV-21318: Wrong results with window functions and implicit grouping +--echo # + +CREATE TABLE t1 (a INT); + +--echo # +--echo # With empty const table +--echo # The expected result here is 1, NULL +--echo # + +explain +SELECT row_number() over(), sum(1) FROM t1; +SELECT row_number() over(), sum(1) FROM t1; + +insert into t1 values (2); + +--echo # +--echo # Const table has 1 row, but still impossible where +--echo # The expected result here is 1, NULL +--echo # + +EXPLAIN SELECT row_number() over(), sum(1) FROM t1 where a=1; +SELECT row_number() over(), sum(1) FROM t1 where a=1; + +--echo # +--echo # Impossible HAVING +--echo # Empty result is expected +--echo # + +EXPLAIN SELECT row_number() over(), sum(1) FROM t1 where a=1 having 1=0; +SELECT row_number() over(), sum(1) FROM t1 where a=1 having 1=0; + +--echo # +--echo # const table has 1 row, no impossible where +--echo # The expected result here is 1, 2 +--echo # + +EXPLAIN SELECT row_number() over(), sum(a) FROM t1 where a=2; +SELECT row_number() over(), sum(a) FROM t1 where a=2; +drop table t1; + +--echo # +--echo # Impossible Where +--echo # + +create table t1(a int); +insert into t1 values (1); + +--echo # +--echo # Expected result is NULL, 0, NULL +--echo # +EXPLAIN SELECT MAX(a) OVER (), COUNT(a), abs(a) FROM t1 WHERE FALSE; +SELECT MAX(a) OVER (), COUNT(a), abs(a) FROM t1 WHERE FALSE; + +--echo # +--echo # Expected result is 1, 0, NULL +--echo # + +EXPLAIN +SELECT MAX(1) OVER (), COUNT(a), abs(a) FROM t1 WHERE FALSE; +SELECT MAX(1) OVER (), COUNT(a), abs(a) FROM t1 WHERE FALSE; + +drop table t1; + +--echo # --echo # End of 10.2 tests --echo # |