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.
{"report":{"fcp":976.0999999046326,"ttfb":170.40000009536743,"pageVisibility":"visible","entityId":48001,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"a2ce9d51-9dcd-46c5-8511-15851b649cfe","navigationType":0,"readyForUser":1052.4000000953674,"redirectCount":0,"resourceLoadedEnd":935.0999999046326,"resourceLoadedStart":176.90000009536743,"resourceTiming":[{"duration":107.69999980926514,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":176.90000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":176.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":284.59999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":109.20000004768372,"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":177.09999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":177.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":286.2999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":162.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":177.20000004768372,"connectEnd":177.20000004768372,"connectStart":177.20000004768372,"domainLookupEnd":177.20000004768372,"domainLookupStart":177.20000004768372,"fetchStart":177.20000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":177.20000004768372,"responseEnd":339.2999999523163,"responseStart":339.2999999523163,"secureConnectionStart":177.20000004768372},{"duration":433.10000014305115,"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":177.29999995231628,"connectEnd":177.29999995231628,"connectStart":177.29999995231628,"domainLookupEnd":177.29999995231628,"domainLookupStart":177.29999995231628,"fetchStart":177.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":177.29999995231628,"responseEnd":610.4000000953674,"responseStart":610.4000000953674,"secureConnectionStart":177.29999995231628},{"duration":436.59999990463257,"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":177.40000009536743,"connectEnd":177.40000009536743,"connectStart":177.40000009536743,"domainLookupEnd":177.40000009536743,"domainLookupStart":177.40000009536743,"fetchStart":177.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":177.40000009536743,"responseEnd":614,"responseStart":613.9000000953674,"secureConnectionStart":177.40000009536743},{"duration":436.90000009536743,"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":177.5,"connectEnd":177.5,"connectStart":177.5,"domainLookupEnd":177.5,"domainLookupStart":177.5,"fetchStart":177.5,"redirectEnd":0,"redirectStart":0,"requestStart":177.5,"responseEnd":614.4000000953674,"responseStart":614.4000000953674,"secureConnectionStart":177.5},{"duration":437.10000014305115,"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":177.59999990463257,"connectEnd":177.59999990463257,"connectStart":177.59999990463257,"domainLookupEnd":177.59999990463257,"domainLookupStart":177.59999990463257,"fetchStart":177.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":177.59999990463257,"responseEnd":614.7000000476837,"responseStart":614.7000000476837,"secureConnectionStart":177.59999990463257},{"duration":437.40000009536743,"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":177.79999995231628,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":177.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":615.2000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":437.2999999523163,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":177.90000009536743,"connectEnd":177.90000009536743,"connectStart":177.90000009536743,"domainLookupEnd":177.90000009536743,"domainLookupStart":177.90000009536743,"fetchStart":177.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":177.90000009536743,"responseEnd":615.2000000476837,"responseStart":615.2000000476837,"secureConnectionStart":177.90000009536743},{"duration":439.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":178,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":178,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":617.9000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":439.90000009536743,"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":178.09999990463257,"connectEnd":178.09999990463257,"connectStart":178.09999990463257,"domainLookupEnd":178.09999990463257,"domainLookupStart":178.09999990463257,"fetchStart":178.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":178.09999990463257,"responseEnd":618,"responseStart":618,"secureConnectionStart":178.09999990463257},{"duration":685.1000001430511,"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":183.09999990463257,"connectEnd":183.09999990463257,"connectStart":183.09999990463257,"domainLookupEnd":183.09999990463257,"domainLookupStart":183.09999990463257,"fetchStart":183.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":183.09999990463257,"responseEnd":868.2000000476837,"responseStart":868.2000000476837,"secureConnectionStart":183.09999990463257},{"duration":751.2999999523163,"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":183.29999995231628,"connectEnd":183.29999995231628,"connectStart":183.29999995231628,"domainLookupEnd":183.29999995231628,"domainLookupStart":183.29999995231628,"fetchStart":183.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":183.29999995231628,"responseEnd":934.5999999046326,"responseStart":934.5999999046326,"secureConnectionStart":183.29999995231628},{"duration":379,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":487.59999990463257,"connectEnd":487.59999990463257,"connectStart":487.59999990463257,"domainLookupEnd":487.59999990463257,"domainLookupStart":487.59999990463257,"fetchStart":487.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":487.59999990463257,"responseEnd":866.5999999046326,"responseStart":866.5999999046326,"secureConnectionStart":487.59999990463257},{"duration":56.39999985694885,"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":878.7000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":878.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":935.0999999046326,"responseStart":0,"secureConnectionStart":0},{"duration":242.70000004768372,"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":879.5999999046326,"connectEnd":879.5999999046326,"connectStart":879.5999999046326,"domainLookupEnd":879.5999999046326,"domainLookupStart":879.5999999046326,"fetchStart":879.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":879.5999999046326,"responseEnd":1122.2999999523163,"responseStart":1122.2999999523163,"secureConnectionStart":879.5999999046326},{"duration":247.20000004768372,"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":880,"connectEnd":880,"connectStart":880,"domainLookupEnd":880,"domainLookupStart":880,"fetchStart":880,"redirectEnd":0,"redirectStart":0,"requestStart":880,"responseEnd":1127.2000000476837,"responseStart":1127.2000000476837,"secureConnectionStart":880},{"duration":158.29999995231628,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":969.7000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":969.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1128,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":36,"responseStart":170,"responseEnd":177,"domLoading":174,"domInteractive":1104,"domContentLoadedEventStart":1104,"domContentLoadedEventEnd":1143,"domComplete":1791,"loadEventStart":1791,"loadEventEnd":1792,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1087.5999999046326},{"name":"bigPipe.sidebar-id.end","time":1088.5},{"name":"bigPipe.activity-panel-pipe-id.start","time":1088.5999999046326},{"name":"bigPipe.activity-panel-pipe-id.end","time":1091.0999999046326},{"name":"activityTabFullyLoaded","time":1153.2000000476837}],"measures":[],"correlationId":"c0fd052d11d1bf","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":78,"dbReadsTimeInMs":12,"dbConnsTimeInMs":19,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}