-
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":754.8000000715256,"ttfb":176.10000002384186,"pageVisibility":"visible","entityId":70190,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"39986362-a1bc-4cc1-a4c5-99de12948bf7","navigationType":0,"readyForUser":894.8000000715256,"redirectCount":0,"resourceLoadedEnd":775.3000000715256,"resourceLoadedStart":181.80000007152557,"resourceTiming":[{"duration":155.89999997615814,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":181.80000007152557,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":181.80000007152557,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":337.7000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":155.80000007152557,"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":182,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":182,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":337.8000000715256,"responseStart":0,"secureConnectionStart":0},{"duration":175.79999995231628,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":182.20000004768372,"connectEnd":182.20000004768372,"connectStart":182.20000004768372,"domainLookupEnd":182.20000004768372,"domainLookupStart":182.20000004768372,"fetchStart":182.20000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":182.20000004768372,"responseEnd":358,"responseStart":358,"secureConnectionStart":182.20000004768372},{"duration":263.7999999523163,"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":182.30000007152557,"connectEnd":182.30000007152557,"connectStart":182.30000007152557,"domainLookupEnd":182.30000007152557,"domainLookupStart":182.30000007152557,"fetchStart":182.30000007152557,"redirectEnd":0,"redirectStart":0,"requestStart":182.30000007152557,"responseEnd":446.10000002384186,"responseStart":446.10000002384186,"secureConnectionStart":182.30000007152557},{"duration":259.7999999523163,"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":182.30000007152557,"connectEnd":182.30000007152557,"connectStart":182.30000007152557,"domainLookupEnd":182.30000007152557,"domainLookupStart":182.30000007152557,"fetchStart":182.30000007152557,"redirectEnd":0,"redirectStart":0,"requestStart":182.30000007152557,"responseEnd":442.10000002384186,"responseStart":442.10000002384186,"secureConnectionStart":182.30000007152557},{"duration":264.1999999284744,"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":182.40000009536743,"connectEnd":182.40000009536743,"connectStart":182.40000009536743,"domainLookupEnd":182.40000009536743,"domainLookupStart":182.40000009536743,"fetchStart":182.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":182.40000009536743,"responseEnd":446.60000002384186,"responseStart":446.60000002384186,"secureConnectionStart":182.40000009536743},{"duration":264.60000002384186,"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":182.5,"connectEnd":182.5,"connectStart":182.5,"domainLookupEnd":182.5,"domainLookupStart":182.5,"fetchStart":182.5,"redirectEnd":0,"redirectStart":0,"requestStart":182.5,"responseEnd":447.10000002384186,"responseStart":447.10000002384186,"secureConnectionStart":182.5},{"duration":264.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":182.60000002384186,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":182.60000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":447.5,"responseStart":0,"secureConnectionStart":0},{"duration":264.7999999523163,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":182.70000004768372,"connectEnd":182.70000004768372,"connectStart":182.70000004768372,"domainLookupEnd":182.70000004768372,"domainLookupStart":182.70000004768372,"fetchStart":182.70000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":182.70000004768372,"responseEnd":447.5,"responseStart":447.5,"secureConnectionStart":182.70000004768372},{"duration":265,"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":182.80000007152557,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":182.80000007152557,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":447.8000000715256,"responseStart":0,"secureConnectionStart":0},{"duration":264.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":183,"connectEnd":183,"connectStart":183,"domainLookupEnd":183,"domainLookupStart":183,"fetchStart":183,"redirectEnd":0,"redirectStart":0,"requestStart":183,"responseEnd":447.90000009536743,"responseStart":447.90000009536743,"secureConnectionStart":183},{"duration":536.7000000476837,"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.70000004768372,"connectEnd":183.70000004768372,"connectStart":183.70000004768372,"domainLookupEnd":183.70000004768372,"domainLookupStart":183.70000004768372,"fetchStart":183.70000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":183.70000004768372,"responseEnd":720.4000000953674,"responseStart":720.4000000953674,"secureConnectionStart":183.70000004768372},{"duration":550.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.80000007152557,"connectEnd":183.80000007152557,"connectStart":183.80000007152557,"domainLookupEnd":183.80000007152557,"domainLookupStart":183.80000007152557,"fetchStart":183.80000007152557,"redirectEnd":0,"redirectStart":0,"requestStart":183.80000007152557,"responseEnd":734.1000000238419,"responseStart":734.1000000238419,"secureConnectionStart":183.80000007152557},{"duration":208.80000007152557,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":512,"connectEnd":512,"connectStart":512,"domainLookupEnd":512,"domainLookupStart":512,"fetchStart":512,"redirectEnd":0,"redirectStart":0,"requestStart":512,"responseEnd":720.8000000715256,"responseStart":720.8000000715256,"secureConnectionStart":512},{"duration":2.299999952316284,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":747.9000000953674,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":747.9000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":750.2000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":3.8000000715255737,"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":771.5,"connectEnd":771.5,"connectStart":771.5,"domainLookupEnd":771.5,"domainLookupStart":771.5,"fetchStart":771.5,"redirectEnd":0,"redirectStart":0,"requestStart":771.5,"responseEnd":775.3000000715256,"responseStart":775.3000000715256,"secureConnectionStart":771.5}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":29,"responseStart":176,"responseEnd":177,"domLoading":179,"domInteractive":963,"domContentLoadedEventStart":963,"domContentLoadedEventEnd":1010,"domComplete":1916,"loadEventStart":1916,"loadEventEnd":1916,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":937.3000000715256},{"name":"bigPipe.sidebar-id.end","time":938.1000000238419},{"name":"bigPipe.activity-panel-pipe-id.start","time":938.3000000715256},{"name":"bigPipe.activity-panel-pipe-id.end","time":940.8000000715256},{"name":"activityTabFullyLoaded","time":1023}],"measures":[],"correlationId":"663d5c01b30701","effectiveType":"4g","downlink":9.9,"rtt":0,"serverDuration":83,"dbReadsTimeInMs":14,"dbConnsTimeInMs":22,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}