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

Paul Ramsey pramsey at cleverelephant.ca
Thu Sep 13 01:38:02 PDT 2018


Author: pramsey
Date: 2018-09-13 13:38:01 -0700 (Thu, 13 Sep 2018)
New Revision: 16787

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


Modified: branches/2.4/postgis/gserialized_estimate.c
===================================================================
--- branches/2.4/postgis/gserialized_estimate.c	2018-09-13 20:28:48 UTC (rev 16786)
+++ branches/2.4/postgis/gserialized_estimate.c	2018-09-13 20:38:01 UTC (rev 16787)
@@ -158,6 +158,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
@@ -735,8 +741,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;
@@ -1338,6 +1348,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.4/regress/tickets.sql
===================================================================
--- branches/2.4/regress/tickets.sql	2018-09-13 20:28:48 UTC (rev 16786)
+++ branches/2.4/regress/tickets.sql	2018-09-13 20:38:01 UTC (rev 16787)
@@ -1041,5 +1041,17 @@
 ) as points;
 
 
+-- #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.4/regress/tickets_expected
===================================================================
--- branches/2.4/regress/tickets_expected	2018-09-13 20:28:48 UTC (rev 16786)
+++ branches/2.4/regress/tickets_expected	2018-09-13 20:38:01 UTC (rev 16787)
@@ -310,3 +310,4 @@
 #4055b|4326
 #4089|LINESTRING Z (1 1 1,3 3 1)
 #4081|f|t
+NOTICE:  table "bug_4144_table" does not exist, skipping



More information about the postgis-tickets mailing list