Changeset: 9c439c6c90bd for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9c439c6c90bd
Modified Files:
monetdb5/mal/Tests/tst866.stable.out
monetdb5/modules/kernel/bat5.c
Branch: Oct2020
Log Message:
Reimplemented vacuum algorithm, fixing a problem in sqlancer06.
diffs (281 lines):
diff --git a/monetdb5/mal/Tests/tst866.stable.out
b/monetdb5/mal/Tests/tst866.stable.out
--- a/monetdb5/mal/Tests/tst866.stable.out
+++ b/monetdb5/mal/Tests/tst866.stable.out
@@ -74,21 +74,21 @@ end user.foo;
# void int # type
#-----------------#
[ 0@0, 1 ]
-[ 1@0, 9 ]
-[ 2@0, 7 ]
-[ 3@0, 4 ]
-[ 4@0, 5 ]
-[ 5@0, 6 ]
-#-----------------#
+[ 1@0, 4 ]
+[ 2@0, 5 ]
+[ 3@0, 6 ]
+[ 4@0, 7 ]
+[ 5@0, 9 ]
+#--------------------------#
# h t # name
# void oid # type
#-----------------#
[ 0@0, 0@0 ]
-[ 1@0, 8@0 ]
-[ 2@0, 6@0 ]
-[ 3@0, 3@0 ]
-[ 4@0, 4@0 ]
-[ 5@0, 5@0 ]
+[ 1@0, 3@0 ]
+[ 2@0, 4@0 ]
+[ 3@0, 5@0 ]
+[ 4@0, 6@0 ]
+[ 5@0, 8@0 ]
# 16:27:48 >
# 16:27:48 > Done.
diff --git a/monetdb5/modules/kernel/bat5.c b/monetdb5/modules/kernel/bat5.c
--- a/monetdb5/modules/kernel/bat5.c
+++ b/monetdb5/modules/kernel/bat5.c
@@ -937,31 +937,26 @@ BKCshrinkBATmap(bat *ret, const bat *bid
/*
* Shrinking a void-headed BAT using a list of oids to ignore.
*/
-#define reuseloop(Type)
\
- do {
\
- Type *p = (Type*)Tloc(b, 0); \
- Type *q = (Type*)Tloc(b, BUNlast(b)); \
- Type *r = (Type*)Tloc(bn, 0); \
- for (;p<q; oidx++, p++) {
\
- if ( *o == oidx ){
\
- while ( ol>o && ol[-1] == bidx) { \
- bidx--;
\
- q--;
\
- ol--;
\
- }
\
- *r++ = *(--q);
\
- o += (o < ol);
\
- bidx--;
\
- } else
\
- *r++ = *p;
\
- }
\
+#define reuseloop(Type)
\
+ do {
\
+ Type *dst = (Type *) Tloc(bn, 0);
\
+ const Type *src = (const Type *) Tloc(b, 0); \
+ for (BUN p = 0; p < b->batCount; p++, src++) { \
+ if (o < ol && b->hseqbase + p == *o) {
\
+ do
\
+ o++;
\
+ while (o < ol && b->hseqbase + p == *o);
\
+ } else {
\
+ *dst++ = *src;
\
+ n++;
\
+ }
\
+ }
\
} while (0)
str
BKCreuseBAT(bat *ret, const bat *bid, const bat *did)
{
BAT *b, *d, *bn, *bs;
- oid oidx = 0, bidx, *o, *ol;
gdk_return res;
if ((b = BATdescriptor(*bid)) == NULL) {
@@ -985,75 +980,70 @@ BKCreuseBAT(bat *ret, const bat *bid, co
throw(MAL, "bat.reuse", SQLSTATE(HY013) MAL_MALLOC_FAIL );
}
- oidx = b->hseqbase;
- bidx = oidx + BATcount(b)-1;
- o = (oid*)Tloc(bs, 0);
- ol= (oid*)Tloc(bs, BUNlast(bs));
-
- switch(ATOMstorage(b->ttype) ){
- case TYPE_bte: reuseloop(bte); break;
- case TYPE_sht: reuseloop(sht); break;
- case TYPE_int: reuseloop(int); break;
- case TYPE_lng: reuseloop(lng); break;
-#ifdef HAVE_HGE
- case TYPE_hge: reuseloop(hge); break;
-#endif
- case TYPE_flt: reuseloop(flt); break;
- case TYPE_dbl: reuseloop(dbl); break;
- case TYPE_oid: reuseloop(oid); break;
- case TYPE_str: /* to be done based on its index width */
- default:
- if (ATOMvarsized(bn->ttype)) {
- BUN p = 0;
- BUN q = BUNlast(b);
- BATiter bi = bat_iterator(b);
-
- for (;p<q; oidx++, p++) {
- if ( *o == oidx ){
- while ( ol > o && ol[-1] == bidx) {
- bidx--;
- q--;
- ol--;
- }
- if (BUNappend(bn, BUNtail(bi, --q),
false) != GDK_SUCCEED) {
- BBPunfix(b->batCacheid);
- BBPunfix(bn->batCacheid);
- throw(MAL, "bat.shrink",
SQLSTATE(HY013) MAL_MALLOC_FAIL);
- }
- o += (o < ol);
- bidx--;
- } else {
- if (BUNappend(bn, BUNtail(bi, p),
false) != GDK_SUCCEED) {
- BBPunfix(b->batCacheid);
- BBPunfix(bn->batCacheid);
- throw(MAL, "bat.shrink",
SQLSTATE(HY013) MAL_MALLOC_FAIL);
- }
- }
- }
- } else {
- switch( b->twidth){
- case 1:reuseloop(bte); break;
- case 2:reuseloop(sht); break;
- case 4:reuseloop(int); break;
- case 8:reuseloop(lng); break;
-#ifdef HAVE_HGE
- case 16:reuseloop(hge); break;
-#endif
- default:
+ const oid *o = (const oid *) Tloc(bs, 0);
+ const oid *ol = o + bs->batCount;
+ while (o < ol && *o < b->hseqbase)
+ o++;
+ if (b->tvarsized) {
+ BATiter bi = bat_iterator(b);
+ for (BUN p = 0; p < b->batCount; p++) {
+ if (o < ol && b->hseqbase + p == *o) {
+ do
+ o++;
+ while (o < ol && b->hseqbase + p == *o);
+ } else if (BUNappend(bn, BUNtail(bi, p), false) !=
GDK_SUCCEED) {
+ BBPunfix(bn->batCacheid);
BBPunfix(b->batCacheid);
- BBPunfix(bn->batCacheid);
- throw(MAL, "bat.shrink", "Illegal argument
type");
+ BBPunfix(bs->batCacheid);
+ throw(MAL, "bat.shrink", GDK_EXCEPTION);
}
}
+ } else {
+ BUN n = 0;
+ switch (b->twidth) {
+ case 1:
+ reuseloop(bte);
+ break;
+ case 2:
+ reuseloop(sht);
+ break;
+ case 4:
+ reuseloop(int);
+ break;
+ case 8:
+ reuseloop(lng);
+ break;
+#ifdef HAVE_HGE
+ case 16:
+ reuseloop(hge);
+ break;
+#endif
+ default: {
+ char *dst = (char *) Tloc(bn, 0);
+ const char *src = (const char *) Tloc(b, 0);
+ for (BUN p = 0; p < b->batCount; p++) {
+ if (o < ol && b->hseqbase + p == *o) {
+ do
+ o++;
+ while (o < ol && b->hseqbase + p == *o);
+ } else {
+ memcpy(dst, src, b->twidth);
+ dst += b->twidth;
+ n++;
+ }
+ src += b->twidth;
+ }
+ break;
+ }
+ }
+ BATsetcount(bn, n);
+ bn->tkey = b->tkey;
+ bn->tsorted = b->tsorted;
+ bn->trevsorted = b->trevsorted;
+ bn->tnonil = b->tnonil;
+ bn->tnil = false; /* can't be sure if values
deleted */
}
- BATsetcount(bn, BATcount(b) - BATcount(bs));
- bn->tsorted = false;
- bn->trevsorted = false;
- bn->tseqbase = oid_nil;
- bn->tkey = b->tkey;
- bn->tnonil = b->tnonil;
-
BBPunfix(b->batCacheid);
BBPunfix(bs->batCacheid);
BBPkeepref(*ret= bn->batCacheid);
@@ -1064,8 +1054,6 @@ str
BKCreuseBATmap(bat *ret, const bat *bid, const bat *did)
{
BAT *b, *d, *bn, *bs;
- oid bidx, oidx = 0, *o, *ol;
- oid *r;
gdk_return res;
if ((b = BATdescriptor(*bid)) == NULL) {
@@ -1089,32 +1077,30 @@ BKCreuseBATmap(bat *ret, const bat *bid,
throw(MAL, "bat.shrinkMap", SQLSTATE(HY013) MAL_MALLOC_FAIL );
}
- oidx = b->hseqbase;
- bidx = oidx + BATcount(b)-1;
- o = (oid*)Tloc(bs, 0);
- ol = (oid*)Tloc(bs, BUNlast(bs));
- r = (oid*)Tloc(bn, 0);
-
- for (; oidx <= bidx; oidx++) {
- if ( *o == oidx ){
- while ( ol > o && ol[-1] == bidx) {
- bidx--;
- ol--;
- }
- *r++ = bidx;
- o += (o < ol);
- bidx--;
+ const oid *o = (const oid *) Tloc(bs, 0);
+ const oid *ol = o + bs->batCount;
+ while (o < ol && *o < b->hseqbase)
+ o++;
+ oid *dst = (oid *) Tloc(bn, 0);
+ BUN n = 0;
+ for (BUN p = 0; p < b->batCount; p++) {
+ if (o < ol && b->hseqbase + p == *o) {
+ do
+ o++;
+ while (o < ol && b->hseqbase + p == *o);
} else {
- *r++ = oidx;
+ *dst++ = b->hseqbase + p;
+ n++;
}
}
-
- BATsetcount(bn, BATcount(b)-BATcount(bs));
- bn->tsorted = false;
- bn->trevsorted = false;
+ BATsetcount(bn, n);
+ bn->tkey = true;
+ bn->tsorted = true;
+ bn->trevsorted = n <= 1;
+ bn->tnil = false;
+ bn->tnonil = true;
bn->tseqbase = oid_nil;
-
BBPunfix(b->batCacheid);
BBPunfix(bs->batCacheid);
BBPkeepref(*ret= bn->batCacheid);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list