[postgis-tickets] [SCM] PostGIS branch master updated. 3.2.0-682-gdf8f5ba41

git at osgeo.org git at osgeo.org
Tue Mar 29 16:48:34 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, master has been updated
       via  df8f5ba41e9d828b76aeb6d05aedc8bd9b054406 (commit)
      from  754c8f9cf7db20721426e3429ba90296cd5c2d37 (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 df8f5ba41e9d828b76aeb6d05aedc8bd9b054406
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 master branch (3.3.0dev)
    Includes regression test

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:
 postgis/gserialized_estimate.c        | 22 ++++++++++++++--------
 regress/core/estimatedextent.sql      | 24 ++++++++++++++++++++++++
 regress/core/estimatedextent_expected |  3 +++
 3 files changed, 41 insertions(+), 8 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list