From 6b1245d1257ca42762981699ed488fee6fea7640 Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Mon, 19 Nov 2012 23:04:21 +0000 Subject: [PATCH] Move box-reading code in geography stats to use serialized box. git-svn-id: http://svn.osgeo.org/postgis/trunk@10707 b70326c6-7e19-0410-871a-916f4a2858ee --- libpgcommon/gserialized_gist.h | 2 -- libpgcommon/lwgeom_pg.h | 8 ++++++++ postgis/geography_estimate.c | 15 +++++---------- postgis/geometry_estimate.c | 2 +- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/libpgcommon/gserialized_gist.h b/libpgcommon/gserialized_gist.h index 72b73d323..4f44f373c 100644 --- a/libpgcommon/gserialized_gist.h +++ b/libpgcommon/gserialized_gist.h @@ -92,8 +92,6 @@ int gserialized_get_gidx_p(GSERIALIZED *g, GIDX *gidx); /* Copy a new bounding box into an existing gserialized */ GSERIALIZED* gserialized_set_gidx(GSERIALIZED *g, GIDX *gidx); -/* Pull out a gbox bounding box as fast as possible. */ -int gserialized_datum_get_gbox_p(Datum gsdatum, GBOX *gbox); /* Given two datums, do they overlap? Computed very fast using embedded boxes. */ /* int gserialized_datum_overlaps(Datum gs1, Datum gs2); */ /* Remove the box from a disk serialization */ diff --git a/libpgcommon/lwgeom_pg.h b/libpgcommon/lwgeom_pg.h index 4dcef332d..ab3d3ce09 100644 --- a/libpgcommon/lwgeom_pg.h +++ b/libpgcommon/lwgeom_pg.h @@ -101,6 +101,14 @@ GSERIALIZED *geometry_serialize(LWGEOM *lwgeom); */ GSERIALIZED* geography_serialize(LWGEOM *lwgeom); +/** +* Pull out a gbox bounding box as fast as possible. +* Tries to read cached box from front of serialized vardata. +* If no cached box, calculates box from scratch. +* Fails on empty. +*/ +int gserialized_datum_get_gbox_p(Datum gsdatum, GBOX *gbox); + /** * Convert cstrings (null-terminated byte array) to textp pointers * (PgSQL varlena structure with VARSIZE header). diff --git a/postgis/geography_estimate.c b/postgis/geography_estimate.c index 6e7854bed..fcae2bb8d 100644 --- a/postgis/geography_estimate.c +++ b/postgis/geography_estimate.c @@ -453,8 +453,6 @@ Datum geography_gist_selectivity(PG_FUNCTION_ARGS) int geogstats_nvalues = 0; Node *other; Var *self; - GSERIALIZED *serialized; - LWGEOM *geometry; GBOX search_box; float8 selectivity = 0; @@ -509,15 +507,12 @@ Datum geography_gist_selectivity(PG_FUNCTION_ARGS) /* * Convert the constant to a GBOX */ - serialized = (GSERIALIZED *)PG_DETOAST_DATUM( ((Const*)other)->constvalue ); - geometry = lwgeom_from_gserialized(serialized); /* Convert coordinates to 3D geodesic */ FLAGS_SET_GEODETIC(search_box.flags, 1); - if (!lwgeom_calculate_gbox_geodetic(geometry, &search_box)) + if ( ! gserialized_datum_get_gbox_p(((Const*)other)->constvalue, &search_box) ) { POSTGIS_DEBUG(3, " search box cannot be calculated"); - PG_RETURN_FLOAT8(0.0); } @@ -863,11 +858,11 @@ compute_geography_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc, if (isnull) continue; - serialized = (GSERIALIZED *)PG_DETOAST_DATUM(datum); - geometry = lwgeom_from_gserialized(serialized); +// serialized = (GSERIALIZED *)PG_DETOAST_DATUM(datum); +// geometry = lwgeom_from_gserialized(serialized); /* Convert coordinates to 3D geodesic */ - if (!lwgeom_calculate_gbox_geodetic(geometry, &gbox)) + if ( ! gserialized_datum_get_gbox_p(datum, &gbox) ) { /* Unable to obtain or calculate a bounding box */ POSTGIS_DEBUGF(3, "skipping geometry at position %d", i); @@ -912,7 +907,7 @@ compute_geography_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc, } /** TODO: ask if we need geom or bvol size for stawidth */ - total_width += serialized->size; + total_width += VARSIZE(serialized); #if USE_STANDARD_DEVIATION /* diff --git a/postgis/geometry_estimate.c b/postgis/geometry_estimate.c index c1ef09dc9..9ba5954da 100644 --- a/postgis/geometry_estimate.c +++ b/postgis/geometry_estimate.c @@ -905,7 +905,7 @@ compute_geometry_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc, } /** TODO: ask if we need geom or bvol size for stawidth */ - total_width += geom->size; + total_width += VARSIZE(geom); total_boxes_area += (box.xmax-box.xmin)*(box.ymax-box.ymin); #if USE_STANDARD_DEVIATION -- 2.40.0