diff --git a/src/gausskernel/optimizer/commands/ddldeparse.cpp b/src/gausskernel/optimizer/commands/ddldeparse.cpp index 548f7f6f9..9948cb6aa 100644 --- a/src/gausskernel/optimizer/commands/ddldeparse.cpp +++ b/src/gausskernel/optimizer/commands/ddldeparse.cpp @@ -891,7 +891,7 @@ static ObjTree* deparse_AlterSchemaStmt(Oid objectId, Node *parsetree) * Verbose syntax * CREATE SCHEMA %{if_not_exists}s %{name}I %{authorization}s */ -static ObjTree* deparse_CreateSchemaStmt(Oid objectId, Node *parsetree) +static ObjTree* deparse_CreateSchemaStmt(Oid objectId, Node *parsetree, bool *include_owner) { CreateSchemaStmt *node = (CreateSchemaStmt *) parsetree; ObjTree *ret; @@ -904,12 +904,14 @@ static ObjTree* deparse_CreateSchemaStmt(Oid objectId, Node *parsetree) node->schemaname ? node->schemaname : ""); auth = new_objtree("AUTHORIZATION"); - if (node->authid) + if (node->authid) { append_string_object(auth, "%{authorization_role}I", "authorization_role", node->authid); - else + *include_owner = false; + } else { append_not_present(auth, "%{authorization_role}I"); + } append_object_object(ret, "%{authorization}s", auth); @@ -3658,7 +3660,7 @@ static ObjTree* deparse_simple_command(CollectedCommand *cmd, bool *include_owne return deparse_CreateFunction(objectId, parsetree); case T_CreateSchemaStmt: - return deparse_CreateSchemaStmt(objectId, parsetree); + return deparse_CreateSchemaStmt(objectId, parsetree, include_owner); case T_CreateSeqStmt: return deparse_CreateSeqStmt(objectId, parsetree); @@ -3685,7 +3687,7 @@ static ObjTree* deparse_simple_command(CollectedCommand *cmd, bool *include_owne return (ObjTree*)((deparseCollectedCommand)(u_sess->hook_cxt.deparseCollectedCommandHook)) (DEPARSE_SIMPLE_COMMAND, cmd, NULL, NULL); } - elog(INFO, "unrecognized node type in deparse command: %d", + elog(LOG, "unrecognized node type in deparse command: %d", (int) nodeTag(parsetree)); } diff --git a/src/gausskernel/optimizer/commands/schemacmds.cpp b/src/gausskernel/optimizer/commands/schemacmds.cpp index d60a93b94..613546932 100644 --- a/src/gausskernel/optimizer/commands/schemacmds.cpp +++ b/src/gausskernel/optimizer/commands/schemacmds.cpp @@ -389,6 +389,7 @@ void AlterSchemaCommand(AlterSchemaStmt* stmt) AclResult aclresult; const int STR_SCHEMA_NAME_LENGTH = 9; const int STR_SNAPSHOT_LENGTH = 8; + ObjectAddress address; if (withBlockchain && ((strncmp(nspName, "dbe_perf", STR_SCHEMA_NAME_LENGTH) == 0) || (strncmp(nspName, "snapshot", STR_SNAPSHOT_LENGTH) == 0))) { @@ -423,6 +424,9 @@ void AlterSchemaCommand(AlterSchemaStmt* stmt) (errcode(ERRCODE_RESERVED_NAME), errmsg("The system schema \"%s\" doesn't allow to alter to blockchain schema", nspName))); + ObjectAddressSet(address, NamespaceNameIndexId, HeapTupleGetOid(tup)); + EventTriggerCollectSimpleCommand(address, InvalidObjectAddress, (Node*)stmt); + Datum new_record[Natts_pg_namespace] = {0}; bool new_record_nulls[Natts_pg_namespace] = {false}; bool new_record_repl[Natts_pg_namespace] = {false}; diff --git a/src/gausskernel/process/tcop/utility.cpp b/src/gausskernel/process/tcop/utility.cpp index d413deede..e7366e4d7 100755 --- a/src/gausskernel/process/tcop/utility.cpp +++ b/src/gausskernel/process/tcop/utility.cpp @@ -5217,6 +5217,7 @@ ProcessUtilitySlow(Node *parse_tree, } #else AlterSchemaCommand((AlterSchemaStmt*)parse_tree); + commandCollected = true; #endif break; @@ -6634,7 +6635,7 @@ ProcessUtilitySlow(Node *parse_tree, ExecUtilityStmtOnNodes(query_string, exec_nodes, sent_to_remote, false, EXEC_ON_ALL_NODES, false); } } else { - ExecAlterOwnerStmt((AlterOwnerStmt*)parse_tree); + address = ExecAlterOwnerStmt((AlterOwnerStmt*)parse_tree); } #else AlterOwnerStmt *stmt = (AlterOwnerStmt *) parse_tree; diff --git a/src/test/subscription/testcase/ddl_replication_sql/A/ddl_create_schema.setup b/src/test/subscription/testcase/ddl_replication_sql/A/ddl_create_schema.setup new file mode 100644 index 000000000..5358fce0b --- /dev/null +++ b/src/test/subscription/testcase/ddl_replication_sql/A/ddl_create_schema.setup @@ -0,0 +1,8 @@ +#!/bin/bsh + +source $1/env_utils.sh $1 $2 +subscription_dir=$1 +case_use_db=$3 + +exec_sql_with_user $case_use_db $pub_node1_port "CREATE USER test_u1 PASSWORD 'Aa123456'" +exec_sql_with_user $case_use_db $sub_node1_port "CREATE USER test_u1 PASSWORD 'Aa123456'" \ No newline at end of file diff --git a/src/test/subscription/testcase/ddl_replication_sql/A/ddl_create_schema.sql b/src/test/subscription/testcase/ddl_replication_sql/A/ddl_create_schema.sql new file mode 100644 index 000000000..831e0b2e2 --- /dev/null +++ b/src/test/subscription/testcase/ddl_replication_sql/A/ddl_create_schema.sql @@ -0,0 +1 @@ +create schema test_own authorization test_u1; \ No newline at end of file diff --git a/src/test/subscription/testcase/ddl_replication_sql/A/ddl_create_schema.teardown b/src/test/subscription/testcase/ddl_replication_sql/A/ddl_create_schema.teardown new file mode 100644 index 000000000..0d3a09fb8 --- /dev/null +++ b/src/test/subscription/testcase/ddl_replication_sql/A/ddl_create_schema.teardown @@ -0,0 +1,8 @@ +#!/bin/sh + +source $1/env_utils.sh $1 $2 +subscription_dir=$1 +case_use_db=$3 + +exec_sql $case_use_db $sub_node1_port "DROP USER test_u1" +exec_sql $case_use_db $sub_node1_port "DROP USER test_u1" diff --git a/src/test/subscription/testcase/ddl_replication_sql/B/acceptable_diff/ddl_alter_schema.diff b/src/test/subscription/testcase/ddl_replication_sql/B/acceptable_diff/ddl_alter_schema.diff new file mode 100644 index 000000000..d4bf13fdb --- /dev/null +++ b/src/test/subscription/testcase/ddl_replication_sql/B/acceptable_diff/ddl_alter_schema.diff @@ -0,0 +1,17 @@ +28,37c28 +< -- Name: regtest_unpriv_user; Type: SCHEMA; Schema: -; Owner: regtest_unpriv_user +< -- +< +< CREATE SCHEMA regtest_unpriv_user; +< +< +< ALTER SCHEMA regtest_unpriv_user OWNER TO regtest_unpriv_user; +< +< -- +< -- Name: test_sche1; Type: SCHEMA; Schema: -; Owner: regtest_unpriv_user +--- +> -- Name: test_sche1; Type: SCHEMA; Schema: -; Owner: ddl_test_user +44c35 +< ALTER SCHEMA test_sche1 OWNER TO regtest_unpriv_user; +--- +> ALTER SCHEMA test_sche1 OWNER TO ddl_test_user; diff --git a/src/test/subscription/testcase/ddl_replication_sql/B/ddl_alter_table_fastcheck.setup b/src/test/subscription/testcase/ddl_replication_sql/B/ddl_alter_table_fastcheck.setup index 4db8109ca..db2469581 100644 --- a/src/test/subscription/testcase/ddl_replication_sql/B/ddl_alter_table_fastcheck.setup +++ b/src/test/subscription/testcase/ddl_replication_sql/B/ddl_alter_table_fastcheck.setup @@ -8,8 +8,4 @@ exec_sql_with_user $case_use_db $pub_node1_port "create schema fastcheck;set sea exec_sql_with_user $case_use_db $sub_node1_port "create schema fastcheck;set search_path=fastcheck;create table t1_full (a int, b text, myc int); insert into t1_full values (101, 'a', 1), (102, 'b', 2);" exec_sql_with_user $case_use_db $pub_node1_port "set search_path=fastcheck;create table tkey1 (a int primary key, b text);insert into tkey1 values (1, 'a'), (2, 'b'), (3, 'c');alter table tkey1 replica identity default;" -exec_sql_with_user $case_use_db $sub_node1_port "set search_path=fastcheck;create table tkey1 (a int primary key, b text, myc int); insert into tkey1 values (101, '101a', 1), (102, '102b', 2);" - -exec_sql_with_user $case_use_db $pub_node1_port "CREATE USER regtest_unpriv_user PASSWORD 'gauss@123'" - -exec_sql_with_user $case_use_db $sub_node1_port "CREATE USER regtest_unpriv_user PASSWORD 'gauss@123'" \ No newline at end of file +exec_sql_with_user $case_use_db $sub_node1_port "set search_path=fastcheck;create table tkey1 (a int primary key, b text, myc int); insert into tkey1 values (101, '101a', 1), (102, '102b', 2);" \ No newline at end of file diff --git a/src/test/subscription/testcase/ddl_replication_sql/B/ddl_create_schema.setup b/src/test/subscription/testcase/ddl_replication_sql/B/ddl_create_schema.setup new file mode 100644 index 000000000..5358fce0b --- /dev/null +++ b/src/test/subscription/testcase/ddl_replication_sql/B/ddl_create_schema.setup @@ -0,0 +1,8 @@ +#!/bin/bsh + +source $1/env_utils.sh $1 $2 +subscription_dir=$1 +case_use_db=$3 + +exec_sql_with_user $case_use_db $pub_node1_port "CREATE USER test_u1 PASSWORD 'Aa123456'" +exec_sql_with_user $case_use_db $sub_node1_port "CREATE USER test_u1 PASSWORD 'Aa123456'" \ No newline at end of file diff --git a/src/test/subscription/testcase/ddl_replication_sql/B/ddl_create_schema.sql b/src/test/subscription/testcase/ddl_replication_sql/B/ddl_create_schema.sql new file mode 100644 index 000000000..831e0b2e2 --- /dev/null +++ b/src/test/subscription/testcase/ddl_replication_sql/B/ddl_create_schema.sql @@ -0,0 +1 @@ +create schema test_own authorization test_u1; \ No newline at end of file diff --git a/src/test/subscription/testcase/ddl_replication_sql/B/ddl_create_schema.teardown b/src/test/subscription/testcase/ddl_replication_sql/B/ddl_create_schema.teardown new file mode 100644 index 000000000..0d3a09fb8 --- /dev/null +++ b/src/test/subscription/testcase/ddl_replication_sql/B/ddl_create_schema.teardown @@ -0,0 +1,8 @@ +#!/bin/sh + +source $1/env_utils.sh $1 $2 +subscription_dir=$1 +case_use_db=$3 + +exec_sql $case_use_db $sub_node1_port "DROP USER test_u1" +exec_sql $case_use_db $sub_node1_port "DROP USER test_u1"