[postgis-tickets] r17191 - Improve notice message when unable to compute stats

Raul raul at rmr.ninja
Mon Jan 21 08:44:29 PST 2019


Author: algunenano
Date: 2019-01-21 08:44:29 -0800 (Mon, 21 Jan 2019)
New Revision: 17191

Modified:
   trunk/NEWS
   trunk/postgis/gserialized_estimate.c
   trunk/regress/core/estimatedextent.sql
   trunk/regress/core/estimatedextent_expected
Log:
Improve notice message when unable to compute stats

Closes #4272
Closes https://github.com/postgis/postgis/pull/364


Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2019-01-18 21:57:54 UTC (rev 17190)
+++ trunk/NEWS	2019-01-21 16:44:29 UTC (rev 17191)
@@ -65,6 +65,7 @@
   - #4289, ST_AsMVTGeom: Transform coordinates space before clipping (Raúl Marín)
   - #4275, Avoid passing a NULL pointer to GEOSisEmpty (Raúl Marín)
   - #4296, Use `server_version_num` instead of parsing `version()` (Raúl Marín)
+  - #4272, Improve notice message when unable to compute stats (Raúl Marín)
 
 
 PostGIS 2.5.0

Modified: trunk/postgis/gserialized_estimate.c
===================================================================
--- trunk/postgis/gserialized_estimate.c	2019-01-18 21:57:54 UTC (rev 17190)
+++ trunk/postgis/gserialized_estimate.c	2019-01-21 16:44:29 UTC (rev 17191)
@@ -1523,7 +1523,12 @@
 	/* If there's no useful features, we can't work out stats */
 	if ( ! notnull_cnt )
 	{
-		elog(NOTICE, "no non-null/empty features, unable to compute statistics");
+		Oid relation_oid = stats->attr->attrelid;
+		char *relation_name = get_rel_name(relation_oid);
+		elog(NOTICE,
+		     "PostGIS: Unable to compute statistics for \"%s.%s\": No non-null/empty features",
+		     relation_name ? relation_name : "(NULL)",
+		     stats->attr->attname.data);
 		stats->stats_valid = false;
 		return;
 	}
@@ -1854,8 +1859,12 @@
 {
 	/* 2D Mode */
 	compute_gserialized_stats_mode(stats, fetchfunc, sample_rows, total_rows, 2);
-	/* ND Mode */
-	compute_gserialized_stats_mode(stats, fetchfunc, sample_rows, total_rows, 0);
+
+	if (stats->stats_valid)
+	{
+		/* ND Mode: Only computed if 2D was computed too (not NULL and valid) */
+		compute_gserialized_stats_mode(stats, fetchfunc, sample_rows, total_rows, 0);
+	}
 }
 
 

Modified: trunk/regress/core/estimatedextent.sql
===================================================================
--- trunk/regress/core/estimatedextent.sql	2019-01-18 21:57:54 UTC (rev 17190)
+++ trunk/regress/core/estimatedextent.sql	2019-01-21 16:44:29 UTC (rev 17191)
@@ -206,3 +206,10 @@
 -- select '6.b null', _postgis_index_extent('test', 'geom2');
 drop table test cascade;
 
+-- Check NOTICE message
+create table test (id serial primary key, geom1 geometry, geom2 geometry);
+insert into test (geom1, geom2) select NULL, NULL;
+insert into test (geom1, geom2) select NULL, NULL;
+insert into test (geom1, geom2) select NULL, NULL;
+ANALYZE test;
+drop table test cascade;
\ No newline at end of file

Modified: trunk/regress/core/estimatedextent_expected
===================================================================
--- trunk/regress/core/estimatedextent_expected	2019-01-18 21:57:54 UTC (rev 17190)
+++ trunk/regress/core/estimatedextent_expected	2019-01-21 16:44:29 UTC (rev 17191)
@@ -47,3 +47,5 @@
 3.b null|
 4.a box|BOX(-100 -100,100 100)
 4.b box|BOX(-200 -200,200 200)
+NOTICE:  PostGIS: Unable to compute statistics for "test.geom1": No non-null/empty features
+NOTICE:  PostGIS: Unable to compute statistics for "test.geom2": No non-null/empty features



More information about the postgis-tickets mailing list