未验证 提交 b949ac96 编写于 作者: J Jialun 提交者: GitHub

Fix bug: zombie record in gp_distribution_policy (#6768)

When a table has been transformed to a view by creating ON SELECT
rule, the record in gp_distribution_policy should be deleted also,
for there is no such record for a view.
Also, the relstorage in pg_class should be changed to 'v'.
上级 78038632
......@@ -549,6 +549,8 @@ DefineQueryRewrite(char *rulename,
/* drop storage while table still looks like a table */
RelationDropStorage(event_relation);
DeleteSystemAttributeTuples(event_relid);
/* delete distribution policy record */
GpPolicyRemove(event_relid);
/*
* Drop the toast table if any. (This won't take care of updating the
......@@ -585,8 +587,8 @@ DefineQueryRewrite(char *rulename,
/*
* Fix pg_class entry to look like a normal view's, including setting
* the correct relkind and removal of reltoastrelid of the toast table
* we potentially removed above.
* the correct relkind/relstorage and removal of reltoastrelid of the
* toast table we potentially removed above.
*/
classTup = SearchSysCacheCopy1(RELOID, ObjectIdGetDatum(event_relid));
if (!HeapTupleIsValid(classTup))
......@@ -600,6 +602,7 @@ DefineQueryRewrite(char *rulename,
classForm->reltoastrelid = InvalidOid;
classForm->relhasindex = false;
classForm->relkind = RELKIND_VIEW;
classForm->relstorage = RELSTORAGE_VIRTUAL;
classForm->relhasoids = false;
classForm->relhaspkey = false;
classForm->relfrozenxid = InvalidTransactionId;
......
......@@ -8,6 +8,23 @@ NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE rule "_RETURN" as on select to table_to_view_test1
do instead select * from table_to_view_test2;
-- relkind and relstorage have been changed to 'v'
SELECT relkind, relstorage FROM pg_class
WHERE oid = 'table_to_view_test1'::regclass;
relkind | relstorage
---------+------------
v | v
(1 row)
-- distribution policy record has been deleted
SELECT 1 FROM gp_distribution_policy
WHERE localoid = 'table_to_view_test1'::regclass;
?column?
----------
(0 rows)
DROP VIEW table_to_view_test1;
DROP TABLE table_to_view_test2;
-- Same for an Append-Only table. It is currently not supported.
CREATE table aotable_to_view_test1 (a int) with (appendonly=true);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
......
......@@ -7,6 +7,16 @@ CREATE table table_to_view_test2 (a int);
CREATE rule "_RETURN" as on select to table_to_view_test1
do instead select * from table_to_view_test2;
-- relkind and relstorage have been changed to 'v'
SELECT relkind, relstorage FROM pg_class
WHERE oid = 'table_to_view_test1'::regclass;
-- distribution policy record has been deleted
SELECT 1 FROM gp_distribution_policy
WHERE localoid = 'table_to_view_test1'::regclass;
DROP VIEW table_to_view_test1;
DROP TABLE table_to_view_test2;
-- Same for an Append-Only table. It is currently not supported.
CREATE table aotable_to_view_test1 (a int) with (appendonly=true);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册