Changeset: 93d6c5bdeaa0 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/93d6c5bdeaa0 Modified Files: sql/server/rel_distribute.c sql/server/rel_optimizer.c sql/server/rel_statistics.c Branch: properties Log Message:
Better solution. Run remote/replica rewriters before statistics diffs (86 lines): diff --git a/sql/server/rel_distribute.c b/sql/server/rel_distribute.c --- a/sql/server/rel_distribute.c +++ b/sql/server/rel_distribute.c @@ -10,7 +10,6 @@ #include "rel_optimizer_private.h" #include "rel_basetable.h" #include "rel_exp.h" -#include "rel_rewriter.h" #include "sql_privileges.h" static int @@ -69,7 +68,6 @@ rewrite_replica(mvc *sql, list *exps, sq node *n, *m; sql_rel *r = rel_basetable(sql, p, t->base.name); int allowed = 1; - sqlstore *store = sql->session->tr->store; if (!table_privs(sql, p, PRIV_SELECT)) /* Test for privileges */ allowed = 0; @@ -100,8 +98,6 @@ rewrite_replica(mvc *sql, list *exps, sq exp_prop_alias(sql->sa, ne, e); } list_hash_clear(r->exps); /* the child table may have different column names, so clear the hash */ - if (isTable(p) && p->s && !isDeclaredTable(p)) /* count active rows only */ - set_count_prop(sql->sa, r, (BUN)store->storage_api.count_col(sql->session->tr, ol_first_node(p->columns)->data, 10)); /* set_remote() */ if (remote_prop && p && isRemote(p)) { @@ -376,7 +372,6 @@ rel_remote_func_(visitor *v, sql_rel *re if (find_prop(rel->p, PROP_REMOTE) != NULL) { list *exps = rel_projections(v->sql, rel, NULL, 1, 1); rel = rel_relational_func(v->sql->sa, rel, exps); - set_count_prop(v->sql->sa, rel, get_rel_count(rel->l)); } return rel; } 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 @@ -656,14 +656,14 @@ const sql_optimizer pre_sql_optimizers[] /* these optimizers/rewriters only run once after the cycle loop */ const sql_optimizer post_sql_optimizers[] = { {22, "setjoins_2_joingroupby", bind_setjoins_2_joingroupby}, - {23, "get_statistics", bind_get_statistics}, /* gather statistics */ - {24, "join_order2", bind_join_order2}, /* run join order one more time with statistics */ - {25, "final_optimization_loop", bind_final_optimization_loop}, /* run select and group by order with statistics gathered */ /* Merge table rewrites may introduce remote or replica tables */ - /* At the moment, make sure the remote table rewriters always run last */ - {26, "rewrite_remote", bind_rewrite_remote}, - {27, "rewrite_replica", bind_rewrite_replica}, - {28, "remote_func", bind_remote_func}, + /* At the moment, make sure the remote table rewriters always run after the merge table one */ + {23, "rewrite_remote", bind_rewrite_remote}, + {24, "rewrite_replica", bind_rewrite_replica}, + {25, "remote_func", bind_remote_func}, + {26, "get_statistics", bind_get_statistics}, /* gather statistics */ + {27, "join_order2", bind_join_order2}, /* run join order one more time with statistics */ + {28, "final_optimization_loop", bind_final_optimization_loop}, /* run select and group by order with statistics gathered */ { 0, NULL, NULL} /* If an optimizer is going to be added, don't forget to update NSQLREWRITERS macro */ }; diff --git a/sql/server/rel_statistics.c b/sql/server/rel_statistics.c --- a/sql/server/rel_statistics.c +++ b/sql/server/rel_statistics.c @@ -679,7 +679,7 @@ rel_get_statistics_(visitor *v, sql_rel for (node *n = rel->exps->h ; n ; n = n->next) rel_basetable_column_get_statistics(v->sql, rel, n->data); } - /* Set table row count. TODO? look for remote/replica tables. Don't look at storage for declared tables, because it won't be cleaned */ + /* Set table row count. TODO? look for remote tables. Don't look at storage for declared tables, because it won't be cleaned */ if (isTable(t) && t->s && !isDeclaredTable(t)) /* count active rows only */ set_count_prop(v->sql->sa, rel, (BUN)store->storage_api.count_col(v->sql->session->tr, ol_first_node(t->columns)->data, 10)); } break; @@ -692,10 +692,10 @@ rel_get_statistics_(visitor *v, sql_rel while (is_sample(pl->op) || is_topn(pl->op)) /* skip topN and sample relations in the middle */ pl = pl->l; - while (is_sample(r->op) || is_topn(pr->op)) + while (is_sample(pr->op) || is_topn(pr->op)) pr = pr->l; /* if it's not a projection, then project and propagate statistics */ - if (!is_project(pl->op) && !is_base(l->op)) { + if (!is_project(pl->op) && !is_base(pl->op)) { pl = rel_project(v->sql->sa, pl, rel_projections(v->sql, pl, NULL, 0, 1)); set_count_prop(v->sql->sa, pl, get_rel_count(pl->l)); pl->exps = exps_exp_visitor_bottomup(v, pl, pl->exps, 0, &rel_propagate_statistics, false); _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org