[postgis-tickets] r16786 - Handle almost-infinite features when building table statistics in ANALYZE

Paul Ramsey pramsey at cleverelephant.ca
Thu Sep 13 01:28:48 PDT 2018


Author: pramsey
Date: 2018-09-13 13:28:48 -0700 (Thu, 13 Sep 2018)
New Revision: 16786

Modified:
   branches/2.5/postgis/gserialized_estimate.c
   branches/2.5/regress/tickets.sql
   branches/2.5/regress/tickets_expected
Log:
Handle almost-infinite features when building table statistics in ANALYZE
References #4144


Modified: branches/2.5/postgis/gserialized_estimate.c
===================================================================
--- branches/2.5/postgis/gserialized_estimate.c	2018-09-13 19:25:24 UTC (rev 16785)
+++ branches/2.5/postgis/gserialized_estimate.c	2018-09-13 20:28:48 UTC (rev 16786)
@@ -203,6 +203,12 @@
 #define MIN_DIMENSION_WIDTH 0.000000001
 
 /**
+* Maximum width of a dimension that we'll bother trying to
+* compute statistics on.
+*/
+#define MAX_DIMENSION_WIDTH 1.0E+20
+
+/**
 * Default geometry selectivity factor
 */
 #define DEFAULT_ND_SEL 0.0001
@@ -782,8 +788,12 @@
 		smax = extent->max[d];
 		swidth = smax - smin;
 
-		/* Don't try and calculate distribution of overly narrow dimensions */
-		if ( swidth < MIN_DIMENSION_WIDTH )
+		/* Don't try and calculate distribution of overly narrow */
+		/* or overly wide dimensions. Here we're being pretty geographical, */
+		/* expecting "normal" planar or geographic coordinates. */
+		/* Otherwise we have to "handle" +/- Inf bounded features and */
+		/* the assumptions needed for that are as bad as this hack. */
+		if ( swidth < MIN_DIMENSION_WIDTH || swidth > MAX_DIMENSION_WIDTH )
 		{
 			distribution[d] = 0;
 			continue;
@@ -1386,6 +1396,9 @@
 	/* Initialize sum and stddev */
 	nd_box_init(&sum);
 	nd_box_init(&stddev);
+	nd_box_init(&avg);
+	nd_box_init(&histo_extent);
+	nd_box_init(&histo_extent_new);
 
 	/*
 	 * This is where gserialized_analyze_nd

Modified: branches/2.5/regress/tickets.sql
===================================================================
--- branches/2.5/regress/tickets.sql	2018-09-13 19:25:24 UTC (rev 16785)
+++ branches/2.5/regress/tickets.sql	2018-09-13 20:28:48 UTC (rev 16786)
@@ -1101,6 +1101,18 @@
 -- #4164
 SELECT ST_AsText(ST_GeomFromGeoJSON('{"type": "Polygon", "coordinates": [[0,0],[0,5],[5, 5],[5,0],[0,0]]}'));
 
+-- #4144
+DROP TABLE IF EXISTS bug_4144_table;
+CREATE TABLE bug_4144_table (
+  geom geometry NOT NULL DEFAULT NULL
+);
+
+INSERT INTO bug_4144_table (geom) 
+  VALUES ('GEOMETRYCOLLECTION(POINT(-3.385894e+38 0 0),POINT(0 0 0))');
+
+ANALYZE bug_4144_table;
+DROP TABLE IF EXISTS bug_4144_table;
+
 -- Clean up
 DELETE FROM spatial_ref_sys;
 

Modified: branches/2.5/regress/tickets_expected
===================================================================
--- branches/2.5/regress/tickets_expected	2018-09-13 19:25:24 UTC (rev 16785)
+++ branches/2.5/regress/tickets_expected	2018-09-13 20:28:48 UTC (rev 16786)
@@ -336,4 +336,5 @@
 ERROR:  lwgeom_pointonsurface: GEOS Error: TopologyException: Input geom 1 is invalid: Self-intersection
 #4081|f|t
 ERROR:  The 'coordinates' in GeoJSON polygon are not sufficiently nested
+NOTICE:  table "bug_4144_table" does not exist, skipping
 #4176|t



More information about the postgis-tickets mailing list