Changeset: d93e6b8726d1 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/d93e6b8726d1
Modified Files:
        sql/server/rel_dump.c
        sql/server/rel_exp.c
        sql/server/rel_optimize_sel.c
        sql/server/rel_rel.c
        sql/server/rel_rel.h
        sql/server/rel_select.c
        sql/server/rel_unnest.c
Branch: resource_management
Log Message:

wip


diffs (196 lines):

diff --git a/sql/server/rel_dump.c b/sql/server/rel_dump.c
--- a/sql/server/rel_dump.c
+++ b/sql/server/rel_dump.c
@@ -120,7 +120,7 @@ exp_print(mvc *sql, stream *fout, sql_ex
        (void)sql;
        if (!e)
                return;
-       //mnstr_printf(fout, "%p ", e);
+       // mnstr_printf(fout, "%p ", e);
        if (mvc_debug_on(sql, 4) && e->alias.label < 0)
                mnstr_printf(fout, "%d: ", e->alias.label);
        switch(e->type) {
diff --git a/sql/server/rel_exp.c b/sql/server/rel_exp.c
--- a/sql/server/rel_exp.c
+++ b/sql/server/rel_exp.c
@@ -3940,12 +3940,22 @@ free_exp(allocator *sa, sql_exp *e)
                        }
                        break;
                case e_cmp:
-                       if (e->l)
-                               free_exp(sa, e->l);
-                       if (e->r)
-                               free_exp(sa, e->r);
-                       if (e->f)
-                               free_exp(sa, e->f);
+                       if (e->flag < cmp_filter) {
+                               // l and r are exp
+                               if (e->l)
+                                       free_exp(sa, e->l);
+                               if (e->r)
+                                       free_exp(sa, e->r);
+                               if (e->f)
+                                       free_exp(sa, e->f);
+                       }
+                       if (e->flag == cmp_or || e->flag == cmp_filter) {
+                               // l and r are list
+                               if (e->l)
+                                       free_exps_list(sa, e->l);
+                               if (e->r)
+                                       free_exps_list(sa, e->r);
+                       }
                        break;
                case e_func:
                case e_aggr:
diff --git a/sql/server/rel_optimize_sel.c b/sql/server/rel_optimize_sel.c
--- a/sql/server/rel_optimize_sel.c
+++ b/sql/server/rel_optimize_sel.c
@@ -3208,7 +3208,7 @@ rel_semijoin_use_fk(visitor *v, sql_rel 
 /*
  * Push {semi}joins down, pushes the joins through group by expressions.
  * When the join is on the group by columns, we can push the joins left
- * under the group by. This should only be done, iff the new semijoin would
+ * under the group by. This should only be done, if the new semijoin would
  * reduce the input table to the groupby. So there should be a reduction
  * (selection) on the table A and this should be propagated to the groupby via
  * for example a primary key.
@@ -3636,7 +3636,7 @@ rel_push_select_down(visitor *v, sql_rel
        /* merge 2 selects */
        r = rel->l;
        if (is_select(rel->op) && r && r->exps && is_select(r->op) && 
!(rel_is_ref(r)) && !exps_have_func(rel->exps)) {
-               (void)list_merge(r->exps, rel->exps, (fdup)NULL);
+               (void)list_merge(r->exps, exps_copy(v->sql, rel->exps), 
(fdup)NULL);
                rel->l = NULL;
                rel_destroy(v->sql, rel);
                v->changes++;
diff --git a/sql/server/rel_rel.c b/sql/server/rel_rel.c
--- a/sql/server/rel_rel.c
+++ b/sql/server/rel_rel.c
@@ -160,7 +160,7 @@ rel_destroy(mvc *sql, sql_rel *rel)
        if (!list_empty(rel->exps) && sql && (!rel->l) && (!rel->r)) {
                // perhaps separate allocator for exps
                // for later
-               // free_exps_list(sql->sa, rel->exps);
+               //free_exps_list(sql->sa, rel->exps);
                rel->exps = NULL;
        }
 }
@@ -290,7 +290,7 @@ rel_select_copy(allocator *sa, sql_rel *
        rel->l = l;
        rel->r = NULL;
        rel->op = op_select;
-       rel->exps = exps?list_dup(exps, (fdup)NULL):NULL;
+       rel->exps = exps? list_dup(exps, (fdup)NULL) : NULL;
        rel->card = CARD_ATOM; /* no relation */
        if (l) {
                rel->card = l->card;
@@ -1714,7 +1714,7 @@ rel_or(mvc *sql, sql_rel *rel, sql_rel *
        assert(!lexps || l == r);
        if (l == r && lexps) { /* merge both lists */
                sql_exp *e = exp_or(sql->sa, lexps, rexps, 0);
-               list *nl = oexps?oexps:new_exp_list(sql->sa);
+               list *nl = oexps? oexps : new_exp_list(sql->sa);
 
                rel_destroy(sql, r);
                append(nl, e);
@@ -1727,8 +1727,7 @@ rel_or(mvc *sql, sql_rel *rel, sql_rel *
        /* favor or expressions over union */
        if (l->op == r->op && is_select(l->op) &&
            ll == rl && ll == rel && !rel_is_ref(l) && !rel_is_ref(r)) {
-               // need a copy of r->exps, r will be destroyed
-               sql_exp *e = exp_or(sql->sa, l->exps, exps_copy(sql, r->exps), 
0);
+               sql_exp *e = exp_or(sql->sa, l->exps, r->exps, 0);
                list *nl = new_exp_list(sql->sa);
 
                rel_destroy(sql, r);
diff --git a/sql/server/rel_rel.h b/sql/server/rel_rel.h
--- a/sql/server/rel_rel.h
+++ b/sql/server/rel_rel.h
@@ -165,4 +165,14 @@ extern bool rel_rebind_exp(mvc *sql, sql
 
 extern int exp_freevar_offset(mvc *sql, sql_exp *e);
 
+#define SQL_REL_DESTROY(sql, rel_ptr)                  \
+       do {                                                                    
\
+               rel_destroy(sql, rel_ptr);                      \
+               if (rel_ptr->ref.refcnt == 0            \
+                               && rel_ptr->l == NULL           \
+                               && rel_ptr->r == NULL           \
+                               && rel_ptr->exps == NULL)       \
+                       rel_ptr = NULL;                                 \
+       } while (0)
+
 #endif /* _REL_REL_H_ */
diff --git a/sql/server/rel_select.c b/sql/server/rel_select.c
--- a/sql/server/rel_select.c
+++ b/sql/server/rel_select.c
@@ -1746,7 +1746,7 @@ rel_filter(mvc *sql, sql_rel *rel, list 
                        e = exp_check_type(sql, &a->type, rel, e, type_equal);
                        if (!e)
                                return NULL;
-                       list_append(nexps, e);
+                       list_append(nexps, exp_copy(sql, e));
                }
                l = nexps;
                nexps = sa_list(sql->sa);
@@ -1757,7 +1757,7 @@ rel_filter(mvc *sql, sql_rel *rel, list 
                        e = exp_check_type(sql, &a->type, rel, e, type_equal);
                        if (!e)
                                return NULL;
-                       list_append(nexps, e);
+                       list_append(nexps, exp_copy(sql, e));
                }
                r = nexps;
        }
@@ -5399,8 +5399,9 @@ group_merge_exps(mvc *sql, list *gexps, 
                }
                hash_add(ht, key, e);
                if (!duplicates) {
-                       list_append(gexps, e);
-                       n->data = exp_ref(sql, e);
+                       sql_exp *e_copy = exp_copy(sql, e);
+                       list_append(gexps, e_copy);
+                       n->data = exp_ref(sql, e_copy);
                }
        }
        return gexps;
@@ -5776,7 +5777,8 @@ rel_select_exp(sql_query *query, sql_rel
                 * obtained so far with the table expression, ie
                 * t1.* or a subquery.
                 */
-               pexps = list_merge(pexps, te, (fdup)NULL);
+               // ss:FIX implement fdup with sa
+               pexps = list_merge(pexps, exps_copy(sql, te), (fdup)NULL);
        }
        if (rel && is_groupby(rel->op) && rel->flag) {
                list *gbe = rel->r;
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
@@ -878,7 +878,7 @@ push_up_project(mvc *sql, sql_rel *rel, 
                                                } else {
                                                        if (!nexps)
                                                                nexps = 
sa_list(sql->sa);
-                                                       append(nexps, e);
+                                                       append(nexps, 
exp_copy(sql, e));
                                                }
                                        }
                                }
@@ -927,7 +927,7 @@ push_up_project(mvc *sql, sql_rel *rel, 
                                }
                                if (!list_empty(r->exps)) {
                                        for (m=r->exps->h; m; m = m->next) {
-                                               sql_exp *e = m->data;
+                                               sql_exp *e = exp_copy(sql, 
m->data);
 
                                                if (exp_has_freevar(sql, e))
                                                        rel_bind_var(sql, l, e);
@@ -4254,7 +4254,7 @@ flatten_values(visitor *v, sql_rel *rel)
                        nrel = rel_project(v->sql->sa, NULL, 
sa_list(v->sql->sa));
                        set_processed(nrel);
                        for(node *n = rel->exps->h; n; n = n->next) {
-                               sql_exp *e = n->data;
+                               sql_exp *e = exp_copy(v->sql, n->data);
                                list *vals = exp_get_values(e);
 
                                if (vals) {
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to