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

Move the projection of constants on candidate lists later. More reviewing 
neeeded


diffs (truncated from 1139 to 300 lines):

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
@@ -56,7 +56,7 @@ static stmt *
 stmt_selectnil( backend *be, stmt *col)
 {
        sql_subtype *t = tail_type(col);
-       stmt *n = stmt_atom(be, atom_general(be->mvc->sa, t, NULL), NULL);
+       stmt *n = stmt_atom(be, atom_general(be->mvc->sa, t, NULL));
        stmt *nn = stmt_uselect2(be, col, n, n, 3, NULL, 0, 1);
        return nn;
 }
@@ -296,22 +296,17 @@ bin_find_smallest_column(backend *be, re
        stmt *res = NULL;
        int best_score = 0;
 
-       if (st->cand) { /* prioritize the candidate list */
-               res = st->cand;
-       } else {
-               for (node *n = st->cols->h ; n ; n = n->next) {
-                       stmt *c = n->data;
-                       int next_score = statment_score(c);
-
-                       if (next_score >= best_score) {
-                               res = c;
-                               best_score = next_score;
-                       }
+       for (node *n = st->cols->h ; n ; n = n->next) {
+               stmt *c = n->data;
+               int next_score = statment_score(c);
+
+               if (next_score >= best_score) {
+                       res = c;
+                       best_score = next_score;
                }
-               if (res->nrcols == 0)
-                       res = const_column(be, res);
-       }
-       res->cand = st->cand;
+       }
+       if (res->nrcols == 0)
+               res = const_column(be, res);
        return res;
 }
 
@@ -368,7 +363,7 @@ static stmt *
 stmt_selectnonil( backend *be, stmt *col, stmt *s )
 {
        sql_subtype *t = tail_type(col);
-       stmt *n = stmt_atom(be, atom_general(be->mvc->sa, t, NULL), NULL);
+       stmt *n = stmt_atom(be, atom_general(be->mvc->sa, t, NULL));
        stmt *nn = stmt_uselect2(be, col, n, n, 3, s, 1, 1);
        return nn;
 }
@@ -410,7 +405,7 @@ handle_in_exps(backend *be, sql_exp *ce,
        }
 
        if (reduce && c->nrcols == 0)
-               c = stmt_const(be, bin_find_smallest_column(be, left), c);
+               c = stmt_const(be, bin_find_smallest_column(be, left), lcand, 
c);
 
        if (c->nrcols == 0 || depth || !reduce) {
                sql_subtype *bt = sql_bind_localtype("bit");
@@ -438,8 +433,8 @@ handle_in_exps(backend *be, sql_exp *ce,
                }
                if (lcand && !(depth || !reduce))
                        s = stmt_uselect(be,
-                               stmt_const(be, bin_find_smallest_column(be, 
left), s),
-                               stmt_bool(be, 1, lcand), cmp_equal, lcand, 0, 
0);
+                               stmt_const(be, bin_find_smallest_column(be, 
left), lcand, s),
+                               stmt_bool(be, 1), cmp_equal, NULL, 0, 0);
        } else if (list_length(nl) < 16) {
                comp_type cmp = (in)?cmp_equal:cmp_notequal;
 
@@ -609,11 +604,11 @@ exp_bin_or(backend *be, sql_exp *e, rel_
                } else if (sel1 && (sel1->nrcols == 0 || s->nrcols == 0)) {
                        stmt *predicate = bin_find_smallest_column(be, left);
 
-                       predicate = stmt_const(be, predicate, stmt_bool(be, 1, 
predicate->cand));
+                       predicate = stmt_const(be, predicate, s->nrcols == 0 ? 
sel1 : s, stmt_bool(be, 1));
                        if (s->nrcols == 0)
-                               s = stmt_uselect(be, predicate, s, cmp_equal, 
sel1, anti, is_semantics(c));
+                               s = stmt_uselect(be, predicate, s, cmp_equal, 
NULL, anti, is_semantics(c));
                        else
-                               s = stmt_uselect(be, predicate, sel1, 
cmp_equal, s, anti, is_semantics(c));
+                               s = stmt_uselect(be, predicate, sel1, 
cmp_equal, NULL, anti, is_semantics(c));
                }
                sel1 = s;
        }
