I just came across strange behavior (bug?) In MySQL 5.7, which does not appear in MySQL 5.5.
So inconvenient, I need an example to explain this.
- Create a table using the left join on 2 tables
- Make sure that the second table is empty (no records), but built using a static value written in one of the fields.
Left join with no conditions creates N rows (as expected)
Left join with a condition that never matches . ALSO produces N lines.
create table PCPL (K1 int);
create table AUX (K2 int);
insert into PCPL values (1),(2),(3);
truncate table AUX;
select PCPL.K1 as K1 , DERIVED.K2 as K2
from PCPL
LEFT JOIN (select K2, 1 as staticValue from AUX) DERIVED
ON PCPL.K1 = DERIVED.K2;
+
| K1 | K2 |
+
| 1 | NULL |
| 2 | NULL |
| 3 | NULL |
+
3 rows in set (0,00 sec)
select PCPL.K1 as K1 , DERIVED.K2 as K2
from PCPL
LEFT JOIN (select K2, 1 as staticValue from AUX) DERIVED
ON PCPL.K1 = DERIVED.K2
where staticValue=1;
+
| K1 | K2 |
+
| 1 | NULL |
| 2 | NULL |
| 3 | NULL |
+
3 rows in set (0,00 sec)
THIS SHOULDN'T HAPPEN !
This behavior does not occur with MySQL 5.5
Is this a bug or some parameter in 5.5 that I forgot to set to 5.7?
Thank you for your time!