[postgis-tickets] [SCM] PostGIS branch stable-3.2 updated. 3.2.1-10-g15fab4096

git at osgeo.org git at osgeo.org
Tue Mar 29 17:15:20 PDT 2022


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, stable-3.2 has been updated
       via  15fab4096e99c44b7e17c0ded22e59fddb09a5c6 (commit)
      from  16d19f0a5b9915166a9f52b75c426b06c78e7c49 (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 15fab4096e99c44b7e17c0ded22e59fddb09a5c6
Author: Sandro Santilli <strk at kbt.io>
Date:   Wed Mar 30 01:21:35 2022 +0200

    Have ST_EstimatedExtent take a NULL box from index as definitive
    
    References #5120 in 3.2 branch (3.2.2dev)
    Includes regression test

diff --git a/NEWS b/NEWS
index 8f393f631..bef5b6d51 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,8 @@ PostGIS 3.2.2dev
 2022/MM/DD
 
 * Bug Fixes *
+  - #5120, Fix not-null result from ST_EstimatedExtent against
+           truncated tables with spatial index (Sandro Santilli)
   - #5115, Allow dropping topologies with pending constraints
            (Sandro Santilli)
   - #5105, Fix false invalidity report from ValidateTopology
diff --git a/postgis/gserialized_estimate.c b/postgis/gserialized_estimate.c
index 9875ca978..eee95e0f4 100644
--- a/postgis/gserialized_estimate.c
+++ b/postgis/gserialized_estimate.c
@@ -2316,7 +2316,7 @@ Datum gserialized_estimated_extent(PG_FUNCTION_ARGS)
 	char *tbl = NULL;
 	text *col = NULL;
 	char *nsp_tbl = NULL;
-	Oid tbl_oid, idx_oid;
+	Oid tbl_oid, idx_oid = 0;
 	ND_STATS *nd_stats;
 	GBOX *gbox = NULL;
 	bool only_parent = false;
@@ -2361,17 +2361,23 @@ Datum gserialized_estimated_extent(PG_FUNCTION_ARGS)
 		PG_RETURN_NULL();
 	}
 
-#if 1
 	/* Read the extent from the head of the spatial index, if there is one */
+#if 1
 	idx_oid = table_get_spatial_index(tbl_oid, col, &key_type);
-	if (!idx_oid)
-		POSTGIS_DEBUGF(2, "index for \"%s.%s\" does not exist", tbl, text_to_cstring(col));
-	gbox = spatial_index_read_extent(idx_oid, key_type);
 #endif
-
-	/* Fall back to reading the stats, if no index answer */
-	if (!gbox)
+	if (idx_oid)
 	{
+		/* TODO: how about only_parent ? */
+		gbox = spatial_index_read_extent(idx_oid, key_type);
+		POSTGIS_DEBUGF(2, "index for \"%s.%s\" exists, reading gbox from there", tbl, text_to_cstring(col));
+		if ( ! gbox ) PG_RETURN_NULL();
+	}
+	else
+	{
+		POSTGIS_DEBUGF(2, "index for \"%s.%s\" does not exist", tbl, text_to_cstring(col));
+
+		/* Fall back to reading the stats, if no index is found */
+
 		/* Estimated extent only returns 2D bounds, so use mode 2 */
 		nd_stats = pg_get_nd_stats_by_name(tbl_oid, col, 2, only_parent);
 
diff --git a/regress/core/estimatedextent.sql b/regress/core/estimatedextent.sql
index efe90121a..e7d08aef7 100644
--- a/regress/core/estimatedextent.sql
+++ b/regress/core/estimatedextent.sql
@@ -179,6 +179,30 @@ from ( select ST_EstimatedExtent('public','c1','g', 't') as e offset 0 ) AS e;
 
 drop table p cascade;
 
+
+-- #5120
+BEGIN;
+CREATE TABLE t(g geometry);
+INSERT INTO t SELECT ST_MakePoint(n,n) FROM generate_series(0,10) n;
+ANALYZE t;
+SELECT '#5120.without_index', ST_AsText(
+	ST_BoundingDiagonal(ST_EstimatedExtent('t','g')),
+	0
+);
+CREATE INDEX ON t USING GIST (g);
+SELECT '#5120.with_index', ST_AsText(
+	ST_BoundingDiagonal(ST_EstimatedExtent('t','g')),
+	0
+);
+TRUNCATE t;
+--DELETE FROM t; -- requires VACUUM to clean index
+--VACUUM t; -- drops entries from index (cannot run within transaction)
+SELECT '#5120.without_data', ST_AsText(
+	ST_BoundingDiagonal(ST_EstimatedExtent('t','g')),
+	0
+);
+ROLLBACK;
+
 --
 -- Index assisted extent generation
 --
diff --git a/regress/core/estimatedextent_expected b/regress/core/estimatedextent_expected
index b25c0e6f6..a28486cb5 100644
--- a/regress/core/estimatedextent_expected
+++ b/regress/core/estimatedextent_expected
@@ -36,6 +36,9 @@ WARNING:  stats for "p.g" do not exist
 #3391.19|0.00|1.00|0.00|1.00
 #3391.20|0.00|1.00|0.00|1.00
 NOTICE:  drop cascades to 2 other objects
+#5120.without_index|LINESTRING(0 0,10 10)
+#5120.with_index|LINESTRING(0 0,10 10)
+#5120.without_data|
 1.a null|
 1.b null|
 2.a null|

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

Summary of changes:
 NEWS                                  |  2 ++
 postgis/gserialized_estimate.c        | 22 ++++++++++++++--------
 regress/core/estimatedextent.sql      | 24 ++++++++++++++++++++++++
 regress/core/estimatedextent_expected |  3 +++
 4 files changed, 43 insertions(+), 8 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list