[postgis-tickets] [SCM] PostGIS branch master updated. 3.1.0alpha1-105-g575ae85

git at osgeo.org git at osgeo.org
Fri May 8 06:27:07 PDT 2020


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PostGIS".

The branch, master has been updated
       via  575ae8580b36b093c90fb6fdde7c00c16cf2e755 (commit)
      from  b5bd6836d4617ebc924e804c42b60de637a94f60 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 575ae8580b36b093c90fb6fdde7c00c16cf2e755
Author: Raúl Marín <git at rmr.ninja>
Date:   Mon May 4 18:38:58 2020 +0200

    Change ST_AsGML(geometry) to use a C function direcly
    
    By using a inline SQL, the cache that lives in the upper context was
    deleted for each processed row (thus being ineffective)
    
    Closes #4674

diff --git a/postgis/geography_inout.c b/postgis/geography_inout.c
index 2e899ac..08f82ec 100644
--- a/postgis/geography_inout.c
+++ b/postgis/geography_inout.c
@@ -36,7 +36,7 @@
 #include "utils/array.h"
 #include "utils/builtins.h"  /* for pg_atoi */
 #include "lib/stringinfo.h"  /* For binary input */
-#include "catalog/pg_type.h" /* for CSTRINGOID */
+#include "catalog/pg_type.h" /* for CSTRINGOID, INT4OID */
 
 #include "liblwgeom.h"         /* For standard geometry types. */
 #include "lwgeom_cache.h"
diff --git a/postgis/lwgeom_export.c b/postgis/lwgeom_export.c
index 572be45..650f556 100644
--- a/postgis/lwgeom_export.c
+++ b/postgis/lwgeom_export.c
@@ -31,6 +31,7 @@
 #include "float.h" /* for DBL_DIG */
 
 #include "postgres.h"
+#include "catalog/pg_type.h" /* for INT4OID */
 #include "executor/spi.h"
 #include "utils/builtins.h"
 #include "utils/jsonb.h"
@@ -71,37 +72,55 @@ Datum LWGEOM_asGML(PG_FUNCTION_ARGS)
 	char *gml_id_buf, *prefix_buf;
 	text *prefix_text, *gml_id_text;
 
-
-	/* Get the version */
-	version = PG_GETARG_INT32(0);
-	if ( version != 2 && version != 3 )
+	/*
+	 * Two potential callers, one starts with GML version,
+	 * one starts with geometry, and we check for initial
+	 * argument type and then dynamically change what args
+	 * we read based on presence/absence
+	 */
+	Oid first_type = get_fn_expr_argtype(fcinfo->flinfo, 0);
+	int argnum = 0;
+	if (first_type != INT4OID)
 	{
-		elog(ERROR, "Only GML 2 and GML 3 are supported");
-		PG_RETURN_NULL();
+		version = 2;
+	}
+	else
+	{
+		/* Get the version */
+		version = PG_GETARG_INT32(argnum++);
+		if (version != 2 && version != 3)
+		{
+			elog(ERROR, "Only GML 2 and GML 3 are supported");
+			PG_RETURN_NULL();
+		}
 	}
 
 	/* Get the geometry */
-	if ( PG_ARGISNULL(1) ) PG_RETURN_NULL();
-	geom = PG_GETARG_GSERIALIZED_P(1);
+	if (PG_ARGISNULL(argnum))
+		PG_RETURN_NULL();
+	geom = PG_GETARG_GSERIALIZED_P(argnum++);
 
 	/* Retrieve precision if any (default is max) */
-	if (PG_NARGS() > 2 && !PG_ARGISNULL(2))
+	if (PG_NARGS() > argnum && !PG_ARGISNULL(argnum))
 	{
-		precision = PG_GETARG_INT32(2);
+		precision = PG_GETARG_INT32(argnum);
 		/* TODO: leave this to liblwgeom ? */
 		if (precision > DBL_DIG)
 			precision = DBL_DIG;
 		else if (precision < 0)
 			precision = 0;
 	}
+	argnum++;
 
 	/* retrieve option */
-	if (PG_NARGS() > 3 && !PG_ARGISNULL(3)) option = PG_GETARG_INT32(3);
+	if (PG_NARGS() > argnum && !PG_ARGISNULL(argnum))
+		option = PG_GETARG_INT32(argnum);
+	argnum++;
 
 	/* retrieve prefix */
