It seems that MariaDB 5.5 handles NOW() and equality checks against time columns in an unexpected way. Notice:
select a.* from (
select now() as now, TIME ( '06:00:00' ) as start, TIME ( '19:00:00' ) as stop
) a
WHERE start <= NOW()
AND stop >= now();
In MySQL 5.0, 5.5, 5.6, 5.7, and MariaDB 10, this query returns a row when NOW() is a time of day between 06:00 and 19:00. However, on MariaDB 5.5, no row is returned. Changing the query to force casting like this allows the query to work:
select a.* from (
select now() as now, TIME ( '06:00:00' ) as start, TIME ( '19:00:00' ) as stop
) a
WHERE start <= time (NOW())
AND stop >= time (now());
It is my guess that MariaDB is casting the NOW() to a string, then comparing against the string equivalent of 'start'. Or perhaps it is casting both fields to DATETIMEs and since the start/stop column omits the date component, MariaDB might be putting some incorrect date into the cast DATETIME.
relates to
MDEV-6102
Comparison between TIME and DATETIME does not use CURRENT_DATE
Closed
Jesse Skrivseth
made changes -
2018-06-20 00:01
Field
Original Value
New Value
Description
It seems that MariaDB 5.5 handles NOW() and equality checks against time columns in an unexpected way. Notice:
{code:sql}
select a.* from (
select now() as now, TIME('06:00:00') as start, TIME('19:00:00') as stop
) a
WHERE start <= NOW()
AND stop >= now();
{code}
In MySQL 5.0, 5.5, 5.6, 5.7, and MariaDB 10, this query returns a row when NOW() is a time of day between 06:00 and 19:00. However, on MariaDB 5.5, no row is returned. Changing the query to force casting like this allows the query to work:
{code:java}
select a.* from (
select now() as now, TIME('06:00:00') as start, TIME('19:00:00') as stop
) a
WHERE start <= time(NOW())
AND stop >= time(now());
{code}
It is my guess that MariaDB is casting the NOW() to a string, then comparing against the string equivalent of 'start'. Or perhaps it is casting both fields to DATETIMEs and since the start/stop column omits the date component, MariaDB might be putting some incorrect date into the cast DATETIME.
It seems that MariaDB 5.5 handles NOW() and equality checks against time columns in an unexpected way. Notice:
{code:sql}
select a.* from (
select now() as now, TIME('06:00:00') as start, TIME('19:00:00') as stop
) a
WHERE start <= NOW()
AND stop >= now();
{code}
In MySQL 5.0, 5.5, 5.6, 5.7, and MariaDB 10, this query returns a row when NOW() is a time of day between 06:00 and 19:00. However, on MariaDB 5.5, no row is returned. Changing the query to force casting like this allows the query to work:
{code:sql}
select a.* from (
select now() as now, TIME('06:00:00') as start, TIME('19:00:00') as stop
) a
WHERE start <= time(NOW())
AND stop >= time(now());
{code}
It is my guess that MariaDB is casting the NOW() to a string, then comparing against the string equivalent of 'start'. Or perhaps it is casting both fields to DATETIMEs and since the start/stop column omits the date component, MariaDB might be putting some incorrect date into the cast DATETIME.
Jesse Skrivseth
made changes -
2018-06-20 00:04
Summary
Casting of now() against time columns behaves unexpectedly
Equality checks between now() and time columns behaves unexpectedly
Elena Stepanova
made changes -
2018-06-20 10:52
Affects Version/s
5.5
[ 15800
]
Alice Sherepa
made changes -
2018-06-20 11:00
Fix Version/s
5.5
[ 15800
]
Alice Sherepa
made changes -
2018-06-20 11:01
Assignee
Alexander Barkov
[ bar
]
Alexander Barkov
made changes -
2018-06-20 12:14
Fix Version/s
N/A
[ 14700
]
Fix Version/s
5.5
[ 15800
]
Resolution
Not a Bug
[ 6
]
Status
Open
[ 1
]
Closed
[ 6
]
Sergei Golubchik
made changes -
2018-06-20 22:26
Resolution
Not a Bug
[ 6
]
Status
Closed
[ 6
]
Stalled
[ 10000
]
Sergei Golubchik
made changes -
2018-06-20 22:26
Resolution
Won't Fix
[ 2
]
Status
Stalled
[ 10000
]
Closed
[ 6
]
Sergei Golubchik
made changes -
2021-12-06 21:47
Workflow
MariaDB v3
[ 87939
]
MariaDB v4
[ 154542
]
{"report":{"fcp":1010.5,"ttfb":371.90000009536743,"pageVisibility":"visible","entityId":68229,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"dadb1a1d-75b8-4266-abf0-e96ebea44b87","navigationType":0,"readyForUser":1093.8000001907349,"redirectCount":0,"resourceLoadedEnd":739.7000002861023,"resourceLoadedStart":379.7000002861023,"resourceTiming":[{"duration":35.39999961853027,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":379.7000002861023,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":379.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":415.09999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":35.69999980926514,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/2bf333562ca6724060a9d5f1535471f6/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":379.90000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":379.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":415.59999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":223.40000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":380.09999990463257,"connectEnd":380.09999990463257,"connectStart":380.09999990463257,"domainLookupEnd":380.09999990463257,"domainLookupStart":380.09999990463257,"fetchStart":380.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":420.7000002861023,"responseEnd":603.5,"responseStart":440.59999990463257,"secureConnectionStart":380.09999990463257},{"duration":359.40000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/2bf333562ca6724060a9d5f1535471f6/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":380.30000019073486,"connectEnd":380.30000019073486,"connectStart":380.30000019073486,"domainLookupEnd":380.30000019073486,"domainLookupStart":380.30000019073486,"fetchStart":380.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":420.59999990463257,"responseEnd":739.7000002861023,"responseStart":462,"secureConnectionStart":380.30000019073486},{"duration":65.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":380.40000009536743,"connectEnd":380.40000009536743,"connectStart":380.40000009536743,"domainLookupEnd":380.40000009536743,"domainLookupStart":380.40000009536743,"fetchStart":380.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":422.09999990463257,"responseEnd":446.09999990463257,"responseStart":442.7000002861023,"secureConnectionStart":380.40000009536743},{"duration":65.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":380.7000002861023,"connectEnd":380.7000002861023,"connectStart":380.7000002861023,"domainLookupEnd":380.7000002861023,"domainLookupStart":380.7000002861023,"fetchStart":380.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":422.59999990463257,"responseEnd":446.40000009536743,"responseStart":444,"secureConnectionStart":380.7000002861023},{"duration":69.40000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":380.90000009536743,"connectEnd":380.90000009536743,"connectStart":380.90000009536743,"domainLookupEnd":380.90000009536743,"domainLookupStart":380.90000009536743,"fetchStart":380.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":423.40000009536743,"responseEnd":450.30000019073486,"responseStart":447,"secureConnectionStart":380.90000009536743},{"duration":40.700000286102295,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":381.09999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":381.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":421.80000019073486,"responseStart":0,"secureConnectionStart":0},{"duration":69.2999997138977,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":381.30000019073486,"connectEnd":381.30000019073486,"connectStart":381.30000019073486,"domainLookupEnd":381.30000019073486,"domainLookupStart":381.30000019073486,"fetchStart":381.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":424.7000002861023,"responseEnd":450.59999990463257,"responseStart":447.59999990463257,"secureConnectionStart":381.30000019073486},{"duration":41.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":381.40000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":381.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":422.90000009536743,"responseStart":0,"secureConnectionStart":0},{"duration":75.10000038146973,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":381.59999990463257,"connectEnd":381.59999990463257,"connectStart":381.59999990463257,"domainLookupEnd":381.59999990463257,"domainLookupStart":381.59999990463257,"fetchStart":381.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":426.59999990463257,"responseEnd":456.7000002861023,"responseStart":454.7000002861023,"secureConnectionStart":381.59999990463257},{"duration":303.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":382.5,"connectEnd":382.5,"connectStart":382.5,"domainLookupEnd":382.5,"domainLookupStart":382.5,"fetchStart":382.5,"redirectEnd":0,"redirectStart":0,"requestStart":509.90000009536743,"responseEnd":686.3000001907349,"responseStart":680.5,"secureConnectionStart":382.5},{"duration":301.90000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":384.59999990463257,"connectEnd":384.59999990463257,"connectStart":384.59999990463257,"domainLookupEnd":384.59999990463257,"domainLookupStart":384.59999990463257,"fetchStart":384.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":511.80000019073486,"responseEnd":686.5,"responseStart":681,"secureConnectionStart":384.59999990463257},{"duration":179.90000009536743,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":748,"connectEnd":748,"connectStart":748,"domainLookupEnd":748,"domainLookupStart":748,"fetchStart":748,"redirectEnd":0,"redirectStart":0,"requestStart":893.5999999046326,"responseEnd":927.9000000953674,"responseStart":926.4000000953674,"secureConnectionStart":748}],"fetchStart":0,"domainLookupStart":99,"domainLookupEnd":116,"connectStart":117,"connectEnd":135,"secureConnectionStart":124,"requestStart":136,"responseStart":372,"responseEnd":378,"domLoading":375,"domInteractive":1153,"domContentLoadedEventStart":1153,"domContentLoadedEventEnd":1210,"domComplete":1714,"loadEventStart":1714,"loadEventEnd":1714,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1128.0999999046326},{"name":"bigPipe.sidebar-id.end","time":1128.8000001907349},{"name":"bigPipe.activity-panel-pipe-id.start","time":1129},{"name":"bigPipe.activity-panel-pipe-id.end","time":1132.3000001907349},{"name":"activityTabFullyLoaded","time":1265.2000002861023}],"measures":[],"correlationId":"862b4577671fdc","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":169,"dbReadsTimeInMs":30,"dbConnsTimeInMs":39,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}