drop table if exists t1;
create table t1 (t datetime);
insert into t1 values (101),(691231),(700101),(991231),(10000101),(99991231),(101000000),(691231000000),(700101000000),(991231235959),(10000101000000),(99991231235959),(20030100000000),(20030000000000);
select * from t1;
t
2000-01-01 00:00:00
2069-12-31 00:00:00
1970-01-01 00:00:00
1999-12-31 00:00:00
1000-01-01 00:00:00
9999-12-31 00:00:00
2000-01-01 00:00:00
2069-12-31 00:00:00
1970-01-01 00:00:00
1999-12-31 23:59:59
1000-01-01 00:00:00
9999-12-31 23:59:59
2003-01-00 00:00:00
2003-00-00 00:00:00
delete from t1 where t > 0;
optimize table t1;
Table	Op	Msg_type	Msg_text
test.t1	optimize	status	OK
check table t1;
Table	Op	Msg_type	Msg_text
test.t1	check	status	OK
delete from t1;
insert into t1 values("000101"),("691231"),("700101"),("991231"),("00000101"),("00010101"),("99991231"),("00101000000"),("691231000000"),("700101000000"),("991231235959"),("10000101000000"),("99991231235959"),("20030100000000"),("20030000000000");
insert into t1 values ("2003-003-03");
insert into t1 values ("20030102T131415"),("2001-01-01T01:01:01"), ("2001-1-1T1:01:01");
select * from t1;
t
2000-01-01 00:00:00
2069-12-31 00:00:00
1970-01-01 00:00:00
1999-12-31 00:00:00
0000-01-01 00:00:00
0001-01-01 00:00:00
9999-12-31 00:00:00
2000-10-10 00:00:00
2069-12-31 00:00:00
1970-01-01 00:00:00
1999-12-31 23:59:59
1000-01-01 00:00:00
9999-12-31 23:59:59
2003-01-00 00:00:00
2003-00-00 00:00:00
2003-03-03 00:00:00
2003-01-02 13:14:15
2001-01-01 01:01:01
2001-01-01 01:01:01
truncate table t1;
insert into t1 values("2003-0303 12:13:14");
Warnings:
Warning	1264	Out of range value adjusted for column 't' at row 1
select * from t1;
t
0000-00-00 00:00:00
drop table t1;
CREATE TABLE t1 (a timestamp, b date, c time, d datetime);
insert into t1 (b,c,d) values(now(),curtime(),now());
Warnings:
Note	1265	Data truncated for column 'b' at row 1
select date_format(a,"%Y-%m-%d")=b,right(a+0,6)=c+0,a=d+0 from t1;
date_format(a,"%Y-%m-%d")=b	right(a+0,6)=c+0	a=d+0
1	1	1
drop table t1;
CREATE TABLE t1 (a datetime not null);
insert into t1 values (0);
select * from t1 where a is null;
a
0000-00-00 00:00:00
drop table t1;
create table t1 (id int, dt datetime);
insert into t1 values (1,"2001-08-14 00:00:00"),(2,"2001-08-15 00:00:00"),(3,"2001-08-16 00:00:00"),(4,"2003-09-15 01:20:30");
select * from t1 where dt='2001-08-14 00:00:00' and dt =  if(id=1,'2001-08-14 00:00:00','1999-08-15');
id	dt
1	2001-08-14 00:00:00
create index dt on t1 (dt);
select * from t1 where dt > 20021020;
id	dt
4	2003-09-15 01:20:30
select * from t1 ignore index (dt) where dt > 20021020;
id	dt
4	2003-09-15 01:20:30
drop table t1;
CREATE TABLE `t1` (
`date` datetime NOT NULL default '0000-00-00 00:00:00',
`numfacture` int(6) unsigned NOT NULL default '0',
`expedition` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY  (`numfacture`),
KEY `date` (`date`),
KEY `expedition` (`expedition`)
) ENGINE=MyISAM;
INSERT INTO t1 (expedition) VALUES ('0001-00-00 00:00:00');
SELECT * FROM t1 WHERE expedition='0001-00-00 00:00:00';
date	numfacture	expedition
0000-00-00 00:00:00	0	0001-00-00 00:00:00
INSERT INTO t1 (numfacture,expedition) VALUES ('1212','0001-00-00 00:00:00');
SELECT * FROM t1 WHERE expedition='0001-00-00 00:00:00';
date	numfacture	expedition
0000-00-00 00:00:00	0	0001-00-00 00:00:00
0000-00-00 00:00:00	1212	0001-00-00 00:00:00
EXPLAIN SELECT * FROM t1 WHERE expedition='0001-00-00 00:00:00';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ref	expedition	expedition	8	const	1	
drop table t1;
create table t1 (a datetime not null, b datetime not null);
insert into t1 values (now(), now());
insert into t1 values (now(), now());
select * from t1 where a is null or b is null;
a	b
drop table t1;
create table t1 (t datetime);
insert into t1 values (20030102030460),(20030102036301),(20030102240401),
(20030132030401),(20031302030401),(100001202030401);
Warnings:
Warning	1264	Out of range value adjusted for column 't' at row 1
Warning	1264	Out of range value adjusted for column 't' at row 2
Warning	1264	Out of range value adjusted for column 't' at row 3
Warning	1264	Out of range value adjusted for column 't' at row 4
Warning	1264	Out of range value adjusted for column 't' at row 5
Warning	1264	Out of range value adjusted for column 't' at row 6
select * from t1;
t
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
delete from t1;
insert into t1 values
("2003-01-02 03:04:60"),("2003-01-02 03:63:01"),("2003-01-02 24:04:01"),
("2003-01-32 03:04:01"),("2003-13-02 03:04:01"), ("10000-12-02 03:04:00");
Warnings:
Warning	1264	Out of range value adjusted for column 't' at row 1
Warning	1264	Out of range value adjusted for column 't' at row 2
Warning	1264	Out of range value adjusted for column 't' at row 3
Warning	1264	Out of range value adjusted for column 't' at row 4
Warning	1264	Out of range value adjusted for column 't' at row 5
Warning	1264	Out of range value adjusted for column 't' at row 6
select * from t1;
t
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
delete from t1;
insert into t1 values ("0000-00-00 00:00:00 some trailer"),("2003-01-01 00:00:00 some trailer");
Warnings:
Warning	1264	Out of range value adjusted for column 't' at row 1
Warning	1264	Out of range value adjusted for column 't' at row 2
select * from t1;
t
0000-00-00 00:00:00
2003-01-01 00:00:00
drop table t1;
create table t1 (dt datetime);
insert into t1 values ("12-00-00"), ("00-00-00 01:00:00");
insert into t1 values ("00-00-00"), ("00-00-00 00:00:00");
select * from t1;
dt
2012-00-00 00:00:00
2000-00-00 01:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
drop table t1;
select cast('2006-12-05 22:10:10' as datetime) + 0;
cast('2006-12-05 22:10:10' as datetime) + 0
20061205221010.000000
CREATE TABLE t1(a DATETIME NOT NULL);
INSERT INTO t1 VALUES ('20060606155555');
SELECT a FROM t1 WHERE a=(SELECT MAX(a) FROM t1) AND (a="20060606155555");
a
2006-06-06 15:55:55
PREPARE s FROM 'SELECT a FROM t1 WHERE a=(SELECT MAX(a) FROM t1) AND (a="20060606155555")';
EXECUTE s;
a
2006-06-06 15:55:55
DROP PREPARE s;
DROP TABLE t1;
SELECT CAST(CAST('2006-08-10' AS DATE) AS DECIMAL(20,6));
CAST(CAST('2006-08-10' AS DATE) AS DECIMAL(20,6))
20060810.000000
SELECT CAST(CAST('2006-08-10 10:11:12' AS DATETIME) AS DECIMAL(20,6));
CAST(CAST('2006-08-10 10:11:12' AS DATETIME) AS DECIMAL(20,6))
20060810101112.000000
SELECT CAST(CAST('2006-08-10 10:11:12' AS DATETIME) + INTERVAL 14 MICROSECOND AS DECIMAL(20,6));
CAST(CAST('2006-08-10 10:11:12' AS DATETIME) + INTERVAL 14 MICROSECOND AS DECIMAL(20,6))
20060810101112.000014
SELECT CAST(CAST('10:11:12.098700' AS TIME) AS DECIMAL(20,6));
CAST(CAST('10:11:12.098700' AS TIME) AS DECIMAL(20,6))
101112.098700
set @org_mode=@@sql_mode;
create table t1 (da date default '1962-03-03 23:33:34', dt datetime default '1962-03-03');
Warnings:
Note	1265	Data truncated for column 'da' at row 1
show create table t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `da` date default '1962-03-03',
  `dt` datetime default '1962-03-03 00:00:00'
) ENGINE=MyISAM DEFAULT CHARSET=latin1
insert into t1 values ();
insert into t1 values ('2007-03-23 13:49:38','2007-03-23 13:49:38');
Warnings:
Note	1265	Data truncated for column 'da' at row 1
set @@sql_mode='ansi,traditional';
insert into t1 values ('2007-03-23 13:49:38','2007-03-23 13:49:38');
Warnings:
Note	1265	Data truncated for column 'da' at row 1
insert into t1 set dt='2007-03-23 13:49:38',da=dt;
Warnings:
Note	1265	Data truncated for column 'da' at row 1
insert into t1 values ('2007-03-32','2007-03-23 13:49:38');
ERROR 22007: Incorrect date value: '2007-03-32' for column 'da' at row 1
select * from t1;
da	dt
1962-03-03	1962-03-03 00:00:00
2007-03-23	2007-03-23 13:49:38
2007-03-23	2007-03-23 13:49:38
2007-03-23	2007-03-23 13:49:38
drop table t1;
create table t1 (da date default '1962-03-32 23:33:34', dt datetime default '1962-03-03');
ERROR 42000: Invalid default value for 'da'
create table t1 (t time default '916:00:00 a');
ERROR 42000: Invalid default value for 't'
set @@sql_mode= @org_mode;
create table t1 (f1 date, f2 datetime, f3 timestamp);
insert into t1(f1) values(curdate());
select curdate() < now(), f1 < now(), cast(f1 as date) < now() from t1;
curdate() < now()	f1 < now()	cast(f1 as date) < now()
1	1	1
delete from t1;
insert into t1 values('2001-01-01','2001-01-01 01:01:01','2001-01-01 01:01:01');
insert into t1 values('2001-02-05','2001-02-05 00:00:00','2001-02-05 01:01:01');
insert into t1 values('2001-03-10','2001-03-09 01:01:01','2001-03-10 01:01:01');
insert into t1 values('2001-04-15','2001-04-15 00:00:00','2001-04-15 00:00:00');
insert into t1 values('2001-05-20','2001-05-20 01:01:01','2001-05-20 01:01:01');
select f1, f3 from t1 where f1 >= '2001-02-05 00:00:00' and f3 <= '2001-04-15';
f1	f3
2001-02-05	2001-02-05 01:01:01
2001-03-10	2001-03-10 01:01:01
2001-04-15	2001-04-15 00:00:00
select f1, f3 from t1 where f1 >= '2001-2-5 0:0:0' and f2 <= '2001-4-15';
f1	f3
2001-02-05	2001-02-05 01:01:01
2001-03-10	2001-03-10 01:01:01
2001-04-15	2001-04-15 00:00:00
select f1, f2 from t1 where if(1, f1, 0) >= f2;
f1	f2
2001-02-05	2001-02-05 00:00:00
2001-03-10	2001-03-09 01:01:01
2001-04-15	2001-04-15 00:00:00
select 1 from dual where cast('2001-1-1 2:3:4' as date) = cast('2001-01-01' as datetime);
1
1
select f1, f2, f1 > f2, f1 = f2, f1 < f2 from t1;
f1	f2	f1 > f2	f1 = f2	f1 < f2
2001-01-01	2001-01-01 01:01:01	0	0	1
2001-02-05	2001-02-05 00:00:00	0	1	0
2001-03-10	2001-03-09 01:01:01	1	0	0
2001-04-15	2001-04-15 00:00:00	0	1	0
2001-05-20	2001-05-20 01:01:01	0	0	1
drop table t1;
create table t1 (f1 date, f2 datetime, f3 timestamp);
insert into t1 values('2001-01-01','2001-01-01 01:01:01','2001-01-01 01:01:01');
insert into t1 values('2001-02-05','2001-02-05 00:00:00','2001-02-05 01:01:01');
insert into t1 values('2001-03-10','2001-03-09 01:01:01','2001-03-10 01:01:01');
insert into t1 values('2001-04-15','2001-04-15 00:00:00','2001-04-15 00:00:00');
insert into t1 values('2001-05-20','2001-05-20 01:01:01','2001-05-20 01:01:01');
select f2 from t1 where f2 between '2001-2-5' and '01-04-14';
f2
2001-02-05 00:00:00
2001-03-09 01:01:01
select f1, f2, f3 from t1 where f1 between f2 and f3;
f1	f2	f3
2001-02-05	2001-02-05 00:00:00	2001-02-05 01:01:01
2001-03-10	2001-03-09 01:01:01	2001-03-10 01:01:01
2001-04-15	2001-04-15 00:00:00	2001-04-15 00:00:00
select f1, f2, f3 from t1 where cast(f1 as datetime) between f2 and
cast(f3 as date);
f1	f2	f3
2001-02-05	2001-02-05 00:00:00	2001-02-05 01:01:01
2001-03-10	2001-03-09 01:01:01	2001-03-10 01:01:01
2001-04-15	2001-04-15 00:00:00	2001-04-15 00:00:00
select f2 from t1 where '2001-04-10 12:34:56' between f2 and '01-05-01';
f2
2001-01-01 01:01:01
2001-02-05 00:00:00
2001-03-09 01:01:01
select f2, f3 from t1 where '01-03-10' between f2 and f3;
f2	f3
2001-03-09 01:01:01	2001-03-10 01:01:01
select f2 from t1 where DATE(f2) between "2001-4-15" AND "01-4-15";
f2
2001-04-15 00:00:00
SELECT 1 from dual where NOW() BETWEEN CURRENT_DATE() - INTERVAL 1 DAY AND CURRENT_DATE();
1
drop table t1;
create table t1 (f1 date);
insert into t1 values('01-01-01'),('01-01-02'),('01-01-03');
select * from t1 where f1 in ('01-01-01','2001-01-02','2001-01-03 00:00:00');
f1
2001-01-01
2001-01-02
2001-01-03
create table t2(f2 datetime);
insert into t2 values('01-01-01 00:00:00'),('01-02-03 12:34:56'),('02-04-06 11:22:33');
select * from t2 where f2 in ('01-01-01','01-02-03 12:34:56','01-02-03');
f2
2001-01-01 00:00:00
2001-02-03 12:34:56
select * from t1,t2 where '01-01-02' in (f1, cast(f2 as date));
f1	f2
2001-01-02	2001-01-01 00:00:00
2001-01-02	2001-02-03 12:34:56
2001-01-02	2002-04-06 11:22:33
select * from t1,t2 where '01-01-01' in (f1, '01-02-03');
f1	f2
2001-01-01	2001-01-01 00:00:00
2001-01-01	2001-02-03 12:34:56
2001-01-01	2002-04-06 11:22:33
select * from t1,t2 where if(1,'01-02-03 12:34:56','') in (f1, f2);
f1	f2
2001-01-01	2001-02-03 12:34:56
2001-01-02	2001-02-03 12:34:56
2001-01-03	2001-02-03 12:34:56
create table t3(f3 varchar(20));
insert into t3 select * from t2;
select * from t2,t3 where f2 in (f3,'03-04-05');
f2	f3
2001-01-01 00:00:00	2001-01-01 00:00:00
2001-02-03 12:34:56	2001-02-03 12:34:56
2002-04-06 11:22:33	2002-04-06 11:22:33
select f1,f2,f3 from t1,t2,t3 where (f1,'1') in ((f2,'1'),(f3,'1'));
f1	f2	f3
2001-01-01	2001-01-01 00:00:00	2001-01-01 00:00:00
2001-01-01	2001-02-03 12:34:56	2001-01-01 00:00:00
2001-01-01	2002-04-06 11:22:33	2001-01-01 00:00:00
2001-01-01	2001-01-01 00:00:00	2001-02-03 12:34:56
2001-01-01	2001-01-01 00:00:00	2002-04-06 11:22:33
select f1 from t1 where ('1',f1) in (('1','01-01-01'),('1','2001-1-1 0:0:0'),('1','02-02-02'));
f1
2001-01-01
drop table t1,t2,t3;
select least(cast('01-01-01' as date), '01-01-02');
least(cast('01-01-01' as date), '01-01-02')
2001-01-01
select greatest(cast('01-01-01' as date), '01-01-02');
greatest(cast('01-01-01' as date), '01-01-02')
01-01-02
select least(cast('01-01-01' as date), '01-01-02') + 0;
least(cast('01-01-01' as date), '01-01-02') + 0
20010101
select greatest(cast('01-01-01' as date), '01-01-02') + 0;
greatest(cast('01-01-01' as date), '01-01-02') + 0
20010102
select least(cast('01-01-01' as datetime), '01-01-02') + 0;
least(cast('01-01-01' as datetime), '01-01-02') + 0
20010101000000
select cast(least(cast('01-01-01' as datetime), '01-01-02') as signed);
cast(least(cast('01-01-01' as datetime), '01-01-02') as signed)
20010101000000
select cast(least(cast('01-01-01' as datetime), '01-01-02') as decimal(20,2));
cast(least(cast('01-01-01' as datetime), '01-01-02') as decimal(20,2))
20010101000000.00
DROP PROCEDURE IF EXISTS test27759 ;
CREATE PROCEDURE test27759()
BEGIN
declare v_a date default '2007-4-10';
declare v_b date default '2007-4-11';
declare v_c datetime default '2004-4-9 0:0:0';
select v_a as a,v_b as b,
least( v_a, v_b ) as a_then_b,
least( v_b, v_a ) as b_then_a,
least( v_c, v_a ) as c_then_a;
END;|
call test27759();
a	b	a_then_b	b_then_a	c_then_a
2007-04-10	2007-04-11	2007-04-10	2007-04-10	2004-04-09 00:00:00
drop procedure test27759;
create table t1 (f1 date);
insert into t1 values (curdate());
select left(f1,10) = curdate() from t1;
left(f1,10) = curdate()
1
drop table t1;
create table t1(f1 date);
insert into t1 values('01-01-01'),('02-02-02'),('01-01-01'),('02-02-02');
set @bug28261='';
select if(@bug28261 = f1, '', @bug28261:= f1) from t1;
if(@bug28261 = f1, '', @bug28261:= f1)
2001-01-01
2002-02-02
2001-01-01
2002-02-02
Warnings:
Warning	1292	Incorrect date value: '' for column 'f1' at row 1
select if(@bug28261 = f1, '', @bug28261:= f1) from t1;
if(@bug28261 = f1, '', @bug28261:= f1)
2001-01-01
2002-02-02
2001-01-01
2002-02-02
select if(@bug28261 = f1, '', @bug28261:= f1) from t1;
if(@bug28261 = f1, '', @bug28261:= f1)
2001-01-01
2002-02-02
2001-01-01
2002-02-02
drop table t1;
create table t1(f1 datetime);
insert into t1 values('2001-01-01'),('2002-02-02');
select * from t1 where f1 between 20020101 and 20070101000000;
f1
2002-02-02 00:00:00
select * from t1 where f1 between 2002010 and 20070101000000;
f1
2001-01-01 00:00:00
2002-02-02 00:00:00
Warnings:
Warning	1292	Incorrect datetime value: '2002010' for column 'f1' at row 1
select * from t1 where f1 between 20020101 and 2007010100000;
f1
Warnings:
Warning	1292	Incorrect datetime value: '2007010100000' for column 'f1' at row 1
drop table t1;
#
# Bug#27216: functions with parameters of different date types may
#            return wrong type of the result.
#
create table t1 (f1 date, f2 datetime, f3 varchar(20));
create table t2 as select coalesce(f1,f1) as f4 from t1;
desc t2;
Field	Type	Null	Key	Default	Extra
f4	date	YES		NULL	
create table t3 as select coalesce(f1,f2) as f4 from t1;
desc t3;
Field	Type	Null	Key	Default	Extra
f4	datetime	YES		NULL	
create table t4 as select coalesce(f2,f2) as f4 from t1;
desc t4;
Field	Type	Null	Key	Default	Extra
f4	datetime	YES		NULL	
create table t5 as select coalesce(f1,f3) as f4 from t1;
desc t5;
Field	Type	Null	Key	Default	Extra
f4	varbinary(20)	YES		NULL	
create table t6 as select coalesce(f2,f3) as f4 from t1;
desc t6;
Field	Type	Null	Key	Default	Extra
f4	varbinary(20)	YES		NULL	
create table t7 as select coalesce(makedate(1997,1),f2) as f4 from t1;
desc t7;
Field	Type	Null	Key	Default	Extra
f4	datetime	YES		NULL	
create table t8 as select coalesce(cast('01-01-01' as datetime),f2) as f4
from t1;
desc t8;
Field	Type	Null	Key	Default	Extra
f4	datetime	YES		NULL	
create table t9 as select case when 1 then cast('01-01-01' as date)
when 0 then cast('01-01-01' as date) end as f4 from t1;
desc t9;
Field	Type	Null	Key	Default	Extra
f4	date	YES		NULL	
create table t10 as select case when 1 then cast('01-01-01' as datetime)
when 0 then cast('01-01-01' as datetime) end as f4 from t1;
desc t10;
Field	Type	Null	Key	Default	Extra
f4	datetime	YES		NULL	
create table t11 as select if(1, cast('01-01-01' as datetime),
cast('01-01-01' as date)) as f4 from t1;
desc t11;
Field	Type	Null	Key	Default	Extra
f4	datetime	YES		NULL	
create table t12 as select least(cast('01-01-01' as datetime),
cast('01-01-01' as date)) as f4 from t1;
desc t12;
Field	Type	Null	Key	Default	Extra
f4	datetime	YES		NULL	
create table t13 as select ifnull(cast('01-01-01' as datetime),
cast('01-01-01' as date)) as f4 from t1;
desc t13;
Field	Type	Null	Key	Default	Extra
f4	datetime	YES		NULL	
drop tables t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13;
###################################################################
create table t1 (f1 time);
insert into t1 set f1 = '45:44:44';
insert into t1 set f1 = '15:44:44';
select * from t1 where (convert(f1,datetime)) != 1;
f1
15:44:44
Warnings:
Warning	1292	Truncated incorrect datetime value: '0000-00-00 45:44:44'
drop table t1;
create table t1 (a tinyint);
insert into t1 values (), (), ();
select sum(a) from t1 group by convert(a, datetime);
sum(a)
NULL
drop table t1;
create table t1 (id int(10) not null, cur_date datetime not null);
create table t2 (id int(10) not null, cur_date date not null);
insert into t1 (id, cur_date) values (1, '2007-04-25 18:30:22');
insert into t2 (id, cur_date) values (1, '2007-04-25');
explain extended
select * from t1
where id in (select id from t1 as x1 where (t1.cur_date is null));
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
2	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
Warnings:
Note	1276	Field or reference 'test.t1.cur_date' of SELECT #2 was resolved in SELECT #1
Note	1003	select '1' AS `id`,'2007-04-25 18:30:22' AS `cur_date` from `test`.`t1` where <in_optimizer>('1',<exists>(select 1 AS `Not_used` from `test`.`t1` `x1` where 0))
select * from t1
where id in (select id from t1 as x1 where (t1.cur_date is null));
id	cur_date
explain extended
select * from t2
where id in (select id from t2 as x1 where (t2.cur_date is null));
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
2	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
Warnings:
Note	1276	Field or reference 'test.t2.cur_date' of SELECT #2 was resolved in SELECT #1
Note	1003	select '1' AS `id`,'2007-04-25' AS `cur_date` from `test`.`t2` where <in_optimizer>('1',<exists>(select 1 AS `Not_used` from `test`.`t2` `x1` where 0))
select * from t2
where id in (select id from t2 as x1 where (t2.cur_date is null));
id	cur_date
insert into t1 (id, cur_date) values (2, '2007-04-26 18:30:22');
insert into t2 (id, cur_date) values (2, '2007-04-26');
explain extended
select * from t1
where id in (select id from t1 as x1 where (t1.cur_date is null));
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	2	Using where
2	DEPENDENT SUBQUERY	x1	ALL	NULL	NULL	NULL	NULL	2	Using where
Warnings:
Note	1276	Field or reference 'test.t1.cur_date' of SELECT #2 was resolved in SELECT #1
Note	1003	select `test`.`t1`.`id` AS `id`,`test`.`t1`.`cur_date` AS `cur_date` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`id`,<exists>(select 1 AS `Not_used` from `test`.`t1` `x1` where ((`test`.`t1`.`cur_date` = 0) and (<cache>(`test`.`t1`.`id`) = `test`.`x1`.`id`))))
select * from t1
where id in (select id from t1 as x1 where (t1.cur_date is null));
id	cur_date
explain extended
select * from t2
where id in (select id from t2 as x1 where (t2.cur_date is null));
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	2	Using where
2	DEPENDENT SUBQUERY	x1	ALL	NULL	NULL	NULL	NULL	2	Using where
Warnings:
Note	1276	Field or reference 'test.t2.cur_date' of SELECT #2 was resolved in SELECT #1
Note	1003	select `test`.`t2`.`id` AS `id`,`test`.`t2`.`cur_date` AS `cur_date` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`id`,<exists>(select 1 AS `Not_used` from `test`.`t2` `x1` where ((`test`.`t2`.`cur_date` = 0) and (<cache>(`test`.`t2`.`id`) = `test`.`x1`.`id`))))
select * from t2
where id in (select id from t2 as x1 where (t2.cur_date is null));
id	cur_date
drop table t1,t2;
SELECT 
CAST('NULL' AS DATE) <=> CAST('2008-01-01' AS DATE) n1, 
CAST('2008-01-01' AS DATE) <=> CAST('NULL' AS DATE) n2,
CAST('NULL' AS DATE) <=> CAST('NULL' AS DATE) n3,
CAST('NULL' AS DATE) <> CAST('2008-01-01' AS DATE) n4, 
CAST('2008-01-01' AS DATE) <> CAST('NULL' AS DATE) n5,
CAST('NULL' AS DATE) <> CAST('NULL' AS DATE) n6,
CAST('NULL' AS DATE) < CAST('2008-01-01' AS DATE) n7, 
CAST('2008-01-01' AS DATE) < CAST('NULL' AS DATE) n8,
CAST('NULL' AS DATE) < CAST('NULL' AS DATE) n9;
n1	n2	n3	n4	n5	n6	n7	n8	n9
0	0	1	NULL	NULL	NULL	NULL	NULL	NULL
Warnings:
Warning	1292	Truncated incorrect datetime value: 'NULL'
Warning	1292	Truncated incorrect datetime value: 'NULL'
Warning	1292	Truncated incorrect datetime value: 'NULL'
Warning	1292	Truncated incorrect datetime value: 'NULL'
Warning	1292	Truncated incorrect datetime value: 'NULL'
Warning	1292	Truncated incorrect datetime value: 'NULL'
Warning	1292	Truncated incorrect datetime value: 'NULL'
Warning	1292	Truncated incorrect datetime value: 'NULL'
Warning	1292	Truncated incorrect datetime value: 'NULL'
Warning	1292	Truncated incorrect datetime value: 'NULL'
End of 5.0 tests