@@ -643,31 +638,31 @@ exp_bin_or(backend *be, sql_exp *e, rel_
                } else if (sel2 && (sel2->nrcols == 0 || s->nrcols == 0)) {
                        stmt *predicate = bin_find_smallest_column(be, left);
 
-                       predicate = stmt_const(be, predicate, stmt_bool(be, 1, 
predicate->cand));
+                       predicate = stmt_const(be, predicate, s->nrcols == 0 ? 
sel2 : s, stmt_bool(be, 1));
                        if (s->nrcols == 0)
-                               s = stmt_uselect(be, predicate, s, cmp_equal, 
sel2, anti, 0);
+                               s = stmt_uselect(be, predicate, s, cmp_equal, 
NULL, anti, 0);
                        else
-                               s = stmt_uselect(be, predicate, sel2, 
cmp_equal, s, anti, 0);
+                               s = stmt_uselect(be, predicate, sel2, 
cmp_equal, NULL, anti, 0);
                }
                sel2 = s;
        }
-       if (left)
-               left->cand = ocand;
        if (sel1->nrcols == 0 && sel2->nrcols == 0) {
                sql_subfunc *f = sql_bind_func(be->mvc, "sys", anti?"and":"or", 
bt, bt, F_FUNC);
                assert(f);
+               if (left)
+                       left->cand = ocand;
                return stmt_binop(be, sel1, sel2, NULL, f);
        }
        if (sel1->nrcols == 0) {
                stmt *predicate = bin_find_smallest_column(be, left);
 
-               predicate = stmt_const(be, predicate, stmt_bool(be, 1, 
predicate->cand));
+               predicate = stmt_const(be, predicate, NULL, stmt_bool(be, 1));
                sel1 = stmt_uselect(be, predicate, sel1, cmp_equal, NULL, 
0/*anti*/, 0);
        }
        if (sel2->nrcols == 0) {
                stmt *predicate = bin_find_smallest_column(be, left);
 
-               predicate = stmt_const(be, predicate, stmt_bool(be, 1, 
predicate->cand));
+               predicate = stmt_const(be, predicate, NULL, stmt_bool(be, 1));
                sel2 = stmt_uselect(be, predicate, sel2, cmp_equal, NULL, 
0/*anti*/, 0);
        }
        if (anti) {
@@ -676,6 +671,8 @@ exp_bin_or(backend *be, sql_exp *e, rel_
                s = stmt_tunion(be, sel1, sel2);
        }
        s->cand = ocand;
+       if (left)
+               left->cand = ocand;
        return s;
 }
 
