This script:
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a INT ZEROFILL);
INSERT INTO t1 VALUES (2010),(2020);
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=2010 AND a>=2010;
SHOW WARNINGS;
returns
+-------+------+---------------------------------------------------------------------------------------+
| Level | Code | Message |
+-------+------+---------------------------------------------------------------------------------------+
| Note | 1003 | select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 2010) and 1) |
+-------+------+---------------------------------------------------------------------------------------+
Notice, the a>=2010 part was simplified to constant, but the constant was not removed.
The same problems is repeatable with the YEAR data type:
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a YEAR);
INSERT INTO t1 VALUES (2010),(2020);
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=2010 AND a>=2010;
SHOW WARNINGS;
If I use "INT" instead of "INT ZEROFILL" or "YEAR", it works as expected:
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (2010),(2020);
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=2010 AND a>=2010;
SHOW WARNINGS;
returns:
+-------+------+-------------------------------------------------------------------------------+
| Level | Code | Message |
+-------+------+-------------------------------------------------------------------------------+
| Note | 1003 | select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 2010) |
+-------+------+-------------------------------------------------------------------------------+
as expected.
blocks
MDEV-8728
Fix a number of problems in equal field and equal expression propagation
Closed
Alexander Barkov
made changes -
2015-09-09 10:13
Fix Version/s
10.1.7
[ 19604
]
Fix Version/s
10.1
[ 16100
]
Resolution
Fixed
[ 1
]
Status
Open
[ 1
]
Closed
[ 6
]
Alexander Barkov
made changes -
2015-09-12 23:13
Labels
propagation
propagation upstream
Sergei Golubchik
made changes -
2021-12-06 21:41
Workflow
MariaDB v3
[ 71346
]
MariaDB v4
[ 149564
]
{"report":{"fcp":1302.3000001907349,"ttfb":592.8000001907349,"pageVisibility":"visible","entityId":52946,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"ffecfe9f-42e4-4ffd-9cdd-10ecc247dca9","navigationType":0,"readyForUser":1384.9000005722046,"redirectCount":0,"resourceLoadedEnd":1465.6000003814697,"resourceLoadedStart":598.1000003814697,"resourceTiming":[{"duration":84.09999942779541,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":598.1000003814697,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":598.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":682.1999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":84.59999942779541,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bv2/820016/12ta74/2380add21a9a1006587582385952de73/_/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":598.4000005722046,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":598.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":683,"responseStart":0,"secureConnectionStart":0},{"duration":172.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/e9b27a47da5fb0f74a35acd57e9847fb-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":598.6000003814697,"connectEnd":598.6000003814697,"connectStart":598.6000003814697,"domainLookupEnd":598.6000003814697,"domainLookupStart":598.6000003814697,"fetchStart":598.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":598.6000003814697,"responseEnd":771.3000001907349,"responseStart":771.3000001907349,"secureConnectionStart":598.6000003814697},{"duration":244.10000038146973,"initiatorType":"script","name":"https://jira.mariadb.org/s/c32eb0da7ad9831253f8397e6cc26afd-CDN/lu2bv2/820016/12ta74/2380add21a9a1006587582385952de73/_/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":598.8000001907349,"connectEnd":598.8000001907349,"connectStart":598.8000001907349,"domainLookupEnd":598.8000001907349,"domainLookupStart":598.8000001907349,"fetchStart":598.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":598.8000001907349,"responseEnd":842.9000005722046,"responseStart":842.9000005722046,"secureConnectionStart":598.8000001907349},{"duration":247.9000005722046,"initiatorType":"script","name":"https://jira.mariadb.org/s/bc0bcb146314416123c992714ee00ff7-CDN/lu2bv2/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":599,"connectEnd":599,"connectStart":599,"domainLookupEnd":599,"domainLookupStart":599,"fetchStart":599,"redirectEnd":0,"redirectStart":0,"requestStart":599,"responseEnd":846.9000005722046,"responseStart":846.9000005722046,"secureConnectionStart":599},{"duration":248.10000038146973,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":599.3000001907349,"connectEnd":599.3000001907349,"connectStart":599.3000001907349,"domainLookupEnd":599.3000001907349,"domainLookupStart":599.3000001907349,"fetchStart":599.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":599.3000001907349,"responseEnd":847.4000005722046,"responseStart":847.4000005722046,"secureConnectionStart":599.3000001907349},{"duration":248.39999961853027,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":599.4000005722046,"connectEnd":599.4000005722046,"connectStart":599.4000005722046,"domainLookupEnd":599.4000005722046,"domainLookupStart":599.4000005722046,"fetchStart":599.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":599.4000005722046,"responseEnd":847.8000001907349,"responseStart":847.8000001907349,"secureConnectionStart":599.4000005722046},{"duration":317.5999994277954,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bv2/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":599.6000003814697,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":599.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":917.1999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":248.39999961853027,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":599.8000001907349,"connectEnd":599.8000001907349,"connectStart":599.8000001907349,"domainLookupEnd":599.8000001907349,"domainLookupStart":599.8000001907349,"fetchStart":599.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":599.8000001907349,"responseEnd":848.1999998092651,"responseStart":848.1999998092651,"secureConnectionStart":599.8000001907349},{"duration":317.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bv2/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":599.9000005722046,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":599.9000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":917.4000005722046,"responseStart":0,"secureConnectionStart":0},{"duration":248.5999994277954,"initiatorType":"script","name":"https://jira.mariadb.org/s/719848dd97ebe0663199f49a3936487a-CDN/lu2bv2/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":600.1000003814697,"connectEnd":600.1000003814697,"connectStart":600.1000003814697,"domainLookupEnd":600.1000003814697,"domainLookupStart":600.1000003814697,"fetchStart":600.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":600.1000003814697,"responseEnd":848.6999998092651,"responseStart":848.6999998092651,"secureConnectionStart":600.1000003814697},{"duration":425.70000076293945,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":605.6999998092651,"connectEnd":605.6999998092651,"connectStart":605.6999998092651,"domainLookupEnd":605.6999998092651,"domainLookupStart":605.6999998092651,"fetchStart":605.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":605.6999998092651,"responseEnd":1031.4000005722046,"responseStart":1031.3000001907349,"secureConnectionStart":605.6999998092651},{"duration":837,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":605.8000001907349,"connectEnd":605.8000001907349,"connectStart":605.8000001907349,"domainLookupEnd":605.8000001907349,"domainLookupStart":605.8000001907349,"fetchStart":605.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":605.8000001907349,"responseEnd":1442.8000001907349,"responseStart":1442.8000001907349,"secureConnectionStart":605.8000001907349},{"duration":104.09999942779541,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":929.9000005722046,"connectEnd":929.9000005722046,"connectStart":929.9000005722046,"domainLookupEnd":929.9000005722046,"domainLookupStart":929.9000005722046,"fetchStart":929.9000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":929.9000005722046,"responseEnd":1034,"responseStart":1034,"secureConnectionStart":929.9000005722046},{"duration":267.80000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2bv2/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":1197.8000001907349,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1197.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1465.6000003814697,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":408,"responseStart":593,"responseEnd":602,"domLoading":596,"domInteractive":1476,"domContentLoadedEventStart":1476,"domContentLoadedEventEnd":1531,"domComplete":1961,"loadEventStart":1961,"loadEventEnd":1961,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1446.5},{"name":"bigPipe.sidebar-id.end","time":1447.4000005722046},{"name":"bigPipe.activity-panel-pipe-id.start","time":1447.6999998092651},{"name":"bigPipe.activity-panel-pipe-id.end","time":1450.8000001907349},{"name":"activityTabFullyLoaded","time":1547.3000001907349}],"measures":[],"correlationId":"bf719f68f740d6","effectiveType":"4g","downlink":9.7,"rtt":0,"serverDuration":112,"dbReadsTimeInMs":17,"dbConnsTimeInMs":25,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
MySQL-5.7.8 does not seem to remove the constant part (the result of propagation) from the WHERE condition:
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a INT ZEROFILL);
INSERT INTO t1 VALUES (2010),(2020);
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=2010 AND a>=2010;
SHOW WARNINGS;
returns
+---------+------+-------------------------------------------------------------------------------------------------------------------+
| Level | Code | Message |
+---------+------+-------------------------------------------------------------------------------------------------------------------+
| Warning | 1681 | 'EXTENDED' is deprecated and will be removed in a future release. |
| Note | 1003 | /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 2010) and (2010 >= 2010)) |
+---------+------+-------------------------------------------------------------------------------------------------------------------