From 4498a19f96b12a66ee9d219d071d27d25b71f65a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ra=C3=BAl=20Mar=C3=ADn=20Rodr=C3=ADguez?= Date: Tue, 9 Jul 2019 15:43:19 +0000 Subject: [PATCH] Speed up ST_GeometryType Closes https://github.com/postgis/postgis/pull/434 Closes #4450 git-svn-id: http://svn.osgeo.org/postgis/trunk@17586 b70326c6-7e19-0410-871a-916f4a2858ee --- NEWS | 1 + postgis/lwgeom_ogc.c | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/NEWS b/NEWS index 902fd75cb..693a96da7 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,7 @@ Additional features enabled if you are running Proj6+ and PostgreSQL 12 - #4433 32-bit hash fix (requires reindexing hash(geometry) indexes) (Raúl Marín) - #4445, Fix a bug in geometry_le (Raúl Marín) - #4451, Fix the calculation of gserialized_max_header_size (Raúl Marín) + - #4450, Speed up ST_GeometryType (Raúl Marín) PostGIS 3.0.0alpha3 diff --git a/postgis/lwgeom_ogc.c b/postgis/lwgeom_ogc.c index 38dbbc074..80997e195 100644 --- a/postgis/lwgeom_ogc.c +++ b/postgis/lwgeom_ogc.c @@ -170,6 +170,23 @@ Datum LWGEOM_getTYPE(PG_FUNCTION_ARGS) PG_RETURN_TEXT_P(text_ob); } +/* Matches lwutil.c::lwgeomTypeName */ +static char *stTypeName[] = {"Unknown", + "ST_Point", + "ST_LineString", + "ST_Polygon", + "ST_MultiPoint", + "ST_MultiLineString", + "ST_MultiPolygon", + "ST_GeometryCollection", + "ST_CircularString", + "ST_CompoundCurve", + "ST_CurvePolygon", + "ST_MultiCurve", + "ST_MultiSurface", + "ST_PolyhedralSurface", + "ST_Triangle", + "ST_Tin"}; /* returns a string representation of this geometry's type */ PG_FUNCTION_INFO_V1(geometry_geometrytype); @@ -177,21 +194,12 @@ Datum geometry_geometrytype(PG_FUNCTION_ARGS) { GSERIALIZED *gser; text *type_text; -# define type_str_len 31 - char type_str[type_str_len + 1]; /* Read just the header from the toasted tuple */ gser = PG_GETARG_GSERIALIZED_P_SLICE(0, 0, gserialized_max_header_size()); - /* Make it empty string to start */ - type_str[0] = 0; - - /* Build up the output string */ - strncat(type_str, "ST_", type_str_len); - strncat(type_str, lwtype_name(gserialized_get_type(gser)), type_str_len - 3); - /* Build a text type to store things in */ - type_text = cstring_to_text(type_str); + type_text = cstring_to_text(stTypeName[gserialized_get_type(gser)]); PG_FREE_IF_COPY(gser, 0); PG_RETURN_TEXT_P(type_text); -- 2.40.0