]> granicus.if.org Git - postgis/commitdiff
Revert change to avoid slicing on box access.
authorPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 7 Nov 2018 17:56:00 +0000 (17:56 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 7 Nov 2018 17:56:00 +0000 (17:56 +0000)
References #4216

git-svn-id: http://svn.osgeo.org/postgis/branches/2.5@16995 b70326c6-7e19-0410-871a-916f4a2858ee

NEWS
liblwgeom/g_serialized.c
postgis/gserialized_gist_2d.c

diff --git a/NEWS b/NEWS
index 36b66bb0b4bb9c3617df2da902e00e4ee7c23659..a53f64d03d8974ce36a11463140cf8314a356f6f 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,7 @@ XXXX/XX/XX
     Praliaskouski)
   - #4223, ST_DistanceTree error for near parallel boxes (Paul Ramsey)
   - Schema qualify more functions for raster (Regina Obe)
+  - #4216, Revert non-sliced box access (Paul Ramsey)
 
 
 PostGIS 2.5.0
index c671ccc4a73d1c0b3dcaa0538f778c6b749033a7..011ef0d23145c531bcb528a809b83aa2aa567706 100644 (file)
@@ -86,6 +86,7 @@ uint32_t gserialized_header_size(const GSERIALIZED *gser)
 uint32_t gserialized_get_type(const GSERIALIZED *s)
 {
        uint32_t *ptr;
+       assert(s);
        ptr = (uint32_t*)(s->data);
        LWDEBUG(4,"entered");
        if ( FLAGS_GET_BBOX(s->flags) )
index fead715ce7bca531983b0136d6bc80ffdff1bf11..a44680aba5eae407aa6b7242c4b60981ede7ebda 100644 (file)
@@ -649,15 +649,18 @@ gserialized_datum_get_box2df_p(Datum gsdatum, BOX2DF *box2df)
        POSTGIS_DEBUG(4, "entered function");
 
        /*
-       ** Because geometry is declared as "storage = main" anything large
-       ** enough to take serious advantage of PG_DETOAST_DATUM_SLICE will have
-       ** already been compressed, which means the entire object will be
-       ** fetched and decompressed before a slice is taken, thus removing
-       ** any efficiencies gained from slicing. We need to move to
-       ** "storage = external" and implement our own geometry compressor
-       ** before we can take advantage of sliced retrieval.
+       ** The most info we need is the 8 bytes of serialized header plus the
+       ** of floats necessary to hold the bounding box.
        */
-       gpart = (GSERIALIZED*)PG_DETOAST_DATUM(gsdatum);
+       if (VARATT_IS_EXTENDED(gsdatum))
+       {
+               gpart = (GSERIALIZED*)PG_DETOAST_DATUM_SLICE(gsdatum, 0, 8 + sizeof(BOX2DF));
+       }
+       else
+       {
+               gpart = (GSERIALIZED*)PG_DETOAST_DATUM(gsdatum);
+       }
+
        flags = gpart->flags;
 
        POSTGIS_DEBUGF(4, "got flags %d", gpart->flags);
@@ -674,21 +677,27 @@ gserialized_datum_get_box2df_p(Datum gsdatum, BOX2DF *box2df)
        {
                /* No, we need to calculate it from the full object. */
                GBOX gbox;
+               GSERIALIZED *g = (GSERIALIZED*)PG_DETOAST_DATUM(gsdatum);
+
                gbox_init(&gbox);
 
-               result = gserialized_get_gbox_p(gpart, &gbox);
-               if ( result == LW_SUCCESS )
+               if (gserialized_get_gbox_p(g, &gbox) == LW_FAILURE)
                {
-                       result = box2df_from_gbox_p(&gbox, box2df);
-               }
-               else
-               {
-                       POSTGIS_DEBUG(4, "could not calculate bbox");
+                       POSTGIS_DEBUG(4, "could not calculate bbox, returning failure");
+                       POSTGIS_FREE_IF_COPY_P(gpart, gsdatum);
+                       POSTGIS_FREE_IF_COPY_P(g, gsdatum);
+                       return LW_FAILURE;
                }
+               POSTGIS_FREE_IF_COPY_P(g, gsdatum);
+               result = box2df_from_gbox_p(&gbox, box2df);
        }
 
        POSTGIS_FREE_IF_COPY_P(gpart, gsdatum);
-       POSTGIS_DEBUGF(4, "result = %d, got box2df %s", result, result == LW_SUCCESS ? box2df_to_string(box2df) : "NONE");
+
+       if ( result == LW_SUCCESS )
+       {
+               POSTGIS_DEBUGF(4, "got box2df %s", box2df_to_string(box2df));
+       }
 
        return result;
 }