From a45e90635c31affd2674d1a80f4d4f76053f33f3 Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Thu, 13 Sep 2018 20:41:00 +0000 Subject: [PATCH] Handle almost-infinite features when building table statistics in ANALYZE Closes #4144 git-svn-id: http://svn.osgeo.org/postgis/trunk@16788 b70326c6-7e19-0410-871a-916f4a2858ee --- postgis/gserialized_estimate.c | 17 +++++++++++++++-- regress/tickets.sql | 12 ++++++++++++ regress/tickets_expected | 1 + 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/postgis/gserialized_estimate.c b/postgis/gserialized_estimate.c index a850c30ef..39ee94992 100644 --- a/postgis/gserialized_estimate.c +++ b/postgis/gserialized_estimate.c @@ -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 diff --git a/regress/tickets.sql b/regress/tickets.sql index 7464364d8..1d599b68f 100644 --- a/regress/tickets.sql +++ b/regress/tickets.sql @@ -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; diff --git a/regress/tickets_expected b/regress/tickets_expected index e721e59be..f74000343 100644 --- a/regress/tickets_expected +++ b/regress/tickets_expected @@ -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 -- 2.40.0