]> granicus.if.org Git - postgis/commitdiff
Peformance patch for gist consistent.
authorPaul Ramsey <pramsey@cleverelephant.ca>
Sun, 12 Oct 2008 17:55:38 +0000 (17:55 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Sun, 12 Oct 2008 17:55:38 +0000 (17:55 +0000)
git-svn-id: http://svn.osgeo.org/postgis/branches/1.3@3092 b70326c6-7e19-0410-871a-916f4a2858ee

lwgeom/lwgeom_gist.c

index c32d016e55e4e96fc93574ba81ccd2cb060bf057..004b3989f7cedb967283361a4be2f079111c0562 100644 (file)
@@ -592,6 +592,7 @@ Datum LWGEOM_gist_consistent(PG_FUNCTION_ARGS)
        PG_LWGEOM *query ; /* lwgeom serialized form */
        StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
        bool result;
+       uchar *serialized_lwgeom;
        BOX2DFLOAT4  box;
 
 #ifdef PGIS_DEBUG_CALLS
@@ -604,7 +605,11 @@ Datum LWGEOM_gist_consistent(PG_FUNCTION_ARGS)
                PG_RETURN_BOOL(false); /* null query - this is screwy! */
        }
 
-       query = (PG_LWGEOM*)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
+       /* 
+       ** First pull only a small amount of the tuple, enough to 
+       ** get the bounding box, if one exists.
+       */
+       query = (PG_LWGEOM*)PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(1), 0, VARHDRSZ + 1 + sizeof(BOX2DFLOAT4) );
 
        if ( ! (DatumGetPointer(entry->key) != NULL && query) )
        {
@@ -613,10 +618,24 @@ Datum LWGEOM_gist_consistent(PG_FUNCTION_ARGS)
                PG_RETURN_BOOL(FALSE);
        }
 
-       if ( ! getbox2d_p(SERIALIZED_FORM(query), &box) )
+       /*
+       ** If the bounding box exists, copy it into the working variable.
+       ** If not, pull the full toasted data out, and call the standard box 
+       ** retrieval function, which will calculate the box from scratch.
+       */
+       serialized_lwgeom = SERIALIZED_FORM(query);
+       if( lwgeom_hasBBOX(serialized_lwgeom[0]) ) 
        {
-               PG_FREE_IF_COPY(query, 1);
-               PG_RETURN_BOOL(FALSE);
+               memcpy(&box, serialized_lwgeom + 1, sizeof(BOX2DFLOAT4));
+       } 
+       else 
+       {
+               query = (PG_LWGEOM*)PG_DETOAST_DATUM(PG_GETARG_DATUM(1)); 
+               if ( ! getbox2d_p(SERIALIZED_FORM(query), &box) )
+               {
+                       PG_FREE_IF_COPY(query, 1);
+                       PG_RETURN_BOOL(FALSE);
+               }
        }
 
        if (GIST_LEAF(entry))