When optimizing queries that have conditions on an indexed string column, we require that collation of the condition matches collation of the column.
In some cases (e.g. in range optimizer) we don't require strict collation match and additionally allow BINARY comparison and COLLATE xxx_bin comparision, even on a case insensitive column. These loose rules could be used in some more cases where they are not used now:
Example 1:
DROP TABLE IF EXISTS t1;
|
CREATE TABLE t1 (c1 VARCHAR(20) CHARACTER SET latin1, PRIMARY KEY(c1));
|
INSERT INTO t1 VALUES ('a'),('b'),('c'),('d');
|
EXPLAIN SELECT * FROM t1 WHERE c1=BINARY 'a';
|
returns:
+------+-------------+-------+-------+---------------+---------+---------+------+------+--------------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|
+------+-------------+-------+-------+---------------+---------+---------+------+------+--------------------------+
|
| 1 | SIMPLE | t1 | range | PRIMARY | PRIMARY | 22 | NULL | 1 | Using where; Using index |
|
+------+-------------+-------+-------+---------------+---------+---------+------+------+--------------------------+
|
It could use "const" access instead.
Example 2:
DROP TABLE IF EXISTS t1,t2;
|
CREATE TABLE t1 (c1 VARCHAR(10) CHARACTER SET latin1 COLLATE latin1_bin);
|
INSERT INTO t1 VALUES ('a');
|
CREATE TABLE t2 (c1 VARCHAR(10) CHARACTER SET latin1, PRIMARY KEY(c1));
|
INSERT INTO t2 VALUES ('a'),('b');
|
SELECT * FROM t1, t2 WHERE t1.c1=t2.c1;
|
EXPLAIN SELECT * FROM t1, t2 WHERE t1.c1=t2.c1;
|
returns
+------+-------------+-------+------+---------------+------+---------+------+------+------------------------------------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|
+------+-------------+-------+------+---------------+------+---------+------+------+------------------------------------------------+
|
| 1 | SIMPLE | t1 | ALL | NULL | NULL | NULL | NULL | 1 | |
|
| 1 | SIMPLE | t2 | ALL | PRIMARY | NULL | NULL | NULL | 2 | Range checked for each record (index map: 0x1) |
|
+------+-------------+-------+------+---------------+------+---------+------+------+------------------------------------------------+
|
It could use "eq_ref" instead of "ALL + Range changed for each record".
Example 3:
DROP TABLE IF EXISTS t1,t2;
|
CREATE TABLE t1 (c1 VARCHAR(10) CHARACTER SET latin1 COLLATE latin1_bin);
|
INSERT INTO t1 VALUES ('a');
|
CREATE TABLE t2 (c1 VARCHAR(10) CHARACTER SET latin1, PRIMARY KEY(c1));
|
INSERT INTO t2 VALUES ('a'),('b');
|
SELECT t1.* FROM t1 LEFT JOIN t2 USING (c1);
|
EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 USING (c1);
|
returns
+------+-------------+-------+------+---------------+------+---------+------+------+------------------------------------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|
+------+-------------+-------+------+---------------+------+---------+------+------+------------------------------------------------+
|
| 1 | SIMPLE | t1 | ALL | NULL | NULL | NULL | NULL | 1 | |
|
| 1 | SIMPLE | t2 | ALL | PRIMARY | NULL | NULL | NULL | 2 | Range checked for each record (index map: 0x1) |
|
+------+-------------+-------+------+---------------+------+---------+------+------+------------------------------------------------+
|
It could safely eliminate table t2 from the query.
There are no comments yet on this issue.
{"report":{"fcp":630.7999999523163,"ttfb":155.89999997615814,"pageVisibility":"visible","entityId":48001,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"bb1a97b1-0779-4636-a621-d1f724219b0a","navigationType":0,"readyForUser":760.2000000476837,"redirectCount":0,"resourceLoadedEnd":689.3999999761581,"resourceLoadedStart":161.70000004768372,"resourceTiming":[{"duration":16,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":161.70000004768372,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":161.70000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":177.70000004768372,"responseStart":0,"secureConnectionStart":0},{"duration":16.600000023841858,"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":162,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":162,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":178.60000002384186,"responseStart":0,"secureConnectionStart":0},{"duration":68.10000002384186,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":162.10000002384186,"connectEnd":162.10000002384186,"connectStart":162.10000002384186,"domainLookupEnd":162.10000002384186,"domainLookupStart":162.10000002384186,"fetchStart":162.10000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":162.10000002384186,"responseEnd":230.20000004768372,"responseStart":230.20000004768372,"secureConnectionStart":162.10000002384186},{"duration":164.90000009536743,"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":162.29999995231628,"connectEnd":162.29999995231628,"connectStart":162.29999995231628,"domainLookupEnd":162.29999995231628,"domainLookupStart":162.29999995231628,"fetchStart":162.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":162.29999995231628,"responseEnd":327.2000000476837,"responseStart":327.2000000476837,"secureConnectionStart":162.29999995231628},{"duration":161,"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":162.29999995231628,"connectEnd":162.29999995231628,"connectStart":162.29999995231628,"domainLookupEnd":162.29999995231628,"domainLookupStart":162.29999995231628,"fetchStart":162.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":162.29999995231628,"responseEnd":323.2999999523163,"responseStart":323.2999999523163,"secureConnectionStart":162.29999995231628},{"duration":166.10000002384186,"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":162.39999997615814,"connectEnd":162.39999997615814,"connectStart":162.39999997615814,"domainLookupEnd":162.39999997615814,"domainLookupStart":162.39999997615814,"fetchStart":162.39999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":162.39999997615814,"responseEnd":328.5,"responseStart":328.5,"secureConnectionStart":162.39999997615814},{"duration":167.89999997615814,"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":162.60000002384186,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":162.60000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":330.5,"responseStart":0,"secureConnectionStart":0},{"duration":167.10000002384186,"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":162.60000002384186,"connectEnd":162.60000002384186,"connectStart":162.60000002384186,"domainLookupEnd":162.60000002384186,"domainLookupStart":162.60000002384186,"fetchStart":162.60000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":162.60000002384186,"responseEnd":329.7000000476837,"responseStart":329.7000000476837,"secureConnectionStart":162.60000002384186},{"duration":167.79999995231628,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":162.70000004768372,"connectEnd":162.70000004768372,"connectStart":162.70000004768372,"domainLookupEnd":162.70000004768372,"domainLookupStart":162.70000004768372,"fetchStart":162.70000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":162.70000004768372,"responseEnd":330.5,"responseStart":330.5,"secureConnectionStart":162.70000004768372},{"duration":168.90000009536743,"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":162.79999995231628,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":162.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":331.7000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":168.80000007152557,"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":162.89999997615814,"connectEnd":162.89999997615814,"connectStart":162.89999997615814,"domainLookupEnd":162.89999997615814,"domainLookupStart":162.89999997615814,"fetchStart":162.89999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":162.89999997615814,"responseEnd":331.7000000476837,"responseStart":331.7000000476837,"secureConnectionStart":162.89999997615814},{"duration":453,"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":163.60000002384186,"connectEnd":163.60000002384186,"connectStart":163.60000002384186,"domainLookupEnd":163.60000002384186,"domainLookupStart":163.60000002384186,"fetchStart":163.60000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":163.60000002384186,"responseEnd":616.6000000238419,"responseStart":616.6000000238419,"secureConnectionStart":163.60000002384186},{"duration":487.89999997615814,"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":163.60000002384186,"connectEnd":163.60000002384186,"connectStart":163.60000002384186,"domainLookupEnd":163.60000002384186,"domainLookupStart":163.60000002384186,"fetchStart":163.60000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":163.60000002384186,"responseEnd":651.5,"responseStart":651.5,"secureConnectionStart":163.60000002384186},{"duration":234.20000004768372,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":383,"connectEnd":383,"connectStart":383,"domainLookupEnd":383,"domainLookupStart":383,"fetchStart":383,"redirectEnd":0,"redirectStart":0,"requestStart":383,"responseEnd":617.2000000476837,"responseStart":617.2000000476837,"secureConnectionStart":383},{"duration":30.600000023841858,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":623,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":623,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":653.6000000238419,"responseStart":0,"secureConnectionStart":0},{"duration":28.100000023841858,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2bu7/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","startTime":646.3999999761581,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":646.3999999761581,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":674.5,"responseStart":0,"secureConnectionStart":0},{"duration":27.699999928474426,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/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","startTime":647.2000000476837,"connectEnd":647.2000000476837,"connectStart":647.2000000476837,"domainLookupEnd":647.2000000476837,"domainLookupStart":647.2000000476837,"fetchStart":647.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":647.2000000476837,"responseEnd":674.8999999761581,"responseStart":674.8999999761581,"secureConnectionStart":647.2000000476837},{"duration":41.89999997615814,"initiatorType":"script","name":"https://jira.mariadb.org/s/f51ef5507eea4c158f257c66c93b2a3f-CDN/lu2bu7/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","startTime":647.5,"connectEnd":647.5,"connectStart":647.5,"domainLookupEnd":647.5,"domainLookupStart":647.5,"fetchStart":647.5,"redirectEnd":0,"redirectStart":0,"requestStart":647.5,"responseEnd":689.3999999761581,"responseStart":689.3999999761581,"secureConnectionStart":647.5}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":17,"responseStart":156,"responseEnd":159,"domLoading":160,"domInteractive":824,"domContentLoadedEventStart":824,"domContentLoadedEventEnd":873,"domComplete":1085,"loadEventStart":1085,"loadEventEnd":1085,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":798.8999999761581},{"name":"bigPipe.sidebar-id.end","time":799.6000000238419},{"name":"bigPipe.activity-panel-pipe-id.start","time":799.7999999523163},{"name":"bigPipe.activity-panel-pipe-id.end","time":800.2999999523163},{"name":"activityTabFullyLoaded","time":879}],"measures":[],"correlationId":"59cc5f15b3a6eb","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":79,"dbReadsTimeInMs":12,"dbConnsTimeInMs":22,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}