I used my fuzzing tool to test Mariadb , and found a bug that can result in an abortion.
Mariadb installation:
1) cd mariadb-10.5.9
2) mkdir build; cd build
3) cmake -DWITH_ASAN=ON -DWITH_ASAN_SCOPE=ON -DWITH_DEBUG=ON ../
4) make -j8 && sudo make install
How to Repeat:
export ASAN_OPTIONS=detect_leaks=0
/usr/local/mysql/bin/mysqld_safe &
/usr/local/mysql/bin/mysql -uroot -p123456(your password)
MariaDB> drop database if exists test_db;
MariaDB> create database test_db;
MariaDB> source fuzz.sql;
I have simplified the content of fuzz.sql, and I hope fuzz.sql can help you reproduce the bug and fix it. In addition, I attach the abortion report (which has its stack trace).
{"report":{"fcp":1162.8000001907349,"ttfb":224.59999990463257,"pageVisibility":"visible","entityId":99510,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":32,"apdex":0.5,"journeyId":"1cd791fd-ad11-4e6f-b49f-a8578e48e769","navigationType":0,"readyForUser":1283.6999998092651,"redirectCount":0,"resourceLoadedEnd":1510.0999999046326,"resourceLoadedStart":229.80000019073486,"resourceTiming":[{"duration":355.8999996185303,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":229.80000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":229.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":585.6999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":356.19999980926514,"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":230,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":230,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":586.1999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":365.1000003814697,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":230.19999980926514,"connectEnd":230.19999980926514,"connectStart":230.19999980926514,"domainLookupEnd":230.19999980926514,"domainLookupStart":230.19999980926514,"fetchStart":230.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":230.19999980926514,"responseEnd":595.3000001907349,"responseStart":595.3000001907349,"secureConnectionStart":230.19999980926514},{"duration":405.19999980926514,"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":230.40000009536743,"connectEnd":230.40000009536743,"connectStart":230.40000009536743,"domainLookupEnd":230.40000009536743,"domainLookupStart":230.40000009536743,"fetchStart":230.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":230.40000009536743,"responseEnd":635.5999999046326,"responseStart":635.5999999046326,"secureConnectionStart":230.40000009536743},{"duration":409.2000002861023,"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":230.59999990463257,"connectEnd":230.59999990463257,"connectStart":230.59999990463257,"domainLookupEnd":230.59999990463257,"domainLookupStart":230.59999990463257,"fetchStart":230.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":230.59999990463257,"responseEnd":639.8000001907349,"responseStart":639.8000001907349,"secureConnectionStart":230.59999990463257},{"duration":409.6000003814697,"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":230.69999980926514,"connectEnd":230.69999980926514,"connectStart":230.69999980926514,"domainLookupEnd":230.69999980926514,"domainLookupStart":230.69999980926514,"fetchStart":230.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":230.69999980926514,"responseEnd":640.3000001907349,"responseStart":640.3000001907349,"secureConnectionStart":230.69999980926514},{"duration":409.69999980926514,"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":230.90000009536743,"connectEnd":230.90000009536743,"connectStart":230.90000009536743,"domainLookupEnd":230.90000009536743,"domainLookupStart":230.90000009536743,"fetchStart":230.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":230.90000009536743,"responseEnd":640.5999999046326,"responseStart":640.5999999046326,"secureConnectionStart":230.90000009536743},{"duration":544.0999999046326,"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":231.09999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":231.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":775.1999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":409.7999997138977,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":231.30000019073486,"connectEnd":231.30000019073486,"connectStart":231.30000019073486,"domainLookupEnd":231.30000019073486,"domainLookupStart":231.30000019073486,"fetchStart":231.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":231.30000019073486,"responseEnd":641.0999999046326,"responseStart":641.0999999046326,"secureConnectionStart":231.30000019073486},{"duration":544,"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":231.40000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":231.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":775.4000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":410.09999990463257,"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":231.59999990463257,"connectEnd":231.59999990463257,"connectStart":231.59999990463257,"domainLookupEnd":231.59999990463257,"domainLookupStart":231.59999990463257,"fetchStart":231.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":231.59999990463257,"responseEnd":641.6999998092651,"responseStart":641.6999998092651,"secureConnectionStart":231.59999990463257},{"duration":1262.5,"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":237.40000009536743,"connectEnd":237.40000009536743,"connectStart":237.40000009536743,"domainLookupEnd":237.40000009536743,"domainLookupStart":237.40000009536743,"fetchStart":237.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":237.40000009536743,"responseEnd":1499.9000000953674,"responseStart":1499.9000000953674,"secureConnectionStart":237.40000009536743},{"duration":1264.8000001907349,"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":238,"connectEnd":238,"connectStart":238,"domainLookupEnd":238,"domainLookupStart":238,"fetchStart":238,"redirectEnd":0,"redirectStart":0,"requestStart":238,"responseEnd":1502.8000001907349,"responseStart":1502.8000001907349,"secureConnectionStart":238},{"duration":92.90000009536743,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":817.6999998092651,"connectEnd":817.6999998092651,"connectStart":817.6999998092651,"domainLookupEnd":817.6999998092651,"domainLookupStart":817.6999998092651,"fetchStart":817.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":817.6999998092651,"responseEnd":910.5999999046326,"responseStart":910.5999999046326,"secureConnectionStart":817.6999998092651},{"duration":404.40000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/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&whisper-enabled=true","startTime":1105.6999998092651,"connectEnd":1105.6999998092651,"connectStart":1105.6999998092651,"domainLookupEnd":1105.6999998092651,"domainLookupStart":1105.6999998092651,"fetchStart":1105.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":1105.6999998092651,"responseEnd":1510.0999999046326,"responseStart":1510.0999999046326,"secureConnectionStart":1105.6999998092651}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":48,"responseStart":225,"responseEnd":237,"domLoading":228,"domInteractive":1542,"domContentLoadedEventStart":1542,"domContentLoadedEventEnd":1598,"domComplete":2298,"loadEventStart":2298,"loadEventEnd":2300,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1506.4000000953674},{"name":"bigPipe.sidebar-id.end","time":1507.3000001907349},{"name":"bigPipe.activity-panel-pipe-id.start","time":1507.4000000953674},{"name":"bigPipe.activity-panel-pipe-id.end","time":1510.6999998092651},{"name":"activityTabFullyLoaded","time":1660.6999998092651}],"measures":[],"correlationId":"fd1a951a79d95b","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":120,"dbReadsTimeInMs":13,"dbConnsTimeInMs":23,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
This is a legacy bug and it's present in 10.2 as well.
Let's try to construct a test case for the bug in 10.2 that would catch the bug in 10.2 where there is no pushdown from HAVING to WHERE. However in 10.2 we have pushdown of conditions into HAVING of materialized tables / views that also builds items of the form Item_direct_view_ref(Item_ref(Item_sum_func(Item_basic_constant))) if the pushdown happens to be from WHERE of mergeable derived tables / views.
Here is a test case that uses such pushdown:
The result set from the query is:
MariaDB [test]> select * from (select * from v1) as dt where a=f and a=g;
+------+------+------+
| a | f | g |
+------+------+------+
| 3 | 3 | 3 |
+------+------+------+
1 row in set
though select from v1 returns
MariaDB [test]> select * from v1;
+------+------+------+
| a | f | g |
+------+------+------+
| 1 | 1 | 1 |
| 3 | 3 | 3 |
| 7 | 3 | 3 |
+------+------+------+
3 rows in set
If we manually push the condition a=f and a=g into v1 we have a proper result set:
MariaDB [test]> select * from (select a, sum(1) as f, sum(1) as g from t1 group by a having a=f and a=g) as dt;
+------+------+------+
| a | f | g |
+------+------+------+
| 1 | 1 | 1 |
| 3 | 3 | 3 |
+------+------+------+
2 rows in set