From 25e1ef81d729fe0e124ba861ca98ecc1082f85ea Mon Sep 17 00:00:00 2001 From: douxin Date: Thu, 6 Jun 2024 15:08:51 +0800 Subject: [PATCH] [bugfix] comment on table support table and view for A compatibilty --- .../optimizer/commands/comment.cpp | 15 +++- src/test/regress/expected/comment_table.out | 79 +++++++++++++++++++ src/test/regress/parallel_schedule0A | 2 +- src/test/regress/sql/comment_table.sql | 72 +++++++++++++++++ 4 files changed, 166 insertions(+), 2 deletions(-) create mode 100644 src/test/regress/expected/comment_table.out create mode 100644 src/test/regress/sql/comment_table.sql diff --git a/src/gausskernel/optimizer/commands/comment.cpp b/src/gausskernel/optimizer/commands/comment.cpp index a18fcf329..ebe7acc42 100644 --- a/src/gausskernel/optimizer/commands/comment.cpp +++ b/src/gausskernel/optimizer/commands/comment.cpp @@ -131,6 +131,19 @@ ObjectAddress CommentObject(CommentStmt* stmt) } } + /* + * For only A compatibility, comment on table support table and view object + */ + if (DB_IS_CMPT(A_FORMAT) && stmt->objtype == OBJECT_TABLE) { + Relation rel = relation_openrv_extended(makeRangeVarFromNameList(stmt->objname), ShareUpdateExclusiveLock, false); + if (rel) { + if(rel->rd_rel->relkind == RELKIND_VIEW) { + stmt->objtype = OBJECT_VIEW; + } + RelationClose(rel); + } + } + /* * Translate the parser representation that identifies this object into an * ObjectAddress. get_object_address() will throw an error if the object @@ -463,4 +476,4 @@ void CreateNonColumnComment(Oid oid, List *options, Oid objectType) break; } } -} \ No newline at end of file +} diff --git a/src/test/regress/expected/comment_table.out b/src/test/regress/expected/comment_table.out new file mode 100644 index 000000000..e546adae0 --- /dev/null +++ b/src/test/regress/expected/comment_table.out @@ -0,0 +1,79 @@ +-- +-- comment on table +-- +-- A compatibility +create database comment_table_testa with dbcompatibility = 'A'; +\c comment_table_testa +create table t1(id int); +create index index1 on t1(id); +create view t1_v as select * from t1; +comment on table t1 is 'table t1'; +comment on table t1_v is 'table t1 view'; +comment on table index1 is 'table t1 index'; +ERROR: "index1" is not a table +comment on index index1 is 'table t1 index'; +drop view t1_v; +drop table t1; +create schema test_comment_schema; +create table test_comment_schema.t1(id int); +create index idx1 on test_comment_schema.t1(id); +create view test_comment_schema.t1_v as select * from test_comment_schema.t1; +comment on table test_comment_schema.t1 is 'table t1'; +comment on table test_comment_schema.t1_v is 'table t1 view'; +comment on table idx1 is 'table t1 index'; +ERROR: relation "idx1" does not exist +comment on table test_comment_schema.idx1 is 'table t1 index'; +ERROR: "idx1" is not a table +comment on index test_comment_schema.idx1 is 'table t1 index'; +-- not exist +comment on table t2 is 'table t2'; +ERROR: relation "t2" does not exist +comment on table test_comment_schema.t2 is 'table test_comment_schema.t2'; +ERROR: relation "test_comment_schema.t2" does not exist +comment on table schema1.t2 is 'table schema1.t2'; +ERROR: schema "schema1" does not exist +drop schema test_comment_schema cascade; +NOTICE: drop cascades to 2 other objects +DETAIL: drop cascades to table test_comment_schema.t1 +drop cascades to view test_comment_schema.t1_v +\c postgres +drop database comment_table_testa; +-- B compatibility +create database comment_table_testb with dbcompatibility = 'B'; +\c comment_table_testb +create table t1(id int); +create index index1 on t1(id); +create view t1_v as select * from t1; +comment on table t1 is 'table t1'; +comment on table t1_v is 'table t1 view'; +ERROR: "t1_v" is not a table +comment on table index1 is 'table t1 index'; +ERROR: "index1" is not a table +comment on index index1 is 'table t1 index'; +drop view t1_v; +drop table t1; +create schema test_comment_schema; +create table test_comment_schema.t1(id int); +create index idx1 on test_comment_schema.t1(id); +create view test_comment_schema.t1_v as select * from test_comment_schema.t1; +comment on table test_comment_schema.t1 is 'table t1'; +comment on table test_comment_schema.t1_v is 'table t1 view'; +ERROR: "t1_v" is not a table +comment on table idx1 is 'table t1 index'; +ERROR: relation "idx1" does not exist +comment on table test_comment_schema.idx1 is 'table t1 index'; +ERROR: "idx1" is not a table +comment on index test_comment_schema.idx1 is 'table t1 index'; +-- not exist +comment on table t2 is 'table t2'; +ERROR: relation "t2" does not exist +comment on table test_comment_schema.t2 is 'table test_comment_schema.t2'; +ERROR: relation "test_comment_schema.t2" does not exist +comment on table schema1.t2 is 'table schema1.t2'; +ERROR: schema "schema1" does not exist +drop schema test_comment_schema cascade; +NOTICE: drop cascades to 2 other objects +DETAIL: drop cascades to table test_comment_schema.t1 +drop cascades to view test_comment_schema.t1_v +\c postgres +drop database comment_table_testb; diff --git a/src/test/regress/parallel_schedule0A b/src/test/regress/parallel_schedule0A index b1f8c2c2a..7a6a348f2 100644 --- a/src/test/regress/parallel_schedule0A +++ b/src/test/regress/parallel_schedule0A @@ -427,7 +427,7 @@ test: create_seg_table # ---------- #test: hw_hashagg_start test: create_misc -test: create_view1 create_view2 create_view3 create_view4 create_view5 +test: create_view1 create_view2 create_view3 create_view4 create_view5 comment_table #test: int8# #dupliacated select int8 diff --git a/src/test/regress/sql/comment_table.sql b/src/test/regress/sql/comment_table.sql new file mode 100644 index 000000000..1f50f845b --- /dev/null +++ b/src/test/regress/sql/comment_table.sql @@ -0,0 +1,72 @@ +-- +-- comment on table +-- + +-- A compatibility +create database comment_table_testa with dbcompatibility = 'A'; +\c comment_table_testa + +create table t1(id int); +create index index1 on t1(id); +create view t1_v as select * from t1; +comment on table t1 is 'table t1'; +comment on table t1_v is 'table t1 view'; +comment on table index1 is 'table t1 index'; +comment on index index1 is 'table t1 index'; +drop view t1_v; +drop table t1; + +create schema test_comment_schema; +create table test_comment_schema.t1(id int); +create index idx1 on test_comment_schema.t1(id); +create view test_comment_schema.t1_v as select * from test_comment_schema.t1; +comment on table test_comment_schema.t1 is 'table t1'; +comment on table test_comment_schema.t1_v is 'table t1 view'; +comment on table idx1 is 'table t1 index'; +comment on table test_comment_schema.idx1 is 'table t1 index'; +comment on index test_comment_schema.idx1 is 'table t1 index'; + +-- not exist +comment on table t2 is 'table t2'; +comment on table test_comment_schema.t2 is 'table test_comment_schema.t2'; +comment on table schema1.t2 is 'table schema1.t2'; + +drop schema test_comment_schema cascade; + +\c postgres +drop database comment_table_testa; + + +-- B compatibility +create database comment_table_testb with dbcompatibility = 'B'; +\c comment_table_testb + +create table t1(id int); +create index index1 on t1(id); +create view t1_v as select * from t1; +comment on table t1 is 'table t1'; +comment on table t1_v is 'table t1 view'; +comment on table index1 is 'table t1 index'; +comment on index index1 is 'table t1 index'; +drop view t1_v; +drop table t1; + +create schema test_comment_schema; +create table test_comment_schema.t1(id int); +create index idx1 on test_comment_schema.t1(id); +create view test_comment_schema.t1_v as select * from test_comment_schema.t1; +comment on table test_comment_schema.t1 is 'table t1'; +comment on table test_comment_schema.t1_v is 'table t1 view'; +comment on table idx1 is 'table t1 index'; +comment on table test_comment_schema.idx1 is 'table t1 index'; +comment on index test_comment_schema.idx1 is 'table t1 index'; + +-- not exist +comment on table t2 is 'table t2'; +comment on table test_comment_schema.t2 is 'table test_comment_schema.t2'; +comment on table schema1.t2 is 'table schema1.t2'; + +drop schema test_comment_schema cascade; + +\c postgres +drop database comment_table_testb;