@@ -693,7 +690,7 @@ exp2bin_case(backend *be, sql_exp *fe, r
        if (single_value) {
                /* var_x = nil; */
                nme = number2name(name, sizeof(name), ++be->mvc->label);
-               (void)stmt_var(be, NULL, nme, exp_subtype(fe), 1, 2, NULL);
+               (void)stmt_var(be, NULL, nme, exp_subtype(fe), 1, 2);
        }
 
        list *exps = fe->l;
@@ -730,14 +727,14 @@ exp2bin_case(backend *be, sql_exp *fe, r
                                stmt *l = isel;
                                if (!l)
                                        l = bin_find_smallest_column(be, left);
-                               res = stmt_const(be, l, stmt_atom(be, 
atom_general(be->mvc->sa, exp_subtype(fe), NULL), isel));
+                               res = stmt_const(be, l, NULL, stmt_atom(be, 
atom_general(be->mvc->sa, exp_subtype(fe), NULL)));
                                ires = l;
                        } else if (res && !next_cond) { /* use result too 
update column */
                                stmt *val = es;
                                stmt *pos = rsel;
 
                                if (val->nrcols == 0)
-                                       val = stmt_const(be, pos, val);
+                                       val = stmt_const(be, pos, NULL, val);
                                else if (!val->cand && nsel)
                                        val = stmt_project(be, nsel, val);
                                res = stmt_replace(be, res, pos, val);
@@ -756,19 +753,19 @@ exp2bin_case(backend *be, sql_exp *fe, r
                                ncond = cond = es;
                                if (!ncond->nrcols) {
                                        if (osel) {
-                                               ncond = stmt_const(be, nsel, 
ncond);
+                                               ncond = stmt_const(be, nsel, 
NULL, ncond);
                                                ncond->cand = nsel;
                                        } else if (isel) {
-                                               ncond = stmt_const(be, isel, 
ncond);
+                                               ncond = stmt_const(be, isel, 
NULL, ncond);
                                                ncond->cand = isel;
                                        } else
-                                               ncond = stmt_const(be, 
bin_find_smallest_column(be, left), ncond);
+                                               ncond = stmt_const(be, 
bin_find_smallest_column(be, left), NULL, ncond);
                                }
                                if (isel && !ncond->cand) {
                                        ncond = stmt_project(be, nsel, ncond);
                                        ncond->cand = nsel;
                                }
-                               stmt *s = stmt_uselect(be, ncond, stmt_bool(be, 
1, !ncond->cand?rsel:NULL), cmp_equal, !ncond->cand?rsel:NULL, 0/*anti*/, 0);
+                               stmt *s = stmt_uselect(be, ncond, stmt_bool(be, 
1), cmp_equal, !ncond->cand?rsel:NULL, 0/*anti*/, 0);
                                if (rsel && ncond->cand)
                                        rsel = stmt_project(be, s, rsel);
                                else
@@ -815,7 +812,7 @@ exp2bin_case(backend *be, sql_exp *fe, r
        if (left)
                left->cand = isel;
        if (single_value)
-               res = stmt_var(be, NULL, nme, exp_subtype(fe), 0, 2, isel);
+               res = stmt_var(be, NULL, nme, exp_subtype(fe), 0, 2);
        res->cand = isel;
        return res;
 }
@@ -835,7 +832,7 @@ exp2bin_casewhen(backend *be, sql_exp *f
        if (single_value) {
                /* var_x = nil; */
                nme = number2name(name, sizeof(name), ++be->mvc->label);
-               (void)stmt_var(be, NULL, nme, exp_subtype(fe), 1, 2, NULL);
+               (void)stmt_var(be, NULL, nme, exp_subtype(fe), 1, 2);
        }
 
        list *exps = fe->l;
@@ -852,7 +849,7 @@ exp2bin_casewhen(backend *be, sql_exp *f
                stmt *l = isel;
                if (!l)
                        l = bin_find_smallest_column(be, left);
-               case_when = stmt_const(be, l, case_when);
+               case_when = stmt_const(be, l, NULL, case_when);
                if (case_when)
                        case_when->cand = isel;
        }
@@ -918,14 +915,14 @@ exp2bin_casewhen(backend *be, sql_exp *f
                                stmt *l = isel;
                                if (!l)
                                        l = bin_find_smallest_column(be, left);
-                               res = stmt_const(be, l, stmt_atom(be, 
atom_general(be->mvc->sa, exp_subtype(fe), NULL), isel));
+                               res = stmt_const(be, l, NULL, stmt_atom(be, 
atom_general(be->mvc->sa, exp_subtype(fe), NULL)));
                                ires = l;
                        } else if (res && !next_cond) { /* use result too 
update column */
                                stmt *val = es;
                                stmt *pos = rsel;
 
                                if (val->nrcols == 0)
-                                       val = stmt_const(be, pos, val);
+                                       val = stmt_const(be, pos, NULL, val);
                                else if (!val->cand && nsel)
                                        val = stmt_project(be, nsel, val);
                                res = stmt_replace(be, res, pos, val);
@@ -944,17 +941,17 @@ exp2bin_casewhen(backend *be, sql_exp *f
                                ncond = cond = es;
                                if (!ncond->nrcols) {
                                        if (osel) {
-                                               ncond = stmt_const(be, nsel, 
ncond);
+                                               ncond = stmt_const(be, nsel, 
NULL, ncond);
                                                ncond->cand = nsel;
                                        } else if (isel) {
-                                               ncond = stmt_const(be, isel, 
ncond);
+                                               ncond = stmt_const(be, isel, 
NULL, ncond);
                                                ncond->cand = isel;
                                        } else
-                                               ncond = stmt_const(be, 
bin_find_smallest_column(be, left), ncond);
+                                               ncond = stmt_const(be, 
bin_find_smallest_column(be, left), NULL, ncond);
                                }
                                if (isel && !ncond->cand)
                                        ncond = stmt_project(be, nsel, ncond);
-                               stmt *s = stmt_uselect(be, ncond, stmt_bool(be, 
1, !ncond->cand?rsel:NULL), cmp_equal, !ncond->cand?rsel:NULL, 0/*anti*/, 0);
+                               stmt *s = stmt_uselect(be, ncond, stmt_bool(be, 
1), cmp_equal, !ncond->cand?rsel:NULL, 0/*anti*/, 0);
                                if (rsel && ncond->cand)
                                        rsel = stmt_project(be, s, rsel);
                                else
@@ -1001,7 +998,7 @@ exp2bin_casewhen(backend *be, sql_exp *f
        if (left)
                left->cand = isel;
        if (single_value)
-               res = stmt_var(be, NULL, nme, exp_subtype(fe), 0, 2, isel);
+               res = stmt_var(be, NULL, nme, exp_subtype(fe), 0, 2);
        res->cand = isel;
        return res;
 }
@@ -1019,7 +1016,7 @@ exp2bin_coalesce(backend *be, sql_exp *f
        if (single_value) {
                /* var_x = nil; */
                nme = number2name(name, sizeof(name), ++be->mvc->label);
-               (void)stmt_var(be, NULL, nme, exp_subtype(fe), 1, 2, NULL);
+               (void)stmt_var(be, NULL, nme, exp_subtype(fe), 1, 2);
        }
 
        list *exps = fe->l;
@@ -1049,7 +1046,7 @@ exp2bin_coalesce(backend *be, sql_exp *f
                                stmt *l = isel;
                                if (!l)
                                        l = bin_find_smallest_column(be, left);
-                               res = stmt_const(be, l, stmt_atom(be, 
atom_general(be->mvc->sa, exp_subtype(fe), NULL), isel));
+                               res = stmt_const(be, l, NULL, stmt_atom(be, 
atom_general(be->mvc->sa, exp_subtype(fe), NULL)));
                        }
                        if (res) {
                                stmt *val = es;
@@ -1062,12 +1059,12 @@ exp2bin_coalesce(backend *be, sql_exp *f
                                                stmt *l = 
bin_find_smallest_column(be, left);
                                                if (nsel && l)
                                                        l = stmt_project(be, 
nsel, l);
-                                               ncond = stmt_const(be, l, 
ncond);
+                                               ncond = stmt_const(be, l, NULL, 
ncond);
                                                if (nsel)
                                                        ncond->cand = nsel;
                                        } else if (!ncond->cand && nsel)
                                                ncond = stmt_project(be, nsel, 
ncond);
-                                       stmt *s = stmt_uselect(be, ncond, 
stmt_bool(be, 1, ncond), cmp_equal, NULL, 0/*anti*/, 0);
+                                       stmt *s = stmt_uselect(be, ncond, 
stmt_bool(be, 1), cmp_equal, NULL, 0/*anti*/, 0);
                                        if (!val->cand && nsel)
                                                val = stmt_project(be, nsel, 
val);
                                        val = stmt_project(be, s, val);
@@ -1079,14 +1076,14 @@ exp2bin_coalesce(backend *be, sql_exp *f
                                        val->cand = pos;
                                }
                                if (val->nrcols == 0)
-                                       val = stmt_const(be, pos, val);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to