Changeset: 8a799f6fb8ec for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8a799f6fb8ec
Modified Files:
monetdb5/modules/mal/Tests/xidlist.stable.out
monetdb5/modules/mal/xid.c
Branch: xid
Log Message:
XID: handle [:oid,:any] & [:any,:oid] BATs next to [:oid,:oid] BATs
In case of [:oid,:any] & [:any,:oid] BATs, we comress only the OID column,
and inherit the ANY column as view from the input BAT.
Net effect: in case of [:oid,:oid] BATs, in case one column cannot be
compressed (e.g., due to NIL or too large value range), we now still
compress the other one, inheriting the non-compressible as view as above.
diffs (276 lines):
diff --git a/monetdb5/modules/mal/Tests/xidlist.stable.out
b/monetdb5/modules/mal/Tests/xidlist.stable.out
--- a/monetdb5/modules/mal/Tests/xidlist.stable.out
+++ b/monetdb5/modules/mal/Tests/xidlist.stable.out
@@ -153,7 +153,7 @@ end main;
[ 78@0, 1280@0 ]
[ 79@0, 1290@0 ]
#xid, 83, tail compress, 80,56, clk 3 usec
-column first 56, size 0,
+column first 56, size 80,
r+:0 3
p:5
p:7
diff --git a/monetdb5/modules/mal/xid.c b/monetdb5/modules/mal/xid.c
--- a/monetdb5/modules/mal/xid.c
+++ b/monetdb5/modules/mal/xid.c
@@ -265,7 +265,7 @@ XIDcompressCol( Client cntxt, InstrPtr p
}
static void
-getMinMaxNIL ( COLrec *c, BUN cnt, oid *o, oid *min, oid *max )
+getMinMax ( COLrec *c, BUN cnt, oid *o, oid *min, oid *max )
{
BUN i;
oid mn = oid_nil, mx = 0;
@@ -286,6 +286,39 @@ getMinMaxNIL ( COLrec *c, BUN cnt, oid *
*max = mx;
}
+/* inspired by VIEWcreate() from gdh_align.c,
+ * but here re-using bn's BAT descriptor
+ */
+static BAT*
+inheritCOL( BAT *bn, COLrec *cn, BAT *b, COLrec *c, bat p )
+{
+ /* inherit column as view */
+ str nme = cn->id;
+ if (p == 0)
+ p = b->batCacheid;
+ assert(bn->U->deleted == b->U->deleted );
+ assert(bn->U->first == b->U->first );
+ assert(bn->U->inserted == b->U->inserted);
+ assert(bn->U->count == b->U->count );
+ //assert(bn->U->capacity == b->U->capacity);
+ bn->U->capacity = MIN( bn->U->capacity, b->U->capacity );
+ *cn = *c;
+ BBPshare(p);
+ if (cn->vheap) {
+ assert(cn->vheap->parentid > 0);
+ BBPshare(cn->vheap->parentid);
+ }
+ cn->heap.copied = 0;
+ cn->props = NULL;
+ cn->heap.parentid = p;
+ cn->id = nme;
+ if (isVIEW(b))
+ cn->hash = NULL;
+ else
+ cn->hash = c->hash;
+ return bn;
+}
+
str
XIDcompress(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{
@@ -294,20 +327,14 @@ XIDcompress(Client cntxt, MalBlkPtr mb,
BAT *b, *bn;
BUN cnt;
str msg = MAL_SUCCEED;
- int ht, tt;
+ int ht, tt, htx, ttx;
oid hmin = 0, tmin = 0, hmax = oid_nil, tmax = oid_nil;
+ bit skip_h, skip_t;
(void) mb;
if ((b = BATdescriptor(*bid)) == NULL)
throw(MAL, "xid.compress", INTERNAL_BAT_ACCESS);
assert(ATOMtype(b->htype) == TYPE_oid || ATOMtype(b->ttype) ==
TYPE_oid);
- if (ATOMtype(b->htype) != TYPE_oid || ATOMtype(b->ttype) != TYPE_oid) {
- /* cannot (yet?) compress */
- mnstr_printf(cntxt->fdout,"#xid head or tail not oid
%d\n",getArg(pci,1));
- BBPkeepref(*ret = b->batCacheid);
- return MAL_SUCCEED;
- }
- assert(ATOMtype(b->htype) == TYPE_oid && ATOMtype(b->ttype) ==
TYPE_oid);
if (b->H->heap.xidcompressed || b->T->heap.xidcompressed) {
BBPreleaseref(b->batCacheid);
throw(MAL, "xid.compress", "cannot compress already
%s%scompressed BAT",
@@ -316,55 +343,77 @@ XIDcompress(Client cntxt, MalBlkPtr mb,
cnt = BATcount(b);
ht = b->htype;
tt = b->ttype;
- if ( isVIEW(b) || isVIEWCOMBINE(b) || cnt == 0 || (ht == TYPE_void &&
tt == TYPE_void) ) {
+ if ( isVIEWCOMBINE(b) || cnt == 0 || (ht == TYPE_void && tt !=
TYPE_oid) || (ht != TYPE_oid && tt == TYPE_void) ) {
/* no need to compress */
mnstr_printf(cntxt->fdout,"#xid %s view %d\n",(cnt==0 ?
"empty":""), getArg(pci,1));
BBPkeepref(*ret = b->batCacheid);
return MAL_SUCCEED;
}
- /* "compress" materialized into non-materialized dense OIDs */
- if (BAThdense(b))
- ht = TYPE_void;
- if (BATtdense(b))
- tt = TYPE_void;
- if (ht == TYPE_oid)
- getMinMaxNIL( b->H, cnt, (oid*)Hloc(b,BUNfirst(b)), &hmin,
&hmax );
- if (tt == TYPE_oid)
- getMinMaxNIL( b->T, cnt, (oid*)Tloc(b,BUNfirst(b)), &tmin,
&tmax );
- if ( (ht == TYPE_oid && hmax - hmin > XID_VAL_MAX) ||
- (tt == TYPE_oid && tmax - tmin > XID_VAL_MAX) ) {
- /* cannot (yet?) compress */
- mnstr_printf(cntxt->fdout,"#xid NIL or too large OID %d\n",
getArg(pci,1));
- BBPkeepref(*ret = b->batCacheid);
- return MAL_SUCCEED;
- }
if (cnt > XID_CNT_MAX) {
BBPreleaseref(b->batCacheid);
throw(MAL, "xid.compress", "original count too large");
}
- bn = BATnew(ht,tt, cnt+XID_IDX_BASE);
+
+ /* "compress" materialized into non-materialized dense OIDs */
+ htx = (BAThdense(b) ? TYPE_void : ht);
+ ttx = (BATtdense(b) ? TYPE_void : tt);
+ if (htx == TYPE_oid)
+ getMinMax( b->H, cnt, (oid*)Hloc(b,BUNfirst(b)), &hmin, &hmax );
+ if (ttx == TYPE_oid)
+ getMinMax( b->T, cnt, (oid*)Tloc(b,BUNfirst(b)), &tmin, &tmax );
+ skip_h = (ATOMtype(ht) != TYPE_oid || (htx == TYPE_oid && hmax - hmin >
XID_VAL_MAX));
+ skip_t = (ATOMtype(tt) != TYPE_oid || (ttx == TYPE_oid && tmax - tmin >
XID_VAL_MAX));
+ if ((skip_h || ht == TYPE_void) && (skip_t || tt == TYPE_void)) {
+ /* cannot (yet?) compress */
+ mnstr_printf(cntxt->fdout,"#xid NIL or too large OID %d\n",
getArg(pci,1));
+ BBPkeepref(*ret = b->batCacheid);
+ return MAL_SUCCEED;
+ }
+ if ( (!skip_h && htx == TYPE_oid && VIEWhparent(b)) || (!skip_t && ttx
== TYPE_oid && VIEWtparent(b)) ) {
+ /* no need to compress */
+ mnstr_printf(cntxt->fdout,"#xid %s view %d\n",(cnt==0 ?
"empty":""), getArg(pci,1));
+ BBPkeepref(*ret = b->batCacheid);
+ return MAL_SUCCEED;
+ }
+
+ bn = BATnew( (skip_h ? TYPE_void : htx), (skip_t ? TYPE_void : ttx),
cnt+XID_IDX_BASE );
if (bn == NULL) {
BBPreleaseref(b->batCacheid);
throw(MAL,"xid.compress", MAL_MALLOC_FAIL);
}
- msg = XIDcompressCol( cntxt, pci, b->H, bn->H, cnt, "head", ht,
(oid*)Hloc(b,BUNfirst(b)), (oid*)Hloc(b,BUNlast(b)), hmin );
- if (msg != MAL_SUCCEED) {
- BBPreleaseref(b->batCacheid);
- BBPreleaseref(bn->batCacheid);
- return msg;
+ if (!skip_h) {
+ msg = XIDcompressCol( cntxt, pci, b->H, bn->H, cnt, "head",
htx, (oid*)Hloc(b,BUNfirst(b)), (oid*)Hloc(b,BUNlast(b)), hmin );
+ if (msg != MAL_SUCCEED) {
+ BBPreleaseref(b->batCacheid);
+ BBPreleaseref(bn->batCacheid);
+ return msg;
+ }
}
- msg = XIDcompressCol( cntxt, pci, b->T, bn->T, cnt, "tail", tt,
(oid*)Tloc(b,BUNfirst(b)), (oid*)Tloc(b,BUNlast(b)), tmin );
- if (msg != MAL_SUCCEED) {
- BBPreleaseref(b->batCacheid);
- BBPreleaseref(bn->batCacheid);
- return msg;
+ if (!skip_t) {
+ msg = XIDcompressCol( cntxt, pci, b->T, bn->T, cnt, "tail",
ttx, (oid*)Tloc(b,BUNfirst(b)), (oid*)Tloc(b,BUNlast(b)), tmin );
+ if (msg != MAL_SUCCEED) {
+ BBPreleaseref(b->batCacheid);
+ BBPreleaseref(bn->batCacheid);
+ return msg;
+ }
}
if (bn->H->heap.xidcompressed || bn->T->heap.xidcompressed) {
- /* pretend to be empty as compressed content is not directly
useable */
- BATsetcount(bn, 0);
- bn->batDirty =1;
+ /* keep original count in case we inherit uncompressed head or
tail */
+ BATsetcount(bn, cnt);
+ bn->batDirty = 1;
+ assert(skip_h || bn->H->heap.xidcompressed || htx == TYPE_void);
+ assert(skip_t || bn->T->heap.xidcompressed || ttx == TYPE_void);
+ if (skip_h) {
+ /* inherit original uncompressed head as view */
+ bn = inheritCOL( bn, bn->H, b, b->H, VIEWhparent(b) );
+ }
+ if (skip_t) {
+ /* inherit original uncompressed tail as view */
+ bn = inheritCOL( bn, bn->T, b, b->T, VIEWtparent(b) );
+ }
+ //BATassertProps(bn);
BBPreleaseref(b->batCacheid);
BBPkeepref(*ret = bn->batCacheid);
} else {
@@ -506,10 +555,17 @@ XIDdecompress(Client cntxt, MalBlkPtr mb
BBPkeepref(*ret = b->batCacheid);
return MAL_SUCCEED;
}
- assert(ATOMtype(b->htype) == TYPE_oid && ATOMtype(b->ttype) ==
TYPE_oid);
- if (isVIEW(b)) {
+ if (isVIEWCOMBINE(b)) {
BBPreleaseref(b->batCacheid);
- throw(MAL, "xid.decompress", "cannot decompress view");
+ throw(MAL, "xid.decompress", "cannot decompress VIEWCOMBINE");
+ }
+ if (b->H->heap.xidcompressed && VIEWhparent(b)) {
+ BBPreleaseref(b->batCacheid);
+ throw(MAL, "xid.decompress", "cannot decompress head-VIEW");
+ }
+ if (b->T->heap.xidcompressed && VIEWtparent(b)) {
+ BBPreleaseref(b->batCacheid);
+ throw(MAL, "xid.decompress", "cannot decompress tail-VIEW");
}
if ( b->H->heap.xidcompressed ) {
@@ -519,29 +575,45 @@ XIDdecompress(Client cntxt, MalBlkPtr mb
if ( b->T->heap.xidcompressed ) {
col = (XIDcolumn) b->T->heap.base;
cap = (BUN) col[XID_IDX_ORIG].count;
- } else
+ } else {
cap = BATcount(b);
- bn = BATnew(b->htype, b->ttype, cap);
+ }
+ assert(cap == BATcount(b));
+
+ bn = BATnew((b->H->heap.xidcompressed ? b->htype : TYPE_void),
(b->T->heap.xidcompressed ? b->ttype : TYPE_void), cap);
if ( bn == NULL) {
BBPreleaseref(b->batCacheid);
throw(MAL, "xid.decompress", MAL_MALLOC_FAIL);
}
- msg = XIDdecompressCol( cntxt, pci, b->H, bn->H, "head", cap,
(oid*)Hloc(bn,BUNfirst(bn)) );
- if (msg != MAL_SUCCEED) {
- BBPreleaseref(b->batCacheid);
- BBPreleaseref(bn->batCacheid);
- return msg;
+ if (b->H->heap.xidcompressed || b->htype == TYPE_void) {
+ msg = XIDdecompressCol( cntxt, pci, b->H, bn->H, "head", cap,
(oid*)Hloc(bn,BUNfirst(bn)) );
+ if (msg != MAL_SUCCEED) {
+ BBPreleaseref(b->batCacheid);
+ BBPreleaseref(bn->batCacheid);
+ return msg;
+ }
}
- msg = XIDdecompressCol( cntxt, pci, b->T, bn->T, "tail", cap,
(oid*)Tloc(bn,BUNfirst(bn)) );
- if (msg != MAL_SUCCEED) {
- BBPreleaseref(b->batCacheid);
- BBPreleaseref(bn->batCacheid);
- return msg;
+ if (b->T->heap.xidcompressed || b->ttype == TYPE_void) {
+ msg = XIDdecompressCol( cntxt, pci, b->T, bn->T, "tail", cap,
(oid*)Tloc(bn,BUNfirst(bn)) );
+ if (msg != MAL_SUCCEED) {
+ BBPreleaseref(b->batCacheid);
+ BBPreleaseref(bn->batCacheid);
+ return msg;
+ }
}
BATsetcount(bn, cap);
- bn->batDirty =1;
+ bn->batDirty = 1;
+ if (!b->H->heap.xidcompressed && b->htype != TYPE_void) {
+ /* inherit original uncompressed head as view */
+ bn = inheritCOL( bn, bn->H, b, b->H, VIEWhparent(b) );
+ }
+ if (!b->T->heap.xidcompressed && b->ttype != TYPE_void) {
+ /* inherit original uncompressed tail as view */
+ bn = inheritCOL( bn, bn->T, b, b->T, VIEWtparent(b) );
+ }
+ //BATassertProps(bn);
BBPreleaseref(b->batCacheid);
BBPkeepref(*ret = bn->batCacheid);
return MAL_SUCCEED;
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list