[postgis-tickets] r17586 - Speed up ST_GeometryType

Raul raul at rmr.ninja
Tue Jul 9 08:43:19 PDT 2019


Author: algunenano
Date: 2019-07-09 08:43:19 -0700 (Tue, 09 Jul 2019)
New Revision: 17586

Modified:
   trunk/NEWS
   trunk/postgis/lwgeom_ogc.c
Log:
Speed up ST_GeometryType

Closes https://github.com/postgis/postgis/pull/434
Closes #4450



Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2019-07-09 15:33:24 UTC (rev 17585)
+++ trunk/NEWS	2019-07-09 15:43:19 UTC (rev 17586)
@@ -8,6 +8,7 @@
   - #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

Modified: trunk/postgis/lwgeom_ogc.c
===================================================================
--- trunk/postgis/lwgeom_ogc.c	2019-07-09 15:33:24 UTC (rev 17585)
+++ trunk/postgis/lwgeom_ogc.c	2019-07-09 15:43:19 UTC (rev 17586)
@@ -170,6 +170,23 @@
 	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 @@
 {
 	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);



More information about the postgis-tickets mailing list