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

    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

        Issue Links

          Activity

            People

              varun Varun Gupta (Inactive)
              varun Varun Gupta (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.