]> granicus.if.org Git - postgis/commitdiff
Speed up ST_GeometryType
authorRaúl Marín Rodríguez <rmrodriguez@carto.com>
Tue, 9 Jul 2019 15:43:19 +0000 (15:43 +0000)
committerRaúl Marín Rodríguez <rmrodriguez@carto.com>
Tue, 9 Jul 2019 15:43:19 +0000 (15:43 +0000)
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
postgis/lwgeom_ogc.c

diff --git a/NEWS b/NEWS
index 902fd75cba7916d6906396ea9927cc2cf7edf46e..693a96da79af9e582e11ee83292a668a15dbaa5e 100644 (file)
--- 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
index 38dbbc07456ffacacf0e2953cbca5b243db8a7e0..80997e195b605a84d3533851073092988e9138a2 100644 (file)
@@ -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);