Changeset: fb6bc35c16a9 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/fb6bc35c16a9 Modified Files: sql/test/rel-optimizers/Tests/merge-unions.test Branch: default Log Message:
Merge with Aug2024 branch. diffs (78 lines): diff --git a/sql/backends/monet5/sql_statement.c b/sql/backends/monet5/sql_statement.c --- a/sql/backends/monet5/sql_statement.c +++ b/sql/backends/monet5/sql_statement.c @@ -4639,6 +4639,8 @@ stmt_has_null(stmt *s) case st_uselect2: case st_atom: return 0; + case st_alias: + return stmt_has_null(s->op1); case st_join: return stmt_has_null(s->op2); case st_bat: 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 @@ -3440,18 +3440,26 @@ rel_push_project_down_union(visitor *v, static inline sql_rel * rel_merge_unions(visitor *v, sql_rel *rel) { - (void)v; + /* stacked munion flattening e.g. + * munion( munion(a, b, c), munion(d, e)) => munion(a,b,c,d,e) + */ if (rel && is_munion(rel->op)) { list *l = rel->l; for(node *n = l->h; n; ) { node *next = n->next; - sql_rel *i = n->data; - if (is_munion(i->op)) { - i = rel_dup(i); + sql_rel *oc = n->data; + sql_rel *c = oc; + + /* acount for any group-bys pushed down between stacked munions */ + if (oc->op == op_groupby) + c = oc->l; + + if (is_munion(c->op)) { + c = rel_dup(c); list_remove_node(l, NULL, n); - l = list_merge(l, i->l, (fdup)NULL); - i->l = NULL; - rel_destroy(i); + l = list_merge(l, c->l, (fdup)NULL); + c->l = NULL; + rel_destroy(oc); if (!next) next = l->h; v->changes++; diff --git a/sql/test/rel-optimizers/Tests/merge-unions.test b/sql/test/rel-optimizers/Tests/merge-unions.test --- a/sql/test/rel-optimizers/Tests/merge-unions.test +++ b/sql/test/rel-optimizers/Tests/merge-unions.test @@ -257,3 +257,25 @@ 2 5 1 +query T nosort +plan select n, count(n) from f_merge_rec group by n +---- +project ( +| group by ( +| | munion ( +| | | group by ( +| | | | table("sys"."f1") [ "f1"."n" UNIQUE as "f_merge_rec"."n" ] +| | | ) [ "f_merge_rec"."n" UNIQUE ] [ "f_merge_rec"."n" UNIQUE, "sys"."count" no nil ("f_merge_rec"."n" UNIQUE) NOT NULL as "%1"."%1" ], +| | | group by ( +| | | | table("sys"."f2") [ "f2"."n" UNIQUE as "f_merge_rec"."n" ] +| | | ) [ "f_merge_rec"."n" UNIQUE ] [ "f_merge_rec"."n" UNIQUE, "sys"."count" no nil ("f_merge_rec"."n" UNIQUE) NOT NULL as "%1"."%1" ], +| | | group by ( +| | | | table("sys"."f3") [ "f3"."n" UNIQUE as "f_merge_rec"."n" ] +| | | ) [ "f_merge_rec"."n" UNIQUE ] [ "f_merge_rec"."n" UNIQUE, "sys"."count" no nil ("f_merge_rec"."n" UNIQUE) NOT NULL as "%1"."%1" ], +| | | group by ( +| | | | table("sys"."f4") [ "f4"."n" UNIQUE as "f_merge_rec"."n" ] +| | | ) [ "f_merge_rec"."n" UNIQUE ] [ "f_merge_rec"."n" UNIQUE, "sys"."count" no nil ("f_merge_rec"."n" UNIQUE) NOT NULL as "%1"."%1" ] +| | ) [ "f_merge_rec"."n", "%1"."%1" NOT NULL ] +| ) [ "f_merge_rec"."n" ] [ "f_merge_rec"."n", "sys"."sum" no nil ("%1"."%1" NOT NULL) NOT NULL as "%1"."%1" ] +) [ "f_merge_rec"."n" UNIQUE, "%1"."%1" NOT NULL ] + _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org