-	if (PG_NARGS() >4 && !PG_ARGISNULL(4))
+	if (PG_NARGS() > argnum && !PG_ARGISNULL(argnum))
 	{
-		prefix_text = PG_GETARG_TEXT_P(4);
+		prefix_text = PG_GETARG_TEXT_P(argnum);
 		if ( VARSIZE(prefix_text) == VARHDRSZ )
 		{
 			prefix = "";
@@ -117,10 +136,11 @@ Datum LWGEOM_asGML(PG_FUNCTION_ARGS)
 			prefix = prefix_buf;
 		}
 	}
+	argnum++;
 
-	if (PG_NARGS() >5 && !PG_ARGISNULL(5))
+	if (PG_NARGS() > argnum && !PG_ARGISNULL(argnum))
 	{
-		gml_id_text = PG_GETARG_TEXT_P(5);
+		gml_id_text = PG_GETARG_TEXT_P(argnum);
 		if ( VARSIZE(gml_id_text) == VARHDRSZ )
 		{
 			gml_id = "";
@@ -134,6 +154,7 @@ Datum LWGEOM_asGML(PG_FUNCTION_ARGS)
 			gml_id = gml_id_buf;
 		}
 	}
+	argnum++;
 
 	srid = gserialized_get_srid(geom);
 	if (srid == SRID_UNKNOWN)      srs = NULL;
@@ -147,7 +168,7 @@ Datum LWGEOM_asGML(PG_FUNCTION_ARGS)
 	if (option & 8)
 	{
 		elog(ERROR,
-		     "Options %d passed to ST_AsGML(geography) sets "
+		     "Options %d passed to ST_AsGML(geometry) sets "
 		     "unsupported value 8",
 		     option);
 		PG_RETURN_NULL();
diff --git a/postgis/postgis.sql.in b/postgis/postgis.sql.in
index 523ed6c..3d72810 100644
--- a/postgis/postgis.sql.in
+++ b/postgis/postgis.sql.in
@@ -4659,8 +4659,8 @@ CREATE OR REPLACE FUNCTION _ST_AsGML(int4, geometry, int4, int4, text, text)
 -- Changed: 2.0.0 to have default args
 CREATE OR REPLACE FUNCTION ST_AsGML(geom geometry, maxdecimaldigits int4 DEFAULT 15, options int4 DEFAULT 0)
 	RETURNS TEXT
-	AS $$ SELECT @extschema at ._ST_AsGML(2, $1, $2, $3, null, null); $$
-	LANGUAGE 'sql' IMMUTABLE STRICT PARALLEL SAFE
+	AS 'MODULE_PATHNAME','LWGEOM_asGML'
+	LANGUAGE 'c' IMMUTABLE PARALLEL SAFE
 	_COST_MEDIUM;
 
 -- ST_AsGML(version, geom, precision, option)
@@ -4672,8 +4672,8 @@ CREATE OR REPLACE FUNCTION ST_AsGML(geom geometry, maxdecimaldigits int4 DEFAULT
 -- Availability: 2.1.0
 CREATE OR REPLACE FUNCTION ST_AsGML(version int4, geom geometry, maxdecimaldigits int4 DEFAULT 15, options int4 DEFAULT 0, nprefix text DEFAULT null, id text DEFAULT null)
 	RETURNS TEXT
-	AS $$ SELECT @extschema at ._ST_AsGML($1, $2, $3, $4, $5, $6); $$
-	LANGUAGE 'sql' IMMUTABLE PARALLEL SAFE
+	AS 'MODULE_PATHNAME','LWGEOM_asGML'
+	LANGUAGE 'c' IMMUTABLE PARALLEL SAFE
 	_COST_MEDIUM;
 
 -----------------------------------------------------------------------

-----------------------------------------------------------------------

Summary of changes:
 postgis/geography_inout.c |  2 +-
 postgis/lwgeom_export.c   | 53 +++++++++++++++++++++++++++++++++--------------
 postgis/postgis.sql.in    |  8 +++----
 3 files changed, 42 insertions(+), 21 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list