Details
-
Task
-
Status: Closed (View Workflow)
-
Blocker
-
Resolution: Fixed
-
10.2.2-2, 10.2.2-3, 10.2.2-1, 10.2.2-2, 10.2.2-3, 10.2.2-4, 10.2.3-1, 10.2.3-2
Description
Would it be possible to make DATE() on datetime column sargable in some cases?
Like rewrite "DATE(col) = const" to "col BETWEEN concat(const, ' 00:00:00') AND concat(const, ' 23:59:59')"
Other similar cases:
- "YEAR(col) = const" is almost the same
- "YEAR(col) = c1 AND MONTH(col) = c2" and other such combinations may be too complex to be worth it.
Attachments
Issue Links
- causes
-
MDEV-30901 Index usage for DATE(datetime_column) = const does not work for engine Memory
-
- Closed
-
-
MDEV-30913 Index usage for DATE(datetime_column) = const does not work for engine Connect
-
- Closed
-
-
MDEV-30946 Index usage for DATE(datetime_column) = const does not work for DELETE and UPDATE
-
- Closed
-
-
MDEV-33299 Assertion `(tm->tv_usec % (int) log_10_int[6 - dec]) == 0' failed in void my_timestamp_to_binary(const timeval*, uchar*, uint)
-
- Closed
-
- is duplicated by
-
MDEV-8937 Optimize date functions in the parser
-
- Closed
-
- relates to
-
MDEV-30930 Make more date conditions sargable
-
- Open
-
-
MDEV-14635 Convert date operations on indexed column to sargable equivalents where possible
-
- Closed
-
There are test failures looking like
main.sargable_date_cond w3 [ fail ]
Test ended at 2023-03-16 04:35:43
CURRENT_TEST: main.sargable_date_cond
--- /usr/share/mysql/mysql-test/main/sargable_date_cond.result 2023-03-16 01:36:33.000000000 -0400
+++ /dev/shm/var/3/log/sargable_date_cond.reject 2023-03-16 04:35:42.953159711 -0400
@@ -1919,6 +1919,8 @@
timestampadd(hour, B.a, date_add('2016-01-01', interval A.a*8 day)),
date_add('2016-01-01', interval A.a*7 day)
from t1 A, t0 B;
+Warnings:
+Warning 1299 Invalid TIMESTAMP value in column 'a' at row 11
that occur only on some machines and not on others. Turns out it depends on whether the system time zone employs daylight saving time.
If it does then calling timestampadd() can lead to execution of the following code
my_time.cc
/*
Fix that if we are in the non existing daylight saving time hour
we move the start of the next real hour.
This code doesn't handle such exotical thing as time-gaps whose length
is more than one hour or non-integer (latter can theoretically happen
if one of seconds will be removed due leap correction, or because of
general time correction like it happened for Africa/Monrovia time zone
in year 1972).
*/
if (loop == 2 && t->hour != (uint) l_time->tm_hour)
{
int days= t->day - l_time->tm_mday;
if (days < -1)
days=1; /* Month has wrapped */
else if (days > 1)
days= -1;
diff=(3600L*(long) (days*24+((int) t->hour - (int) l_time->tm_hour))+
(long) (60*((int) t->minute - (int) l_time->tm_min)) +
(long) ((int) t->second - (int) l_time->tm_sec));
if (diff == 3600)
tmp+=3600 - t->minute*60 - t->second; /* Move to next hour */
else if (diff == -3600)
tmp-=t->minute*60 + t->second; /* Move to previous hour */
*error_code= ER_WARN_INVALID_TIMESTAMP;
}