Description:
Unknown error is issued instead of empty set.
This is caused by a fact that a self join is done which resolve to no rows.
But in the process, first filtering on constants is performed and when JT_REF is to be optimised (for filesort), reference to a NULL is made for a NOT NULL column.
This is because this is how join was devised.
How to repeat:
drop table if exists t1;
create table t1 ( id1 int not null, id2 int not null, idnull int null, c char(20), primary key (id1,id2));
insert into t1 values (0,1,NULL,"aaa");
insert into t1 values (1,1,NULL,"aaa");
insert into t1 values (2,1,NULL,"aaa");
insert into t1 values (3,1,NULL,"aaa");
insert into t1 values (4,1,NULL,"aaa");
insert into t1 values (5,1,NULL,"aaa");
insert into t1 values (6,1,NULL,"aaa");
insert into t1 values (7,1,NULL,"aaa");
insert into t1 values (8,1,NULL,"aaa");
insert into t1 values (9,1,NULL,"aaa");
insert into t1 values (10,1,NULL,"aaa");
insert into t1 values (11,1,NULL,"aaa");
insert into t1 values (12,1,NULL,"aaa");
insert into t1 values (13,1,NULL,"aaa");
insert into t1 values (14,1,NULL,"aaa");
insert into t1 values (15,1,NULL,"aaa");
insert into t1 values (16,1,NULL,"aaa");
insert into t1 values (17,1,NULL,"aaa");
insert into t1 values (18,1,NULL,"aaa");
insert into t1 values (19,1,NULL,"aaa");
insert into t1 values (20,1,NULL,"aaa");
select a.id1, b.idnull from t1 as a, t1 as b where a.id2=1 and a.id1=1 and b.id1=a.idnull order by b.id2 desc limit 1;
drop table if exists t1;