Changeset: c70d4b7de4d1 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/c70d4b7de4d1
Modified Files:
monetdb5/modules/atoms/uuid.c
monetdb5/modules/kernel/batmmath.c
monetdb5/modules/kernel/mmath.c
sql/backends/monet5/rel_bin.c
sql/backends/monet5/sql_statement.c
sql/backends/monet5/sql_statement.h
Branch: pushcands
Log Message:
Pushing candidate lists further down on projections. More cleanup and testing
needed. After that I can propagate it to other relations
diffs (truncated from 2455 to 300 lines):
diff --git a/monetdb5/modules/atoms/uuid.c b/monetdb5/modules/atoms/uuid.c
--- a/monetdb5/modules/atoms/uuid.c
+++ b/monetdb5/modules/atoms/uuid.c
@@ -66,7 +66,7 @@ UUIDgenerateUuid(uuid *retval)
}
static str
-UUIDgenerateUuidInt(uuid *retval, int *d)
+UUIDgenerateUuidInt(uuid *retval, void *d)
{
(void)d;
return UUIDgenerateUuid(retval);
@@ -421,8 +421,8 @@ bailout:
#include "mel.h"
mel_func uuid_init_funcs[] = {
command("uuid", "new", UUIDgenerateUuid, true, "Generate a new uuid",
args(1,1, arg("",uuid))),
- command("uuid", "new", UUIDgenerateUuidInt, true, "Generate a new uuid (dummy
version for side effect free multiplex loop)", args(1,2,
arg("",uuid),arg("d",int))),
- command("batuuid", "new", UUIDgenerateUuidInt_bulk, true, "Generate a new
uuid (dummy version for side effect free multiplex loop)", args(1,2,
batarg("",uuid),batarg("d",int))),
+ command("uuid", "new", UUIDgenerateUuidInt, true, "Generate a new uuid (dummy
version for side effect free multiplex loop)", args(1,2,
arg("",uuid),argany("d",0))),
+ command("batuuid", "new", UUIDgenerateUuidInt_bulk, true, "Generate a new
uuid (dummy version for side effect free multiplex loop)", args(1,2,
batarg("",uuid),batargany("d",0))),
command("uuid", "uuid", UUIDstr2uuid, false, "Coerce a string to a uuid,
validating its format", args(1,2, arg("",uuid),arg("s",str))),
command("uuid", "str", UUIDuuid2str, false, "Coerce a uuid to its string
type", args(1,2, arg("",str),arg("u",uuid))),
command("uuid", "isaUUID", UUIDisaUUID, false, "Test a string for a UUID
format", args(1,2, arg("",bit),arg("u",str))),
diff --git a/monetdb5/modules/kernel/batmmath.c
b/monetdb5/modules/kernel/batmmath.c
--- a/monetdb5/modules/kernel/batmmath.c
+++ b/monetdb5/modules/kernel/batmmath.c
@@ -569,8 +569,8 @@ mel_func batmmath_init_funcs[] = {
pattern("batmmath", "pow", CMDscience_bat_pow, false, "", args(1,4,
batarg("",dbl),arg("x",dbl),batarg("y",dbl),batarg("s",oid))),
pattern("batmmath", "pow", CMDscience_bat_pow, false, "", args(1,3,
batarg("",flt),arg("x",flt),batarg("y",flt))),
pattern("batmmath", "pow", CMDscience_bat_pow, false, "", args(1,4,
batarg("",flt),arg("x",flt),batarg("y",flt),batarg("s",oid))),
- pattern("batmmath", "rand", CMDscience_bat_randintarg, true, "", args(1,2,
batarg("",int),batarg("v",int))),
- pattern("batmmath", "rand", CMDscience_bat_randintarg, true, "", args(1,3,
batarg("",int),batarg("v",int),batarg("s",oid))),
+ pattern("batmmath", "rand", CMDscience_bat_randintarg, true, "", args(1,2,
batarg("",int),batargany("v",0))),
+ pattern("batmmath", "rand", CMDscience_bat_randintarg, true, "", args(1,3,
batarg("",int),batargany("v",0),batarg("s",oid))),
{ .imp=NULL }
};
#include "mal_import.h"
diff --git a/monetdb5/modules/kernel/mmath.c b/monetdb5/modules/kernel/mmath.c
--- a/monetdb5/modules/kernel/mmath.c
+++ b/monetdb5/modules/kernel/mmath.c
@@ -272,7 +272,7 @@ MATHrandint(int *res)
}
static str
-MATHrandintarg(int *res, const int *dummy)
+MATHrandintarg(int *res, const void *dummy)
{
(void) dummy;
#ifdef __COVERITY__
@@ -372,7 +372,7 @@ mel_func mmath_init_funcs[] = {
command("mmath", "isinf", MATHunary_ISINF, false, "The isinf(x) function
returns -1 if x represents negative \ninfinity, 1 if x represents positive
infinity, and 0 otherwise.", args(1,2, arg("",int),arg("d",dbl))),
command("mmath", "finite", MATHunary_FINITE, false, "The finite(x) function
returns true if x is neither infinite \nnor a 'not-a-number' (NaN) value, and
false otherwise.", args(1,2, arg("",bit),arg("d",dbl))),
command("mmath", "rand", MATHrandint, true, "return a random number",
args(1,1, arg("",int))),
- command("mmath", "rand", MATHrandintarg, true, "return a random number",
args(1,2, arg("",int),arg("v",int))),
+ command("mmath", "rand", MATHrandintarg, true, "return a random number",
args(1,2, arg("",int),argany("v",0))),
command("mmath", "srand", MATHsrandint, false, "initialize the rand()
function with a seed", args(1,2, arg("",void),arg("seed",int))),
command("mmath", "sqlrand", MATHsqlrandint, false, "initialize the rand()
function with a seed and call rand()", args(1,2, arg("",int),arg("seed",int))),
command("mmath", "pi", MATHpi, false, "return an important mathematical
value", args(1,1, arg("",dbl))),
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,7 +26,7 @@
#define OUTER_ZERO 64
-static stmt * exp_bin(backend *be, sql_exp *e, rel_bin_stmt *left,
rel_bin_stmt *right, int depth, int reduce, int push);
+static stmt * exp_bin(backend *be, sql_exp *e, rel_bin_stmt *left,
rel_bin_stmt *right, int depth, int reduce);
static rel_bin_stmt * rel_bin(backend *be, sql_rel *rel);
static rel_bin_stmt * subrel_bin(backend *be, sql_rel *rel, list *refs);
@@ -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));
+ stmt *n = stmt_atom(be, atom_general(be->mvc->sa, t, NULL), NULL);
stmt *nn = stmt_uselect2(be, col, n, n, 3, NULL, 0, 1);
return nn;
}
@@ -296,17 +296,22 @@ bin_find_smallest_column(backend *be, re
stmt *res = NULL;
int best_score = 0;
- 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 (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;
+ }
}
- }
- if (res->nrcols == 0)
- return const_column(be, res);
+ if (res->nrcols == 0)
+ res = const_column(be, res);
+ }
+ res->cand = st->cand;
return res;
}
@@ -331,7 +336,7 @@ row2cols(backend *be, rel_bin_stmt *sub)
return sub;
}
-static stmt*
+static stmt *
distinct_value_list(backend *be, list *vals, stmt **last_null_value)
{
list *l = sa_list(be->mvc->sa);
@@ -340,7 +345,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, 0, 0, 0);
+ stmt *i = exp_bin(be, e, NULL, NULL, 0, 0);
if (exp_is_null(e))
*last_null_value = i;
@@ -363,21 +368,11 @@ 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));
+ stmt *n = stmt_atom(be, atom_general(be->mvc->sa, t, NULL), NULL);
stmt *nn = stmt_uselect2(be, col, n, n, 3, s, 1, 1);
return nn;
}
-static int
-is_tid_chain(stmt *cand)
-{
- while (cand && cand->type != st_tid && cand->cand)
- cand = cand->cand;
- if (cand && cand->type == st_tid)
- return 1;
- return 0;
-}
-
static rel_bin_stmt *
subrel_project( backend *be, rel_bin_stmt *s, list *refs, sql_rel *rel)
{
@@ -386,28 +381,11 @@ subrel_project( backend *be, rel_bin_stm
list *l = sa_list(be->mvc->sa);
stmt *cand = s->cand;
- if (!l)
- return NULL;
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);
- if (c->type != st_alias) {
- c = stmt_project(be, cand, c);
- } else if (c->op1->type == st_mirror && is_tid_chain(cand)) {
/* alias with mirror (ie full row ids) */
- c = stmt_alias(be, cand, c->tname, c->cname);
- } else { /* st_alias */
- stmt *s = c->op1;
- if (s->nrcols == 0)
- s = stmt_const(be, cand, s);
- else
- s = stmt_project(be, cand, s);
- c = stmt_alias(be, s, c->tname, c->cname);
- }
- append(l, c);
+ list_append(l, stmt_project_column_on_cand(be, cand, c));
}
s = create_rel_bin_stmt(be->mvc->sa, l, NULL, NULL, NULL, NULL);
- //s->cols = l;
stmt_set_nrcols(s);
if (rel && rel_is_ref(rel))
refs_update_stmt(refs, rel, s);
@@ -424,7 +402,7 @@ handle_in_exps(backend *be, sql_exp *ce,
lcand = left->cand;
left->cand = NULL;
}
- c = exp_bin(be, ce, left, right, 0, 0, 0);
+ c = exp_bin(be, ce, left, right, depth+1, 0);
if (!c) {
if (left)
left->cand = lcand;
@@ -445,7 +423,7 @@ handle_in_exps(backend *be, sql_exp *ce,
for( node *n = nl->h; n; n = n->next) {
sql_exp *e = n->data;
- stmt *i = exp_bin(be, use_r?e->r:e, left, right, 0, 0,
0);
+ stmt *i = exp_bin(be, use_r?e->r:e, left, right,
depth+1, 0);
if (!i) {
if (left)
left->cand = lcand;
@@ -461,7 +439,7 @@ 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), cmp_equal, lcand, 0, 0);
+ stmt_bool(be, 1, lcand), cmp_equal, lcand, 0,
0);
} else if (list_length(nl) < 16) {
comp_type cmp = (in)?cmp_equal:cmp_notequal;
@@ -470,7 +448,7 @@ handle_in_exps(backend *be, sql_exp *ce,
for( node *n = nl->h; n; n = n->next) {
sql_exp *e = n->data;
- stmt *i = exp_bin(be, use_r?e->r:e, left, right, 0, 0,
0);
+ stmt *i = exp_bin(be, use_r?e->r:e, left, right,
depth+1, 0);
if (!i) {
if (left)
left->cand = lcand;
@@ -533,6 +511,7 @@ handle_in_exps(backend *be, sql_exp *ce,
}
if (left)
left->cand = lcand;
+ s->cand = lcand;
return s;
}
@@ -541,13 +520,14 @@ value_list(backend *be, list *vals, rel_
{
sql_subtype *type = exp_subtype(vals->h->data);
list *l = sa_list(be->mvc->sa);
+ stmt *res = NULL;
if (!type)
return sql_error(be->mvc, 02, SQLSTATE(42000) "Could not infer
the type of a value list column");
/* create bat append values */
for (node *n = vals->h; n; n = n->next) {
sql_exp *e = n->data;
- stmt *i = exp_bin(be, e, left, NULL, 0, 0, 0);
+ stmt *i = exp_bin(be, e, left, NULL, 0, 0);
if (!i)
return NULL;
@@ -556,7 +536,9 @@ value_list(backend *be, list *vals, rel_
return i;
list_append(l, i);
}
- return stmt_append_bulk(be, stmt_temp(be, type), l);
+ res = stmt_append_bulk(be, stmt_temp(be, type), l);
+ res->cand = left ? left->cand : NULL;
+ return res;
}
static stmt *
@@ -567,7 +549,7 @@ exp_list(backend *be, list *exps, rel_bi
for(node *n = exps->h; n; n = n->next) {
sql_exp *e = n->data;
- stmt *i = exp_bin(be, e, left, right, 0, 0, 0);
+ stmt *i = exp_bin(be, e, left, right, 0, 0);
if(!i)
return NULL;
@@ -597,7 +579,7 @@ exp_count_no_nil_arg( sql_exp *e, stmt *
}
static stmt *
-exp_bin_or(backend *be, sql_exp *e, rel_bin_stmt *left, rel_bin_stmt *right,
int depth, bool reduce, int push)
+exp_bin_or(backend *be, sql_exp *e, rel_bin_stmt *left, rel_bin_stmt *right,
int depth, bool reduce)
{
sql_subtype *bt = sql_bind_localtype("bit");
list *l = e->l;
@@ -613,7 +595,7 @@ exp_bin_or(backend *be, sql_exp *e, rel_
/* propagate the anti flag */
if (anti)
set_anti(c);
- s = exp_bin(be, c, left, right, depth, reduce, push);
+ s = exp_bin(be, c, left, right, depth+1, reduce);
if (!s) {
if (left)
left->cand = ocand;
@@ -627,7 +609,7 @@ 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 = stmt_const(be, predicate, stmt_bool(be, 1,
predicate->cand));
if (s->nrcols == 0)
s = stmt_uselect(be, predicate, s, cmp_equal,
sel1, anti, is_semantics(c));
else
@@ -647,7 +629,7 @@ exp_bin_or(backend *be, sql_exp *e, rel_
/* propagate the anti flag */
if (anti)
set_anti(c);
- s = exp_bin(be, c, left, right, depth, reduce, push);
+ s = exp_bin(be, c, left, right, depth+1, reduce);
if (!s) {
if (left)
left->cand = ocand;
@@ -661,7 +643,7 @@ exp_bin_or(backend *be, sql_exp *e, rel_
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list