[postgis-tickets] [SCM] PostGIS branch stable-3.0 updated. 3.0.5-4-ge1b72b53e
git at osgeo.org
git at osgeo.org
Tue Mar 29 17:15:29 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.0 has been updated
via e1b72b53e4feee02e749e91ca011d5c72e845f71 (commit)
from 5c1acb6629ee2fb5f03e9fe10270525770e2c41f (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 e1b72b53e4feee02e749e91ca011d5c72e845f71
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
Closes #5120 in 3.0 branch (3.0.6dev)
Includes regression test
diff --git a/NEWS b/NEWS
index 7c9b46afb..ef2fde126 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,4 @@
-PostGIS 3.0.6
+PostGIS 3.0.6dev
2022/XX/XX
* Bug Fixes and Enhancements *
@@ -6,6 +6,8 @@ PostGIS 3.0.6
and note in docs, PostgreSQL > 13 major
is not supported (Regina Obe)
- #5115, Allow dropping topologies with pending constraints (Sandro Santilli)
+ - #5120, Fix not-null result from ST_EstimatedExtent against
+ truncated tables with spatial index (Sandro Santilli)
PostGIS 3.0.5
2022/02/02
diff --git a/postgis/gserialized_estimate.c b/postgis/gserialized_estimate.c
index f94441ca3..7540ba11b 100644
--- a/postgis/gserialized_estimate.c
+++ b/postgis/gserialized_estimate.c
@@ -2306,7 +2306,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;
@@ -2351,17 +2351,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..7b94bb78a 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(1,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 0cf866bce..1329685e8 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(1 1,10 10)
+#5120.with_index|LINESTRING(1 1,10 10)
+#5120.without_data|
1.a null|
1.b null|
2.a null|
-----------------------------------------------------------------------
Summary of changes:
NEWS | 4 +++-
postgis/gserialized_estimate.c | 22 ++++++++++++++--------
regress/core/estimatedextent.sql | 24 ++++++++++++++++++++++++
regress/core/estimatedextent_expected | 3 +++
4 files changed, 44 insertions(+), 9 deletions(-)
hooks/post-receive
--
PostGIS
More information about the postgis-tickets
mailing list