Changeset: fdca24df4a1a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/fdca24df4a1a
Modified Files:
sql/backends/monet5/rel_bin.c
sql/backends/monet5/sql_statement.c
sql/include/sql_relation.h
Branch: default
Log Message:
Cleaning function call code generation
diffs (210 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
@@ -2276,7 +2276,7 @@ rel2bin_hash_lookup(backend *be, sql_rel
sql_subfunc *xor = sql_bind_func_result(sql, "sys",
"rotate_xor_hash", F_FUNC, lng, 3, lng, it, tail_type(s));
h = stmt_Nop(be, stmt_list(be, list_append( list_append(
- list_append(sa_list(sql->sa), h), bits), s)),
NULL, xor, false);
+ list_append(sa_list(sql->sa), h), bits), s)),
NULL, xor, NULL);
semantics = 1;
} else {
sql_subfunc *hf = sql_bind_func_result(sql, "sys",
"hash", F_FUNC, lng, 1, tail_type(s));
@@ -2324,7 +2324,6 @@ join_hash_key( backend *be, list *l )
static stmt *
releqjoin( backend *be, list *l1, list *l2, list *exps, int used_hash, int
need_left, int is_semantics )
{
- mvc *sql = be->mvc;
node *n1 = l1->h, *n2 = l2->h, *n3 = NULL;
stmt *l, *r, *res;
sql_exp *e;
@@ -2361,25 +2360,14 @@ releqjoin( backend *be, list *l1, list *
stmt *rd = n2->data;
stmt *le = stmt_project(be, l, ld );
stmt *re = stmt_project(be, r, rd );
+ stmt *cmp;
/* intentional both tail_type's of le (as re sometimes is a
find for bulk loading */
- sql_subfunc *f = NULL;
- stmt * cmp;
- list *ops;
-
- f = sql_bind_func(sql, "sys", "=", tail_type(le),
tail_type(le), F_FUNC);
- assert(f);
-
- ops = sa_list(be->mvc->sa);
- list_append(ops, le);
- list_append(ops, re);
+
if (!semantics && exps) {
e = n3->data;
semantics = is_semantics(e);
}
- if (semantics)
- list_append(ops, stmt_bool(be, 1));
- cmp = stmt_Nop(be, stmt_list(be, ops), NULL, f, NULL);
- cmp = stmt_uselect(be, cmp, stmt_bool(be, 1), cmp_equal, NULL,
0, 0);
+ cmp = stmt_uselect(be, le, re, cmp_equal, NULL, 0, semantics);
l = stmt_project(be, cmp, l );
r = stmt_project(be, cmp, r );
}
@@ -4951,7 +4939,7 @@ hash_update(backend *be, sql_idx * i, st
h = stmt_Nop(be, stmt_list( be, list_append(
list_append(
list_append(sa_list(sql->sa), h),
stmt_atom_int(be, bits)), upd)), NULL,
- xor, false);
+ xor, NULL);
} else if (h) {
stmt *h2;
sql_subfunc *lsh = sql_bind_func_result(sql, "sys",
"left_shift", F_FUNC, lng, 2, lng, it);
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
@@ -40,14 +40,6 @@ convertMultiplexFcn(const char *op)
return op;
}
-static const char *
-convertOperator(const char *op)
-{
- if (strcmp(op, "=") == 0)
- return "==";
- return op;
-}
-
static InstrPtr
multiplex2(MalBlkPtr mb, const char *mod, const char *name, int o1, int o2,
int rtype)
{
@@ -1369,7 +1361,7 @@ stmt_genselect(backend *be, stmt *lops,
node *n;
op = sa_strconcat(be->mvc->sa, op, selectRef);
- q = newStmtArgs(mb, mod, convertOperator(op), 9);
+ q = newStmtArgs(mb, mod, convertMultiplexFcn(op), 9);
// push pointer to the SQL structure into the MAL call
// allows getting argument names for example
if (LANG_EXT(f->func->lang))
@@ -1472,7 +1464,7 @@ stmt_uselect(backend *be, stmt *op1, stm
TRC_ERROR(SQL_EXECUTION, "Unknown operator\n");
}
- if ((q = multiplex2(mb, mod, convertOperator(op), l, r,
TYPE_bit)) == NULL)
+ if ((q = multiplex2(mb, mod, convertMultiplexFcn(op), l, r,
TYPE_bit)) == NULL)
return NULL;
if (sub && (op1->cand || op2->cand)) {
if (op1->cand && !op2->cand) {
@@ -3312,16 +3304,16 @@ stmt_Nop(backend *be, stmt *ops, stmt *s
InstrPtr q = NULL;
const char *mod = sql_func_mod(f->func), *fimp = sql_func_imp(f->func);
sql_subtype *tpe = NULL;
- int push_cands = 0;
-
- node *n;
- stmt *o = NULL;
+ int push_cands = 0, default_nargs;
+ stmt *o = NULL, *card = NULL;
if (rows) {
+ if (sel) /* if there's a candidate list, use it instead of
'rows' */
+ rows = sel;
o = rows;
- }
- else if (list_length(ops->op4.lval)) {
- for (n = ops->op4.lval->h, o = n->data; n; n = n->next) {
+ } else if (list_length(ops->op4.lval)) {
+ o = ops->op4.lval->h->data;
+ for (node *n = ops->op4.lval->h; n; n = n->next) {
stmt *c = n->data;
if (c && o->nrcols < c->nrcols)
@@ -3358,40 +3350,38 @@ stmt_Nop(backend *be, stmt *ops, stmt *s
if (backend_create_subfunc(be, f, ops->op4.lval) < 0)
return NULL;
mod = sql_func_mod(f->func);
- fimp = sql_func_imp(f->func);
+ fimp = convertMultiplexFcn(sql_func_imp(f->func));
push_cands = can_push_cands(sel, mod, fimp);
+ default_nargs = (f->res && list_length(f->res) ?
list_length(f->res) : 1) + list_length(ops->op4.lval) + (o && o->nrcols > 0 ? 6
: 4);
+ if (rows) {
+ card = stmt_aggr(be, rows, NULL, NULL,
sql_bind_func(be->mvc, "sys", "count", sql_bind_localtype("void"), NULL,
F_AGGR), 1, 0, 1);
+ default_nargs++;
+ }
+
if (o && o->nrcols > 0 && f->func->type != F_LOADER &&
f->func->type != F_PROC) {
sql_subtype *res = f->res->h->data;
- fimp = convertMultiplexFcn(fimp);
- q = NULL;
- if (strcmp(fimp, "rotate_xor_hash") == 0 &&
- strcmp(mod, calcRef) == 0 &&
- (q = newStmt(mb, mkeyRef,
bulk_rotate_xor_hashRef)) == NULL)
- return NULL;
- if (!q) {
- if (f->func->type == F_UNION)
- q = newStmtArgs(mb, batmalRef,
multiplexRef, (f->res && list_length(f->res) ? list_length(f->res) : 1) +
list_length(ops->op4.lval) + 6);
- else {
- if (rows) {
- stmt *card = stmt_aggr(be,
rows, NULL, NULL, sql_bind_func(be->mvc, "sys", "count",
sql_bind_localtype("void"), NULL, F_AGGR), 1, 0, 1);
- q = newStmtArgs(mb, malRef,
multiplexRef, (f->res && list_length(f->res) ? list_length(f->res) : 1) +
list_length(ops->op4.lval) + 7);
- q = pushArgument(mb, q,
card->nr);
- }
- else
- q = newStmtArgs(mb, malRef,
multiplexRef, (f->res && list_length(f->res) ? list_length(f->res) : 1) +
list_length(ops->op4.lval) + 6);
- }
+
+ if (strcmp(fimp, "rotate_xor_hash") == 0 && strcmp(mod,
calcRef) == 0) {
+ q = newStmt(mb, mkeyRef,
bulk_rotate_xor_hashRef);
+ if (q == NULL)
+ return NULL;
+ } else {
+ q = newStmtArgs(mb, f->func->type == F_UNION ?
batmalRef : malRef, multiplexRef, default_nargs);
if (q == NULL)
return NULL;
- setVarType(mb, getArg(q, 0),
newBatType(res->type->localtype));
+ if (rows)
+ q = pushArgument(mb, q, card->nr);
q = pushStr(mb, q, mod);
q = pushStr(mb, q, fimp);
- } else {
- setVarType(mb, getArg(q, 0),
newBatType(res->type->localtype));
}
+ setVarType(mb, getArg(q, 0),
newBatType(res->type->localtype));
} else {
- fimp = convertOperator(fimp);
- q = newStmtArgs(mb, mod, fimp, (f->res &&
list_length(f->res) ? list_length(f->res) : 1) + list_length(ops->op4.lval) +
4);
-
+ q = newStmtArgs(mb, mod, fimp, default_nargs);
+ if (q == NULL)
+ return NULL;
+
+ if (rows)
+ q = pushArgument(mb, q, card->nr);
if (f->res && list_length(f->res)) {
sql_subtype *res = f->res->h->data;
@@ -3415,13 +3405,13 @@ stmt_Nop(backend *be, stmt *ops, stmt *s
if (list_length(ops->op4.lval))
tpe = tail_type(ops->op4.lval->h->data);
- for (n = ops->op4.lval->h; n; n = n->next) {
+ for (node *n = ops->op4.lval->h; n; n = n->next) {
stmt *op = n->data;
q = pushArgument(mb, q, op->nr);
}
/* push candidate lists if that's the case */
if (f->func->type == F_FUNC && push_cands) {
- for (n = ops->op4.lval->h; n; n = n->next) {
+ for (node *n = ops->op4.lval->h; n; n = n->next) {
stmt *op = n->data;
if (op->nrcols > 0) {
diff --git a/sql/include/sql_relation.h b/sql/include/sql_relation.h
--- a/sql/include/sql_relation.h
+++ b/sql/include/sql_relation.h
@@ -52,7 +52,7 @@ typedef struct expression {
nulls_last:1, /* return null after all other rows */
zero_if_empty:1, /* in case of partial aggregator computation,
some aggregators need to return 0 instead of NULL */
distinct:1,
- argument_independence:1, /* compare between symmetric */
+ argument_independence:1, /* for a function expression, the arguments
are independent of the inner project relation. */
semantics:1, /* is vs = semantics (nil = nil vs unknown != unknown),
ranges with or without nil, aggregation with or without nil */
need_no_nil:1,
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list