Changeset: 2f4aaddd7096 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2f4aaddd7096
Modified Files:
sql/backends/monet5/BDCC/bdcc.c
sql/backends/monet5/BDCC/bdcc.h
sql/backends/monet5/BDCC/bdcc.mal
sql/server/rel_optimizer.c
Branch: BDCC
Log Message:
removed xtrrev, created remap. Remap means extract bits according to oldMask,
and map them into new clustering with newMask.
diffs (203 lines):
diff --git a/sql/backends/monet5/BDCC/bdcc.c b/sql/backends/monet5/BDCC/bdcc.c
--- a/sql/backends/monet5/BDCC/bdcc.c
+++ b/sql/backends/monet5/BDCC/bdcc.c
@@ -1,64 +1,107 @@
#include "bdcc.h"
-int xtrRev (int n, int m);
+// remap n according to oldM (to extract) and newM (to map)
+static inline int remap (int n,
+ int oldM, int oldMul,
+ int newM, int newMul, int newMWeight);
-int xtrRev (int n, int m) {
- int mul;
- int res;
+// number of set bits
+static inline int weight (int n);
- for (mul = 1, res = 0; n & m; n >>= 1, m >>= 1)
- if (m % 2) {
- if (n % 2) res |= mul;
+// most significant bit of n is 2^(result)
+static inline int msb (int n);
- mul <<= 1;
- }
+static inline int weight (int n) {
+ int res = 0;
+
+ while (n > 0) {
+ res += n & 1;
+ n >>= 1;
+ }
return res;
}
-bdcc_export char * BDCCxtrRev (bat * res, bat * b, int * m) {
- BAT * B = BATdescriptor(*b);
- BAT * Res = BATcopy(B, TYPE_void, TYPE_int, TRUE, TRANSIENT);
-
- int mIsRShift;
- int mCopy = *m;
- int mVal = *m;
- int seenOne;
- int numRShift;
+static inline int msb (int n) {
+ int res;
- BUN i;
- BATiter ResI = bat_iterator(Res);
- BUN ResL;
+ if (n == 0) return 0;
+ else res = 1;
- if (BATcount(B) == 0 || Res == NULL) throw(MAL, "bdcc.xtrRev", "ERROR");
+ while (n >>= 1) res <<= 1;
- for (mIsRShift = 1, seenOne = 0, numRShift = 0; mCopy; mCopy >>= 1) {
- if (mCopy % 2) {
- if (!seenOne) seenOne = 1;
- }
- else {
- if (seenOne) {
- mIsRShift = 0;
- break;
- }
- else numRShift++;
- }
+ return res;
+}
+
+static inline int remap (int n,
+ int oldM, int oldMul,
+ int newM, int newMul, int newMWeight) {
+ int res = 0;
+ int i = 0;
+
+ while (i < newMWeight) {
+ while (!(oldMul & oldM)) oldMul >>= 1;
+ while (!(newMul & newM)) newMul >>= 1;
+
+ if (oldMul & n) res |= newMul;
+
+ oldMul >>= 1;
+ newMul >>= 1;
+ i++;
}
- if (mIsRShift)
- for (i = BUNfirst(Res), ResL = BUNlast(Res); i < ResL; i++) {
- int * ResLoc = (int *) BUNtail(ResI, i);
-
- *ResLoc = *ResLoc >> numRShift;
- }
+ return res;
+}
+
+bdcc_export char * BDCCremap (bat * res, bat * b, bat * oldMasks, bat *
newMasks) {
+ BAT * B = BATdescriptor(*b);
+ BAT * Res;
+ BAT * OldMasks = BATdescriptor(*oldMasks);
+ BAT * NewMasks = BATdescriptor(*newMasks);
+
+ BATiter OldMasksIter = bat_iterator(OldMasks);
+ BATiter NewMasksIter = bat_iterator(NewMasks);
+
+ BATiter BIter;
+ BATiter ResIter;
+
+ int * BStart;
+ int * ResStart;
+ BUN BCount = BATcount(B);
- else for (i = BUNfirst(Res), ResL = BUNlast(Res); i < ResL; i++) {
- int * ResLoc = (int *) BUNtail(ResI, i);
+ BUN i;
- *ResLoc = xtrRev(*ResLoc, mVal);
- }
+ int zero;
- Res->tsorted = (B->tsorted && mIsRShift) ? 1 : 0;
+ Res = BATconst(B, TYPE_int, &zero, TRANSIENT);
+
+ if (Res == NULL) throw(MAL, "bdcc.remap", "ERROR");
+
+ BIter = bat_iterator(B);
+ ResIter = bat_iterator(Res);
+
+ BStart = (int *) BUNtail(BIter, BUNfirst(B));
+ ResStart = (int *) BUNtail(ResIter, BUNfirst(Res));
+
+ for (i = BUNfirst(OldMasks); i < BUNlast(OldMasks); i++) {
+ int oldM = *(int *) BUNtail(OldMasksIter, i);
+ int newM = *(int *) BUNtail(NewMasksIter, i);
+
+ int oldMul = msb(oldM);
+ int newMul = msb(newM);
+
+ int newMWeight = weight(newM);
+
+ BUN j;
+
+ for (j = 0; j < BCount; j++)
+ ResStart[j] |= remap(BStart[j],
+ oldM, oldMul,
+ newM, newMul, newMWeight);
+ }
+
+ Res->tsorted = 0;
+ Res->trevsorted = 0;
BBPkeepref(*res = Res->batCacheid);
diff --git a/sql/backends/monet5/BDCC/bdcc.h b/sql/backends/monet5/BDCC/bdcc.h
--- a/sql/backends/monet5/BDCC/bdcc.h
+++ b/sql/backends/monet5/BDCC/bdcc.h
@@ -14,6 +14,6 @@
#define bdcc_export extern
#endif
-bdcc_export char * BDCCxtrRev (bat * res, bat * b, int * m);
+bdcc_export char * BDCCremap (bat * res, bat * b, bat * oldMasks, bat *
newMasks);
#endif
diff --git a/sql/backends/monet5/BDCC/bdcc.mal
b/sql/backends/monet5/BDCC/bdcc.mal
--- a/sql/backends/monet5/BDCC/bdcc.mal
+++ b/sql/backends/monet5/BDCC/bdcc.mal
@@ -1,11 +1,12 @@
module bdcc;
-command xtrRev(b:bat[:oid,:int], mask:int):bat[:oid,:int]
-address BDCCxtrRev;
+command remap(b:bat[:oid,:int], oldMasks:bat[:oid,:int],
newMasks:bat[:oid,:int]):bat[:oid,:int]
+address BDCCremap;
-function xtrrevjoin(x:bat[:oid,:int], xM:int, y:bat[:oid,:int], yM:int)
(l:bat[:oid,:oid],r:bat[:oid,:oid]);
- xRev := xtrRev(x, xM);
- yRev := xtrRev(y, yM);
- (l, r) := algebra.join(xRev, yRev);
+function remapjoin(x:bat[:oid,:int], xOldMasks:bat[:oid,:int],
xNewMasks:bat[:oid,:int],
+ y:bat[:oid,:int], yOldMasks:bat[:oid,:int],
yNewMasks:bat[:oid,:int]) (l:bat[:oid,:oid],r:bat[:oid,:oid]);
+ xRemap := remap(x, xOldMasks, xNewMasks);
+ yRemap := remap(y, yOldMasks, yNewMasks);
+ (l, r) := algebra.join(xRemap, yRemap);
return (l, r);
-end xtrrevjoin;
+end remapjoin;
diff --git a/sql/server/rel_optimizer.c b/sql/server/rel_optimizer.c
--- a/sql/server/rel_optimizer.c
+++ b/sql/server/rel_optimizer.c
@@ -377,8 +377,8 @@ exp_count(int *cnt, int seqnr, sql_exp *
}
return 6;
case cmp_filter:
- *cnt += 2;
- return 2;
+ *cnt += 1000;
+ return 1000;
case cmp_in:
case cmp_notin: {
list *l = e->r;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list