diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c index 1216e901860..a67f822b592 100644 --- a/src/backend/commands/analyze.c +++ b/src/backend/commands/analyze.c @@ -1975,18 +1975,6 @@ acquire_inherited_sample_rows(Relation onerel, int elevel, ListCell *lc; bool has_child; - /* - * Like in acquire_sample_rows(), if we're in the QD, fetch the sample - * from segments. - */ - if (Gp_role == GP_ROLE_DISPATCH && ENABLE_DISPATCH()) - { - return acquire_sample_rows_dispatcher(onerel, - true, /* inherited stats */ - elevel, rows, targrows, - totalrows, totaldeadrows); - } - /* * Find all members of inheritance set. We only need AccessShareLock on * the children. @@ -2000,6 +1988,7 @@ acquire_inherited_sample_rows(Relation onerel, int elevel, * child but no longer does. In that case, we can clear the * relhassubclass field so as not to make the same mistake again later. * (This is safe because we hold ShareUpdateExclusiveLock.) + * Please refer to https://github.com/greenplum-db/gpdb/issues/14644 */ if (list_length(tableOIDs) < 2) { @@ -2012,7 +2001,20 @@ acquire_inherited_sample_rows(Relation onerel, int elevel, (errmsg("skipping analyze of \"%s.%s\" inheritance tree --- this inheritance tree contains no child tables", get_namespace_name(RelationGetNamespace(onerel)), RelationGetRelationName(onerel)))); - return 0; + if (Gp_role == GP_ROLE_EXECUTE) + return 0; + } + + /* + * Like in acquire_sample_rows(), if we're in the QD, fetch the sample + * from segments. + */ + if (Gp_role == GP_ROLE_DISPATCH) + { + return acquire_sample_rows_dispatcher(onerel, + true, /* inherited stats */ + elevel, rows, targrows, + totalrows, totaldeadrows); } /* diff --git a/src/test/regress/expected/analyze.out b/src/test/regress/expected/analyze.out index 37f490b75a9..1f5fa43bb70 100644 --- a/src/test/regress/expected/analyze.out +++ b/src/test/regress/expected/analyze.out @@ -1230,3 +1230,37 @@ create table analyze_replicated(tc1 int,tc2 int) distributed replicated; insert into analyze_replicated select i, i from generate_series(1,1000) i; analyze analyze_replicated; drop table analyze_replicated; +-- Issue 14644 keep catalog inconsistency of relhassubclass after analyze +CREATE TYPE test_type_14644 AS (a int, b text); +CREATE TABLE test_tb_14644 OF test_type_14644; +CREATE TABLE test_tb_14644_subclass () INHERITS (test_tb_14644); +DROP TABLE test_tb_14644_subclass; +select relhassubclass from pg_class where relname = 'test_tb_14644'; + relhassubclass +---------------- + t +(1 row) + +select relhassubclass from gp_dist_random('pg_class') where relname = 'test_tb_14644'; + relhassubclass +---------------- + t + t + t +(3 rows) + +ANALYZE; +select relhassubclass from pg_class where relname = 'test_tb_14644'; + relhassubclass +---------------- + f +(1 row) + +select relhassubclass from gp_dist_random('pg_class') where relname = 'test_tb_14644'; + relhassubclass +---------------- + f + f + f +(3 rows) + diff --git a/src/test/regress/sql/analyze.sql b/src/test/regress/sql/analyze.sql index 3210c059f52..f8705d8aa2a 100644 --- a/src/test/regress/sql/analyze.sql +++ b/src/test/regress/sql/analyze.sql @@ -631,3 +631,13 @@ create table analyze_replicated(tc1 int,tc2 int) distributed replicated; insert into analyze_replicated select i, i from generate_series(1,1000) i; analyze analyze_replicated; drop table analyze_replicated; +-- Issue 14644 keep catalog inconsistency of relhassubclass after analyze +CREATE TYPE test_type_14644 AS (a int, b text); +CREATE TABLE test_tb_14644 OF test_type_14644; +CREATE TABLE test_tb_14644_subclass () INHERITS (test_tb_14644); +DROP TABLE test_tb_14644_subclass; +select relhassubclass from pg_class where relname = 'test_tb_14644'; +select relhassubclass from gp_dist_random('pg_class') where relname = 'test_tb_14644'; +ANALYZE; +select relhassubclass from pg_class where relname = 'test_tb_14644'; +select relhassubclass from gp_dist_random('pg_class') where relname = 'test_tb_14644';