]> granicus.if.org Git - postgis/commitdiff
Handle almost-infinite features when building table statistics in ANALYZE
authorPaul Ramsey <pramsey@cleverelephant.ca>
Thu, 13 Sep 2018 20:38:01 +0000 (20:38 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Thu, 13 Sep 2018 20:38:01 +0000 (20:38 +0000)
References #4144

git-svn-id: http://svn.osgeo.org/postgis/branches/2.4@16787 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/gserialized_estimate.c
regress/tickets.sql
regress/tickets_expected

index 104a5f3ebad39d4f5e95a6bfd2acb9a78a32c67b..aa04a807fa6e2cfd6e50c9b21fc7c806be418b70 100644 (file)
@@ -157,6 +157,12 @@ Datum geometry_estimated_extent(PG_FUNCTION_ARGS);
 */
 #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
 */
@@ -735,8 +741,12 @@ nd_box_array_distribution(const ND_BOX **nd_boxes, int num_boxes, const ND_BOX *
                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 @@ compute_gserialized_stats_mode(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfu
        /* 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
index abd3649de8f45eec060f9e1640c7b285d58f4ec5..28c23b5a762134cc52e4ce63be59d86855e77f60 100644 (file)
@@ -1041,5 +1041,17 @@ from (
 ) 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;
index b8af393067a9885c9b376d4d6ad101b74f160105..48178f6762663d4f3e82e0803c6aba24a376470c 100644 (file)
@@ -310,3 +310,4 @@ ERROR:  invalid KML representation
 #4055b|4326
 #4089|LINESTRING Z (1 1 1,3 3 1)
 #4081|f|t
+NOTICE:  table "bug_4144_table" does not exist, skipping