Commit b249680f authored by Igor Babaev's avatar Igor Babaev

Made consistent handling of the predicates of the form

<non-nullable datatime field> IS NULL in outer joins with
that in inner joins.
Previously such condition was transformed into the condition
<non-nullable datatime field> = 0 unless the field belonged
to an inner table of an outer join. In this case the predicate
was interpreted as for any other field.
Now if the field in the predicate <non-nullable datatime field> IS NULL
belongs to an inner table of an outer join the predicate is 
transformed into the disjunction
<non-nullable datatime field> = 0 OR <non-nullable datatime field> IS NULL.
This is fully compatible with the semantics of such predicates in 5.5.
parent 86f43c30
......@@ -665,4 +665,20 @@ Warning 1292 Incorrect datetime value: '10:19:31'
Warning 1292 Incorrect datetime value: '22:55:23'
Warning 1292 Incorrect datetime value: '10:19:31'
drop table t1;
#
# Semantics of the condition <non-nullable datetime field> IS NULL
# when the field belongs to an inner table of an outer join
#
create table t1 (a int, b date not null);
insert t1 values (1, 0), (2, '1999-01-02');
create table t2 (c int);
insert t2 values (1),(3);
select * from t2 left join t1 on t1.a=t2.c where t1.a is null;
c a b
3 NULL NULL
select * from t2 left join t1 on t1.a=t2.c where t1.b is null;
c a b
1 1 0000-00-00
3 NULL NULL
drop table t1,t2;
End of 5.3 tests
......@@ -471,5 +471,20 @@ insert into t1 values ('2000-12-03','22:55:23'),('2008-05-03','10:19:31');
select case when d = '2012-12-12' then d else t end as cond, group_concat( d ) from t1 group by cond;
drop table t1;
--echo #
--echo # Semantics of the condition <non-nullable datetime field> IS NULL
--echo # when the field belongs to an inner table of an outer join
--echo #
create table t1 (a int, b date not null);
insert t1 values (1, 0), (2, '1999-01-02');
create table t2 (c int);
insert t2 values (1),(3);
select * from t2 left join t1 on t1.a=t2.c where t1.a is null;
select * from t2 left join t1 on t1.a=t2.c where t1.b is null;
drop table t1,t2;
--echo End of 5.3 tests
......@@ -13325,20 +13325,27 @@ remove_eq_conds(THD *thd, COND *cond, Item::cond_result *cond_value)
/* fix to replace 'NULL' dates with '0' (shreeve@uci.edu) */
else if (((field->type() == MYSQL_TYPE_DATE) ||
(field->type() == MYSQL_TYPE_DATETIME)) &&
(field->flags & NOT_NULL_FLAG) &&
!field->table->maybe_null)
(field->flags & NOT_NULL_FLAG))
{
COND *new_cond;
if ((new_cond= new Item_func_eq(args[0],new Item_int("0", 0, 2))))
COND *eq_cond;
if (!(eq_cond= new Item_func_eq(args[0],new Item_int("0", 0, 2))))
return cond;
if (field->table->pos_in_table_list->outer_join)
{
cond=new_cond;
/*
Item_func_eq can't be fixed after creation so we do not check
cond->fixed, also it do not need tables so we use 0 as second
argument.
*/
cond->fix_fields(thd, &cond);
// outer join: transform "col IS NULL" to "col IS NULL or col=0"
Item *or_cond= new Item_cond_or(eq_cond, cond);
if (!or_cond)
return cond;
cond= or_cond;
}
else
{
// not outer join: transform "col IS NULL" to "col=0"
cond= eq_cond;
}
cond->fix_fields(thd, &cond);
}
}
if (cond->const_item() && !cond->is_expensive())
......
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