[postgis-tickets] [SCM] PostGIS branch master updated. 3.3.0rc1-29-geec975ea5

git at osgeo.org git at osgeo.org
Wed Aug 17 10:24:59 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  eec975ea5bec2390c986b0813cc3493fd09832bb (commit)
      from  d34a0d18f68f5c983aef58c2aad1943f8b91d65d (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 eec975ea5bec2390c986b0813cc3493fd09832bb
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 84b546266..56c685dfc 100644
--- a/postgis/gserialized_estimate.c
+++ b/postgis/gserialized_estimate.c
@@ -145,8 +145,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);
@@ -2309,7 +2310,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() */
@@ -2355,13 +2356,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();
 	}
@@ -2427,7 +2427,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;
@@ -2466,6 +2466,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),
@@ -2475,6 +2476,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? */
@@ -2482,6 +2484,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_KIND_2D : STATISTIC_KIND_ND);
 				break;
@@ -2492,7 +2496,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;
@@ -2525,7 +2529,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_KIND_2D)
@@ -2584,6 +2588,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;
@@ -2594,11 +2599,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();
 
-	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:
 postgis/gserialized_estimate.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list