Changeset: 045469a1c3b8 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/045469a1c3b8
Modified Files:
        sql/server/rel_optimize_proj.c
Branch: default
Log Message:

make sure we push down conversions introduced by the split select optimizer.


diffs (66 lines):

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
@@ -42,6 +42,19 @@ rel_used_projections(mvc *sql, list *exp
        return nexps;
 }
 
+static bool
+exp_is_useless_rename_or_convert(sql_exp *e)
+{
+       if (e->type == e_column && e->alias.label == e->nid)
+               return true;
+       if (e->type == e_convert && has_label(e) && e->card > CARD_ATOM) {
+               sql_exp *l = e->l;
+               if (l && l->type == e_column)
+                       return true;
+       }
+       return false;
+}
+
 /* move projects down with the goal of removing them completely (ie push 
renames/reduced lists into basetable)
  * for some cases we can directly remove if renames rename into same alias
  * */
@@ -66,6 +79,42 @@ rel_push_project_down_(visitor *v, sql_r
        }
 
        if (v->depth > 1 && is_simple_project(rel->op) && !need_distinct(rel) 
&& !rel_is_ref(rel) && rel->l && !rel->r &&
+                       is_join(l->op) && list_empty(l->attr) && !rel_is_ref(l) 
&&
+                       v->parent && (is_select(v->parent->op) || 
is_join(v->parent->op)) &&
+                       list_check_prop_all(rel->exps, 
(prop_check_func)&exp_is_useless_rename_or_convert)) {
+
+                       /* push converts down */
+                       for (node *n = rel->exps->h; n; n = n->next) {
+                               sql_exp *e = n->data;
+                               if (e->type == e_convert) {
+                                       sql_rel *j = l, *p = rel;
+                                       while(is_join(j->op) && 
list_empty(l->attr)) {
+                                               if (rel_has_exp(j->l, e->l, 
false) == 0) {
+                                                       p = j;
+                                                       j = j->l;
+                                               } else if (rel_has_exp(j->r, 
e->l, false) == 0) {
+                                                       p = j;
+                                                       j = j->r;
+                                               }
+                                               break;
+                                       }
+                                       if (j && j != l) {
+                                               sql_rel *np = 
rel_project(v->sql->sa, j, rel_projections(v->sql, j, NULL, 0, 1));
+                                               rel_project_add_exp(v->sql, np, 
exp_copy(v->sql, e));
+                                               if (p->l == j)
+                                                       p->l = np;
+                                               else if (p->r == j)
+                                                       p->r = np;
+                                       }
+                               }
+                       }
+                       rel->l = NULL;
+                       rel_destroy(v->sql, rel);
+                       v->changes++;
+                       return l;
+       }
+
+       if (v->depth > 1 && is_simple_project(rel->op) && !need_distinct(rel) 
&& !rel_is_ref(rel) && rel->l && !rel->r &&
                        v->parent &&
                        !is_modify(v->parent->op) && !is_topn(v->parent->op) && 
!is_sample(v->parent->op) &&
                        !is_ddl(v->parent->op) && !is_set(v->parent->op) && 
!is_munion(v->parent->op) &&
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to