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":1154,"ttfb":339.7999999523163,"pageVisibility":"visible","entityId":99510,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"3ff4033f-a602-4fa9-b077-9f1b20771b9c","navigationType":0,"readyForUser":1250,"redirectCount":0,"resourceLoadedEnd":1235,"resourceLoadedStart":354.5,"resourceTiming":[{"duration":365.7999999523163,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":354.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":354.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":720.2999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":365.90000009536743,"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":354.7999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":354.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":720.7000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":375.10000002384186,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":355,"connectEnd":355,"connectStart":355,"domainLookupEnd":355,"domainLookupStart":355,"fetchStart":355,"redirectEnd":0,"redirectStart":0,"requestStart":355,"responseEnd":730.1000000238419,"responseStart":730.1000000238419,"secureConnectionStart":355},{"duration":401.89999997615814,"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":355.2000000476837,"connectEnd":355.2000000476837,"connectStart":355.2000000476837,"domainLookupEnd":355.2000000476837,"domainLookupStart":355.2000000476837,"fetchStart":355.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":355.2000000476837,"responseEnd":757.1000000238419,"responseStart":757.1000000238419,"secureConnectionStart":355.2000000476837},{"duration":406.2000000476837,"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":355.2999999523163,"connectEnd":355.2999999523163,"connectStart":355.2999999523163,"domainLookupEnd":355.2999999523163,"domainLookupStart":355.2999999523163,"fetchStart":355.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":355.2999999523163,"responseEnd":761.5,"responseStart":761.3999999761581,"secureConnectionStart":355.2999999523163},{"duration":406.2999999523163,"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":355.60000002384186,"connectEnd":355.60000002384186,"connectStart":355.60000002384186,"domainLookupEnd":355.60000002384186,"domainLookupStart":355.60000002384186,"fetchStart":355.60000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":355.60000002384186,"responseEnd":761.8999999761581,"responseStart":761.8999999761581,"secureConnectionStart":355.60000002384186},{"duration":407.7000000476837,"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":355.89999997615814,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":355.89999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":763.6000000238419,"responseStart":0,"secureConnectionStart":0},{"duration":406.39999997615814,"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":355.89999997615814,"connectEnd":355.89999997615814,"connectStart":355.89999997615814,"domainLookupEnd":355.89999997615814,"domainLookupStart":355.89999997615814,"fetchStart":355.89999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":355.89999997615814,"responseEnd":762.2999999523163,"responseStart":762.2999999523163,"secureConnectionStart":355.89999997615814},{"duration":407.10000002384186,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":356.10000002384186,"connectEnd":356.10000002384186,"connectStart":356.10000002384186,"domainLookupEnd":356.10000002384186,"domainLookupStart":356.10000002384186,"fetchStart":356.10000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":356.10000002384186,"responseEnd":763.2000000476837,"responseStart":763.2000000476837,"secureConnectionStart":356.10000002384186},{"duration":407.7000000476837,"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":356.2999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":356.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":764,"responseStart":0,"secureConnectionStart":0},{"duration":407.39999997615814,"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":356.39999997615814,"connectEnd":356.39999997615814,"connectStart":356.39999997615814,"domainLookupEnd":356.39999997615814,"domainLookupStart":356.39999997615814,"fetchStart":356.39999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":356.39999997615814,"responseEnd":763.7999999523163,"responseStart":763.7999999523163,"secureConnectionStart":356.39999997615814},{"duration":872.2000000476837,"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":362.39999997615814,"connectEnd":362.39999997615814,"connectStart":362.39999997615814,"domainLookupEnd":362.39999997615814,"domainLookupStart":362.39999997615814,"fetchStart":362.39999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":362.39999997615814,"responseEnd":1234.6000000238419,"responseStart":1234.6000000238419,"secureConnectionStart":362.39999997615814},{"duration":866.7999999523163,"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":368.2000000476837,"connectEnd":368.2000000476837,"connectStart":368.2000000476837,"domainLookupEnd":368.2000000476837,"domainLookupStart":368.2000000476837,"fetchStart":368.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":368.2000000476837,"responseEnd":1235,"responseStart":1235,"secureConnectionStart":368.2000000476837},{"duration":244.89999997615814,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":961.5,"connectEnd":961.5,"connectStart":961.5,"domainLookupEnd":961.5,"domainLookupStart":961.5,"fetchStart":961.5,"redirectEnd":0,"redirectStart":0,"requestStart":961.5,"responseEnd":1206.3999999761581,"responseStart":1206.3999999761581,"secureConnectionStart":961.5}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":166,"responseStart":340,"responseEnd":368,"domLoading":353,"domInteractive":1387,"domContentLoadedEventStart":1387,"domContentLoadedEventEnd":1432,"domComplete":2198,"loadEventStart":2198,"loadEventEnd":2199,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1337.7000000476837},{"name":"bigPipe.sidebar-id.end","time":1338.3999999761581},{"name":"bigPipe.activity-panel-pipe-id.start","time":1338.5},{"name":"bigPipe.activity-panel-pipe-id.end","time":1342.6000000238419},{"name":"activityTabFullyLoaded","time":1445.3999999761581}],"measures":[],"correlationId":"959b532659a7ed","effectiveType":"4g","downlink":9.1,"rtt":0,"serverDuration":113,"dbReadsTimeInMs":15,"dbConnsTimeInMs":24,"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