-
Bug
-
-
Major
-
Resolution:
Fixed
-
10.0(EOL), 10.1(EOL), 10.2(EOL), 10.3(EOL), 10.4(EOL)
-
-
-
WHERE optimization does not seem to distinguish between a simple CASE and a searched CASE with the same arguments.
I create and populate a table:
DROP TABLE IF EXISTS t1;
|
CREATE TABLE t1 (a INT, b INT, KEY(a));
|
INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
|
A query with a simple CASE:
SELECT * FROM t1 WHERE CASE a WHEN b THEN 1 END=1;
|
+------+------+
|
| a | b |
|
+------+------+
|
| 1 | 1 |
|
| 2 | 2 |
|
| 3 | 3 |
|
+------+------+
|
returns 3 rows.
A query with a searched CASE:
SELECT * FROM t1 WHERE CASE WHEN a THEN b ELSE 1 END=3;
|
+------+------+
|
| a | b |
|
+------+------+
|
| 3 | 3 |
|
+------+------+
|
returns one row.
Now I combine both conditions using AND:
SELECT * FROM t1 WHERE
|
CASE a WHEN b THEN 1 END=1
|
AND
|
CASE WHEN a THEN b ELSE 1 END=3;
|
The expected result is to return one row, as in the second query.
The condition was erroneously optimized to WHERE 0;
EXPLAIN EXTENDED
|
SELECT * FROM t1 WHERE
|
CASE a WHEN b THEN 1 END=1
|
AND
|
CASE WHEN a THEN b ELSE 1 END=3;
|
SHOW WARNINGS;
|
+-------+------+-------------------------------------------------------------------------------+
|
| Level | Code | Message |
|
+-------+------+-------------------------------------------------------------------------------+
|
| Note | 1003 | select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where 0 |
|
+-------+------+-------------------------------------------------------------------------------+
|
- relates to
-
MDEV-16885
A method of CASE searched/simple detection
-
-
Closed
{"report":{"fcp":3430.1000003814697,"ttfb":1293.7000002861023,"pageVisibility":"visible","entityId":70190,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"6819c24b-9916-4d9f-8ceb-7f8910e7e0f4","navigationType":0,"readyForUser":3413.6000003814697,"redirectCount":0,"resourceLoadedEnd":4711.700000286102,"resourceLoadedStart":1309.9000000953674,"resourceTiming":[{"duration":1023.7000002861023,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":1309.9000000953674,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1309.9000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":2333.6000003814697,"responseStart":0,"secureConnectionStart":0},{"duration":1023.7999997138977,"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":1310.2000002861023,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1310.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":2334,"responseStart":0,"secureConnectionStart":0},{"duration":1031.5999999046326,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":1310.4000000953674,"connectEnd":1310.4000000953674,"connectStart":1310.4000000953674,"domainLookupEnd":1310.4000000953674,"domainLookupStart":1310.4000000953674,"fetchStart":1310.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":1310.4000000953674,"responseEnd":2342,"responseStart":2342,"secureConnectionStart":1310.4000000953674},{"duration":1229.5,"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":1310.6000003814697,"connectEnd":1310.6000003814697,"connectStart":1310.6000003814697,"domainLookupEnd":1310.6000003814697,"domainLookupStart":1310.6000003814697,"fetchStart":1310.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":1310.6000003814697,"responseEnd":2540.1000003814697,"responseStart":2540.1000003814697,"secureConnectionStart":1310.6000003814697},{"duration":1444.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":1311,"connectEnd":1311,"connectStart":1311,"domainLookupEnd":1311,"domainLookupStart":1311,"fetchStart":1311,"redirectEnd":0,"redirectStart":0,"requestStart":1311,"responseEnd":2755.5,"responseStart":2755.5,"secureConnectionStart":1311},{"duration":1594.8000001907349,"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":1311.3000001907349,"connectEnd":1311.3000001907349,"connectStart":1311.3000001907349,"domainLookupEnd":1311.3000001907349,"domainLookupStart":1311.3000001907349,"fetchStart":1311.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":1311.3000001907349,"responseEnd":2906.1000003814697,"responseStart":2906.1000003814697,"secureConnectionStart":1311.3000001907349},{"duration":1646.3000001907349,"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":1311.5,"connectEnd":1311.5,"connectStart":1311.5,"domainLookupEnd":1311.5,"domainLookupStart":1311.5,"fetchStart":1311.5,"redirectEnd":0,"redirectStart":0,"requestStart":1311.5,"responseEnd":2957.800000190735,"responseStart":2957.800000190735,"secureConnectionStart":1311.5},{"duration":1872.8999996185303,"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":1311.6000003814697,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1311.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":3184.5,"responseStart":0,"secureConnectionStart":0},{"duration":1686.3000001907349,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":1311.8000001907349,"connectEnd":1311.8000001907349,"connectStart":1311.8000001907349,"domainLookupEnd":1311.8000001907349,"domainLookupStart":1311.8000001907349,"fetchStart":1311.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":1311.8000001907349,"responseEnd":2998.1000003814697,"responseStart":2998.1000003814697,"secureConnectionStart":1311.8000001907349},{"duration":1872.7000002861023,"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":1312,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1312,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":3184.7000002861023,"responseStart":0,"secureConnectionStart":0},{"duration":1686.5999999046326,"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":1312.2000002861023,"connectEnd":1312.2000002861023,"connectStart":1312.2000002861023,"domainLookupEnd":1312.2000002861023,"domainLookupStart":1312.2000002861023,"fetchStart":1312.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":1312.2000002861023,"responseEnd":2998.800000190735,"responseStart":2998.800000190735,"secureConnectionStart":1312.2000002861023},{"duration":3175.6000003814697,"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":1313,"connectEnd":1313,"connectStart":1313,"domainLookupEnd":1313,"domainLookupStart":1313,"fetchStart":1313,"redirectEnd":0,"redirectStart":0,"requestStart":1313,"responseEnd":4488.60000038147,"responseStart":4488.60000038147,"secureConnectionStart":1313},{"duration":3398.5999999046326,"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":1313.1000003814697,"connectEnd":1313.1000003814697,"connectStart":1313.1000003814697,"domainLookupEnd":1313.1000003814697,"domainLookupStart":1313.1000003814697,"fetchStart":1313.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":1313.1000003814697,"responseEnd":4711.700000286102,"responseStart":4711.700000286102,"secureConnectionStart":1313.1000003814697},{"duration":1411.9000000953674,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":2789.800000190735,"connectEnd":2789.800000190735,"connectStart":2789.800000190735,"domainLookupEnd":2789.800000190735,"domainLookupStart":2789.800000190735,"fetchStart":2789.800000190735,"redirectEnd":0,"redirectStart":0,"requestStart":2789.800000190735,"responseEnd":4201.700000286102,"responseStart":4201.700000286102,"secureConnectionStart":2789.800000190735},{"duration":1471.2000002861023,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":3265.9000000953674,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":3265.9000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":4737.10000038147,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":892,"responseStart":1293,"responseEnd":1297,"domLoading":1299,"domInteractive":4738,"domContentLoadedEventStart":4738,"domContentLoadedEventEnd":4801,"domComplete":7848,"loadEventStart":7848,"loadEventEnd":7852,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":4721.400000095367},{"name":"bigPipe.sidebar-id.end","time":4722.300000190735},{"name":"bigPipe.activity-panel-pipe-id.start","time":4722.5},{"name":"bigPipe.activity-panel-pipe-id.end","time":4725.10000038147},{"name":"activityTabFullyLoaded","time":4805.400000095367}],"measures":[],"correlationId":"55769dcc1895b6","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":106,"dbReadsTimeInMs":15,"dbConnsTimeInMs":26,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}