Changeset: d2ead1ca8f95 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d2ead1ca8f95
Modified Files:
sql/backends/monet5/rel_bin.c
sql/backends/monet5/sql_statement.c
sql/backends/monet5/sql_statement.h
Branch: batcalc-updated
Log Message:
handle pushing down the candidates and correct the use of the new bit column
for conditional execution
diffs (216 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
@@ -592,6 +592,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l
if (!l)
return NULL;
s = stmt_convert(be, l, from, to, NULL);
+ s->cand = l->cand;
} break;
case e_func: {
node *en;
@@ -599,6 +600,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l
sql_subfunc *f = e->f;
stmt *rows = NULL, *cond_execution = NULL;
char name[16], *nme = NULL;
+ int nrcands = 0, push_cands = 0;
if (f->func->side_effect && left) {
if (!exps || list_empty(exps))
@@ -613,11 +615,15 @@ exp_bin(backend *be, sql_exp *e, stmt *l
assert(!e->r);
if (exps) {
int nrcols = 0;
+
+ if (sel && strcmp(sql_func_mod(f->func), "calc") == 0
&& strcmp(sql_func_imp(f->func), "ifthenelse") != 0)
+ push_cands = 1;
+
for (en = exps->h; en; en = en->next) {
sql_exp *e = en->data;
stmt *es;
- es = exp_bin(be, e, left, right, grp, ext, cnt,
sel);
+ es = exp_bin(be, e, left, right, grp, ext, cnt,
(push_cands)?sel:NULL);
if (!es)
return NULL;
@@ -633,6 +639,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l
}
/* last argument is condition, change into
candidate list */
if (f->func->type != F_ANALYTIC && !en->next &&
!f->func->varres && !f->func->vararg && list_length(exps) >
list_length(f->func->ops)) {
+ /* optional bit column for applying the
function only on the selected rows */
if (es->nrcols) {
if (!nrcols) {
node *n;
@@ -645,7 +652,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l
l = nl;
}
- es = stmt_uselect(be, es,
stmt_bool(be,1), cmp_equal, NULL, 0);
+ //es = stmt_uselect(be, es,
stmt_bool(be,1), cmp_equal, NULL, 0);
} else /* need a condition */
cond_execution = es;
}
@@ -653,9 +660,23 @@ exp_bin(backend *be, sql_exp *e, stmt *l
nrcols = es->nrcols;
if (!cond_execution)
list_append(l,es);
+ if (push_cands && es->nrcols)
+ nrcands++;
}
- if (sel && strcmp(sql_func_mod(f->func), "calc") == 0
&& nrcols && strcmp(sql_func_imp(f->func), "ifthenelse") != 0)
- list_append(l,sel);
+ //if (sel && strcmp(sql_func_mod(f->func), "calc") == 0
&& nrcols && strcmp(sql_func_imp(f->func), "ifthenelse") != 0) {
+ if (push_cands) {
+ if (strcmp(sql_func_imp(f->func), "and") != 0
&& strcmp(sql_func_imp(f->func), "or") != 0) {
+ int i;
+ for (i=0, en = l->h; i<nrcands && en;
i++, en = en->next) {
+ stmt *s = en->data;
+ /* if handled use bat nil */
+ if (s->cand)
+ list_append(l, NULL);
+ else
+ list_append(l,sel);
+ }
+ }
+ }
}
if (cond_execution) {
/* var_x = nil; */
@@ -670,6 +691,8 @@ exp_bin(backend *be, sql_exp *e, stmt *l
s = stmt_Nop(be, stmt_list(be, l), e->f);
if (!s)
return NULL;
+ if (s && sel && push_cands)
+ s->cand = sel;
if (cond_execution) {
/* var_x = s */
(void)stmt_assign(be, nme, s, 2);
diff --git a/sql/backends/monet5/sql_statement.c
b/sql/backends/monet5/sql_statement.c
--- a/sql/backends/monet5/sql_statement.c
+++ b/sql/backends/monet5/sql_statement.c
@@ -230,6 +230,7 @@ stmt_create(sql_allocator *sa, st_type t
s->nr = 0;
s->partition = 0;
s->tname = s->cname = NULL;
+ s->cand = NULL;
return s;
}
@@ -1396,6 +1397,7 @@ stmt_genselect(backend *be, stmt *lops,
s->nrcols = (lops->nrcols == 2) ? 2 : 1;
s->nr = getDestVar(q);
s->q = q;
+ s->cand = sub;
return s;
}
return NULL;
@@ -1407,6 +1409,7 @@ stmt_uselect(backend *be, stmt *op1, stm
MalBlkPtr mb = be->mb;
InstrPtr q = NULL;
int l, r;
+ stmt *sel = sub;
if (op1->nr < 0 || op2->nr < 0 || (sub && sub->nr < 0))
return NULL;
@@ -1447,6 +1450,16 @@ stmt_uselect(backend *be, stmt *op1, stm
if ((q = multiplex2(mb, mod, convertOperator(op), l, r,
TYPE_bit)) == NULL)
return NULL;
+ if (sub && (op1->cand || op2->cand)) {
+ if (op1->cand && !op2->cand) {
+ q = pushNil(mb, q, TYPE_bat);
+ q = pushArgument(mb, q, sub->nr);
+ } else if (!op1->cand && op2->cand) {
+ q = pushArgument(mb, q, sub->nr);
+ q = pushNil(mb, q, TYPE_bat);
+ }
+ sub = NULL;
+ }
if (cmptype == cmp_equal_nil)
q = pushBit(mb, q, TRUE);
k = getDestVar(q);
@@ -1468,7 +1481,7 @@ stmt_uselect(backend *be, stmt *op1, stm
if (cmptype == cmp_equal_nil) {
q = newStmt(mb, algebraRef, selectRef);
q = pushArgument(mb, q, l);
- if (sub)
+ if (sub && !op1->cand)
q = pushArgument(mb, q, sub->nr);
q = pushArgument(mb, q, r);
q = pushArgument(mb, q, r);
@@ -1478,8 +1491,10 @@ stmt_uselect(backend *be, stmt *op1, stm
} else {
q = newStmt(mb, algebraRef, thetaselectRef);
q = pushArgument(mb, q, l);
- if (sub)
+ if (sub && !op1->cand)
q = pushArgument(mb, q, sub->nr);
+ else
+ sub = NULL;
q = pushArgument(mb, q, r);
switch (cmptype) {
case mark_in:
@@ -1526,6 +1541,9 @@ stmt_uselect(backend *be, stmt *op1, stm
s->nrcols = (op1->nrcols == 2) ? 2 : 1;
s->nr = getDestVar(q);
s->q = q;
+ s->cand = sub;
+ if (!sub && sel) /* project back the old ids */
+ return stmt_project(be, s, sel);
return s;
}
return NULL;
@@ -1734,6 +1752,7 @@ stmt_uselect2(backend *be, stmt *op1, st
s->nrcols = (op1->nrcols == 2) ? 2 : 1;
s->nr = getDestVar(q);
s->q = q;
+ s->cand = sub;
return s;
}
return NULL;
@@ -2889,6 +2908,7 @@ stmt_convert(backend *be, stmt *v, sql_s
s->op4.typeval = *t;
s->nr = getDestVar(q);
s->q = q;
+ s->cand = sel;
return s;
}
return NULL;
@@ -2927,7 +2947,7 @@ stmt_Nop(backend *be, stmt *ops, sql_sub
for (n = ops->op4.lval->h, o = n->data; n; n = n->next) {
stmt *c = n->data;
- if (o->nrcols < c->nrcols)
+ if (c && o->nrcols < c->nrcols)
o = c;
}
}
@@ -2992,8 +3012,11 @@ stmt_Nop(backend *be, stmt *ops, sql_sub
for (n = ops->op4.lval->h; n; n = n->next) {
stmt *op = n->data;
- q = pushArgument(mb, q, op->nr);
- if (special) {
+ if (!op)
+ q = pushNil(mb, q, TYPE_bat);
+ else
+ q = pushArgument(mb, q, op->nr);
+ if (op && special) {
q = pushInt(mb, q, tpe->digits);
setVarUDFtype(mb, getArg(q, q->argc-1));
q = pushInt(mb, q, tpe->scale);
diff --git a/sql/backends/monet5/sql_statement.h
b/sql/backends/monet5/sql_statement.h
--- a/sql/backends/monet5/sql_statement.h
+++ b/sql/backends/monet5/sql_statement.h
@@ -115,8 +115,9 @@ typedef struct stmt {
char aggr; /* aggregated */
char partition; /* selected as mitosis candidate */
+ struct stmt *cand; /* optional candidate list */
+
int flag;
-
int nr; /* variable assignment */
const char *tname;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list