postgis.git / summary / log / commit / refs
commit 7b3effebd8b00be30c046c8d2291eccc28fbd7bc
Author: Raúl Marín <git@rmr.ninja>
Date: Tue Jul 21 12:36:16 2020 +0000
Optimize ST_ClipByBox2d(compressed_geom, bbox) when the geom is fully outside the bbox
libpgcommon/gserialized_gist.c | 18 ++++++++----------
libpgcommon/lwgeom_pg.h | 5 +++++
postgis/lwgeom_geos.c | 7 +++++--
3 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/libpgcommon/gserialized_gist.c b/libpgcommon/gserialized_gist.c
index 4aad26e86..89a391d35 100644
--- a/libpgcommon/gserialized_gist.c
+++ b/libpgcommon/gserialized_gist.c
@@ -166,6 +166,13 @@ gserialized_datum_get_gbox_p(Datum gsdatum, GBOX *gbox)
return LW_SUCCESS;
}
+void
+gserialized_datum_get_type_and_srid_p(Datum gsdatum, uint8_t *type, int32_t *srid)
+{
+ GSERIALIZED *gpart = (GSERIALIZED *)PG_DETOAST_DATUM_SLICE(gsdatum, 0, gserialized_max_header_size());
+ *type = gserialized_get_type(gpart);
+ *srid = gserialized_get_srid(gpart);
+}
/**
* Peak into a #GSERIALIZED datum to find the bounding box. If the
@@ -176,16 +183,7 @@ gserialized_datum_get_gbox_p(Datum gsdatum, GBOX *gbox)
int
gserialized_datum_get_gidx_p(Datum gsdatum, GIDX *gidx)
{
- GSERIALIZED *gpart;
-
- POSTGIS_DEBUG(4, "entered function");
-
- /*
- ** The most info we need is the 8 bytes of serialized header plus the 32 bytes
- ** of floats necessary to hold the 8 floats of the largest XYZM index
- ** bounding box, so 40 bytes.
- */
- gpart = (GSERIALIZED *)PG_DETOAST_DATUM_SLICE(gsdatum, 0, gserialized_max_header_size());
+ GSERIALIZED *gpart = (GSERIALIZED *)PG_DETOAST_DATUM_SLICE(gsdatum, 0, gserialized_max_header_size());
/* Do we even have a serialized bounding box? */
if (gserialized_has_bbox(gpart))
diff --git a/libpgcommon/lwgeom_pg.h b/libpgcommon/lwgeom_pg.h
index 64e35ae97..032678d71 100644
--- a/libpgcommon/lwgeom_pg.h
+++ b/libpgcommon/lwgeom_pg.h
@@ -186,6 +186,11 @@ void gserialized_error_if_srid_mismatch_reference(const GSERIALIZED *g1, const i
*/
int gserialized_datum_get_gbox_p(Datum gsdatum, GBOX *gbox);
+/**
+ * Pull the type and srid of a datum (containing a GSERIALIZEDs)
+ */
+void gserialized_datum_get_type_and_srid_p(Datum gsdatum, uint8_t *type, int32_t *srid);
+
/* PG-exposed */
Datum BOX2D_same(PG_FUNCTION_ARGS);
Datum BOX2D_overlap(PG_FUNCTION_ARGS);
diff --git a/postgis/lwgeom_geos.c b/postgis/lwgeom_geos.c
index c8ac4ff7a..9c328d748 100644
--- a/postgis/lwgeom_geos.c
+++ b/postgis/lwgeom_geos.c
@@ -1524,17 +1524,20 @@ Datum ST_ClipByBox2d(PG_FUNCTION_ARGS)
PG_RETURN_DATUM(PG_GETARG_DATUM(geom_idx));
}
- lwgeom1 = lwgeom_from_gserialized(PG_GETARG_GSERIALIZED_P(geom_idx));
/* If bbox1 outside of bbox2, return empty */
if (!gbox_overlaps_2d(&bbox1, bbox2))
{
+ uint8_t type;
+ int32_t srid;
+ gserialized_datum_get_type_and_srid_p(PG_GETARG_DATUM(geom_idx), &type, &srid);
/* Get type and srid from datum */
- lwresult = lwgeom_construct_empty(lwgeom1->type, lwgeom1->srid, 0, 0);
+ lwresult = lwgeom_construct_empty(type, srid, 0, 0);
result = geometry_serialize(lwresult) ;
lwgeom_free(lwresult) ;
PG_RETURN_POINTER(result);
}
+ lwgeom1 = lwgeom_from_gserialized(PG_GETARG_GSERIALIZED_P(geom_idx));
lwresult = lwgeom_clip_by_rect(lwgeom1, bbox2->xmin, bbox2->ymin,
bbox2->xmax, bbox2->ymax);
[parent: 864294821174]