Commit 862c42dd authored by Sergei Golubchik's avatar Sergei Golubchik

lp:731229 Different results depending on table access method with TIME column and CURDATE()

issue a warning when a datetime is truncated for storing in a TIME column.
this automatically prevents optimizer from using indexes when comparing time column to a datetime
parent edad8ed9
......@@ -3134,6 +3134,7 @@ values
'1991-01-01 01:01:01', '1991-01-01 01:01:01') ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -3141,6 +3142,7 @@ values
( 21, @arg00, @arg00, @arg00, @arg00, @arg00) ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
prepare stmt1 from "insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -3150,6 +3152,7 @@ values
execute stmt1 ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
prepare stmt2 from "insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -3158,6 +3161,7 @@ values
execute stmt2 using @arg00, @arg00, @arg00, @arg00, @arg00 ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
set @arg00= CAST('1991-01-01 01:01:01' as datetime) ;
insert into t9
......@@ -3170,6 +3174,7 @@ CAST('1991-01-01 01:01:01' as datetime),
CAST('1991-01-01 01:01:01' as datetime)) ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -3177,6 +3182,7 @@ values
( 31, @arg00, @arg00, @arg00, @arg00, @arg00) ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
prepare stmt1 from "insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -3189,6 +3195,7 @@ values
execute stmt1 ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
prepare stmt2 from "insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -3197,6 +3204,7 @@ values
execute stmt2 using @arg00, @arg00, @arg00, @arg00, @arg00 ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
set @arg00= 2000000000 ;
insert into t9
......
......@@ -3117,6 +3117,7 @@ values
'1991-01-01 01:01:01', '1991-01-01 01:01:01') ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -3124,6 +3125,7 @@ values
( 21, @arg00, @arg00, @arg00, @arg00, @arg00) ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
prepare stmt1 from "insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -3133,6 +3135,7 @@ values
execute stmt1 ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
prepare stmt2 from "insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -3141,6 +3144,7 @@ values
execute stmt2 using @arg00, @arg00, @arg00, @arg00, @arg00 ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
set @arg00= CAST('1991-01-01 01:01:01' as datetime) ;
insert into t9
......@@ -3153,6 +3157,7 @@ CAST('1991-01-01 01:01:01' as datetime),
CAST('1991-01-01 01:01:01' as datetime)) ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -3160,6 +3165,7 @@ values
( 31, @arg00, @arg00, @arg00, @arg00, @arg00) ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
prepare stmt1 from "insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -3172,6 +3178,7 @@ values
execute stmt1 ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
prepare stmt2 from "insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -3180,6 +3187,7 @@ values
execute stmt2 using @arg00, @arg00, @arg00, @arg00, @arg00 ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
set @arg00= 2000000000 ;
insert into t9
......
......@@ -3118,6 +3118,7 @@ values
'1991-01-01 01:01:01', '1991-01-01 01:01:01') ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -3125,6 +3126,7 @@ values
( 21, @arg00, @arg00, @arg00, @arg00, @arg00) ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
prepare stmt1 from "insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -3134,6 +3136,7 @@ values
execute stmt1 ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
prepare stmt2 from "insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -3142,6 +3145,7 @@ values
execute stmt2 using @arg00, @arg00, @arg00, @arg00, @arg00 ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
set @arg00= CAST('1991-01-01 01:01:01' as datetime) ;
insert into t9
......@@ -3154,6 +3158,7 @@ CAST('1991-01-01 01:01:01' as datetime),
CAST('1991-01-01 01:01:01' as datetime)) ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -3161,6 +3166,7 @@ values
( 31, @arg00, @arg00, @arg00, @arg00, @arg00) ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
prepare stmt1 from "insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -3173,6 +3179,7 @@ values
execute stmt1 ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
prepare stmt2 from "insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -3181,6 +3188,7 @@ values
execute stmt2 using @arg00, @arg00, @arg00, @arg00, @arg00 ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
set @arg00= 2000000000 ;
insert into t9
......
......@@ -3054,6 +3054,7 @@ values
'1991-01-01 01:01:01', '1991-01-01 01:01:01') ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -3061,6 +3062,7 @@ values
( 21, @arg00, @arg00, @arg00, @arg00, @arg00) ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
prepare stmt1 from "insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -3070,6 +3072,7 @@ values
execute stmt1 ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
prepare stmt2 from "insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -3078,6 +3081,7 @@ values
execute stmt2 using @arg00, @arg00, @arg00, @arg00, @arg00 ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
set @arg00= CAST('1991-01-01 01:01:01' as datetime) ;
insert into t9
......@@ -3090,6 +3094,7 @@ CAST('1991-01-01 01:01:01' as datetime),
CAST('1991-01-01 01:01:01' as datetime)) ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -3097,6 +3102,7 @@ values
( 31, @arg00, @arg00, @arg00, @arg00, @arg00) ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
prepare stmt1 from "insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -3109,6 +3115,7 @@ values
execute stmt1 ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
prepare stmt2 from "insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -3117,6 +3124,7 @@ values
execute stmt2 using @arg00, @arg00, @arg00, @arg00, @arg00 ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
set @arg00= 2000000000 ;
insert into t9
......@@ -6400,6 +6408,7 @@ values
'1991-01-01 01:01:01', '1991-01-01 01:01:01') ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -6407,6 +6416,7 @@ values
( 21, @arg00, @arg00, @arg00, @arg00, @arg00) ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
prepare stmt1 from "insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -6416,6 +6426,7 @@ values
execute stmt1 ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
prepare stmt2 from "insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -6424,6 +6435,7 @@ values
execute stmt2 using @arg00, @arg00, @arg00, @arg00, @arg00 ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
set @arg00= CAST('1991-01-01 01:01:01' as datetime) ;
insert into t9
......@@ -6436,6 +6448,7 @@ CAST('1991-01-01 01:01:01' as datetime),
CAST('1991-01-01 01:01:01' as datetime)) ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -6443,6 +6456,7 @@ values
( 31, @arg00, @arg00, @arg00, @arg00, @arg00) ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
prepare stmt1 from "insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -6455,6 +6469,7 @@ values
execute stmt1 ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
prepare stmt2 from "insert into t9
( c1, c13, c14, c15, c16, c17 )
......@@ -6463,6 +6478,7 @@ values
execute stmt2 using @arg00, @arg00, @arg00, @arg00, @arg00 ;
Warnings:
Note 1265 Data truncated for column 'c13' at row 1
Note 1265 Data truncated for column 'c16' at row 1
Warning 1265 Data truncated for column 'c17' at row 1
set @arg00= 2000000000 ;
insert into t9
......
drop table if exists t1;
create table t1 (t time);
insert into t1 values("10:22:33"),("12:34:56.78"),(10),(1234),(123456.78),(1234559.99),("1"),("1:23"),("1:23:45"), ("10.22"), ("-10 1:22:33.45"),("20 10:22:33"),("1999-02-03 20:33:34");
Warnings:
Note 1265 Data truncated for column 't' at row 13
insert t1 values (30),(1230),("1230"),("12:30"),("12:30:35"),("1 12:30:31.32");
select * from t1;
t
......@@ -154,3 +156,14 @@ select * from t1;
a
-13:14:15
drop table t1;
create table t1 (f1 time , f2 varchar(5), key(f1));
insert into t1 values ('00:20:01','a'),('00:20:03','b');
select * from t1 force key (f1) where f1 < curdate();
f1 f2
00:20:01 a
00:20:03 b
select * from t1 ignore key (f1) where f1 < curdate();
f1 f2
00:20:01 a
00:20:03 b
drop table t1;
......@@ -3,6 +3,8 @@ create table t1 (a time(7));
ERROR 42000: Too big precision 7 specified for column 'a'. Maximum is 6.
create table t1 (a time(3));
insert t1 values ('2010-12-11 01:02:03.4567');
Warnings:
Note 1265 Data truncated for column 'a' at row 1
insert t1 values (20101211010203.45678);
Warnings:
Warning 1264 Out of range value for column 'a' at row 1
......@@ -43,6 +45,8 @@ a
drop table t1;
create table t1 (a time(4)) engine=innodb;
insert t1 values ('2010-12-11 01:02:03.456789');
Warnings:
Note 1265 Data truncated for column 'a' at row 1
select * from t1;
a
01:02:03.4567
......@@ -82,6 +86,8 @@ select * from t1;
a
01:02:13.3332
insert t1 select a + interval 2 year from t1;
Warnings:
Note 1265 Data truncated for column 'a' at row 1
select * from t1;
a
01:02:13.3332
......@@ -105,6 +111,9 @@ drop table t1, t2, t3;
create table t1 (a time(6), b time(6));
create procedure foo(x time, y time(4)) insert into t1 values (x, y);
call foo('2010-02-03 4:5:6.789123', '2010-02-03 4:5:6.789123');
Warnings:
Note 1265 Data truncated for column 'x' at row 1
Note 1265 Data truncated for column 'y' at row 1
select * from t1;
a b
04:05:06.000000 04:05:06.789100
......@@ -115,6 +124,8 @@ set b = c + interval a microsecond;
insert t1 values (b, c + interval a microsecond);
end|
call bar(1111111, '2011-01-02 3:4:5.123456');
Warnings:
Note 1265 Data truncated for column 'c' at row 1
select * from t1;
a b
04:05:06.000000 04:05:06.789100
......@@ -126,6 +137,8 @@ return addtime('2010-10-10 10:10:10.101010', s);
select xyz('1:1:1.010101');
xyz('1:1:1.010101')
11:11:11.1111
Warnings:
Note 1265 Data truncated for column 'xyz('1:1:1.010101')' at row 1
drop function xyz;
create view v1 as select * from t1 group by a,b;
select * from v1;
......
......@@ -106,3 +106,12 @@ insert t1 values (-131415);
select * from t1;
drop table t1;
#
# lp:731229 Different results depending on table access method with TIME column and CURDATE()
#
create table t1 (f1 time , f2 varchar(5), key(f1));
insert into t1 values ('00:20:01','a'),('00:20:03','b');
select * from t1 force key (f1) where f1 < curdate();
select * from t1 ignore key (f1) where f1 < curdate();
drop table t1;
......@@ -5197,6 +5197,14 @@ int Field_temporal::store_TIME_with_warning(MYSQL_TIME *ltime,
was_cut|= MYSQL_TIME_WARN_TRUNCATED;
ret= 3;
}
else if (temporal_type() == MYSQL_TIMESTAMP_TIME &&
(ltime->year || ltime->month))
{
ltime->year= ltime->month= ltime->day= 0;
trunc_level= MYSQL_ERROR::WARN_LEVEL_NOTE;
was_cut|= MYSQL_TIME_WARN_TRUNCATED;
ret= 3;
}
/*
error code logic:
......@@ -5207,7 +5215,6 @@ int Field_temporal::store_TIME_with_warning(MYSQL_TIME *ltime,
Also, MYSQL_TIME_WARN_TRUNCATED is used when storing a DATETIME in
a DATE field and non-zero time part is thrown away.
QQ Why don't we do the same when storing DATETIME in TIME?
*/
if (was_cut & MYSQL_TIME_WARN_TRUNCATED)
set_datetime_warning(trunc_level, WARN_DATA_TRUNCATED,
......@@ -5330,10 +5337,6 @@ int Field_time::store(const char *from,uint len,CHARSET_INFO *cs)
int was_cut;
int have_smth_to_conv= str_to_datetime(from, len, &ltime, TIME_TIME_ONLY,
&was_cut) > MYSQL_TIMESTAMP_ERROR;
if (ltime.month)
ltime.day=0;
ltime.month= ltime.year= 0;
return store_TIME_with_warning(&ltime, &str, was_cut, have_smth_to_conv);
}
......@@ -5345,11 +5348,6 @@ int Field_time::store_time(MYSQL_TIME *ltime, timestamp_type time_type)
Lazy_string_time str(ltime);
int was_cut= 0;
if (l_time.month)
l_time.day=0;
l_time.year= 0;
l_time.month= 0;
int have_smth_to_conv= !check_time_range(&l_time, &was_cut);
return store_TIME_with_warning(&l_time, &str, was_cut, have_smth_to_conv);
}
......
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