This script:
SET NAMES latin1;
|
DROP TABLE IF EXISTS t1;
|
CREATE TABLE t1 (a VARCHAR(20) COLLATE latin1_bin);
|
INSERT INTO t1 VALUES ('a');
|
SELECT * FROM t1 WHERE a='A';
|
SELECT * FROM t1 WHERE a='A' AND a=_latin1'a';
|
correctly returns empty set for both SELECT queries.
If I now change the order of the two conditions in the second SELECT query:
SELECT * FROM t1 WHERE a=_latin1'a' AND a='A';
|
it erroneously returns one row:
+------+
|
| a |
|
+------+
|
| a |
|
+------+
|
The same problem is repeatable with character set introducers
(SET NAMES latin1 is not needed in this case):
DROP TABLE IF EXISTS t1;
|
CREATE TABLE t1 (a VARCHAR(20) COLLATE latin1_bin);
|
INSERT INTO t1 VALUES ('a');
|
SELECT * FROM t1 WHERE a=_latin1'A';
|
SELECT * FROM t1 WHERE a=_latin1'A' AND a=_latin1'a';
|
SELECT * FROM t1 WHERE a=_latin1'a' AND a=_latin1'A';
|
The problem happens in Item_equal::add_const(), in this code:
else
|
{
|
Item_func_eq *func= new (thd->mem_root) Item_func_eq(thd, c, const_item);
|
if (func->set_cmp_func())
|
{
|
/*
|
Setting a comparison function fails when trying to compare
|
incompatible charsets. Charset compatibility is checked earlier,
|
except for constant subqueries where we may do it here.
|
*/
|
return;
|
}
|
func->quick_fix_field();
|
cond_false= !func->val_int();
|
}
|
It does not take into account the column collation (latin1_bin) and compares the two constants as latin1_swedish_ci, which gives TRUE. The second part of the AND is then eliminated from the query.
So:
SELECT * FROM t1 WHERE a=_latin1'A' AND a=_latin1'a';
|
gets rewritten to:
SELECT * FROM t1 WHERE a=_latin1'A';
|
which returns no rows, while:
SELECT * FROM t1 WHERE a=_latin1'a' AND a=_latin1'A';
|
gets rewritten as
SELECT * FROM t1 WHERE a=_latin1'a';
|
which returns one row.
- duplicates
-
MDEV-8705
Wrong result for SELECT..WHERE latin1_bin_column='a' AND latin1_bin_column='A'
-
-
Closed
{"report":{"fcp":884.2999999523163,"ttfb":318.2000000476837,"pageVisibility":"visible","entityId":52909,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":32,"apdex":1,"journeyId":"ecdcce62-eeb6-4b9e-bf1a-9cfa7b9deab4","navigationType":0,"readyForUser":950.0999999046326,"redirectCount":0,"resourceLoadedEnd":1199,"resourceLoadedStart":324.40000009536743,"resourceTiming":[{"duration":82,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":324.40000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":324.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":406.40000009536743,"responseStart":0,"secureConnectionStart":0},{"duration":81.70000004768372,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/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":324.7000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":324.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":406.40000009536743,"responseStart":0,"secureConnectionStart":0},{"duration":91.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":324.7999999523163,"connectEnd":324.7999999523163,"connectStart":324.7999999523163,"domainLookupEnd":324.7999999523163,"domainLookupStart":324.7999999523163,"fetchStart":324.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":324.7999999523163,"responseEnd":416.2999999523163,"responseStart":416.2999999523163,"secureConnectionStart":324.7999999523163},{"duration":123.39999985694885,"initiatorType":"script","name":"https://jira.mariadb.org/s/099b33461394b8015fc36c0a4b96e19f-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/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":324.90000009536743,"connectEnd":324.90000009536743,"connectStart":324.90000009536743,"domainLookupEnd":324.90000009536743,"domainLookupStart":324.90000009536743,"fetchStart":324.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":324.90000009536743,"responseEnd":448.2999999523163,"responseStart":448.2999999523163,"secureConnectionStart":324.90000009536743},{"duration":126.79999995231628,"initiatorType":"script","name":"https://jira.mariadb.org/s/94c15bff32baef80f4096a08aceae8bc-CDN/lu2bu7/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":325,"connectEnd":325,"connectStart":325,"domainLookupEnd":325,"domainLookupStart":325,"fetchStart":325,"redirectEnd":0,"redirectStart":0,"requestStart":325,"responseEnd":451.7999999523163,"responseStart":451.7999999523163,"secureConnectionStart":325},{"duration":127.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":325.09999990463257,"connectEnd":325.09999990463257,"connectStart":325.09999990463257,"domainLookupEnd":325.09999990463257,"domainLookupStart":325.09999990463257,"fetchStart":325.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":325.09999990463257,"responseEnd":452.59999990463257,"responseStart":452.59999990463257,"secureConnectionStart":325.09999990463257},{"duration":128.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bu7/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":325.2999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":325.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":453.7999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":127.79999995231628,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":325.2999999523163,"connectEnd":325.2999999523163,"connectStart":325.2999999523163,"domainLookupEnd":325.2999999523163,"domainLookupStart":325.2999999523163,"fetchStart":325.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":325.2999999523163,"responseEnd":453.09999990463257,"responseStart":453.09999990463257,"secureConnectionStart":325.2999999523163},{"duration":128.19999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":325.40000009536743,"connectEnd":325.40000009536743,"connectStart":325.40000009536743,"domainLookupEnd":325.40000009536743,"domainLookupStart":325.40000009536743,"fetchStart":325.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":325.40000009536743,"responseEnd":453.59999990463257,"responseStart":453.59999990463257,"secureConnectionStart":325.40000009536743},{"duration":128.70000004768372,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bu7/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":325.7000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":325.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":454.40000009536743,"responseStart":0,"secureConnectionStart":0},{"duration":128.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/3339d87fa2538a859872f2df449bf8d0-CDN/lu2bu7/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":325.7000000476837,"connectEnd":325.7000000476837,"connectStart":325.7000000476837,"domainLookupEnd":325.7000000476837,"domainLookupStart":325.7000000476837,"fetchStart":325.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":325.7000000476837,"responseEnd":454.2000000476837,"responseStart":454.2000000476837,"secureConnectionStart":325.7000000476837},{"duration":380.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":326.40000009536743,"connectEnd":326.40000009536743,"connectStart":326.40000009536743,"domainLookupEnd":326.40000009536743,"domainLookupStart":326.40000009536743,"fetchStart":326.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":326.40000009536743,"responseEnd":706.5,"responseStart":706.5,"secureConnectionStart":326.40000009536743},{"duration":872.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":326.5,"connectEnd":326.5,"connectStart":326.5,"domainLookupEnd":326.5,"domainLookupStart":326.5,"fetchStart":326.5,"redirectEnd":0,"redirectStart":0,"requestStart":326.5,"responseEnd":1199,"responseStart":1199,"secureConnectionStart":326.5},{"duration":541.5999999046326,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":654.4000000953674,"connectEnd":654.4000000953674,"connectStart":654.4000000953674,"domainLookupEnd":654.4000000953674,"domainLookupStart":654.4000000953674,"fetchStart":654.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":654.4000000953674,"responseEnd":1196,"responseStart":1196,"secureConnectionStart":654.4000000953674}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":183,"responseStart":318,"responseEnd":319,"domLoading":322,"domInteractive":1249,"domContentLoadedEventStart":1249,"domContentLoadedEventEnd":1285,"domComplete":2083,"loadEventStart":2083,"loadEventEnd":2085,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1232.2000000476837},{"name":"bigPipe.sidebar-id.end","time":1233},{"name":"bigPipe.activity-panel-pipe-id.start","time":1233.2000000476837},{"name":"bigPipe.activity-panel-pipe-id.end","time":1235.7000000476837},{"name":"activityTabFullyLoaded","time":1291.5999999046326}],"measures":[],"correlationId":"95a2589fd0cc58","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":78,"dbReadsTimeInMs":14,"dbConnsTimeInMs":21,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}