[MDEV-14987] Memory leak when max or min column function used within user defined function Created: 2018-01-18  Updated: 2018-01-18  Resolved: 2018-01-18

Status: Closed
Project: MariaDB Server
Component/s: Stored routines
Affects Version/s: 10.2.6
Fix Version/s: 10.2.7

Type: Bug Priority: Major
Reporter: David Crimmins Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None
Environment:

Windows 64 bit. MyISAM


Issue Links:
Duplicate
duplicates MDEV-12992 MariaDB 10.2.6 leaks memory while exe... Closed

 Description   

Significant memory usage when using min or max function within a user defined function. Several gb can be consumed in a few seconds. Droping the function or closing the client connection releases the memory.

Attached is a example. In reality our function is much more complicated.

I get an error when attempting to add an attachment so here is the sql:

CREATE DATABASE IF NOT EXISTS sample;
 
USE sample;
 
DROP TABLE IF EXISTS sample_data;
 
CREATE TABLE IF NOT EXISTS sample_data (
  id int(10) unsigned
) ENGINE=MyISAM;
 
DROP FUNCTION IF EXISTS udf_example;
 
DELIMITER $$
 
CREATE FUNCTION udf_example (cnt INT(10) UNSIGNED) RETURNS int(10) unsigned
BEGIN
  DECLARE i, j INT UNSIGNED DEFAULT 0;
  
  WHILE i < cnt
  DO 
    SELECT max(id) FROM sample_data
    INTO j;
    SET i = i + 1;
  END WHILE;
       
  
  RETURN cnt;
  
END
$$
 
DELIMITER ;

SHOW GLOBAL STATUS LIKE 'Memory_used';
SELECT udf_example(10000);
SHOW GLOBAL STATUS LIKE 'Memory_used';
SELECT udf_example(10000);
SHOW GLOBAL STATUS LIKE 'Memory_used';
SELECT udf_example(10000);
SHOW GLOBAL STATUS LIKE 'Memory_used';
 
DROP FUNCTION IF EXISTS udf_example;
SHOW GLOBAL STATUS LIKE 'Memory_used';



 Comments   
Comment by Elena Stepanova [ 2018-01-18 ]

Thanks for the report and the test case. The problem was fixed in 10.2.7 release, in scope of MDEV-12992. Please upgrade your server to the latest 10.2 version.

Generated at Thu Feb 08 08:17:50 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.