Changeset: a27adabe3689 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/a27adabe3689
Modified Files:
        monetdb5/optimizer/opt_prelude.c
        monetdb5/optimizer/opt_prelude.h
        sql/backends/monet5/rel_bin.c
        sql/backends/monet5/rel_bin.h
        sql/backends/monet5/sql_gencode.c
        sql/backends/monet5/sql_statement.c
        sql/backends/monet5/sql_statement.h
Branch: pushcands
Log Message:

Added rel_bin_stmt in code generation (not finished yet). By grouping statments 
into relations will allow further optimizations at this phase such as pushing 
candidates. Some tests don't run yet. More cleanup needed


diffs (truncated from 3827 to 300 lines):

diff --git a/monetdb5/optimizer/opt_prelude.c b/monetdb5/optimizer/opt_prelude.c
--- a/monetdb5/optimizer/opt_prelude.c
+++ b/monetdb5/optimizer/opt_prelude.c
@@ -235,7 +235,6 @@ const char *pyapi3mapRef;
 const char *pyapi3Ref;
 const char *querylogRef;
 const char *queryRef;
-const char *raiseRef;
 const char *rangejoinRef;
 const char *rankRef;
 const char *rapiRef;
@@ -545,7 +544,6 @@ void optimizerInit(void)
        pyapi3Ref = putName("pyapi3");
        querylogRef = putName("querylog");
        queryRef = putName("query");
-       raiseRef = putName("raise");
        rangejoinRef = putName("rangejoin");
        rankRef = putName("rank");
        rapiRef = putName("rapi");
diff --git a/monetdb5/optimizer/opt_prelude.h b/monetdb5/optimizer/opt_prelude.h
--- a/monetdb5/optimizer/opt_prelude.h
+++ b/monetdb5/optimizer/opt_prelude.h
@@ -234,7 +234,6 @@ mal_export  const char *pyapi3mapRef;
 mal_export  const char *pyapi3Ref;
 mal_export  const char *querylogRef;
 mal_export  const char *queryRef;
-mal_export  const char *raiseRef;
 mal_export  const char *rangejoinRef;
 mal_export  const char *rankRef;
 mal_export  const char *rapiRef;
diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -26,9 +26,9 @@
 
 #define OUTER_ZERO 64
 
-static stmt * exp_bin(backend *be, sql_exp *e, stmt *left, stmt *right, stmt 
*grp, stmt *ext, stmt *cnt, stmt *sel, int depth, int reduce, int push);
-static stmt * rel_bin(backend *be, sql_rel *rel);
-static stmt * subrel_bin(backend *be, sql_rel *rel, list *refs);
+static stmt * exp_bin(backend *be, sql_exp *e, rel_bin_stmt *left, 
rel_bin_stmt *right, int depth, int reduce, int push);
+static rel_bin_stmt * rel_bin(backend *be, sql_rel *rel);
+static rel_bin_stmt * subrel_bin(backend *be, sql_rel *rel, list *refs);
 
 static stmt *check_types(backend *be, sql_subtype *fromtype, stmt *s, 
check_type tpe);
 
@@ -85,14 +85,12 @@ sql_unop_(backend *be, const char *fname
        return NULL;
 }
 
