[MDEV-7357] [PATCH] UDF aggregate functions with WITH ROLLUP wrong results Created: 2014-12-21  Updated: 2022-11-29

Status: Open
Project: MariaDB Server
Component/s: OTHER
Affects Version/s: 5.1.67, 5.5.40, 10.0.15, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9
Fix Version/s: 5.5, 10.3

Type: Bug Priority: Minor
Reporter: Daniel Black Assignee: Sergei Golubchik
Resolution: Unresolved Votes: 0
Labels: upstream

Attachments: File udf-rollup.patch    

 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.


Generated at Thu Feb 08 07:18:58 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.