[MDEV-14731] EXTRACT(HOUR ....) gives incorect value when hour > 23 Created: 2017-12-15 Updated: 2017-12-23 Resolved: 2017-12-23 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Temporal Types |
| Affects Version/s: | 5.5, 10.0, 10.1, 10.2 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Minor |
| Reporter: | MIke Thibodeau | Assignee: | Alexander Barkov |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | None | ||
| Description |
|
Using extract to get number of hours from a time_diff function produces incorrect results when number of hours is greater than 23. Here's the details...
|
| Comments |
| Comment by David Thompson (Inactive) [ 2017-12-19 ] | |||||||||||||||||||||
|
I think this is working as designed. Extract (hour from ..) is meant to be hour of day not total hours. This behaves the same in both columnstore and regular mariadb 10.2. Is your goal to calculate the total number of hours between the 2 dates, if so i think the following is what you need: | |||||||||||||||||||||
| Comment by MIke Thibodeau [ 2017-12-19 ] | |||||||||||||||||||||
|
Thanks David, I came across this issue doing some testing. We are looking at moving an app from MySQL to MariaDB column store. As you pointed out there are many ways to solve the problem. I thought it was a bug because it behaves differently on our MySQL servers running 5.1.53, 5.6.23 and 5.7.17. They all return the total hours... SET @prev_ts = '2017-11-30 11:00:00'; This is not going to be a problem for me, but I thought i should report it. | |||||||||||||||||||||
| Comment by David Thompson (Inactive) [ 2017-12-21 ] | |||||||||||||||||||||
|
I see what you mean. This actually seems to be more of a general behavior difference between mysql and mariadb so i'm moving it over to the core server component for their review as i'm not sure if this is intentional behavior difference or not. | |||||||||||||||||||||
| Comment by Elena Stepanova [ 2017-12-22 ] | |||||||||||||||||||||
|
The basic test case is this:
The change in behavior was introduced in 5.5.35 and later versions by this fix:
The change for HOUR function was obviously intentional, but one of justifications was that MySQL 5.6 had a fix. For EXTRACT, however, the behavior in all versions of MySQL is the same – "presumably correct" in the examples above. Both MariaDB KB and MySQL manual are unclear on what should actually be returned; the best that I found in the standard was this:
"Immediately contained" probably means in our case that hours should be taken as is, rather than converted into a remainder of full days. However, it's still vague, so I'm leaving it to bar, who is both the data type expert and the author of the change, to decide if it needs to be fixed. | |||||||||||||||||||||
| Comment by Alexander Barkov [ 2017-12-23 ] | |||||||||||||||||||||
|
The SQL standard has two different data types:
Historically, MySQL (and MariaDB) uses the same TIME data type to store both. The function TIMEDIFF is not standard, but obviously it returns The function EXTRACT() is standard. In case when its argument So in the above example, EXTRACT() follows the standard and for the given This change was made under terms of Sorry for this inconvenience. As a simple workaround instead of EXTRACT(HOUR),
Notice, HOUR() still returns DD*24+hh. |