ADDTIME(expr1,expr2) is a hybrid function.
- In case when expr1 is DATETIME, the result type is DATETIME.
- In case when expr1 is TIME, the result type is TIME.
- Otherwise, the result type is VARCHAR, and the choice between
DATETIME or TIME format is done per-row.
In case of VARCHAR result, the function must follow the standard
MySQL/MariaDB convention:
character set and collation of a string function returning a result
from numeric or temporal input should be set according to
@@character_set_connection and @@collation_connection
respectively.
http://dev.mysql.com/doc/refman/5.6/en/type-conversion.html
In MySQL 5.6, implicit conversion of a numeric or temporal value to string produces a value that has a character set and collation determined by the character_set_connection and collation_connection system variables.
Consider this SQL script:
set character_set_connection=ucs2;
|
select charset(addtime(_latin1'10:01:01',_latin1'10:00:00'));
|
drop table if exists t1;
|
create table t1 as select addtime(_latin1'10:01:01',_latin1'10:00:00') as a;
|
show create table t1;
|
MySQL-5.6 does follow this rule, and the output is:
+-------------------------------------------------------+
|
| charset(addtime(_latin1'10:01:01',_latin1'10:00:00')) |
|
+-------------------------------------------------------+
|
| ucs2 |
|
+-------------------------------------------------------+
|
1
|
+-------+--------------------------------------------------------------------------------------------
|
|
...
|
|
------------------+
|
| Table | Create Table |
|
+-------+--------------------------------------------------------------------------------------------------------------+
|
| t1 | CREATE TABLE `t1` (
|
`a` varchar(29) CHARACTER SET ucs2 DEFAULT NULL
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
|
+-------+--------------------------------------------------------------------------------------------------------------+
|
Notice: ucs2 is consistently reported in both tables in the output.
MariaDB does not follow this rule, and the output is:
+-------------------------------------------------------+
|
| charset(addtime(_latin1'10:01:01',_latin1'10:00:00')) |
|
+-------------------------------------------------------+
|
| binary |
|
+-------------------------------------------------------+
|
|
...
|
|
+-------+-------------------------------------------------------------------------------------------+
|
| Table | Create Table |
|
+-------+-------------------------------------------------------------------------------------------+
|
| t1 | CREATE TABLE `t1` (
|
`a` varchar(26) DEFAULT NULL
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
|
+-------+-------------------------------------------------------------------------------------------
|
Moreover, the result of CHARSET() and of "SHOW CREATE" do not
match to each over (binary vs latin1).
The same problem is observed with another temporal hybrid function DATE_ADD.
The script:
set character_set_connection=ucs2;
|
select charset(date_add(_latin1'10:01:01',interval 10 second));
|
drop table if exists t1;
|
create table t1 as select date_add(_latin1'10:01:01',interval 10 second) as a;
|
show create table t1;
|
Results from MySQL-5.6 are consistently correct:
+---------------------------------------------------------+
|
| charset(date_add(_latin1'10:01:01',interval 10 second)) |
|
+---------------------------------------------------------+
|
| ucs2 |
|
+---------------------------------------------------------+
|
+-------+--------------------------------------------------------------------------------------------------------------+
|
| Table | Create Table |
|
+-------+--------------------------------------------------------------------------------------------------------------+
|
| t1 | CREATE TABLE `t1` (
|
`a` varchar(29) CHARACTER SET ucs2 DEFAULT NULL
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
|
+-------+--------------------------------------------------------------------------------------------------------------+
|
Result from MariaDB-10.0 are wrong and non-consistent:
+---------------------------------------------------------+
|
| charset(date_add(_latin1'10:01:01',interval 10 second)) |
|
+---------------------------------------------------------+
|
| binary |
|
+---------------------------------------------------------+
|
+-------+-------------------------------------------------------------------------------------------+
|
| Table | Create Table |
|
+-------+-------------------------------------------------------------------------------------------+
|
| t1 | CREATE TABLE `t1` (
|
`a` varchar(26) DEFAULT NULL
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
|
+-------+-------------------------------------------------------------------------------------------+
|
|
{"report":{"fcp":2613.7999997138977,"ttfb":435.5,"pageVisibility":"visible","entityId":25025,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":32,"apdex":0.5,"journeyId":"8d7e937e-e61a-4fa9-9757-db882a4ce9cc","navigationType":0,"readyForUser":2803.0999999046326,"redirectCount":0,"resourceLoadedEnd":2881.199999809265,"resourceLoadedStart":460.69999980926514,"resourceTiming":[{"duration":972.0999999046326,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":460.69999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":460.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1432.7999997138977,"responseStart":0,"secureConnectionStart":0},{"duration":972.3000001907349,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/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&whisper-enabled=true","startTime":460.8999996185303,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":460.8999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1433.1999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":980.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":461.19999980926514,"connectEnd":461.19999980926514,"connectStart":461.19999980926514,"domainLookupEnd":461.19999980926514,"domainLookupStart":461.19999980926514,"fetchStart":461.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":461.19999980926514,"responseEnd":1441.6999998092651,"responseStart":1441.6999998092651,"secureConnectionStart":461.19999980926514},{"duration":1104.8000001907349,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/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&whisper-enabled=true","startTime":461.2999997138977,"connectEnd":461.2999997138977,"connectStart":461.2999997138977,"domainLookupEnd":461.2999997138977,"domainLookupStart":461.2999997138977,"fetchStart":461.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":461.2999997138977,"responseEnd":1566.0999999046326,"responseStart":1566.0999999046326,"secureConnectionStart":461.2999997138977},{"duration":1123.0999999046326,"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":461.5,"connectEnd":461.5,"connectStart":461.5,"domainLookupEnd":461.5,"domainLookupStart":461.5,"fetchStart":461.5,"redirectEnd":0,"redirectStart":0,"requestStart":461.5,"responseEnd":1584.5999999046326,"responseStart":1584.5999999046326,"secureConnectionStart":461.5},{"duration":1141.1999998092651,"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":461.69999980926514,"connectEnd":461.69999980926514,"connectStart":461.69999980926514,"domainLookupEnd":461.69999980926514,"domainLookupStart":461.69999980926514,"fetchStart":461.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":461.69999980926514,"responseEnd":1602.8999996185303,"responseStart":1602.8999996185303,"secureConnectionStart":461.69999980926514},{"duration":1141.9000000953674,"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":461.8999996185303,"connectEnd":461.8999996185303,"connectStart":461.8999996185303,"domainLookupEnd":461.8999996185303,"domainLookupStart":461.8999996185303,"fetchStart":461.8999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":461.8999996185303,"responseEnd":1603.7999997138977,"responseStart":1603.7999997138977,"secureConnectionStart":461.8999996185303},{"duration":1320,"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":462,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":462,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1782,"responseStart":0,"secureConnectionStart":0},{"duration":1143,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":462.19999980926514,"connectEnd":462.19999980926514,"connectStart":462.19999980926514,"domainLookupEnd":462.19999980926514,"domainLookupStart":462.19999980926514,"fetchStart":462.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":462.19999980926514,"responseEnd":1605.1999998092651,"responseStart":1605.1999998092651,"secureConnectionStart":462.19999980926514},{"duration":1317.7000002861023,"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":464.3999996185303,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":464.3999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1782.0999999046326,"responseStart":0,"secureConnectionStart":0},{"duration":1141.5,"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":464.5,"connectEnd":464.5,"connectStart":464.5,"domainLookupEnd":464.5,"domainLookupStart":464.5,"fetchStart":464.5,"redirectEnd":0,"redirectStart":0,"requestStart":464.5,"responseEnd":1606,"responseStart":1606,"secureConnectionStart":464.5},{"duration":2316.2000002861023,"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":465.2999997138977,"connectEnd":465.2999997138977,"connectStart":465.2999997138977,"domainLookupEnd":465.2999997138977,"domainLookupStart":465.2999997138977,"fetchStart":465.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":465.2999997138977,"responseEnd":2781.5,"responseStart":2781.5,"secureConnectionStart":465.2999997138977},{"duration":2415.800000190735,"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":465.3999996185303,"connectEnd":465.3999996185303,"connectStart":465.3999996185303,"domainLookupEnd":465.3999996185303,"domainLookupStart":465.3999996185303,"fetchStart":465.3999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":465.3999996185303,"responseEnd":2881.199999809265,"responseStart":2881.199999809265,"secureConnectionStart":465.3999996185303},{"duration":939,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1845.1999998092651,"connectEnd":1845.1999998092651,"connectStart":1845.1999998092651,"domainLookupEnd":1845.1999998092651,"domainLookupStart":1845.1999998092651,"fetchStart":1845.1999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":1845.1999998092651,"responseEnd":2784.199999809265,"responseStart":2784.199999809265,"secureConnectionStart":1845.1999998092651},{"duration":362.80000019073486,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":2605.699999809265,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":2605.699999809265,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":2968.5,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":266,"responseStart":436,"responseEnd":438,"domLoading":459,"domInteractive":2927,"domContentLoadedEventStart":2927,"domContentLoadedEventEnd":2968,"domComplete":3461,"loadEventStart":3461,"loadEventEnd":3461,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":2899.699999809265},{"name":"bigPipe.sidebar-id.end","time":2900.5999999046326},{"name":"bigPipe.activity-panel-pipe-id.start","time":2900.7999997138977},{"name":"bigPipe.activity-panel-pipe-id.end","time":2901.5999999046326},{"name":"activityTabFullyLoaded","time":2983.199999809265}],"measures":[],"correlationId":"94b9e15a3c0c1","effectiveType":"4g","downlink":9.4,"rtt":0,"serverDuration":92,"dbReadsTimeInMs":8,"dbConnsTimeInMs":16,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Pushed into 10.0.5