Changeset: 8a38f46f50f0 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/8a38f46f50f0
Modified Files:
        sql/server/rel_dump.c
        sql/server/rel_optimize_sel.c
Branch: cmp-or-patterns
Log Message:

Handling multicol single list cmp_eq exp WIP


diffs (109 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
@@ -638,7 +638,7 @@ rel_print_rel(mvc *sql, stream  *fout, s
                }
                if (rel->op == op_groupby)  /* group by columns */
                        exps_print(sql, fout, rel->r, depth, refs, 1, 0, 
decorate, 0);
-               exps_print(sql, fout, rel->exps, depth, refs, 1, 0, decorate, 
0);
+               exps_print(sql, fout, rel->exps, depth, refs, 1, 0, decorate, 
(mvc_debug_on(sql, 32768) && rel->op == op_select)?1:0);
                if (rel->r && rel->op == op_project) /* order by columns */
                        exps_print(sql, fout, rel->r, depth, refs, 1, 0, 
decorate, 0);
                break;
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
@@ -531,6 +531,7 @@ typedef struct exp_eq_atoms {
 
 typedef struct exp_eq_multi_cols_atoms {
        char *cs; /* col(rname, name) concat str */
+       list *first;
        list *ces; /* list of col exps */
        list *gvs; /* list of lists of atoms */
 } mca;
@@ -552,6 +553,7 @@ detect_multivalue_cmp_eqs(mvc *sql, list
                bool eq_only = true;
                list *l = n->data;
 
+               // TODO: remove this we already have what we want in cmp_eq
                /* check if this list has only cmp_eq with a column lhs and an 
atom rhs */
                for (node *m = l->h; m && eq_only; m = m->next) {
                        sql_exp *se = m->data;
@@ -598,12 +600,20 @@ detect_multivalue_cmp_eqs(mvc *sql, list
                     for (node *m = sl->h; m; m = m->next)
                         atms = append(atms, ((sql_exp*)m->data)->r);
                                        mcas->gvs = append(mcas->gvs, atms);
+                                       /* remove this and the previous 
occurrence (which means that's the first time
+                                        * that we found the *same* multi 
cmp_eq exp)
+                                        */
+                                       if (mcas->first)
+                                               list_remove_data(ceq_ands, 
NULL, mcas->first);
+                                       list_remove_data(ceq_ands, NULL, sl);
                                }
                        }
 
                        if (!found) {
                                mca *mcas = SA_NEW(sql->sa, mca);
                                mcas->cs = cs;
+                               // TODO: explain!!
+                               mcas->first = sl;
                                mcas->ces = sa_list(sql->sa);
                                for (node *m = sl->h; m; m = m->next)
                                        mcas->ces = append(mcas->ces, 
((sql_exp*)m->data)->l);
@@ -746,7 +756,7 @@ merge_ors_NEW(mvc *sql, list *exps, int 
 
                        if (mas) {
                                /* from multivalue cmp_eq atoms in the hash 
generate
-                                * "(col1, col2, ...) in [(val10, val20, ...), 
(val11, val21, ...)]"
+                                * "(col1, col2, ...) in [(val10, val20, ...), 
(val11, val21, ...), ... ]"
                                 * see detect_multivalue_cmp_eqs()
                                 */
                                mins = new_exp_list(sql->sa);
@@ -754,13 +764,12 @@ merge_ors_NEW(mvc *sql, list *exps, int 
                                        sql_hash_e *he = meqh->buckets[i];
                                        while (he) {
                                                mca *mcas = he->value;
+                                               /* NOTE: multivalue cmp_eq 
expressions with a single entry are still in ceq_ands */
                                                if (list_length(mcas->gvs) > 1) 
{
                                                        sql_exp *mc = 
exp_label(sql->sa, exp_values(sql->sa, mcas->ces), ++sql->label);
                                                        for (node *a = 
mcas->gvs->h; a; a = a->next)
                                                                a->data = 
exp_values(sql->sa, a->data);
                                                        mins = append(mins, 
exp_in(sql->sa, mc, mcas->gvs, cmp_in));
-                                               } else {
-                                                       /* TODO */
                                                }
                                                he = he->chain;
                                        }
@@ -781,7 +790,7 @@ merge_ors_NEW(mvc *sql, list *exps, int 
                        }
 
                        if (mins) {
-                               for (node *i = ((!ins) ? mins->h->next : 
mins->h); i; i = i->next) {
+                               for (node *i = ((ins) ? mins->h : 
mins->h->next); i; i = i->next) {
                                        list *l = new_exp_list(sql->sa);
                                        list *r = new_exp_list(sql->sa);
                                        l = append(l, new);
@@ -790,6 +799,14 @@ merge_ors_NEW(mvc *sql, list *exps, int 
                                }
                        }
 
+                       if (list_length(ceq_ands)) {
+                               for (node *i = ceq_ands->h; i; i = i->next) {
+                                       list *l = new_exp_list(sql->sa);
+                                       l = append(l, new);
+                                       new = exp_or(sql->sa, l, i->data, 0);
+                               }
+                       }
+
                        for (node *a = gen_ands->h; a; a = a->next){
                                list *l = new_exp_list(sql->sa);
                                l = append(l, new);
@@ -806,6 +823,8 @@ merge_ors_NEW(mvc *sql, list *exps, int 
 
                        list_remove_node(exps, NULL, n);
                        exps = append(exps, new);
+
+                       // TODO: should that be per col/multicol group?
                        (*changes)++;
                }
        }
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to