Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-14987

Memory leak when max or min column function used within user defined function

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 10.2.6
    • Fix Version/s: 10.2.7
    • Component/s: Stored routines
    • Labels:
      None
    • Environment:
      Windows 64 bit. MyISAM

      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';
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              David Crimmins David Crimmins
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Git Integration