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

Custom aggregate functions work incorrectly with WITH ROLLUP clause

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

            elenst Elena Stepanova created issue -
            elenst Elena Stepanova made changes -
            Field Original Value New Value
            elenst Elena Stepanova made changes -
            Description _Note: The {{agg_sum}} function definition is taken as is from main.aggregate_functions test

            {code:sql}
            --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;
            {code}

            {noformat:title=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
            {noformat}
            {noformat:title=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
            {noformat}
            _Note: The {{agg_sum}} function definition is taken as is from main.aggregate_functions test._

            {code:sql}
            --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;
            {code}

            {noformat:title=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
            {noformat}
            {noformat:title=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
            {noformat}
            varun Varun Gupta (Inactive) made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            varun Varun Gupta (Inactive) made changes -
            Assignee Varun Gupta [ varun ] Vicentiu Ciorbaru [ cvicentiu ]
            Status In Progress [ 3 ] In Review [ 10002 ]
            serg Sergei Golubchik made changes -
            Sprint 10.3.6-0 [ 237 ]
            serg Sergei Golubchik made changes -
            Priority Major [ 3 ] Critical [ 2 ]
            serg Sergei Golubchik made changes -
            Affects Version/s 10.3 [ 22126 ]
            Affects Version/s N/A [ 14700 ]
            cvicentiu Vicențiu Ciorbaru made changes -
            Status In Review [ 10002 ] Stalled [ 10000 ]
            cvicentiu Vicențiu Ciorbaru made changes -
            Assignee Vicentiu Ciorbaru [ cvicentiu ] Varun Gupta [ varun ]
            varun Varun Gupta (Inactive) made changes -
            Fix Version/s 10.3.7 [ 23005 ]
            Fix Version/s 10.3 [ 22126 ]
            Resolution Fixed [ 1 ]
            Status Stalled [ 10000 ] Closed [ 6 ]
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 84128 ] MariaDB v4 [ 153256 ]

            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.