Changeset: b8401dc50b1f for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/b8401dc50b1f
Added Files:
        
sql/test/BugTracker-2026/Tests/8070-sum-constant-drops-groupby-aggregates.test
Modified Files:
        sql/server/rel_optimize_proj.c
        sql/test/BugTracker-2026/Tests/All
Branch: default
Log Message:

add fix for issue # 8070, continue loop rewriting constant aggregates (else we 
loose some of the expressions)


diffs (80 lines):

diff --git a/sql/server/rel_optimize_proj.c b/sql/server/rel_optimize_proj.c
--- a/sql/server/rel_optimize_proj.c
+++ b/sql/server/rel_optimize_proj.c
@@ -2783,7 +2783,7 @@ rel_remove_const_aggr(visitor *v, sql_re
                                                        (cnt && !wa->isnull)) {
                                                append(naggrs, e);
                                                append(nexps, exp_ref(v->sql, 
e));
-                                               break;
+                                               continue;
                                        }
                                        if (cnt)
                                                w=exp_atom_lng(v->sql->sa, 0);
diff --git 
a/sql/test/BugTracker-2026/Tests/8070-sum-constant-drops-groupby-aggregates.test
 
b/sql/test/BugTracker-2026/Tests/8070-sum-constant-drops-groupby-aggregates.test
new file mode 100644
--- /dev/null
+++ 
b/sql/test/BugTracker-2026/Tests/8070-sum-constant-drops-groupby-aggregates.test
@@ -0,0 +1,48 @@
+statement ok
+CREATE TABLE t8070 (grp INTEGER, x INTEGER)
+
+statement ok rowcount 3
+INSERT INTO t8070 VALUES (1, 10), (1, 20), (1, 30)
+
+# a non-foldable constant aggregate must not stop the rewrite of later 
aggregates
+query IIII nosort
+SELECT grp, SUM(2), MIN(1), SUM(x) FROM t8070 GROUP BY grp
+----
+1      6       1       60
+
+# without the group key
+query III nosort
+SELECT SUM(2), MIN(1), SUM(x) FROM t8070 GROUP BY grp
+----
+6      1       60
+
+# reordered projections still work
+query IIII nosort
+SELECT grp, SUM(x), MIN(1), SUM(2) FROM t8070 GROUP BY grp
+----
+1      60      1       6
+
+# several non-foldable constant aggregates followed by a real aggregate
+query IIII nosort
+SELECT grp, SUM(2), SUM(3), SUM(x) FROM t8070 GROUP BY grp
+----
+1      6       9       60
+
+# foldable constant aggregates mixed with non-foldable ones
+query IIII nosort
+SELECT grp, SUM(0), SUM(2), SUM(x) FROM t8070 GROUP BY grp
+----
+1      0       6       60
+
+query IIII nosort
+SELECT grp, COUNT(NULL), SUM(2), SUM(x) FROM t8070 GROUP BY grp
+----
+1      0       6       60
+
+query IIII nosort
+SELECT grp, SUM(2), PROD(1), SUM(x) FROM t8070 GROUP BY grp
+----
+1      6       1       60
+
+statement ok
+DROP TABLE t8070
diff --git a/sql/test/BugTracker-2026/Tests/All 
b/sql/test/BugTracker-2026/Tests/All
--- a/sql/test/BugTracker-2026/Tests/All
+++ b/sql/test/BugTracker-2026/Tests/All
@@ -219,9 +219,10 @@ KNOWNFAIL?8030-inner-join-group-by-bug
 8049-alter-add-column-default-dependencies
 8054-correlated-not-notequal
 8056-date-generator
+8057-drop-function-check-update
 8059-aggr-on-pipeline-local-string-col-causes-nulls
 8062-groupby-inet6
 8064-explain-show-details-pkey
 8065-unnamed-fkeys-same-column
 8061-session-authorization-current-user
-8057-drop-function-check-update
+8070-sum-constant-drops-groupby-aggregates
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to