This script demonstrates that although TIME'00:00:00.0' and TIME'00:00:00.00' are equal to each other for comparison, they are still not equal in other contexts:
Looks wrong. The SELECT query should return empty set, and EXPLAIN should not tell that the condition was simplified to true.
Alexander Barkov
added a comment - The same problem is repeatable with DECIMAL:
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a DECIMAL (10,3));
INSERT INTO t1 VALUES (10.0),(10.1);
SELECT LENGTH(10.0)+a,LENGTH(10.000)+a FROM t1;
+----------------+------------------+
| LENGTH(10.0)+a | LENGTH(10.000)+a |
+----------------+------------------+
| 14.000 | 16.000 |
| 14.100 | 16.100 |
+----------------+------------------+
SELECT * FROM t1 WHERE LENGTH(10.0)+a<=>LENGTH(10.000)+a;
+--------+
| a |
+--------+
| 10.000 |
| 10.100 |
+--------+
EXPLAIN EXTENDED SELECT * FROM t1 WHERE LENGTH(10.0)+a<=>LENGTH(10.000)+a;
SHOW WARNINGS;
+-------+------+--------------------------------------------------------+
| Level | Code | Message |
+-------+------+--------------------------------------------------------+
| Note | 1003 | select `test`.`t1`.`a` AS `a` from `test`.`t1` where 1 |
+-------+------+--------------------------------------------------------+
Looks wrong. The SELECT query should return empty set, and EXPLAIN should not tell that the condition was simplified to true .
The problem happens because Item_bool_func2::remove_eq_conds() correctly calls eq() for the arguments like this:
if (args[0]->eq(args[1], true)) // Notice true
but further eq() can handle binary vs non-binary comparison only for string constants (and not for temporal or decimal).
eq() should be fixed to take into account possible different formats when the binary_cmp parameter is true, for all affected data types (such as temporal and DECIMAL).
Alexander Barkov
added a comment - - edited The problem happens because Item_bool_func2::remove_eq_conds() correctly calls eq() for the arguments like this:
if (args[0]->eq(args[1], true )) // Notice true
but further eq() can handle binary vs non-binary comparison only for string constants (and not for temporal or decimal).
eq() should be fixed to take into account possible different formats when the binary_cmp parameter is true , for all affected data types (such as temporal and DECIMAL).
because Item_hex_constant::type() and Item_string::type() returns different codes (STRING_ITEM vs VARBIN_ITEM).
Alexander Barkov
added a comment - - edited In this scenario it works fine (the constants 'a' and 0x61 are not detected as same):
SET NAMES utf8;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a DECIMAL (10,3));
INSERT INTO t1 VALUES (10.0),(10.1);
SELECT CHARSET( 'a' ),CHARSET(0x61),LENGTH(CHARSET( 'a' ))+a,LENGTH(CHARSET(0x61))+a FROM t1;
+--------------+---------------+------------------------+-------------------------+
| CHARSET('a') | CHARSET(0x61) | LENGTH(CHARSET('a'))+a | LENGTH(CHARSET(0x61))+a |
+--------------+---------------+------------------------+-------------------------+
| utf8 | binary | 14.000 | 16.000 |
| utf8 | binary | 14.100 | 16.100 |
+--------------+---------------+------------------------+-------------------------+
SELECT * FROM t1 WHERE LENGTH(CHARSET( 'a' ))+a<=>LENGTH(CHARSET(0x61))+a;
Empty set (1.80 sec)
EXPLAIN EXTENDED SELECT * FROM t1 WHERE LENGTH(CHARSET( 'a' ))+a<=>LENGTH(CHARSET(0x61))+a;
SHOW WARNINGS;
+-------+------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Level | Code | Message |
+-------+------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Note | 1003 | select `test`.`t1`.`a` AS `a` from `test`.`t1` where <cache>(octet_length(charset('a'))) + `test`.`t1`.`a` <=> <cache>(octet_length(charset(0x61))) + `test`.`t1`.`a` |
+-------+------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
because Item_hex_constant::type() and Item_string::type() returns different codes (STRING_ITEM vs VARBIN_ITEM).
People
Alexander Barkov
Alexander Barkov
Votes:
0Vote for this issue
Watchers:
1Start watching this issue
Dates
Created:
Updated:
Resolved:
Git Integration
Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.
{"report":{"fcp":2141.199999809265,"ttfb":381.5999994277954,"pageVisibility":"visible","entityId":68029,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":32,"apdex":0.5,"journeyId":"f7db4846-a2d0-4042-bdf5-781619367779","navigationType":0,"readyForUser":2308.2999992370605,"redirectCount":0,"resourceLoadedEnd":2678.5,"resourceLoadedStart":394,"resourceTiming":[{"duration":785.5999994277954,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":394,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":394,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1179.5999994277954,"responseStart":0,"secureConnectionStart":0},{"duration":785.8999996185303,"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":394.19999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":394.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1180.0999994277954,"responseStart":0,"secureConnectionStart":0},{"duration":795.3999996185303,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":394.3999996185303,"connectEnd":394.3999996185303,"connectStart":394.3999996185303,"domainLookupEnd":394.3999996185303,"domainLookupStart":394.3999996185303,"fetchStart":394.3999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":394.3999996185303,"responseEnd":1189.7999992370605,"responseStart":1189.7999992370605,"secureConnectionStart":394.3999996185303},{"duration":878.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":403.19999980926514,"connectEnd":403.19999980926514,"connectStart":403.19999980926514,"domainLookupEnd":403.19999980926514,"domainLookupStart":403.19999980926514,"fetchStart":403.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":403.19999980926514,"responseEnd":1282,"responseStart":1282,"secureConnectionStart":403.19999980926514},{"duration":881.5,"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":405.19999980926514,"connectEnd":405.19999980926514,"connectStart":405.19999980926514,"domainLookupEnd":405.19999980926514,"domainLookupStart":405.19999980926514,"fetchStart":405.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":405.19999980926514,"responseEnd":1286.6999998092651,"responseStart":1286.6999998092651,"secureConnectionStart":405.19999980926514},{"duration":886.5,"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":406.5999994277954,"connectEnd":406.5999994277954,"connectStart":406.5999994277954,"domainLookupEnd":406.5999994277954,"domainLookupStart":406.5999994277954,"fetchStart":406.5999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":406.5999994277954,"responseEnd":1293.0999994277954,"responseStart":1293.0999994277954,"secureConnectionStart":406.5999994277954},{"duration":887.5,"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":407.3999996185303,"connectEnd":407.3999996185303,"connectStart":407.3999996185303,"domainLookupEnd":407.3999996185303,"domainLookupStart":407.3999996185303,"fetchStart":407.3999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":407.3999996185303,"responseEnd":1294.8999996185303,"responseStart":1294.8999996185303,"secureConnectionStart":407.3999996185303},{"duration":1175.9000005722046,"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":407.5999994277954,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":407.5999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1583.5,"responseStart":0,"secureConnectionStart":0},{"duration":888.4000005722046,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":407.79999923706055,"connectEnd":407.79999923706055,"connectStart":407.79999923706055,"domainLookupEnd":407.79999923706055,"domainLookupStart":407.79999923706055,"fetchStart":407.79999923706055,"redirectEnd":0,"redirectStart":0,"requestStart":407.79999923706055,"responseEnd":1296.1999998092651,"responseStart":1296.1999998092651,"secureConnectionStart":407.79999923706055},{"duration":1176.8999996185303,"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":408.69999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":408.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1585.5999994277954,"responseStart":0,"secureConnectionStart":0},{"duration":888.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":408.79999923706055,"connectEnd":408.79999923706055,"connectStart":408.79999923706055,"domainLookupEnd":408.79999923706055,"domainLookupStart":408.79999923706055,"fetchStart":408.79999923706055,"redirectEnd":0,"redirectStart":0,"requestStart":408.79999923706055,"responseEnd":1297.2999992370605,"responseStart":1297.2999992370605,"secureConnectionStart":408.79999923706055},{"duration":1443.5999994277954,"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":410.19999980926514,"connectEnd":410.19999980926514,"connectStart":410.19999980926514,"domainLookupEnd":410.19999980926514,"domainLookupStart":410.19999980926514,"fetchStart":410.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":410.19999980926514,"responseEnd":1853.7999992370605,"responseStart":1853.7999992370605,"secureConnectionStart":410.19999980926514},{"duration":2268.1000003814697,"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":410.3999996185303,"connectEnd":410.3999996185303,"connectStart":410.3999996185303,"domainLookupEnd":410.3999996185303,"domainLookupStart":410.3999996185303,"fetchStart":410.3999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":410.3999996185303,"responseEnd":2678.5,"responseStart":2678.5,"secureConnectionStart":410.3999996185303},{"duration":245.39999961853027,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1614.1999998092651,"connectEnd":1614.1999998092651,"connectStart":1614.1999998092651,"domainLookupEnd":1614.1999998092651,"domainLookupStart":1614.1999998092651,"fetchStart":1614.1999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":1614.1999998092651,"responseEnd":1859.5999994277954,"responseStart":1859.5999994277954,"secureConnectionStart":1614.1999998092651},{"duration":749.7999992370605,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2cib/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/css/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":2058.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":2058.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":2808.2999992370605,"responseStart":0,"secureConnectionStart":0},{"duration":740.3999996185303,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/e65b778d185daf5aee24936755b43da6/_/download/contextbatch/js/browser-metrics-plugin.contrib,-_super,-project.issue.navigator,-jira.view.issue,-atl.general/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":2059.699999809265,"connectEnd":2059.699999809265,"connectStart":2059.699999809265,"domainLookupEnd":2059.699999809265,"domainLookupStart":2059.699999809265,"fetchStart":2059.699999809265,"redirectEnd":0,"redirectStart":0,"requestStart":2059.699999809265,"responseEnd":2800.0999994277954,"responseStart":2800.0999994277954,"secureConnectionStart":2059.699999809265},{"duration":745.5999994277954,"initiatorType":"script","name":"https://jira.mariadb.org/s/097ae97cb8fbec7d6ea4bbb1f26955b9-CDN/lu2cib/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/js/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":2060,"connectEnd":2060,"connectStart":2060,"domainLookupEnd":2060,"domainLookupStart":2060,"fetchStart":2060,"redirectEnd":0,"redirectStart":0,"requestStart":2060,"responseEnd":2805.5999994277954,"responseStart":2805.5999994277954,"secureConnectionStart":2060}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":201,"responseStart":381,"responseEnd":397,"domLoading":392,"domInteractive":2744,"domContentLoadedEventStart":2744,"domContentLoadedEventEnd":2808,"domComplete":3586,"loadEventStart":3586,"loadEventEnd":3587,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":2690.8999996185303},{"name":"bigPipe.sidebar-id.end","time":2691.699999809265},{"name":"bigPipe.activity-panel-pipe-id.start","time":2691.8999996185303},{"name":"bigPipe.activity-panel-pipe-id.end","time":2695},{"name":"activityTabFullyLoaded","time":2842.3999996185303}],"measures":[],"correlationId":"81f2ba379e3d66","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":113,"dbReadsTimeInMs":15,"dbConnsTimeInMs":24,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
The same problem is repeatable with DECIMAL:
+----------------+------------------+
| LENGTH(10.0)+a | LENGTH(10.000)+a |
+----------------+------------------+
| 14.000 | 16.000 |
| 14.100 | 16.100 |
+----------------+------------------+
+--------+
| a |
+--------+
| 10.000 |
| 10.100 |
+--------+
SHOW WARNINGS;
+-------+------+--------------------------------------------------------+
| Level | Code | Message |
+-------+------+--------------------------------------------------------+
| Note | 1003 | select `test`.`t1`.`a` AS `a` from `test`.`t1` where 1 |
+-------+------+--------------------------------------------------------+
Looks wrong. The SELECT query should return empty set, and EXPLAIN should not tell that the condition was simplified to true.