[postgis-tickets] [SCM] PostGIS branch stable-3.0 updated. 3.0.6-26-ga91856fe4

git at osgeo.org git at osgeo.org
Wed Aug 17 11:16:04 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  a91856fe49cdef3675c781645039e927d1a346b4 (commit)
       via  295d6c71362698c4983dca62213a0140a7545b4c (commit)
      from  03c2128af64985ff75b23e601e7f3433a3217d8b (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 a91856fe49cdef3675c781645039e927d1a346b4
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Wed Aug 17 11:15:56 2022 -0700

    News entry for #5032

diff --git a/NEWS b/NEWS
index 50520365d..95f3ca1ce 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@ PostGIS 3.0.7dev
   - #5202, Guard against downgrades (Sandro Santilli)
   - #4643, Fix upgrade from unpackaged on PostgreSQL >= 13 (Sandro Santilli)
   - #5209, #5210, Fix upgrades with CVE-2022-2625 PostgreSQL fix
+  - #5032, Correctly read extent off multi-key GIST indexes (Paul Ramsey)
 
 PostGIS 3.0.6
 2022/07/20

commit 295d6c71362698c4983dca62213a0140a7545b4c
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Wed Aug 17 10:24:50 2022 -0700

    Correctly read geometry extent off multi-key GIST indexes. References #5032

diff --git a/postgis/gserialized_estimate.c b/postgis/gserialized_estimate.c
index 2bd422bb5..04ec120ca 100644
--- a/postgis/gserialized_estimate.c
+++ b/postgis/gserialized_estimate.c
@@ -140,8 +140,9 @@ Datum _postgis_gserialized_joinsel(PG_FUNCTION_ARGS);
 Datum _postgis_gserialized_stats(PG_FUNCTION_ARGS);
 
 /* Local prototypes */
-static Oid table_get_spatial_index(Oid tbl_oid, text *col, int *key_type);
-static GBOX * spatial_index_read_extent(Oid idx_oid, int key_type);
+static Oid table_get_spatial_index(Oid tbl_oid, text *col, int *key_type, int *att_num);
+static GBOX * spatial_index_read_extent(Oid idx_oid, int key_type, int att_num);
+
 
 /* Other prototypes */
 float8 gserialized_joinsel_internal(PlannerInfo *root, List *args, JoinType jointype, int mode);
@@ -2310,7 +2311,7 @@ Datum gserialized_estimated_extent(PG_FUNCTION_ARGS)
 	ND_STATS *nd_stats;
 	GBOX *gbox = NULL;
 	bool only_parent = false;
-	int key_type;
+	int key_type, att_num;
 	size_t sz;
 
 	/* We need to initialize the internal cache to access it later via postgis_oid() */
@@ -2356,13 +2357,12 @@ Datum gserialized_estimated_extent(PG_FUNCTION_ARGS)
 	}
 
 	/* 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);
-#endif
+
+	idx_oid = table_get_spatial_index(tbl_oid, col, &key_type, &att_num);
 	if (idx_oid)
 	{
 		/* TODO: how about only_parent ? */
-		gbox = spatial_index_read_extent(idx_oid, key_type);
+		gbox = spatial_index_read_extent(idx_oid, key_type, att_num);
 		POSTGIS_DEBUGF(2, "index for \"%s.%s\" exists, reading gbox from there", tbl, text_to_cstring(col));
 		if ( ! gbox ) PG_RETURN_NULL();
 	}
@@ -2428,7 +2428,7 @@ Datum geometry_estimated_extent(PG_FUNCTION_ARGS)
 /************************************************************************/
 
 static Oid
-table_get_spatial_index(Oid tbl_oid, text *col, int *key_type)
+table_get_spatial_index(Oid tbl_oid, text *col, int *key_type, int *att_num)
 {
 	Relation tbl_rel;
 	ListCell *lc;
@@ -2467,6 +2467,7 @@ table_get_spatial_index(Oid tbl_oid, text *col, int *key_type)
 		{
 			Form_pg_attribute att;
 			Oid atttypid;
+			int attnum;
 			/* Is the index on the column name we are looking for? */
 			HeapTuple att_tup = SearchSysCache2(ATTNAME,
 			                                    ObjectIdGetDatum(idx_oid),
@@ -2476,6 +2477,7 @@ table_get_spatial_index(Oid tbl_oid, text *col, int *key_type)
 
 			att = (Form_pg_attribute) GETSTRUCT(att_tup);
 			atttypid = att->atttypid;
+			attnum = att->attnum;
 			ReleaseSysCache(att_tup);
 
 			/* Is the column actually spatial? */
@@ -2483,6 +2485,8 @@ table_get_spatial_index(Oid tbl_oid, text *col, int *key_type)
 			{
 				/* Save result, clean up, and break out */
 				result = idx_oid;
+				if (att_num)
+					*att_num = attnum;
 				if (key_type)
 					*key_type = (atttypid == b2d_oid ? STATISTIC_SLOT_2D : STATISTIC_SLOT_ND);
 				break;
@@ -2493,7 +2497,7 @@ table_get_spatial_index(Oid tbl_oid, text *col, int *key_type)
 }
 
 static GBOX *
-spatial_index_read_extent(Oid idx_oid, int key_type)
+spatial_index_read_extent(Oid idx_oid, int key_type, int att_num)
 {
 	BOX2DF *bounds_2df = NULL;
 	GIDX *bounds_gidx = NULL;
@@ -2526,7 +2530,7 @@ spatial_index_read_extent(Oid idx_oid, int key_type)
 		if (!GistTupleIsInvalid(ituple))
 		{
 			bool isnull;
-			Datum idx_attr = index_getattr(ituple, 1, idx_rel->rd_att, &isnull);
+			Datum idx_attr = index_getattr(ituple, att_num, idx_rel->rd_att, &isnull);
 			if (!isnull)
 			{
 				if (key_type == STATISTIC_SLOT_2D)
@@ -2585,6 +2589,7 @@ Datum _postgis_gserialized_index_extent(PG_FUNCTION_ARGS)
 {
 	GBOX *gbox = NULL;
 	int key_type;
+	int att_num;
 	Oid tbl_oid = PG_GETARG_DATUM(0);
 	text *col = PG_GETARG_TEXT_P(1);
 	Oid idx_oid;
@@ -2595,11 +2600,11 @@ Datum _postgis_gserialized_index_extent(PG_FUNCTION_ARGS)
 	/* We need to initialize the internal cache to access it later via postgis_oid() */
 	postgis_initialize_cache(fcinfo);
 
-	idx_oid = table_get_spatial_index(tbl_oid, col, &key_type);
+	idx_oid = table_get_spatial_index(tbl_oid, col, &key_type, &att_num);
 	if (!idx_oid)
 		PG_RETURN_NULL();
 
-	gbox = spatial_index_read_extent(idx_oid, key_type);
+	gbox = spatial_index_read_extent(idx_oid, key_type, att_num);
 	if (!gbox)
 		PG_RETURN_NULL();
 	else

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

Summary of changes:
 NEWS                           |  1 +
 postgis/gserialized_estimate.c | 29 +++++++++++++++++------------
 2 files changed, 18 insertions(+), 12 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list