summaryrefslogtreecommitdiff
path: root/sql/time.cc
diff options
context:
space:
mode:
authorMartin Hansson <martin.hansson@sun.com>2009-11-02 13:24:07 +0100
committerMartin Hansson <martin.hansson@sun.com>2009-11-02 13:24:07 +0100
commitf539e0c8252aa8a54ddb0ca52e9708ec463c829b (patch)
treec3d0d1053c98a11a0ee39be7f8a6159d69706175 /sql/time.cc
parentbcf28194d7cc5a19aeb96dcefb23ef644f511deb (diff)
downloadmariadb-git-f539e0c8252aa8a54ddb0ca52e9708ec463c829b.tar.gz
Bug#47925: regression of range optimizer and date comparison in 5.1.39!
When a query was using a DATE or DATETIME value formatted using any other separator characters beside hyphen '-', a query with a greater-or-equal '>=' condition matching only the greatest value in an indexed column, the result was empty if index range scan was employed. The range optimizer got a new feature between 5.1.38 and 5.1.39 that changes a greater-or-equal condition to a greater-than if the value matching that in the query was not present in the table. But the value comparison function compared the dates as strings instead of dates. The bug was fixed by splitting the function get_date_from_str in two: One part that parses and does error checking. This function is now visible outside the module. The old get_date_from_str now calls the new function.
Diffstat (limited to 'sql/time.cc')
-rw-r--r--sql/time.cc16
1 files changed, 9 insertions, 7 deletions
diff --git a/sql/time.cc b/sql/time.cc
index 962b65e454c..8b554beb94b 100644
--- a/sql/time.cc
+++ b/sql/time.cc
@@ -965,20 +965,22 @@ calc_time_diff(MYSQL_TIME *l_time1, MYSQL_TIME *l_time2, int l_sign, longlong *s
0 - a == b
1 - a > b
- NOTES
- TIME.second_part is not considered during comparison
*/
-int
-my_time_compare(MYSQL_TIME *a, MYSQL_TIME *b)
+int my_time_compare(MYSQL_TIME *a, MYSQL_TIME *b)
{
- my_ulonglong a_t= TIME_to_ulonglong_datetime(a);
- my_ulonglong b_t= TIME_to_ulonglong_datetime(b);
+ ulonglong a_t= TIME_to_ulonglong_datetime(a);
+ ulonglong b_t= TIME_to_ulonglong_datetime(b);
+ if (a_t < b_t)
+ return -1;
if (a_t > b_t)
return 1;
- else if (a_t < b_t)
+
+ if (a->second_part < b->second_part)
return -1;
+ if (a->second_part > b->second_part)
+ return 1;
return 0;
}