Changeset: b30c8109881a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=b30c8109881a
Modified Files:
sql/server/rel_optimizer.c
sql/test/miscellaneous/Tests/groupby_error.sql
sql/test/miscellaneous/Tests/groupby_error.stable.out
Branch: Oct2020
Log Message:
If the input arguments to an aggregate are atoms, then no distinct
transformation is needed. Also found a new crash with distinct aggregates with
more than 1 argument
diffs (57 lines):
diff --git a/sql/server/rel_optimizer.c b/sql/server/rel_optimizer.c
--- a/sql/server/rel_optimizer.c
+++ b/sql/server/rel_optimizer.c
@@ -5998,13 +5998,17 @@ rel_groupby_distinct(visitor *v, sql_rel
for (n=rel->exps->h; n && nr <= 2; n = n->next) {
sql_exp *e = n->data;
if (need_distinct(e)) {
- distinct = n->data;
- nr++;
+ if (e->type == e_aggr && (!e->l ||
exps_are_atoms(e->l))) {
+ set_nodistinct(e);
+ } else {
+ distinct = n->data;
+ nr++;
+ }
}
}
if (nr < 1 || distinct->type != e_aggr)
return rel;
- if ((nr > 1 || list_length(rel->r) + nr !=
list_length(rel->exps)))
+ if (nr > 1 || list_length(rel->r) + nr !=
list_length(rel->exps))
return rel;//rel_groupby_distinct2(v, rel);
arg = distinct->l;
if (list_length(arg) != 1 || list_length(rel->r) + nr !=
list_length(rel->exps))
diff --git a/sql/test/miscellaneous/Tests/groupby_error.sql
b/sql/test/miscellaneous/Tests/groupby_error.sql
--- a/sql/test/miscellaneous/Tests/groupby_error.sql
+++ b/sql/test/miscellaneous/Tests/groupby_error.sql
@@ -192,6 +192,11 @@ SELECT CAST(COUNT ( DISTINCT + CAST ( NU
-- 93
-- 93
-- 93
+INSERT INTO "tab0" VALUES (83, 0, 38), (26, 0, 79), (43, 81, 24);
+select group_concat(distinct col1, col2) from tab0 group by col0;
+ -- 0
+ -- 81
+ -- 0
ROLLBACK;
START TRANSACTION;
diff --git a/sql/test/miscellaneous/Tests/groupby_error.stable.out
b/sql/test/miscellaneous/Tests/groupby_error.stable.out
--- a/sql/test/miscellaneous/Tests/groupby_error.stable.out
+++ b/sql/test/miscellaneous/Tests/groupby_error.stable.out
@@ -489,6 +489,14 @@ project (
#CREATE TABLE "tab0" ("col0" INTEGER,"col1" INTEGER,"col2" INTEGER);
#INSERT INTO "tab0" VALUES (83, 0, 38), (26, 0, 79), (43, 81, 24);
[ 3 ]
+#SELECT CAST(COUNT ( DISTINCT + CAST ( NULL AS INTEGER ) ) + 93 as BIGINT) AS
col2 FROM tab0 GROUP BY col0 HAVING NOT ( COUNT ( * ) ) = 94 / COUNT ( * );
+% . # table_name
+% col2 # name
+% bigint # type
+% 2 # length
+[ 93 ]
+[ 93 ]
+[ 93 ]
#ROLLBACK;
#START TRANSACTION;
#CREATE TABLE tab2 ("col0" INTEGER,"col1" INTEGER,"col2" INTEGER);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list