Changeset: 9d099829ebf5 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/9d099829ebf5
Modified Files:
        gdk/gdk_rtree.c
        geom/monetdb5/geom.c
        geom/sql/40_geom.sql
Branch: geo-update-dev
Log Message:

Improved the RTREEdestroy function, changed the conditions for creating and 
persisting rtrees, changed the module of rtree functions.


diffs (136 lines):

diff --git a/gdk/gdk_rtree.c b/gdk/gdk_rtree.c
--- a/gdk/gdk_rtree.c
+++ b/gdk/gdk_rtree.c
@@ -2,21 +2,18 @@
 #include "gdk.h"
 #include "gdk_private.h"
 
-//TODO Why use BBPselectfarm?
 //TODO Check if we need to input RTREEdestroy into drop_index func in sql_cat.c
-
-//TODO Do we need to guard against dirty heap and deleted rows? -> Panos only 
does this for persisting, not creating
-//TODO Where do put the RTREEdestroy calls? We should invalidate on updates, 
deletes and inserts -> Check Panos impl
+//TODO Should you check if the parent BAT is null?
 
 //TODO Re-check the conditions
-/* Conditions to create and persist the RTree:
+/* Conditions to persist the RTree:
  * - BAT has to be persistent
  * - No deleted rows (when does batInserted update?)
  * - The heap is not dirty -> no new values
  * - DB Farm is persistent i.e. not in memory
  */
 static bool
