Changeset: 3fa382121669 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=3fa382121669
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:
Generalize dropping distinct property on aggregates on atoms on global
aggregates too
diffs (83 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
@@ -5969,9 +5969,9 @@ rel_groupby_distinct2(visitor *v, sql_re
static sql_rel *
rel_groupby_distinct(visitor *v, sql_rel *rel)
{
+ node *n;
+
if (is_groupby(rel->op) && !rel_is_ref(rel) && rel->exps &&
list_empty(rel->r)) {
- node *n;
-
for (n = rel->exps->h; n; n = n->next) {
sql_exp *e = n->data;
@@ -5983,13 +5983,21 @@ rel_groupby_distinct(visitor *v, sql_rel
}
}
+ /*if the input expressions are atoms, drop distinct property */
+ if (is_groupby(rel->op) && !list_empty(rel->exps)) {
+ for (n=rel->exps->h; n ; n = n->next) {
+ sql_exp *e = n->data;
+ if (e->type == e_aggr && need_distinct(e) && (!e->l ||
exps_are_atoms(e->l)))
+ set_nodistinct(e);
+ }
+ }
+
if (is_groupby(rel->op)) {
sql_rel *l = rel->l;
if (!l || is_groupby(l->op))
return rel;
}
if (is_groupby(rel->op) && rel->r && !rel_is_ref(rel)) {
- node *n;
int nr = 0;
list *gbe, *ngbe, *arg, *exps, *nexps;
sql_exp *distinct = NULL, *darg;
@@ -5998,12 +6006,8 @@ 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)) {
- if (e->type == e_aggr && (!e->l ||
exps_are_atoms(e->l))) {
- set_nodistinct(e);
- } else {
- distinct = n->data;
- nr++;
- }
+ distinct = n->data;
+ nr++;
}
}
if (nr < 1 || distinct->type != e_aggr)
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,8 @@ SELECT CAST(COUNT ( DISTINCT + CAST ( NU
-- 93
-- 93
-- 93
+select group_concat(distinct 'a') from tab0;
+ -- a,a,a
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
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
@@ -497,6 +497,14 @@ project (
[ 93 ]
[ 93 ]
[ 93 ]
+#select group_concat(distinct 'a') from tab0;
+% .%1 # table_name
+% %1 # name
+% clob # type
+% 5 # length
+[ "a,a,a" ]
+#INSERT INTO "tab0" VALUES (83, 0, 38), (26, 0, 79), (43, 81, 24);
+[ 3 ]
#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