Changeset: c8ed99d620c5 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/c8ed99d620c5
Modified Files:
gdk/gdk.h
gdk/gdk_rtree.c
geom/monetdb5/geomBulk.c
Branch: geo-update-dev
Log Message:
Use non-index version of intersects if RTree was not created, fixes to
RTREEexists and RTree initialization
diffs (167 lines):
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -1874,6 +1874,7 @@ typedef struct mbr_t {
} mbr_t;
gdk_export bool RTREEexists(BAT *b);
+gdk_export bool RTREEexists_bid(bat *bid);
gdk_export gdk_return BATrtree(BAT *wkb, BAT* mbr);
gdk_export BUN* RTREEsearch(BAT *b, mbr_t *inMBR, int result_limit);
gdk_export void RTREEdestroy(BAT *b);
diff --git a/gdk/gdk_rtree.c b/gdk/gdk_rtree.c
--- a/gdk/gdk_rtree.c
+++ b/gdk/gdk_rtree.c
@@ -108,20 +108,38 @@ BATcheckrtree(BAT *b) {
fclose(file_stream);
return GDK_FAIL;
}
+ b->trtree = GDKmalloc(sizeof(struct RTree));
b->trtree->rtree = rtree;
+ b->trtree->destroy = false;
+ ATOMIC_INIT(&b->trtree->refs, 1);
fclose(file_stream);
+ return GDK_SUCCEED;
}
else {
GDKerror("%s",strerror(errno));
close(fd);
return GDK_FAIL;
}
- b->trtree->destroy = false;
- ATOMIC_INIT(&b->trtree->refs, 1);
- return GDK_SUCCEED;
+}
+
+//Check if RTree exists on file (previously created index)
+static bool
+RTREEexistsonfile(BAT *b) {
+ const char * filename = BBP_physical(b->batCacheid);
+ int farmid = b->theap->farmid;
+ int fd = GDKfdlocate(farmid, filename, "r", "bsrt");
+
+ //Do we have the rtree on file?
+ if (fd == -1)
+ return false;
+ else {
+ close(fd);
+ return true;
+ }
}
//Check if RTree exists
+//We also check if it exists on file. If the index is not loaded, it will be
bool
RTREEexists(BAT *b)
{
@@ -135,13 +153,25 @@ RTREEexists(BAT *b)
}
MT_lock_set(&pb->batIdxLock);
- ret = pb->trtree->rtree != NULL;
+ ret = (pb->trtree != NULL || RTREEexistsonfile(pb));
MT_lock_unset(&pb->batIdxLock);
return ret;
}
+bool
+RTREEexists_bid(bat *bid)
+{
+ BAT *b;
+ bool ret;
+ if ((b = BATdescriptor(*bid)) == NULL)
+ return false;
+ ret = RTREEexists(b);
+ BBPunfix(b->batCacheid);
+ return ret;
+}
+
gdk_return
BATrtree(BAT *wkb, BAT *mbr)
{
@@ -159,12 +189,12 @@ BATrtree(BAT *wkb, BAT *mbr)
}
//Check if rtree already exists
- if (pb->trtree->rtree == NULL && RTREEcreatecheck(pb)) {
+ if (pb->trtree == NULL && RTREEcreatecheck(pb)) {
//If it doesn't exist, take the lock to create/get the rtree
MT_lock_set(&pb->batIdxLock);
//Try to load it from disk
- if (BATcheckrtree(pb) == GDK_SUCCEED && pb->trtree->rtree !=
NULL) {
+ if (BATcheckrtree(pb) == GDK_SUCCEED && pb->trtree != NULL) {
MT_lock_unset(&pb->batIdxLock);
return GDK_SUCCEED;
}
@@ -191,12 +221,14 @@ BATrtree(BAT *wkb, BAT *mbr)
rtree_add_rect(rtree,rtree_id,rect);
}
bat_iterator_end(&bi);
+ pb->trtree = GDKmalloc(sizeof(struct RTree));
pb->trtree->rtree = rtree;
pb->trtree->destroy = false;
ATOMIC_INIT(&pb->trtree->refs, 1);
persistRtree(pb);
MT_lock_unset(&pb->batIdxLock);
}
+ //TODO What do we do when the conditions are not right for creating the
index? Or when it already exists?
return GDK_SUCCEED;
}
diff --git a/geom/monetdb5/geomBulk.c b/geom/monetdb5/geomBulk.c
--- a/geom/monetdb5/geomBulk.c
+++ b/geom/monetdb5/geomBulk.c
@@ -50,19 +50,13 @@ filterSelectRTree(bat* outid, const bat
throw(MAL, name, SQLSTATE(HY013) MAL_MALLOC_FAIL);
}
- if (!RTREEexists(b)) {
- //TODO Do we create RTree on the first thread that gets here?
- }
-
//Calculate the MBR for the constant geometry
mbr *const_mbr = NULL;
wkbMBR(&const_mbr,&wkb_const);
//Get a candidate list from searching on the rtree with the constant mbr
//Note: the candidates returned from RTREEsearch are BUNs not OIDs
- BUN* results_rtree = NULL;
- if (RTREEexists(b))
- results_rtree = RTREEsearch(b,(mbr_t*)const_mbr, b->batCount);
+ BUN* results_rtree = RTREEsearch(b,(mbr_t*)const_mbr, b->batCount);
//Cycle through rtree candidates
//If there is a original candidate list, make sure the rtree cand is in
there
@@ -124,7 +118,7 @@ filterSelectNoIndex(bat* outid, const ba
BAT *out = NULL, *b = NULL, *s = NULL;
BATiter b_iter;
struct canditer ci;
- GEOSGeom col_geom, const_geom;
+ GEOSGeom const_geom, col_geom;
//WKB constant is NULL
if ((const_geom = wkb2geos(wkb_const)) == NULL) {
@@ -186,6 +180,7 @@ filterSelectNoIndex(bat* outid, const ba
}
GEOSGeom_destroy(col_geom);
}
+
GEOSGeom_destroy(const_geom);
bat_iterator_end(&b_iter);
BBPunfix(b->batCacheid);
@@ -198,7 +193,11 @@ filterSelectNoIndex(bat* outid, const ba
str
wkbIntersectsSelectRTree(bat* outid, const bat *bid , const bat *sid, wkb
**wkb_const, bit *anti) {
- return
filterSelectRTree(outid,bid,sid,*wkb_const,*anti,GEOSIntersects,"geom.wkbIntersectsSelectRTree");
+ //If there is an RTree on memory or on file, use the RTree method.
Otherwise, use the no index version.
+ if (RTREEexists_bid((bat*)bid))
+ return
filterSelectRTree(outid,bid,sid,*wkb_const,*anti,GEOSIntersects,"geom.wkbIntersectsSelectRTree");
+ else
+ return
filterSelectNoIndex(outid,bid,sid,*wkb_const,*anti,GEOSIntersects,"geom.wkbIntersectsSelectNoIndex");
}
str
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]