-RTREEcreatecheck (BAT *b) {
+RTREEpersistcheck (BAT *b) {
        return ((BBP_status(b->batCacheid) & BBPEXISTING)
                && b->batInserted == b->batCount
                && !b->theap->dirty
@@ -47,7 +44,7 @@ RTREEincref(BAT *b)
 static gdk_return
 persistRtree (BAT *b)
 {
-       if (RTREEcreatecheck(b)) {
+       if (RTREEpersistcheck(b)) {
                //TODO Necessary?
                BBPfix(b->batCacheid);
                rtree_t *rtree = b->trtree->rtree;
@@ -141,6 +138,7 @@ RTREEexistsonfile(BAT *b) {
 
 //Check if RTree exists
 //We also check if it exists on file. If the index is not loaded, it will be
+//TODO Check for destroy -> it does not exist if destroy
 bool
 RTREEexists(BAT *b)
 {
@@ -190,7 +188,7 @@ BATrtree(BAT *wkb, BAT *mbr)
        }
 
        //Check if rtree already exists
-       if (pb->trtree == NULL && RTREEcreatecheck(pb)) {
+       if (pb->trtree == NULL) {
                //If it doesn't exist, take the lock to create/get the rtree
                MT_lock_set(&pb->batIdxLock);
 
@@ -229,7 +227,7 @@ BATrtree(BAT *wkb, BAT *mbr)
                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?
+       //TODO What do we do when the conditions are not right for creating the 
index?
        return GDK_SUCCEED;
 }
 
@@ -245,7 +243,7 @@ RTREEfree(BAT *b)
                pb = b;
        }
 
-       if (pb && pb->trtree->rtree) {
+       if (pb && pb->trtree) {
                MT_lock_set(&pb->batIdxLock);
                //Mark the RTree for destruction
                pb->trtree->destroy = true;
@@ -266,9 +264,8 @@ RTREEdestroy(BAT *b)
                pb = b;
        }
 
-       //TODO When there is a RTree index on file (i.e. not loaded yet) and 
this method is called, we should unlink the file (no need to touch refs)
-       if (pb && pb->trtree) {
-               MT_lock_set(&pb->batIdxLock);
+       MT_lock_set(&pb->batIdxLock);
+       if (pb->trtree) {
                //Mark the RTree for destruction
                pb->trtree->destroy = true;
                RTREEdecref(pb);
@@ -279,8 +276,18 @@ RTREEdestroy(BAT *b)
                                BBP_physical(b->batCacheid),
                                "bsrt");
                }
-               MT_lock_unset(&b->batIdxLock);
        }
+       //If the rtree is not loaded (pb->trtree is null), but there is a file 
with the index (from previous execution),
+       //we should remove the file
+       else if (RTREEexistsonfile(pb)) {
+               if (!GDKinmemory(pb->theap->farmid)) {
+                       GDKunlink(pb->theap->farmid,
+                               BATDIR,
+                               BBP_physical(b->batCacheid),
+                               "bsrt");
+               }
+       }
+       MT_lock_unset(&b->batIdxLock);
 }
 
 struct results_rtree {
diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c
--- a/geom/monetdb5/geom.c
+++ b/geom/monetdb5/geom.c
@@ -5513,9 +5513,13 @@ static mel_func geom_init_funcs[] = {
  command("geom", "IntersectsGeographicselect", wkbIntersectsGeographicSelect, 
false, "TODO", args(1, 5, batarg("", oid), batarg("b", wkb), batarg("s", oid), 
arg("c", wkb), arg("anti",bit))),
  command("geom", "IntersectsGeographicjoin", wkbIntersectsGeographicJoin, 
false, "TODO", args(2, 9, batarg("lr",oid),batarg("rr",oid), batarg("a", wkb), 
batarg("b", wkb), 
batarg("sl",oid),batarg("sr",oid),arg("nil_matches",bit),arg("estimate",lng),arg("anti",bit))),
 
- command("geom", "Intersects", wkbIntersects, false, "Returns true if these 
Geometries 'spatially intersect in 2D'", args(1,3, 
arg("",bit),arg("a",wkb),arg("b",wkb))),
- command("geom", "Intersectsselect", wkbIntersectsSelectRTree, false, "TODO", 
args(1, 5, batarg("", oid), batarg("b", wkb), batarg("s", oid), arg("c", wkb), 
arg("anti",bit))),
- command("geom", "Intersectsjoin", wkbIntersectsJoinRTree, false, "TODO", 
args(2, 8, batarg("lr",oid),batarg("rr",oid), batarg("a", wkb), batarg("b", 
wkb), 
batarg("sl",oid),batarg("sr",oid),arg("nil_matches",bit),arg("estimate",lng))),
+ command("rtree", "Intersects", wkbIntersects, false, "Returns true if these 
Geometries 'spatially intersect in 2D'", args(1,3, 
arg("",bit),arg("a",wkb),arg("b",wkb))),
+ command("rtree", "Intersectsselect", wkbIntersectsSelectRTree, false, "TODO", 
args(1, 5, batarg("", oid), batarg("b", wkb), batarg("s", oid), arg("c", wkb), 
arg("anti",bit))),
+ command("rtree", "Intersectsjoin", wkbIntersectsJoinRTree, false, "TODO", 
args(2, 8, batarg("lr",oid),batarg("rr",oid), batarg("a", wkb), batarg("b", 
wkb), 
batarg("sl",oid),batarg("sr",oid),arg("nil_matches",bit),arg("estimate",lng))),
+
+ //command("rtree", "DWithin", wkbIntersects, false, "Returns true if these 
Geometries 'spatially intersect in 2D'", args(1,3, 
arg("",bit),arg("a",wkb),arg("b",wkb))),
+ //command("rtree", "DWithinselect", wkbIntersectsSelectRTree, false, "TODO", 
args(1, 5, batarg("", oid), batarg("b", wkb), batarg("s", oid), arg("c", wkb), 
arg("anti",bit))),
+ //command("rtree", "DWithinjoin", wkbIntersectsJoinRTree, false, "TODO", 
args(2, 8, batarg("lr",oid),batarg("rr",oid), batarg("a", wkb), batarg("b", 
wkb), 
batarg("sl",oid),batarg("sr",oid),arg("nil_matches",bit),arg("estimate",lng))),
 
  command("geom", "Intersects_noindex", wkbIntersects, false, "Returns true if 
these Geometries 'spatially intersect in 2D'", args(1,3, 
arg("",bit),arg("a",wkb),arg("b",wkb))),
  command("geom", "Intersects_noindexselect", wkbIntersectsSelectNoIndex, 
false, "TODO", args(1, 5, batarg("", oid), batarg("b", wkb), batarg("s", oid), 
arg("c", wkb), arg("anti",bit))),
diff --git a/geom/sql/40_geom.sql b/geom/sql/40_geom.sql
--- a/geom/sql/40_geom.sql
+++ b/geom/sql/40_geom.sql
@@ -20,7 +20,7 @@ CREATE FILTER FUNCTION ST_DWithinGeograp
 CREATE FILTER FUNCTION ST_IntersectsGeographic(geom1 Geometry, geom2 Geometry) 
EXTERNAL NAME geom."IntersectsGeographic";
 
 CREATE FUNCTION ST_IntersectsMBR(mbr1 mbr, mbr2 mbr) RETURNS bool EXTERNAL 
NAME geom."IntersectsMBR";
-CREATE FILTER FUNCTION ST_Intersects(geom1 Geometry, geom2 Geometry) EXTERNAL 
NAME geom."Intersects";
+CREATE FILTER FUNCTION ST_Intersects(geom1 Geometry, geom2 Geometry) EXTERNAL 
NAME rtree."Intersects";
 CREATE FILTER FUNCTION ST_Intersects_NoIndex(geom1 Geometry, geom2 Geometry) 
EXTERNAL NAME geom."Intersects_noindex";
 -------------------------------------------------------------------------
 ------------------------- Geography functions ---------------------------
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to