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

User defined aggregate functions not working correctly when the schema is changed

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: In Review (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 10.3, 10.4
    • Fix Version/s: 10.3, 10.4
    • Component/s: Stored routines
    • Labels:
      None

      Description

      CREATE SCHEMA IF NOT EXISTS common_schema;
      DELIMITER $$
      DROP FUNCTION IF EXISTS common_schema.add_ints $$
      CREATE FUNCTION common_schema.add_ints(int_1 INT, int_2 INT) RETURNS INT NO SQL 
      BEGIN 
          RETURN int_1 + int_2; 
      END $$ 
      DROP FUNCTION IF EXISTS common_schema.sum_ints $$
      CREATE AGGREGATE FUNCTION common_schema.sum_ints(int_val INT) RETURNS INT 
      BEGIN 
          DECLARE result INT DEFAULT 0; 
          DECLARE CONTINUE HANDLER FOR NOT FOUND RETURN result; 
          LOOP FETCH GROUP NEXT ROW; 
              SET result = common_schema.add_ints(result, int_val); 
          END LOOP; 
      END $$
       
      DELIMITER ;
      

      MariaDB [test]> USE common_schema;
      Database changed
      MariaDB [common_schema]> SELECT common_schema.sum_ints(seq)
          -> FROM (SELECT 1 seq UNION ALL SELECT 2) t;
      +-----------------------------+
      | common_schema.sum_ints(seq) |
      +-----------------------------+
      |                           3 |
      +-----------------------------+
      1 row in set (0.009 sec)
      

      MariaDB [test]> USE another_schema;
      Database changed
      MariaDB [another_schema]> SELECT common_schema.sum_ints(seq) FROM (SELECT 1 seq UNION ALL SELECT 2) t;
      +-----------------------------+
      | common_schema.sum_ints(seq) |
      +-----------------------------+
      |                        NULL |
      +-----------------------------+
      1 row in set (0.028 sec)
      

      On changing the schema the custom aggregate function returns NULL , which is incorrect

        Attachments

          Activity

            People

            Assignee:
            cvicentiu Vicențiu Ciorbaru
            Reporter:
            varun Varun Gupta
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: