Changeset: 9ba18d687f21 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/9ba18d687f21
Modified Files:
monetdb5/optimizer/opt_dict.c
monetdb5/optimizer/opt_mergetable.c
sql/backends/monet5/dict.c
sql/backends/monet5/dict.h
sql/backends/monet5/sql.c
Branch: dict
Log Message:
added dict.thetaselect
diffs (250 lines):
diff --git a/monetdb5/optimizer/opt_dict.c b/monetdb5/optimizer/opt_dict.c
--- a/monetdb5/optimizer/opt_dict.c
+++ b/monetdb5/optimizer/opt_dict.c
@@ -107,35 +107,47 @@ OPTdictImplementation(Client cntxt, MalB
done = 1;
break;
} else if (isSelect(p)) {
- /* pos = select(col, cand, l, h, ...)
with col = dict.decompress(o,u)
- * tp = select(u, nil, l, h, ...)
- * tp2 = batcalc.bte/sht/int(tp)
- * pos = intersect(o, tp2, cand, nil) */
+ if (getFunctionId(p) == thetaselectRef)
{
+ InstrPtr r =
newInstructionArgs(mb, dictRef, thetaselectRef, 6);
- int cand = getArg(p, j+1);
- InstrPtr r = copyInstruction(p);
- getArg(r, j) = vardictvalue[k];
- if (cand)
- r = ReplaceWithNil(mb, r, j+1,
TYPE_bat); /* no candidate list */
- pushInstruction(mb,r);
+ getArg(r, 0) = getArg(p, 0);
+ addArgument(mb, r,
varisdict[k]);
+ addArgument(mb, r, getArg(p,
2)); /* cand */
+ addArgument(mb, r,
vardictvalue[k]);
+ addArgument(mb, r, getArg(p,
3)); /* val */
+ addArgument(mb, r, getArg(p,
4)); /* op */
+ pushInstruction(mb,r);
+ } else {
+ /* pos = select(col, cand, l,
h, ...) with col = dict.decompress(o,u)
+ * tp = select(u, nil, l, h,
...)
+ * tp2 = batcalc.bte/sht/int(tp)
+ * pos = intersect(o, tp2,
cand, nil) */
- int tpe = getVarType(mb, varisdict[k]);
- InstrPtr s = newInstructionArgs(mb,
dictRef, putName("convert"), 3);
- getArg(s, 0) = newTmpVariable(mb, tpe);
- addArgument(mb, s, getArg(r, 0));
- pushInstruction(mb,s);
+ int cand = getArg(p, j+1);
+ InstrPtr r = copyInstruction(p);
+ getArg(r, j) = vardictvalue[k];
+ if (cand)
+ r = ReplaceWithNil(mb,
r, j+1, TYPE_bat); /* no candidate list */
+ pushInstruction(mb,r);
+
+ int tpe = getVarType(mb,
varisdict[k]);
+ InstrPtr s =
newInstructionArgs(mb, dictRef, putName("convert"), 3);
+ getArg(s, 0) =
newTmpVariable(mb, tpe);
+ addArgument(mb, s, getArg(r,
0));
+ pushInstruction(mb,s);
- InstrPtr t = newInstructionArgs(mb,
algebraRef, intersectRef, 5);
- getArg(t, 0) = getArg(p, 0);
- addArgument(mb, t, varisdict[k]);
- addArgument(mb, t, getArg(s, 0));
- addArgument(mb, t, cand);
- t = pushNil(mb, t, TYPE_bat);
- t = pushBit(mb, t, FALSE); /* nil
matches */
- t = pushBit(mb, t, TRUE); /*
max_one */
- t = pushNil(mb, t, TYPE_lng); /*
estimate */
- pushInstruction(mb,t);
-
+ InstrPtr t =
newInstructionArgs(mb, algebraRef, intersectRef, 9);
+ //InstrPtr t =
newInstructionArgs(mb, dictRef, intersectRef, 9);
+ getArg(t, 0) = getArg(p, 0);
+ addArgument(mb, t,
varisdict[k]);
+ addArgument(mb, t, getArg(s,
0));
+ addArgument(mb, t, cand);
+ t = pushNil(mb, t, TYPE_bat);
+ t = pushBit(mb, t, FALSE);
/* nil matches */
+ t = pushBit(mb, t, TRUE);
/* max_one */
+ t = pushNil(mb, t, TYPE_lng);
/* estimate */
+ pushInstruction(mb,t);
+ }
done = 1;
break;
} else if (j == 2 && p->argc > j+1 &&
getModuleId(p) == algebraRef && getFunctionId(p) == joinRef
diff --git a/monetdb5/optimizer/opt_mergetable.c
b/monetdb5/optimizer/opt_mergetable.c
--- a/monetdb5/optimizer/opt_mergetable.c
+++ b/monetdb5/optimizer/opt_mergetable.c
@@ -2348,7 +2348,7 @@ OPTmergetableImplementation(Client cntxt
/* select on update, with nil bat */
if (match == 1 && fm == 1 && isSelect(p) && p->retc == 1 &&
- (m=is_a_mat(getArg(p,fm), &ml)) >= 0 && bats == 2 &&
+ (m=is_a_mat(getArg(p,fm), &ml)) >= 0 && bats >= 2 /* include
dict */ &&
isaBatType(getArgType(mb,p,2)) &&
isVarConstant(mb,getArg(p,2)) &&
is_bat_nil(getVarConstant(mb,getArg(p,2)).val.bval)) {
if (mat_apply1(mb, p, &ml, m, fm)) {
@@ -2359,6 +2359,16 @@ OPTmergetableImplementation(Client cntxt
continue;
}
+ /* handle dict select */
+ if (match == 2 && match == bats-1 && p->retc == 1 &&
isSelect(p) && getModuleId(p) == dictRef) {
+ if(mat_apply(mb, p, &ml, match)) {
+ msg =
createException(MAL,"optimizer.mergetable",SQLSTATE(HY013) MAL_MALLOC_FAIL);
+ goto cleanup;
+ }
+ actions++;
+ continue;
+ }
+
if (match == bats && p->retc == 1 && (isMap2Op(p) || isMapOp(p)
|| isFragmentGroup(p) || isFragmentGroup2(p))) {
if(mat_apply(mb, p, &ml, match)) {
msg =
createException(MAL,"optimizer.mergetable",SQLSTATE(HY013) MAL_MALLOC_FAIL);
diff --git a/sql/backends/monet5/dict.c b/sql/backends/monet5/dict.c
--- a/sql/backends/monet5/dict.c
+++ b/sql/backends/monet5/dict.c
@@ -195,14 +195,35 @@ DICTdecompress(Client cntxt, MalBlkPtr m
BATiter ui = bat_iterator_nolock(u);
if (o->ttype == TYPE_bte) {
unsigned char *op = Tloc(o, 0);
- BATloop(o, p, q) {
- BUN up = op[p];
- if (BUNappend(b, BUNtail(ui, up), false) != GDK_SUCCEED) {
- bat_iterator_end(&oi);
- bat_destroy(b);
- bat_destroy(o);
- bat_destroy(u);
- throw(SQL, "dict.decompress", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
+
+ if (ATOMstorage(u->ttype) == TYPE_int) {
+ int *up = Tloc(u, 0);
+ int *bp = Tloc(b, 0);
+
+ BATloop(o, p, q) {
+ bp[p] = up[op[p]];
+ }
+ BATsetcount(b, BATcount(o));
+ BATnegateprops(b);
+ } else if (ATOMstorage(u->ttype) == TYPE_lng) {
+ lng *up = Tloc(u, 0);
+ lng *bp = Tloc(b, 0);
+
+ BATloop(o, p, q) {
+ bp[p] = up[op[p]];
+ }
+ BATsetcount(b, BATcount(o));
+ BATnegateprops(b);
+ } else {
+ BATloop(o, p, q) {
+ BUN up = op[p];
+ if (BUNappend(b, BUNtail(ui, up), false) !=
GDK_SUCCEED) {
+ bat_iterator_end(&oi);
+ bat_destroy(b);
+ bat_destroy(o);
+ bat_destroy(u);
+ throw(SQL, "dict.decompress",
SQLSTATE(HY013) MAL_MALLOC_FAIL);
+ }
}
}
} else if (o->ttype == TYPE_sht) {
@@ -217,6 +238,15 @@ DICTdecompress(Client cntxt, MalBlkPtr m
}
BATsetcount(b, BATcount(o));
BATnegateprops(b);
+ } else if (ATOMstorage(u->ttype) == TYPE_lng) {
+ lng *up = Tloc(u, 0);
+ lng *bp = Tloc(b, 0);
+
+ BATloop(o, p, q) {
+ bp[p] = up[op[p]];
+ }
+ BATsetcount(b, BATcount(o));
+ BATnegateprops(b);
} else {
BATloop(o, p, q) {
BUN up = op[p];
@@ -475,3 +505,58 @@ DICTjoin(Client cntxt, MalBlkPtr mb, Mal
throw(MAL, "BATjoin", GDK_EXCEPTION);
return res;
}
+
+str
+DICTselect(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+{
+ (void)cntxt;
+ (void)mb;
+ bat *R0 = getArgReference_bat(stk, pci, 0);
+ bat LO = *getArgReference_bat(stk, pci, 1);
+ bat LC = *getArgReference_bat(stk, pci, 2);
+ bat LV = *getArgReference_bat(stk, pci, 3);
+ ptr v = getArgReference(stk, pci, 4);
+ const char *op = *getArgReference_str(stk, pci, 5);
+
+ BAT *lc = NULL, *bn = NULL;
+ BAT *lo = BATdescriptor(LO);
+ BAT *lv = BATdescriptor(LV);
+ BUN p = BUN_NONE;
+
+ if (!lo || !lv) {
+ bat_destroy(lo);
+ bat_destroy(lv);
+ throw(SQL, "dict.select", SQLSTATE(HY013) MAL_MALLOC_FAIL);
+ }
+ if (!is_bat_nil(LC))
+ lc = BATdescriptor(LC);
+ if (op[0] == '=' || ((op[0] == '<' || op[0] == '>') && lv->tsorted)) {
+ if (op[0] == '=')
+ p = BUNfnd(lv, v);
+ else if (op[0] == '<')
+ p = SORTfndlast(lv, v);
+ else if (op[0] == '>')
+ p = SORTfndfirst(lv, v);
+ if (p != BUN_NONE) {
+ BATiter li = bat_iterator_nolock(lv);
+ ptr v = BUNtail(li, 0);
+ bn = BATthetaselect(lo, lc, v, op);
+ } else {
+ bn = BATdense(0, 0, 0);
+ }
+ } else { /* select + intersect */
+ bn = BATthetaselect(lv, NULL, v, op);
+ if (bn) {
+ BAT *n = BATintersect(lo, bn, lc, NULL, true, true,
BATcount(lo));
+ bat_destroy(bn);
+ bn = n;
+ }
+ }
+ bat_destroy(lo);
+ bat_destroy(lv);
+ bat_destroy(lc);
+ if (!bn)
+ throw(SQL, "dict.select", SQLSTATE(HY013) MAL_MALLOC_FAIL);
+ BBPkeepref(*R0 = bn->batCacheid);
+ return MAL_SUCCEED;
+}
diff --git a/sql/backends/monet5/dict.h b/sql/backends/monet5/dict.h
--- a/sql/backends/monet5/dict.h
+++ b/sql/backends/monet5/dict.h
@@ -8,6 +8,7 @@ extern str DICTcompress(Client cntxt, Ma
extern str DICTdecompress(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr
pci);
extern str DICTconvert(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr
pci);
extern str DICTjoin(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
+extern str DICTselect(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
#endif /* _DICT_H */
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -5400,6 +5400,7 @@ static mel_func sql_init_funcs[] = {
pattern("dict", "decompress", DICTdecompress, false, "decompress a dictionary
compressed (sub)column", args(1, 3, batargany("", 1), batargany("o", 0),
batargany("u", 1))),
pattern("dict", "convert", DICTconvert, false, "convert candidate list into
compressed offsets", args(1, 2, batargany("", 1), batargany("o", 0))),
pattern("dict", "join", DICTjoin, false, "join 2 dictionaries", args(2, 10,
batarg("r0", oid), batarg("r1", oid), batargany("lo", 0), batargany("lv", 1),
batargany("ro", 0), batargany("rv", 1), batarg("lc", oid), batarg("rc", oid),
arg("nil_matches",bit), arg("estimate",lng))),
+ pattern("dict", "thetaselect", DICTselect, false, "thetaselect on a
dictionary", args(1, 6, batarg("r0", oid), batargany("lo", 0), batarg("lc",
oid), batargany("lv", 1), argany("val",1), arg("op", str))),
command("calc", "dec_round", bte_dec_round_wrap, false, "round off the value
v to nearests multiple of r", args(1,3, arg("",bte),arg("v",bte),arg("r",bte))),
pattern("batcalc", "dec_round", bte_bat_dec_round_wrap, false, "round off the
value v to nearests multiple of r", args(1,3,
batarg("",bte),batarg("v",bte),arg("r",bte))),
pattern("batcalc", "dec_round", bte_bat_dec_round_wrap, false, "round off the
value v to nearests multiple of r", args(1,4,
batarg("",bte),batarg("v",bte),arg("r",bte),batarg("s",oid))),
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list