Type:
Bug
Priority:
Major
Resolution:
Fixed
Affects Version/s:
10.0(EOL) , 10.1(EOL) , 10.2(EOL) , 10.3(EOL) , 10.4(EOL)
The problem is repeatable starting from 10.0 with help of the Memory_used status variable, but the excessive memory consumption probably also takes place in 5.5 (which does not have Memory_used).
This script:
DROP PROCEDURE IF EXISTS p1;
DELIMITER $$
CREATE PROCEDURE p1()
BEGIN
DECLARE i INT DEFAULT 1;
WHILE i <= 500000
DO
BEGIN
DECLARE cur CURSOR FOR SELECT 1 FROM DUAL;
IF (i % 100000 = 0) THEN
SHOW STATUS LIKE 'Memory_used' ;
END IF ;
END ;
SET i=i+1;
END WHILE;
END ;
$$
DELIMITER ;
CALL p1;
produced the following output:
+---------------+---------+
| Variable_name | Value |
+---------------+---------+
| Memory_used | 7391264 |
+---------------+---------+
1 row in set (2.09 sec)
+---------------+----------+
| Variable_name | Value |
+---------------+----------+
| Memory_used | 14459048 |
+---------------+----------+
1 row in set (4.19 sec)
+---------------+----------+
| Variable_name | Value |
+---------------+----------+
| Memory_used | 21746936 |
+---------------+----------+
1 row in set (6.21 sec)
+---------------+----------+
| Variable_name | Value |
+---------------+----------+
| Memory_used | 29132648 |
+---------------+----------+
1 row in set (8.24 sec)
+---------------+----------+
| Variable_name | Value |
+---------------+----------+
| Memory_used | 36045544 |
+---------------+----------+
1 row in set (10.25 sec)
The thread leaks some memory at every loop iteration.
If I now comment out the line with cursor:
-- DECLARE cur CURSOR FOR SELECT 1 FROM DUAL;
and rerun the script, the amount of thread memory reported permanently stays near 64K and does not grow through iterations.
The problem resides in this code:
bool sp_rcontext::push_cursor(THD *thd, sp_lex_keeper *lex_keeper)
{
/*
We should create cursors in the callers arena, as
it could be (and usually is) used in several instructions.
*/
sp_cursor *c= new (callers_arena->mem_root) sp_cursor(thd, lex_keeper);
...
}
At the the push_cursor() call time, callers_area points to THD::main_mem_root , which is freed only after the SP instructions loop.
Cursors should be created at some different memory root.
relates to
MDEV-16595
SP with a CONTINUE HANDLER inside a loop wastes THD memory aggressively
Closed
{"report":{"fcp":1274,"ttfb":232,"pageVisibility":"visible","entityId":68348,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"639b3cac-e6b5-4f1f-88c6-a958e7a4deee","navigationType":0,"readyForUser":1364.5999999046326,"redirectCount":0,"resourceLoadedEnd":1659.4000000953674,"resourceLoadedStart":237.30000019073486,"resourceTiming":[{"duration":547.0999999046326,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":237.30000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":237.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":784.4000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":547.2000002861023,"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":237.59999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":237.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":784.8000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":556.0999999046326,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":237.80000019073486,"connectEnd":237.80000019073486,"connectStart":237.80000019073486,"domainLookupEnd":237.80000019073486,"domainLookupStart":237.80000019073486,"fetchStart":237.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":237.80000019073486,"responseEnd":793.9000000953674,"responseStart":793.9000000953674,"secureConnectionStart":237.80000019073486},{"duration":625.0999999046326,"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":238,"connectEnd":238,"connectStart":238,"domainLookupEnd":238,"domainLookupStart":238,"fetchStart":238,"redirectEnd":0,"redirectStart":0,"requestStart":238,"responseEnd":863.0999999046326,"responseStart":863.0999999046326,"secureConnectionStart":238},{"duration":628.7999997138977,"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":238.2000002861023,"connectEnd":238.2000002861023,"connectStart":238.2000002861023,"domainLookupEnd":238.2000002861023,"domainLookupStart":238.2000002861023,"fetchStart":238.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":238.2000002861023,"responseEnd":867,"responseStart":867,"secureConnectionStart":238.2000002861023},{"duration":629.0999999046326,"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":238.30000019073486,"connectEnd":238.30000019073486,"connectStart":238.30000019073486,"domainLookupEnd":238.30000019073486,"domainLookupStart":238.30000019073486,"fetchStart":238.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":238.30000019073486,"responseEnd":867.4000000953674,"responseStart":867.4000000953674,"secureConnectionStart":238.30000019073486},{"duration":629.2000002861023,"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":238.59999990463257,"connectEnd":238.59999990463257,"connectStart":238.59999990463257,"domainLookupEnd":238.59999990463257,"domainLookupStart":238.59999990463257,"fetchStart":238.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":238.59999990463257,"responseEnd":867.8000001907349,"responseStart":867.8000001907349,"secureConnectionStart":238.59999990463257},{"duration":699.9000000953674,"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":238.80000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":238.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":938.7000002861023,"responseStart":0,"secureConnectionStart":0},{"duration":629.3000001907349,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":239,"connectEnd":239,"connectStart":239,"domainLookupEnd":239,"domainLookupStart":239,"fetchStart":239,"redirectEnd":0,"redirectStart":0,"requestStart":239,"responseEnd":868.3000001907349,"responseStart":868.3000001907349,"secureConnectionStart":239},{"duration":699.5999999046326,"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":239.2000002861023,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":239.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":938.8000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":629.5,"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":239.30000019073486,"connectEnd":239.30000019073486,"connectStart":239.30000019073486,"domainLookupEnd":239.30000019073486,"domainLookupStart":239.30000019073486,"fetchStart":239.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":239.30000019073486,"responseEnd":868.8000001907349,"responseStart":868.8000001907349,"secureConnectionStart":239.30000019073486},{"duration":843.4000000953674,"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":245,"connectEnd":245,"connectStart":245,"domainLookupEnd":245,"domainLookupStart":245,"fetchStart":245,"redirectEnd":0,"redirectStart":0,"requestStart":245,"responseEnd":1088.4000000953674,"responseStart":1088.4000000953674,"secureConnectionStart":245},{"duration":1413.5,"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":245.2000002861023,"connectEnd":245.2000002861023,"connectStart":245.2000002861023,"domainLookupEnd":245.2000002861023,"domainLookupStart":245.2000002861023,"fetchStart":245.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":245.2000002861023,"responseEnd":1658.7000002861023,"responseStart":1658.7000002861023,"secureConnectionStart":245.2000002861023},{"duration":138.60000038146973,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":951.0999999046326,"connectEnd":951.0999999046326,"connectStart":951.0999999046326,"domainLookupEnd":951.0999999046326,"domainLookupStart":951.0999999046326,"fetchStart":951.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":951.0999999046326,"responseEnd":1089.7000002861023,"responseStart":1089.7000002861023,"secureConnectionStart":951.0999999046326},{"duration":446.90000009536743,"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":1212.5,"connectEnd":1212.5,"connectStart":1212.5,"domainLookupEnd":1212.5,"domainLookupStart":1212.5,"fetchStart":1212.5,"redirectEnd":0,"redirectStart":0,"requestStart":1212.5,"responseEnd":1659.4000000953674,"responseStart":1659.4000000953674,"secureConnectionStart":1212.5}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":69,"responseStart":232,"responseEnd":242,"domLoading":236,"domInteractive":1676,"domContentLoadedEventStart":1676,"domContentLoadedEventEnd":1718,"domComplete":3088,"loadEventStart":3088,"loadEventEnd":3090,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1663.2000002861023},{"name":"bigPipe.sidebar-id.end","time":1664.0999999046326},{"name":"bigPipe.activity-panel-pipe-id.start","time":1664.2000002861023},{"name":"bigPipe.activity-panel-pipe-id.end","time":1666.5999999046326},{"name":"activityTabFullyLoaded","time":1725}],"measures":[],"correlationId":"59afc4e279ed59","effectiveType":"4g","downlink":9.2,"rtt":0,"serverDuration":97,"dbReadsTimeInMs":11,"dbConnsTimeInMs":20,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}