From 72b7c8402467b643785f7a3d3b4eeb7f575e3091 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Fri, 12 May 2017 17:35:49 -0300 Subject: [PATCH 2/2] add AUTO dependency on table --- src/backend/commands/statscmds.c | 7 +++++++ src/test/regress/expected/stats_ext.out | 6 ++---- src/test/regress/sql/stats_ext.sql | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/backend/commands/statscmds.c b/src/backend/commands/statscmds.c index d3b5430369..46ccaeabac 100644 --- a/src/backend/commands/statscmds.c +++ b/src/backend/commands/statscmds.c @@ -323,6 +323,13 @@ CreateStatistics(CreateStatsStmt *stmt) } /* + * Also add an AUTO dependency on the table itself. If the table is gone, + * we don't require a CASCADE in order to also drop the statistics object. + */ + ObjectAddressSet(parentobject, RelationRelationId, relid); + recordDependencyOn(&childobject, &parentobject, DEPENDENCY_AUTO); + + /* * Also add dependency on the schema. This is required to ensure that we * drop the statistics on DROP SCHEMA. This is not handled automatically * by DROP TABLE because the statistics might be in a different schema diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out index f2ae0ab80f..242a6bfff5 100644 --- a/src/test/regress/expected/stats_ext.out +++ b/src/test/regress/expected/stats_ext.out @@ -62,8 +62,7 @@ NOTICE: drop cascades to 2 other objects Statistics: "public"."ab1_b_c_stats" (ndistinct, dependencies) ON b, c FROM ab1 -DROP TABLE ab1 CASCADE; -NOTICE: drop cascades to statistics object ab1_b_c_stats +DROP TABLE ab1; \set VERBOSITY default -- Ensure things work sanely with SET STATISTICS 0 CREATE TABLE ab1 (a INTEGER, b INTEGER); @@ -77,8 +76,7 @@ ALTER TABLE ab1 ALTER a SET STATISTICS -1; ANALYZE ab1 (a); WARNING: extended statistics "public.ab1_a_b_stats" could not be collected for relation public.ab1 ANALYZE ab1; -DROP TABLE ab1 CASCADE; -NOTICE: drop cascades to statistics object ab1_a_b_stats +DROP TABLE ab1; -- Verify supported object types for extended statistics CREATE schema tststats; CREATE TABLE tststats.t (a int, b int, c text); diff --git a/src/test/regress/sql/stats_ext.sql b/src/test/regress/sql/stats_ext.sql index df9f47a3b6..fd738dc9fe 100644 --- a/src/test/regress/sql/stats_ext.sql +++ b/src/test/regress/sql/stats_ext.sql @@ -39,7 +39,7 @@ CREATE STATISTICS ab1_a_b_stats ON a, b FROM ab1; ALTER TABLE ab1 DROP COLUMN a; -- fail ALTER TABLE ab1 DROP COLUMN a CASCADE; \d ab1 -DROP TABLE ab1 CASCADE; +DROP TABLE ab1; \set VERBOSITY default -- Ensure things work sanely with SET STATISTICS 0 @@ -52,7 +52,7 @@ ALTER TABLE ab1 ALTER a SET STATISTICS -1; -- partial analyze doesn't build stats either ANALYZE ab1 (a); ANALYZE ab1; -DROP TABLE ab1 CASCADE; +DROP TABLE ab1; -- Verify supported object types for extended statistics CREATE schema tststats; -- 2.11.0