Changeset: 9efa05e8bf56 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9efa05e8bf56
Modified Files:
monetdb5/extras/crackers/crackers_selecthol_ops.mx
Branch: holindex
Log Message:
Add "updates" in holistic indexing operators.
diffs (truncated from 535 to 300 lines):
diff --git a/monetdb5/extras/crackers/crackers_selecthol_ops.mx
b/monetdb5/extras/crackers/crackers_selecthol_ops.mx
--- a/monetdb5/extras/crackers/crackers_selecthol_ops.mx
+++ b/monetdb5/extras/crackers/crackers_selecthol_ops.mx
@@ -32,7 +32,6 @@ All Rights Reserved.
* @- Type expansion
*/
@= TypeSwitch
-@:@1(bte,simple,,bte)@
@:@1(sht,simple,,sht)@
@:@1(int,simple,,int)@
@:@1(lng,simple,,lng)@
@@ -261,6 +260,17 @@ CRKthetauselecthol_@1(int *vid, int *bid
CRKcrackUnorderedZero@2_RE_@1(b,*low, cl1, ch1,&vl);
else
CRKcrackUnorderedZero@2_LE_@1(b,*low, cl1, ch1,&vl);
+
+ if (vl < cl1){
+ /*then the left piece is empty*/
+ gapL = -1;
+ }
+ if (vl > ch1){
+ /*then the right piece is empty*/
+ /*vl--;*/
+ gapL = -1;
+ }
+
vl++; /* We need to take next position because the crack function
always returns the last bun of the left piece.
Instead we want the first bun of the right piece*/
@@ -272,6 +282,14 @@ CRKthetauselecthol_@1(int *vid, int *bid
else
CRKcrackUnorderedZero@2_RE_@1(b,*hgh, cl2, ch2,&vh);
+ if (vh < cl2)
+ /*then the left piece is empty*/
+ gapH = -1;
+ if (vh > ch2){
+ /*then the right piece is empty*/
+ gapH = -1;
+ /*vh--;*/
+ }
@
@= CreateResult
createView:
@@ -302,6 +320,11 @@ createView:
oid _vl=0,temp_vl=0,temp_vh=0;
bit HBound, foundLow=0, foundHgh=0;
bit LBound=FALSE;
+ int gapL = 1;
+ int gapH = 1;
+ bit rippledDeletions = FALSE;
+ struct Node *lowNode=NULL, *hghNode=NULL, *lowNodeNext=NULL, *temp;
+ BUN idxFirst;
bit copy=TRUE;
@@ -453,7 +476,43 @@ createView:
if ((b = BATdescriptor(CrackerIndex[m].cbid)) == NULL)
throw(MAL, "crackers.crackRange", "Cannot access crack index");
+ idxFirst = BUNfirst(c);
+
+ /* deal with pending deletions if any */
+
+ if (CrackerIndex[m].mergeDeletions >= 0){
+ str msg = selectMergeDeletionsPart_@1(bid, low, inclusiveLow,
hgh, inclusiveHgh, &rippledDeletions, m);
+ if (msg != NULL)
+ throw(MAL, "crackers.crackRange", "%s", msg);
+ }
+
+ if (CrackerIndex[m].mergeDeletions == 2 && rippledDeletions == FALSE){
+ lowNode = findNodeL_@1(*low, *inclusiveLow,
CrackerIndex[m].Tree, c, idxFirst, NULL);
+ if (lowNode == NULL){
+ lowNodeNext = NULL;
+ temp = CrackerIndex[m].Tree;
+ if (temp->deleted == FALSE)
+ lowNodeNext = temp;
+ while (temp->left != NULL){
+ temp = temp->left;
+ if (temp->deleted == FALSE)
+ lowNodeNext = temp;
+ }
+ } else
+ lowNodeNext = findNextPiece(lowNode);
+
+ shiftHoles_@1(lowNode, lowNodeNext, b, c, idxFirst, hgh,
inclusiveHgh, m);
+ }
+
+ /* deal with pending insertions if any */
+ if (CrackerIndex[m].mergeInsertions >= 0){
+ str msg;
+ msg = selectMergeInsertionsPart_@1(bid, low, inclusiveLow, hgh,
inclusiveHgh, m);
+ if (msg != NULL)
+ throw(MAL, "crackers.crackRange", "%s", msg);
+ }
+
/* find out where in the index the low falls */
foundLow = GetLow_@1(*low, *inclusiveLow, CrackerIndex[m].Tree, c,
BUNfirst(c), &cl1, &ch1, 0, BUNlast(b)-(oid)1,&LBound);
@@ -467,7 +526,39 @@ createView:
/*printf("cl1 "OIDFMT" cl2 "OIDFMT" ", cl1,cl2 );*/
-
+ /* find the hols if any in the pieces to crack so that cracking does
not touch deleted buns */
+ if (CrackerIndex[m].mergeDeletions == 2){
+ oid holsLow = 0, holsHgh = 0;
+ /* if not done before while shifting hols find lowNode and
lowNodeNext */
+ if (rippledDeletions == TRUE){
+ lowNode = findNodeL_@1(*low, *inclusiveLow,
CrackerIndex[m].Tree, c, idxFirst, NULL);
+ if (lowNode == NULL){
+ lowNodeNext = NULL;
+ temp = CrackerIndex[m].Tree;
+ if (temp->deleted == FALSE)
+ lowNodeNext = temp;
+ while (temp->left != NULL){
+ temp = temp->left;
+ if (temp->deleted == FALSE)
+ lowNodeNext = temp;
+ }
+ } else
+ lowNodeNext = findNextPiece(lowNode);
+ }
+
+ hghNode = findNodeH_@1(*hgh, *inclusiveHgh,
CrackerIndex[m].Tree, c, idxFirst, NULL);
+ if (lowNodeNext != NULL)
+ holsLow = lowNodeNext->hols;
+
+ if (hghNode != NULL)
+ holsHgh = hghNode->hols;
+
+ /* so if there are hols the positions where we crack are
appropriately decreased */
+ ch1 -= holsLow;
+ ch2 -= holsHgh;
+ }
+
+
if((foundLow!=0 && foundHgh!=0)&&(isIdleQuery!=1)) FN->f2 = FN->f2 + 1;
/* If one or both of the result view bounds were not found using the
@@ -488,7 +579,7 @@ createView:
if (IndexSize <IndexStop)
{
- addCrackerIndex_@1(m,hgh,HBound,vh,c);
+ if (gapH>0)
addCrackerIndex_@1(m,hgh,HBound,vh,c);
FN->c = FN->c + 1;
}
@@ -502,7 +593,7 @@ createView:
if (IndexSize <IndexStop){
if (vl>0) _vl=vl-1; else _vl=vl;
-
addCrackerIndex_@1(m,low,*inclusiveLow,_vl,c);
+ if (gapL>0)
addCrackerIndex_@1(m,low,*inclusiveLow,_vl,c);
FN->c = FN->c + 1;
temp_vl=vl;
}
@@ -535,7 +626,7 @@ createView:
if (IndexSize <IndexStop){
if (vl>0) _vl=vl-1; else _vl=vl;
- addCrackerIndex_@1(m,low,*inclusiveLow,_vl,c);
+ if (gapL>0)
addCrackerIndex_@1(m,low,*inclusiveLow,_vl,c);
FN->c = FN->c + 1;
}
foundHgh = GetHgh_@1(*hgh, *inclusiveHgh,
CrackerIndex[m].Tree, c, BUNfirst(c), &cl2, &ch2, 0, BUNlast(b)-(oid)1);
@@ -548,7 +639,7 @@ createView:
if (IndexSize <IndexStop)
{
- addCrackerIndex_@1(m,hgh,HBound,vh,c);
+ if (gapH>0)
addCrackerIndex_@1(m,hgh,HBound,vh,c);
FN->c = FN->c + 1;
}
@@ -584,6 +675,285 @@ createView:
@
@= crackOperations
+static oid
+shiftHoles_@1(struct Node *lowNode, struct Node *lowNodeNext, BAT *b, BAT *c,
BUN idxFirst, @1 *hgh, bit *inclusiveHgh, int position){
+ oid holSize = 0, LposCr = 0, HposCr = 0, holPiece = 0, buns;
+ oid *fh;
+ @1 *ft;
+ oid *hghPos = NULL;
+ struct Node *hghNode, *stopNode;
+
+ fh = (oid*)Hloc(b, BUNfirst(b));
+ ft = (@1 *)Tloc(b, BUNfirst(b));
+ stopNode = findNodeH_@1(*hgh, *inclusiveHgh,
CrackerIndex[position].Tree, c, idxFirst, NULL);
+
+ while (1){
+ if (lowNode == NULL)
+ hghNode = lowNodeNext;
+ else
+ hghNode = findNextPiece(lowNode);
+
+ /* find deletes that belong in this piece */
+ if (lowNode != NULL && hghNode != NULL){
+ hghPos = (oid*)Hloc(c, idxFirst +
hghNode->position);
+ LposCr = *(oid*)Hloc(c, idxFirst + lowNode->position) +
holSize;
+ HposCr = *hghPos;
+ } else
+ if (lowNode == NULL && hghNode != NULL){
+ hghPos = (oid*)Hloc(c, idxFirst +
hghNode->position);
+ LposCr = 0;
+ HposCr = *hghPos;
+ } else
+ if (lowNode != NULL && hghNode == NULL){
+ LposCr = *(oid*)Hloc(c, idxFirst + lowNode->position) +
holSize;
+ HposCr = BATcount(b)-1;
+ }
+
+ if (hghNode != NULL)
+ holPiece = hghNode->hols;
+ else
+ holPiece = 0;
+
+ HposCr -= holPiece;
+ buns = HposCr - LposCr;
+ /* no need to to shift if nothing has been deleted from
previous pieces */
+ if (holSize > 0 && buns > 0){
+ if (holSize >= buns){
+ memcpy(fh+(LposCr-(holSize-1)), fh+(LposCr+1),
buns*sizeof(oid));
+ memcpy(ft+(LposCr-(holSize-1)), ft+(LposCr+1),
buns*sizeof(@1 ));
+ }
+ else{
+ memcpy(fh+(LposCr-(holSize-1)),
fh+(LposCr+1+(buns-holSize)), holSize*sizeof(oid));
+ memcpy(ft+(LposCr-(holSize-1)),
ft+(LposCr+1+(buns-holSize)), holSize*sizeof(@1 ));
+ }
+ }
+ holSize += holPiece;
+ if (hghNode != NULL){
+ if (hghNode == stopNode)
+ break;
+ hghNode->hols = 0;
+ lowNode = hghNode;
+ *hghPos = *hghPos - holSize;
+ } else
+ break;
+ }
+
+ if (holSize > 0){
+ if (hghNode == NULL){
+ /*BUN crkLast = BUNlast(b) - holSize;
+ b->batBuns->free = crkLast - b->batBuns->base;*/
+ BATsetcount(b, BUNlast(b)-holSize);
+ } else
+ hghNode->hols = holSize;
+ }
+
+ return holSize;
+}
+
+
+static str
+selectMergeDeletionsPart_@1(int *bid, @1 *low, bit *inclusiveLow, @1 *hgh, bit
*inclusiveHgh, bit *rippledDeletions, int position){
+ BAT *u;
+ oid updates, updatesStart, updatesEnd;
+ BUN l;
+ @1 *lt, *updLast, *t0 ;
+
+ if (CrackerIndex[position].did == -1) return NULL;
+ if ((u = BATdescriptor(CrackerIndex[position].did)) == NULL)
+ return "Cannot access the deletions BAT";
+
+ if (CrackerIndex[position].mergeInsertions > 0){
+ BAT *insertions, *intersect;
+ if (CrackerIndex[position].iid < 0) goto findDeletes;
+ if ((insertions =
BATdescriptor(CrackerIndex[position].iid)) == NULL)
+ goto findDeletes;
+ if (BATcount(insertions)==0) {
+ BBPunfix(insertions->batCacheid);
+ goto findDeletes;
+ }
+
+ intersect = BATsintersect(insertions,u);
+
+ if (BATcount(intersect)>0){
+ insertions = BATdel(insertions,intersect,TRUE);
+ u = BATdel(u,intersect,TRUE);
+ }
+
+ BBPunfix(intersect->batCacheid);
+ BBPunfix(insertions->batCacheid);
+ }
+
+ findDeletes:;
+
+ updates = BATcount(u);
+ if (updates == 0){
+ BBPunfix(u->batCacheid);
+ return NULL; /* no qualifying values in the deletions */
+ }
+
+ /* if necessary, sort in place the deletions bat */
+ if (u->tsorted == FALSE){
+ u->batRestricted = BAT_WRITE;
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list