Replace WARNING about skipped stats with a SELECT
authorTomas Vondra <tomas@2ndquadrant.com>
Thu, 13 Jul 2017 18:58:06 +0000 (20:58 +0200)
committerTomas Vondra <tomas@2ndquadrant.com>
Thu, 13 Jul 2017 18:58:06 +0000 (20:58 +0200)
ANALYZE throws a WARNING that extended statistics was not built due to
statistics target being 0 for some of the columns, but that gets thrown
on the datanode and we never forward it to the coordinator.

So explicitly check contents of pg_statistic_ext if the statistic was
built or not.

src/test/regress/expected/stats_ext.out
src/test/regress/sql/stats_ext.sql

index 45aa599cc2851337bf618f28658928e229a08220..2194c5a342567a64975c4a61efb768765bc5f227 100644 (file)
@@ -79,12 +79,37 @@ ALTER TABLE ab1 ALTER a SET STATISTICS 0;
 INSERT INTO ab1 SELECT a, a%23 FROM generate_series(1, 1000) a;
 CREATE STATISTICS ab1_a_b_stats ON a, b FROM ab1;
 ANALYZE ab1;
-WARNING:  statistics object "public.ab1_a_b_stats" could not be computed for relation "public.ab1"
+SELECT
+  (stxndistinct IS NOT NULL) AS ndistinct,
+  (stxdependencies IS NOT NULL) AS dependencies
+FROM pg_statistic_ext WHERE stxname = 'ab1_a_b_stats';
+ ndistinct | dependencies 
+-----------+--------------
+ f         | f
+(1 row)
+
 ALTER TABLE ab1 ALTER a SET STATISTICS -1;
 -- partial analyze doesn't build stats either
 ANALYZE ab1 (a);
-WARNING:  statistics object "public.ab1_a_b_stats" could not be computed for relation "public.ab1"
+SELECT
+  (stxndistinct IS NOT NULL) AS ndistinct,
+  (stxdependencies IS NOT NULL) AS dependencies
+FROM pg_statistic_ext WHERE stxname = 'ab1_a_b_stats';
+ ndistinct | dependencies 
+-----------+--------------
+ f         | f
+(1 row)
+
 ANALYZE ab1;
+SELECT
+  (stxndistinct IS NOT NULL) AS ndistinct,
+  (stxdependencies IS NOT NULL) AS dependencies
+FROM pg_statistic_ext WHERE stxname = 'ab1_a_b_stats';
+ ndistinct | dependencies 
+-----------+--------------
+ t         | t
+(1 row)
+
 DROP TABLE ab1;
 -- Verify supported object types for extended statistics
 CREATE schema tststats;
index 2a02f8e0acc3a1f85569312176651b2062a47fd2..9e90842d616d4562a936275aa0cc3b1ac0106c2a 100644 (file)
@@ -49,10 +49,22 @@ ALTER TABLE ab1 ALTER a SET STATISTICS 0;
 INSERT INTO ab1 SELECT a, a%23 FROM generate_series(1, 1000) a;
 CREATE STATISTICS ab1_a_b_stats ON a, b FROM ab1;
 ANALYZE ab1;
+SELECT
+  (stxndistinct IS NOT NULL) AS ndistinct,
+  (stxdependencies IS NOT NULL) AS dependencies
+FROM pg_statistic_ext WHERE stxname = 'ab1_a_b_stats';
 ALTER TABLE ab1 ALTER a SET STATISTICS -1;
 -- partial analyze doesn't build stats either
 ANALYZE ab1 (a);
+SELECT
+  (stxndistinct IS NOT NULL) AS ndistinct,
+  (stxdependencies IS NOT NULL) AS dependencies
+FROM pg_statistic_ext WHERE stxname = 'ab1_a_b_stats';
 ANALYZE ab1;
+SELECT
+  (stxndistinct IS NOT NULL) AS ndistinct,
+  (stxdependencies IS NOT NULL) AS dependencies
+FROM pg_statistic_ext WHERE stxname = 'ab1_a_b_stats';
 DROP TABLE ab1;
 
 -- Verify supported object types for extended statistics