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

Custom aggregate functions work incorrectly with WITH ROLLUP clause

    XMLWordPrintable

Details

    • 10.3.6-1

    Description

      Note: The agg_sum function definition is taken as is from main.aggregate_functions test.

      --delimiter |
      create aggregate function agg_sum(x INT) returns INT
      begin
      declare z int default 0;
      declare continue handler for not found return z;
      loop
      fetch group next row;
      set z= z+x;
      end loop;
      end|
      --delimiter ;
       
      create table t1 (i int);
      insert into t1 values (1),(2),(2),(3);
      select i, agg_sum(i) from t1 group by i with rollup;
      --echo #
      --echo # Compare with
      select i, sum(i) from t1 group by i with rollup;
       
      # Cleanup
      drop function agg_sum;
      drop table t1;
      

      Actual result with agg_sum

      select i, agg_sum(i) from t1 group by i with rollup;
      i	agg_sum(i)
      1	1
      2	8
      3	6
      NULL	6
      

      Expected result with agg_sum, actual result with sum

      select i, sum(i) from t1 group by i with rollup;
      i	sum(i)
      1	1
      2	4
      3	3
      NULL	8
      

      Attachments

        Issue Links

          Activity

            People

              varun Varun Gupta (Inactive)
              elenst Elena Stepanova
              Votes:
              0 Vote for this issue
              Watchers:
              3 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.