Changeset: 842feff7722a for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=842feff7722a Modified Files: sql/server/rel_optimizer.c sql/server/rel_unnest.c Branch: Jun2020 Log Message:
Small fixes for rel_join2semijoin optimizer. Disallow rel_join2semijoin on selection relations, because upper projections may use the right side of the semijoin. Only e_columns are allowed as the single projection under the candidate join (e.g. aggregates may not be distinct). A better way to fix this would be adding an "unique" property under SQL expressions. Fixed grouping cardinalities at exp_reset_card. diffs (53 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 @@ -5452,11 +5452,14 @@ find_simple_projection_for_join2semi(sql if (rel->card < CARD_AGGR) /* const or groupby without group by exps */ return true; - if (e->card <= CARD_AGGR || find_prop(e->p, PROP_HASHCOL)) - return true; - sql_exp *found = rel_find_exp(rel->l, e); /* grouping column on inner relation */ - if (found && (found->card <= CARD_AGGR || find_prop(found->p, PROP_HASHCOL))) - return true; + /* a single group by column in the projection list from a group by relation is guaranteed to be unique, but not an aggregate */ + if (e->type == e_column) { + if (is_groupby(rel->op) || find_prop(e->p, PROP_HASHCOL)) + return true; + sql_exp *found = rel_find_exp(rel->l, e); /* grouping column on inner relation */ + if (found && ((found->type == e_column && found->card <= CARD_AGGR) || find_prop(found->p, PROP_HASHCOL))) + return true; + } } return false; } @@ -5524,7 +5527,7 @@ static sql_rel * rel_join2semijoin(mvc *sql, sql_rel *rel, int *changes) { (void)sql; - if ((is_simple_project(rel->op) || is_groupby(rel->op) || (is_select(rel->op) && !rel_is_ref(rel))) && rel->l) { + if ((is_simple_project(rel->op) || is_groupby(rel->op)) && rel->l) { bool swap = false; sql_rel *l = rel->l; sql_rel *c = find_candidate_join2semi(l, &swap); diff --git a/sql/server/rel_unnest.c b/sql/server/rel_unnest.c --- a/sql/server/rel_unnest.c +++ b/sql/server/rel_unnest.c @@ -1652,7 +1652,7 @@ exp_reset_card(mvc *sql, sql_rel *rel, s switch(e->type) { case e_aggr: case e_column: - e->card = CARD_AGGR; + e->card = rel->card; break; case e_func: case e_convert: @@ -1673,6 +1673,8 @@ exp_reset_card(mvc *sql, sql_rel *rel, s l = rel->l; if (e->card < l->card) e->card = l->card; + if (need_distinct(rel)) /* Need distinct, all expressions should have CARD_AGGR at max */ + e->card = MIN(e->card, CARD_AGGR); break; case e_aggr: /* should have been corrected by rewrites already */ case e_cmp: _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list