Commit 1570c6e3 authored by Sergei Golubchik's avatar Sergei Golubchik

bugfix: join a=b where cast(a as type_of_b) can produce NULL

optimizer implicitly assumed that if `a` in `a=b` is not NULL,
then it's safe to convert `a` to the type of `b` and search the
result in the index(b).

which is not always the case, as converting a non-null value
to a different type might produce NULL. And searching for NULL
in the index might find NULL there, so NULL will be equal to NULL,
making `a=b` behave as if it was `a<=>b`
parent ef84f813
...@@ -1698,7 +1698,7 @@ Subquery_cache_miss 18 ...@@ -1698,7 +1698,7 @@ Subquery_cache_miss 18
show status like '%Handler_read%'; show status like '%Handler_read%';
Variable_name Value Variable_name Value
Handler_read_first 0 Handler_read_first 0
Handler_read_key 32 Handler_read_key 29
Handler_read_last 0 Handler_read_last 0
Handler_read_next 0 Handler_read_next 0
Handler_read_prev 0 Handler_read_prev 0
...@@ -1763,7 +1763,7 @@ Subquery_cache_miss 10 ...@@ -1763,7 +1763,7 @@ Subquery_cache_miss 10
show status like '%Handler_read%'; show status like '%Handler_read%';
Variable_name Value Variable_name Value
Handler_read_first 0 Handler_read_first 0
Handler_read_key 13 Handler_read_key 12
Handler_read_last 0 Handler_read_last 0
Handler_read_next 0 Handler_read_next 0
Handler_read_prev 0 Handler_read_prev 0
......
...@@ -16,7 +16,21 @@ select * from t2; ...@@ -16,7 +16,21 @@ select * from t2;
select * from t2 order by a; select * from t2 order by a;
show create table t2; show create table t2;
select * from t1, t2 where t1.a=t2.a; explain select * from t1 left join t2 on (t1.a=t2.a);
--sorted_result
select * from t1 left join t2 on (t1.a=t2.a);
explain select * from t1 left join t2 on (t1.a<=>t2.a);
--sorted_result
select * from t1 left join t2 on (t1.a<=>t2.a);
explain select * from t2 left join t1 on (t1.a=t2.a);
--sorted_result
select * from t2 left join t1 on (t1.a=t2.a);
explain select * from t2 left join t1 on (t1.a<=>t2.a);
--sorted_result
select * from t2 left join t1 on (t1.a<=>t2.a);
--sorted_result --sorted_result
select * from t1 union select * from t2; select * from t1 union select * from t2;
......
...@@ -25562,7 +25562,8 @@ cp_buffer_from_ref(THD *thd, TABLE *table, TABLE_REF *ref) ...@@ -25562,7 +25562,8 @@ cp_buffer_from_ref(THD *thd, TABLE *table, TABLE_REF *ref)
thd->count_cuted_fields= CHECK_FIELD_IGNORE; thd->count_cuted_fields= CHECK_FIELD_IGNORE;
for (store_key **copy=ref->key_copy ; *copy ; copy++) for (store_key **copy=ref->key_copy ; *copy ; copy++)
{ {
if ((*copy)->copy(thd) & 1) if ((*copy)->copy(thd) & 1 ||
(ref->null_rejecting && (*copy)->null_key))
{ {
result= 1; result= 1;
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment