diff options
author | Sergei Golubchik <sergii@pisem.net> | 2011-03-08 22:01:40 +0100 |
---|---|---|
committer | Sergei Golubchik <sergii@pisem.net> | 2011-03-08 22:01:40 +0100 |
commit | 743b6f866b3fdc7a40e5b3e81228be61353aeba6 (patch) | |
tree | 2e8feb581797548dbcbff2fab0dca990ebb7818f /sql/field.cc | |
parent | 8b7fd8f577fe3edc84eea54288c7d30775a1559b (diff) | |
download | mariadb-git-743b6f866b3fdc7a40e5b3e81228be61353aeba6.tar.gz |
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
Diffstat (limited to 'sql/field.cc')
-rw-r--r-- | sql/field.cc | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/sql/field.cc b/sql/field.cc index 32ac51a1e39..f32f7d3c214 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -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, <ime, TIME_TIME_ONLY, &was_cut) > MYSQL_TIMESTAMP_ERROR; - - if (ltime.month) - ltime.day=0; - ltime.month= ltime.year= 0; return store_TIME_with_warning(<ime, &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); } |