This bug is similar to http://bugs.mysql.com/bug.php?id=5134
Note, the patch for MySQL bug#5134 fixed only a particular case of the problem when the BINARY keyword is used. The problem is in fact more general.
This script:
SET NAMES latin1;
|
DROP TABLE IF EXISTS t1;
|
CREATE TABLE t1 (a CHAR(10));
|
INSERT INTO t1 VALUES ('a'),('A');
|
SELECT * FROM t1 WHERE a = 'a' COLLATE latin1_bin;
|
correctly returns one row:
+------+
|
| a |
|
+------+
|
| a |
|
+------+
|
Now if I add an extra part into the condition:
SELECT * FROM t1 WHERE a='a' AND a='a' COLLATE latin1_bin;
|
it returns two rows:
+------+
|
| a |
|
+------+
|
| a |
|
| A |
|
+------+
|
The expected result is to return one row in both cases.
The problem happens because "AND a='a' COLLATE latin1_bin" gets erroneously replaced to "AND 'a'='a' COLLATE latin1_bin" which is further evaluates to TRUE and gets removed from the WHERE condition. So, the query gets rewritten to:
SELECT * FROM t1 WHERE a='a';
|
The method which actually replaces the field to the constant is Item_field::equal_fields_propagator() in item.cc.
This condition is not strict enough:
if (!item || !has_compatible_context(item))
|
item= this;
|
It should also take into account the collations of the two operations that the field "a" appears in.
- blocks
-
MDEV-8728
Fix a number of problems in equal field and equal expression propagation
-
-
Closed
{"report":{"fcp":5734.5,"ttfb":1132.0999999046326,"pageVisibility":"visible","entityId":52771,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0,"journeyId":"05493306-ec5c-464f-bda6-8e490d825614","navigationType":0,"readyForUser":5340.799999952316,"redirectCount":0,"resourceLoadedEnd":4728.700000047684,"resourceLoadedStart":1164.5,"resourceTiming":[{"duration":1011.3999998569489,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":1164.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1164.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":2175.899999856949,"responseStart":0,"secureConnectionStart":0},{"duration":1011.5,"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":1164.7999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1164.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":2176.2999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":2937.2999999523163,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":1165,"connectEnd":1165,"connectStart":1165,"domainLookupEnd":1165,"domainLookupStart":1165,"fetchStart":1165,"redirectEnd":0,"redirectStart":0,"requestStart":2177.399999856949,"responseEnd":4102.299999952316,"responseStart":2189.2999999523163,"secureConnectionStart":1165},{"duration":3291.2000000476837,"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":1165.0999999046326,"connectEnd":1165.0999999046326,"connectStart":1165.0999999046326,"domainLookupEnd":1165.0999999046326,"domainLookupStart":1165.0999999046326,"fetchStart":1165.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":2179.2000000476837,"responseEnd":4456.299999952316,"responseStart":2318.0999999046326,"secureConnectionStart":1165.0999999046326},{"duration":2260.300000190735,"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":1165.3999998569489,"connectEnd":1165.3999998569489,"connectStart":1165.3999998569489,"domainLookupEnd":1165.3999998569489,"domainLookupStart":1165.3999998569489,"fetchStart":1165.3999998569489,"redirectEnd":0,"redirectStart":0,"requestStart":2180.5,"responseEnd":3425.7000000476837,"responseStart":2484.0999999046326,"secureConnectionStart":1165.3999998569489},{"duration":2410.899999856949,"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":1165.5,"connectEnd":1165.5,"connectStart":1165.5,"domainLookupEnd":1165.5,"domainLookupStart":1165.5,"fetchStart":1165.5,"redirectEnd":0,"redirectStart":0,"requestStart":2183.2000000476837,"responseEnd":3576.399999856949,"responseStart":3574.399999856949,"secureConnectionStart":1165.5},{"duration":2409.899999856949,"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":1165.7000000476837,"connectEnd":1165.7000000476837,"connectStart":1165.7000000476837,"domainLookupEnd":1165.7000000476837,"domainLookupStart":1165.7000000476837,"fetchStart":1165.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":2183.5,"responseEnd":3575.5999999046326,"responseStart":3425.7999999523163,"secureConnectionStart":1165.7000000476837},{"duration":1011.9000000953674,"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":1165.8999998569489,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1165.8999998569489,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":2177.7999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":1389.7000000476837,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":1166.0999999046326,"connectEnd":1166.0999999046326,"connectStart":1166.0999999046326,"domainLookupEnd":1166.0999999046326,"domainLookupStart":1166.0999999046326,"fetchStart":1166.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":2183.5999999046326,"responseEnd":2555.7999999523163,"responseStart":2554.0999999046326,"secureConnectionStart":1166.0999999046326},{"duration":1011.7999999523163,"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":1166.2000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1166.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":2178,"responseStart":0,"secureConnectionStart":0},{"duration":1389.2000000476837,"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":1166.3999998569489,"connectEnd":1166.3999998569489,"connectStart":1166.3999998569489,"domainLookupEnd":1166.3999998569489,"domainLookupStart":1166.3999998569489,"fetchStart":1166.3999998569489,"redirectEnd":0,"redirectStart":0,"requestStart":2183.7000000476837,"responseEnd":2555.5999999046326,"responseStart":2527,"secureConnectionStart":1166.3999998569489},{"duration":3554.600000143051,"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":1173.0999999046326,"connectEnd":1173.0999999046326,"connectStart":1173.0999999046326,"domainLookupEnd":1173.0999999046326,"domainLookupStart":1173.0999999046326,"fetchStart":1173.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":3060.7999999523163,"responseEnd":4727.700000047684,"responseStart":4588.5,"secureConnectionStart":1173.0999999046326},{"duration":3555.600000143051,"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":1173.0999999046326,"connectEnd":1173.0999999046326,"connectStart":1173.0999999046326,"domainLookupEnd":1173.0999999046326,"domainLookupStart":1173.0999999046326,"fetchStart":1173.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":3575.7000000476837,"responseEnd":4728.700000047684,"responseStart":4622.700000047684,"secureConnectionStart":1173.0999999046326},{"duration":543.2000000476837,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":4293.899999856949,"connectEnd":4293.899999856949,"connectStart":4293.899999856949,"domainLookupEnd":4293.899999856949,"domainLookupStart":4293.899999856949,"fetchStart":4293.899999856949,"redirectEnd":0,"redirectStart":0,"requestStart":4729.5,"responseEnd":4837.099999904633,"responseStart":4764.700000047684,"secureConnectionStart":4293.899999856949},{"duration":649,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":5111.5,"connectEnd":5111.5,"connectStart":5111.5,"domainLookupEnd":5111.5,"domainLookupStart":5111.5,"fetchStart":5111.5,"redirectEnd":0,"redirectStart":0,"requestStart":5617.700000047684,"responseEnd":5760.5,"responseStart":5747.799999952316,"secureConnectionStart":5111.5},{"duration":497.90000009536743,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":5227.399999856949,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":5227.399999856949,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":5725.299999952316,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":956,"responseStart":1132,"responseEnd":1171,"domLoading":1143,"domInteractive":5727,"domContentLoadedEventStart":5727,"domContentLoadedEventEnd":5828,"domComplete":7534,"loadEventStart":7534,"loadEventEnd":7534,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":5690.200000047684},{"name":"bigPipe.sidebar-id.end","time":5691},{"name":"bigPipe.activity-panel-pipe-id.start","time":5691.200000047684},{"name":"bigPipe.activity-panel-pipe-id.end","time":5692.799999952316},{"name":"activityTabFullyLoaded","time":5983.799999952316}],"measures":[],"correlationId":"7c363ce1442bc3","effectiveType":"4g","downlink":9.5,"rtt":0,"serverDuration":106,"dbReadsTimeInMs":10,"dbConnsTimeInMs":18,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Another example:
SET NAMES latin1;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET latin1 COLLATE latin1_swedish_ci);
INSERT INTO t1 VALUES ('a'),('A');
SELECT * FROM t1 WHERE a='a' COLLATE latin1_bin;
SELECT * FROM t1 WHERE a='A' COLLATE latin1_swedish_ci;
The above script returns one row in the first SELECT and two rows in the second SELECT:
+------+
| a |
+------+
| a |
+------+
1 row in set (0.00 sec)
+------+
| a |
+------+
| a |
| A |
+------+
2 rows in set (0.00 sec)
Now if I join the above two condition using AND:
SELECT * FROM t1 WHERE a='a' COLLATE latin1_bin AND a='A' COLLATE latin1_swedish_ci;
I get empty set. This is wrong. The expected result is to return one row, the same result as in the first SELECT.