Changeset: c990d96ff45b for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c990d96ff45b Modified Files: sql/server/rel_optimizer.c Branch: default Log Message:
rel_push_count_down optimizer can join the other group by optimizers diffs (61 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 @@ -1593,17 +1593,13 @@ rel_push_func_down(visitor *v, sql_rel * * ) [ sql_mul(.., .. NOT NULL) ] * ) */ -static sql_rel * +static inline sql_rel * rel_push_count_down(visitor *v, sql_rel *rel) { - sql_rel *r; - - if (!is_groupby(rel->op)) - return rel; - - r = rel->l; - - if (is_groupby(rel->op) && !rel_is_ref(rel) && list_empty(rel->r) && + sql_rel *r = rel->l; + + assert(is_groupby(rel->op)); + if (!rel_is_ref(rel) && list_empty(rel->r) && r && !r->exps && r->op == op_join && !(rel_is_ref(r)) && /* currently only single count aggregation is handled, no other projects or aggregation */ list_length(rel->exps) == 1 && exp_aggr_is_count(rel->exps->h->data)) { @@ -6183,6 +6179,7 @@ rel_optimize_group_by(visitor *v, sql_re rel = rel_groupby_order(v, rel); rel = rel_reduce_groupby_exps(v, rel); rel = rel_groupby_distinct(v, rel); + rel = rel_push_count_down(v, rel); return rel; } @@ -9754,21 +9751,12 @@ optimize_rel(mvc *sql, sql_rel *rel, int rel = rel_visitor_bottomup(&v, rel, &rel_join_push_exps_down); } + /* push_join_down introduces semijoins */ + /* rewrite semijoin (A, join(A,B)) into semijoin (A,B) */ + if (level <= 0 && gp.cnt[op_groupby] && (gp.cnt[op_join] || gp.cnt[op_semi] || gp.cnt[op_anti] || gp.cnt[op_left])) + rel = rel_visitor_topdown(&v, rel, &rel_push_join_down); + /* Important -> Re-write semijoins after rel_join_order */ - if ((gp.cnt[op_join] || gp.cnt[op_semi] || gp.cnt[op_anti] || gp.cnt[op_left] || gp.cnt[op_right]) && gp.cnt[op_groupby]) { - if (gp.cnt[op_join]) - rel = rel_visitor_topdown(&v, rel, &rel_push_count_down); - if (level <= 0) { - if (gp.cnt[op_select]) - rel = rel_visitor_topdown(&v, rel, &rel_push_select_down); - if (gp.cnt[op_join] || gp.cnt[op_semi] || gp.cnt[op_anti] || gp.cnt[op_left]) { - /* push_join_down introduces semijoins */ - /* rewrite semijoin (A, join(A,B)) into semijoin (A,B) */ - rel = rel_visitor_topdown(&v, rel, &rel_push_join_down); /* rel_rewrite_semijoin will run in the next iteration */ - } - } - } - if (gp.cnt[op_anti] || gp.cnt[op_semi]) { rel = rel_visitor_bottomup(&v, rel, &rel_optimize_semi_and_anti); if (level <= 0) _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list