-static stmt *
+static rel_bin_stmt *
 refs_find_rel(list *refs, sql_rel *rel)
 {
-       node *n;
-
-       for(n=refs->h; n; n = n->next->next) {
+       for(node *n=refs->h; n; n = n->next->next) {
                sql_rel *ref = n->data;
-               stmt *s = n->next->data;
+               rel_bin_stmt *s = n->next->data;
 
                if (rel == ref)
                        return s;
@@ -101,11 +99,9 @@ refs_find_rel(list *refs, sql_rel *rel)
 }
 
 static void
-refs_update_stmt(list *refs, sql_rel *rel, stmt *s)
+refs_update_stmt(list *refs, sql_rel *rel, rel_bin_stmt *s)
 {
-       node *n;
-
-       for(n=refs->h; n; n = n->next->next) {
+       for(node *n=refs->h; n; n = n->next->next) {
                sql_rel *ref = n->data;
 
                if (rel == ref) {
@@ -115,13 +111,11 @@ refs_update_stmt(list *refs, sql_rel *re
        }
 }
 
-
 static void
-print_stmtlist(sql_allocator *sa, stmt *l)
+print_stmtlist(sql_allocator *sa, rel_bin_stmt *l)
 {
-       node *n;
        if (l) {
-               for (n = l->op4.lval->h; n; n = n->next) {
+               for (node *n = l->cols->h; n; n = n->next) {
                        const char *rnme = table_name(sa, n->data);
                        const char *nme = column_name(sa, n->data);
 
@@ -130,6 +124,14 @@ print_stmtlist(sql_allocator *sa, stmt *
        }
 }
 
+static int
+stmt_key(stmt *s)
+{
+       const char *nme = column_name(NULL, s);
+
+       return hash_key(nme);
+}
+
 static stmt *
 list_find_column(backend *be, list *l, const char *rname, const char *name )
 {
@@ -213,26 +215,9 @@ list_find_column(backend *be, list *l, c
 }
 
 static stmt *
-bin_find_column( backend *be, stmt *sub, const char *rname, const char *name )
-{
-       return list_find_column( be, sub->op4.lval, rname, name);
-}
-
-static list *
-bin_find_columns( backend *be, stmt *sub, const char *name )
+bin_find_column( backend *be, rel_bin_stmt *st, const char *rname, const char 
*name )
 {
-       node *n;
-       list *l = sa_list(be->mvc->sa);
-
-       for (n = sub->op4.lval->h; n; n = n->next) {
-               const char *nme = column_name(be->mvc->sa, n->data);
-
-               if (strcmp(nme, name) == 0)
-                       append(l, n->data);
-       }
-       if (list_length(l))
-               return l;
-       return NULL;
+       return list_find_column( be, st->cols, rname, name);
 }
 
 static stmt *column(backend *be, stmt *val )
@@ -293,12 +278,12 @@ statment_score(stmt *c)
 }
 
 static stmt *
-bin_find_smallest_column(backend *be, stmt *sub)
+bin_find_smallest_column(backend *be, rel_bin_stmt *st)
 {
        stmt *res = NULL;
        int best_score = 0;
 
-       for (node *n = sub->op4.lval->h ; n ; n = n->next) {
+       for (node *n = st->cols->h ; n ; n = n->next) {
                stmt *c = n->data;
                int next_score = statment_score(c);
 
@@ -312,14 +297,14 @@ bin_find_smallest_column(backend *be, st
        return res;
 }
 
-static stmt *
-row2cols(backend *be, stmt *sub)
+static rel_bin_stmt *
+row2cols(backend *be, rel_bin_stmt *sub)
 {
        if (sub->nrcols == 0 && sub->key) {
                node *n;
                list *l = sa_list(be->mvc->sa);
 
-               for (n = sub->op4.lval->h; n; n = n->next) {
+               for (n = sub->cols->h; n; n = n->next) {
                        stmt *sc = n->data;
                        const char *cname = column_name(be->mvc->sa, sc);
                        const char *tname = table_name(be->mvc->sa, sc);
@@ -327,13 +312,14 @@ row2cols(backend *be, stmt *sub)
                        sc = column(be, sc);
                        list_append(l, stmt_alias(be, sc, tname, cname));
                }
-               sub = stmt_list(be, l);
+               sub->cols = l;
+               stmt_set_nrcols(sub);
        }
        return sub;
 }
 
 static stmt*
-distinct_value_list(backend *be, list *vals, stmt ** last_null_value)
+distinct_value_list(backend *be, list *vals, stmt **last_null_value)
 {
        list *l = sa_list(be->mvc->sa);
        stmt *s;
@@ -341,7 +327,7 @@ distinct_value_list(backend *be, list *v
        /* create bat append values */
        for (node *n = vals->h; n; n = n->next) {
                sql_exp *e = n->data;
-               stmt *i = exp_bin(be, e, NULL, NULL, NULL, NULL, NULL, NULL, 0, 
0, 0);
+               stmt *i = exp_bin(be, e, NULL, NULL, 0, 0, 0);
 
                if (exp_is_null(e))
                        *last_null_value = i;
@@ -372,25 +358,24 @@ stmt_selectnonil( backend *be, stmt *col
 static int
 is_tid_chain(stmt *cand)
 {
-       while(cand && cand->type != st_tid && cand->cand) {
+       while (cand && cand->type != st_tid && cand->cand)
                cand = cand->cand;
-       }
        if (cand && cand->type == st_tid)
                return 1;
        return 0;
 }
 
-static stmt *
-subrel_project( backend *be, stmt *s, list *refs, sql_rel *rel)
+static rel_bin_stmt *
+subrel_project( backend *be, rel_bin_stmt *s, list *refs, sql_rel *rel)
 {
-       if (!s || s->type != st_list || !s->cand)
+       if (!s || !s->cand)
                return s;
 
        list *l = sa_list(be->mvc->sa);
        stmt *cand = s->cand;
        if (!l)
                return NULL;
-       for(node *n = s->op4.lval->h; n; n = n->next) {
+       for(node *n = s->cols->h; n; n = n->next) {
                stmt *c = n->data;
 
                assert(c->type == st_alias || (c->type == st_join && c->flag == 
cmp_project) || c->type == st_bat || c->type == st_idxbat || c->type == 
st_single);
@@ -408,18 +393,19 @@ subrel_project( backend *be, stmt *s, li
                }
                append(l, c);
        }
-       s = stmt_list(be, l);
+       s->cols = l;
+       stmt_set_nrcols(s);
        if (rel && rel_is_ref(rel))
                refs_update_stmt(refs, rel, s);
        return s;
 }
 
 static stmt *
-handle_in_exps(backend *be, sql_exp *ce, list *nl, stmt *left, stmt *right, 
stmt *grp, stmt *ext, stmt *cnt, stmt *sel, bool in, int use_r, int depth, int 
reduce)
+handle_in_exps(backend *be, sql_exp *ce, list *nl, rel_bin_stmt *left, 
rel_bin_stmt *right, bool in, int use_r, int depth, int reduce)
 {
        mvc *sql = be->mvc;
        node *n;
-       stmt *s = NULL, *c = exp_bin(be, ce, left, right, grp, ext, cnt, NULL, 
0, 0, 0);
+       stmt *s = NULL, *c = exp_bin(be, ce, left, right, 0, 0, 0);
 
        if(!c)
                return NULL;
@@ -437,7 +423,7 @@ handle_in_exps(backend *be, sql_exp *ce,
 
                for( n = nl->h; n; n = n->next) {
                        sql_exp *e = n->data;
-                       stmt *i = exp_bin(be, use_r?e->r:e, left, right, grp, 
ext, cnt, NULL, 0, 0, 0);
+                       stmt *i = exp_bin(be, use_r?e->r:e, left, right, 0, 0, 
0);
                        if(!i)
                                return NULL;
 
@@ -447,23 +433,23 @@ handle_in_exps(backend *be, sql_exp *ce,
                        else
                                s = i;
                }
-               if (sel && !(depth || !reduce))
+               if (left && left->cand && !(depth || !reduce))
                        s = stmt_uselect(be,
                                stmt_const(be, bin_find_smallest_column(be, 
left), s),
-                               stmt_bool(be, 1), cmp_equal, sel, 0, 0);
+                               stmt_bool(be, 1), cmp_equal, left->cand, 0, 0);
        } else if (list_length(nl) < 16) {
                comp_type cmp = (in)?cmp_equal:cmp_notequal;
 
                if (!in)
-                       s = sel;
+                       s = left ? left->cand : NULL;
                for( n = nl->h; n; n = n->next) {
                        sql_exp *e = n->data;
-                       stmt *i = exp_bin(be, use_r?e->r:e, left, right, grp, 
ext, cnt, NULL, 0, 0, 0);
+                       stmt *i = exp_bin(be, use_r?e->r:e, left, right, 0, 0, 
0);
                        if(!i)
                                return NULL;
 
                        if (in) {
-                               i = stmt_uselect(be, c, i, cmp, sel, 0, 0);
+                               i = stmt_uselect(be, c, i, cmp, left ? 
left->cand : NULL, 0, 0);
                                if (s)
                                        s = stmt_tunion(be, s, i);
                                else
@@ -490,7 +476,7 @@ handle_in_exps(backend *be, sql_exp *ce,
                }
 
                if (in) {
-                       s = stmt_semijoin(be, c, s, sel, NULL, 0, false);
+                       s = stmt_semijoin(be, c, s, left ? left->cand : NULL, 
NULL, 0, false);
                } else {
                        if (last_null_value) {
                                /* CORNER CASE ALERT:
@@ -507,7 +493,7 @@ handle_in_exps(backend *be, sql_exp *ce,
                                /* BACK TO HAPPY FLOW:
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to