]> 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:41:00 +0000 (20:41 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Thu, 13 Sep 2018 20:41:00 +0000 (20:41 +0000)
Closes #4144

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

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

index a850c30efa1f87fa6a1ef85a2dff8392061b1a4f..39ee94992463d655673777e425d717156de0c3e0 100644 (file)
@@ -201,6 +201,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
 */
@@ -781,8 +787,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;
@@ -1386,6 +1396,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 7464364d81c4e6139ddb08ccfa7809142a1aafb9..1d599b68f93fb0c34cf02fcfb25a629a884cda5d 100644 (file)
@@ -1101,6 +1101,18 @@ from (
 -- #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;
 
index e721e59be4e3e3c513d83bbaee35bb764a77bb5f..f74000343cd7df6492613885884159bc9f87b618 100644 (file)
@@ -336,4 +336,5 @@ ERROR:  lwgeom_union: GEOS Error: TopologyException: Input geom 0 is invalid: Se
 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