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

[PATCH] UDF aggregate functions with WITH ROLLUP wrong results

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 5.1.67, 5.5.40, 10.0.15
    • Fix Version/s: 10.0, 5.5
    • Component/s: OTHER
    • Labels:

      Description

      upstream: http://bugs.mysql.com/bug.php?id=38297

      CREATE AGGREGATE FUNCTION avgcost
              RETURNS REAL SONAME "udf_example.so";
      create table t1(sum int, price float(24), g int);
      insert into t1 values(100, 50.00, 1), (100, 100.00, 1);
      insert into t1 values(10, 2.00, 2), (100, 100.00, 2);
      
      MariaDB [test]> select avgcost(sum, price) from t1 where g=1;
      +---------------------+
      | avgcost(sum, price) |
      +---------------------+
      |             75.0000 |
      +---------------------+
      1 row in set (0.06 sec)
      
      MariaDB [test]> select avgcost(sum, price) from t1 where g=2;
      +---------------------+
      | avgcost(sum, price) |
      +---------------------+
      |             91.0909 |
      +---------------------+
      1 row in set (0.00 sec)
      
      MariaDB [test]> select avgcost(sum, price) from t1;
      +---------------------+
      | avgcost(sum, price) |
      +---------------------+
      |             80.7097 |
      +---------------------+
      1 row in set (0.00 sec)
      
      MariaDB [test]> select avgcost(sum, price) from t1 group by g;
      +---------------------+
      | avgcost(sum, price) |
      +---------------------+
      |             75.0000 |
      |             91.0909 |
      +---------------------+
      
      MariaDB [test]> select avgcost(sum, price) from t1 group by g with rollup;
      +---------------------+
      | avgcost(sum, price) |
      +---------------------+
      |             83.3333 |
      |             91.0909 |
      |             91.0909 |
      +---------------------+
      

      The ROLLUP structure is copied however the UDF init function isn't called meaning the initid->ptr is use for an aggregation and the rollup calculation at the same time.

      Patch based on upstream submission. Added test case but its not got the correct result yet.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

              There are no comments yet on this issue.

                People

                • Assignee:
                  serg Sergei Golubchik
                  Reporter:
                  danblack Daniel Black
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  2 Start watching this issue

                  Dates

                  • Created:
                    Updated: