A minimal example for MariaDB (reproduced with with 10.2 and latest):
DROP TABLE IF EXISTS t;
CREATE TABLE t
(
id int unsigned not null,
value int unsigned null
);
INSERT INTO t
values (1, null);
CREATE OR REPLACE VIEW v
as
select 1 as id,
ifnull(null, 999) as value
from t
;
select *,
MIN(t.value) over (PARTITION BY t.id) as min_t,
MIN(v.value) over (PARTITION BY t.id) as min_v
from t
left join v
on t.id > v.id
;
It returns
id value id value min_t min_v
1 null null null null 999
bit I would expect it to return
id value id value min_t min_v
1 null null null null null <-- null instead of 999
because there is only a single row and it has value = null
in the window for MIN
function. Sure, it is backed by a ifnull()
in view's select
, but the resulting set has null
from a left join
with no corresponding row, so it shouldn't be handled by ifnull()
in the view, right?
Can this be considered a bug?
MySQL sqlfiddle example comparing using a view vs using nested selects. Nested selects produce the result I expect, using view doesn't.
Comparing to other RDBMS:
Oracle example: both ways work as I expect.
PostgreSQL example: both ways work as I expect.
-
Looks like a bug.ypercubeᵀᴹ– ypercubeᵀᴹ2020年03月04日 20:39:25 +00:00Commented Mar 4, 2020 at 20:39
-
Have you tested with the latest version? Try on dbfiddle.uk that has MYSQL 8 and Maria 10.4ypercubeᵀᴹ– ypercubeᵀᴹ2020年03月04日 20:58:57 +00:00Commented Mar 4, 2020 at 20:58
-
@ypercubeTM Thanks for the suggestion. MySQL 8 works properly. MariaDB 10.3 has incorrect behavior, and MariaDB 10.4 (latest) just fails to execute the query. I ran the query in a MariaDB 10.4.12 docker container, and there is still incorrect behavior.jojman– jojman2020年03月04日 21:08:41 +00:00Commented Mar 4, 2020 at 21:08
-
I suggest you should send a bug report to MariaDB list then. And feel free to self answer here that this is a bug.ypercubeᵀᴹ– ypercubeᵀᴹ2020年03月04日 21:12:18 +00:00Commented Mar 4, 2020 at 21:12
1 Answer 1
Reported this as a bug to MariaDB bug tracker: