diff --git a/src/gausskernel/optimizer/commands/ddldeparse.cpp b/src/gausskernel/optimizer/commands/ddldeparse.cpp index 548f7f6f9..fd654b557 100644 --- a/src/gausskernel/optimizer/commands/ddldeparse.cpp +++ b/src/gausskernel/optimizer/commands/ddldeparse.cpp @@ -927,7 +927,7 @@ static ObjTree* deparse_CreateSchemaStmt(Oid objectId, Node *parsetree) * If isgrant is true, then this function is called while deparsing GRANT * statement and some object names are replaced. */ -static const char* string_objtype(ObjectType objtype, bool isgrant) +const char* string_objtype(ObjectType objtype, bool isgrant) { switch (objtype) { case OBJECT_COLUMN: diff --git a/src/gausskernel/storage/replication/logical/ddltrigger.cpp b/src/gausskernel/storage/replication/logical/ddltrigger.cpp index 0a19ffc02..fe4d03399 100644 --- a/src/gausskernel/storage/replication/logical/ddltrigger.cpp +++ b/src/gausskernel/storage/replication/logical/ddltrigger.cpp @@ -28,6 +28,8 @@ #include "tcop/ddldeparse.h" #include "utils/lsyscache.h" +const char* string_objtype(ObjectType objtype, bool isgrant); + /* * Check if the command can be published. * @@ -110,7 +112,6 @@ Datum publication_deparse_ddl_command_start(PG_FUNCTION_ARGS) { EventTriggerData *trigdata; - char *command = psprintf("Drop table command start"); DropStmt *stmt; ListCell *cell1; @@ -126,11 +127,18 @@ publication_deparse_ddl_command_start(PG_FUNCTION_ARGS) Node *object = (Node*)lfirst(cell1); ObjectAddress address; Relation relation = NULL; + StringInfoData commandbuf; + char *removetype = NULL; char *schemaname = NULL; char *objname = NULL; TypeName *typname = NULL; Node *ptype = NULL; + initStringInfo(&commandbuf); + + removetype = pstrdup(string_objtype(stmt->removeType, false)); + removetype = pg_strtolower(removetype); + if (stmt->removeType == OBJECT_TYPE) { /* for DROP TYPE */ Assert(IsA(object, List) && list_length((List*)object) >= 1); @@ -152,6 +160,15 @@ publication_deparse_ddl_command_start(PG_FUNCTION_ARGS) &relation, AccessExclusiveLock, true); + if (!OidIsValid(address.objectId)) { + ereport(ERROR, (errcode(ERRCODE_UNDEFINED_OBJECT), + errmsg("%s \"%s\" does not exist", + removetype, objname))); + } + + appendStringInfo(&commandbuf, "Drop %s command start", removetype); + + pfree(removetype); /* Object does not exist, nothing to do */ if (relation) { @@ -170,16 +187,17 @@ publication_deparse_ddl_command_start(PG_FUNCTION_ARGS) */ if (support) LogLogicalDDLMessage("deparse", address.objectId, DCT_TableDropStart, - command, strlen(command) + 1); + commandbuf.data, strlen(commandbuf.data) + 1); relation_close(relation, NoLock); } else if (stmt->removeType == OBJECT_TYPE) { support = type_support_ddl_replication(address.objectId); if (support) LogLogicalDDLMessage("deparse", address.objectId, - DCT_TypeDropStart, command, strlen(command) + 1); + DCT_TypeDropStart, commandbuf.data, strlen(commandbuf.data) + 1); } } + return PointerGetDatum(NULL); } diff --git a/src/test/regress/expected/type_with_event_trigger.out b/src/test/regress/expected/type_with_event_trigger.out new file mode 100644 index 000000000..a247375c9 --- /dev/null +++ b/src/test/regress/expected/type_with_event_trigger.out @@ -0,0 +1,7 @@ +create database type_with_event_trigger; +\c type_with_event_trigger +create publication pub_test for all tables with (ddl='all'); +drop type type_not_exists cascade; +ERROR: type "type_not_exists" does not exist +\c regression +drop database type_with_event_trigger; diff --git a/src/test/regress/parallel_schedule0 b/src/test/regress/parallel_schedule0 index c12c7342e..225d1b22f 100644 --- a/src/test/regress/parallel_schedule0 +++ b/src/test/regress/parallel_schedule0 @@ -505,7 +505,7 @@ test: hw_procedure_define #test: hw_anonymous_block #test: hw_procedure# test: hw_grant_all hw_dynamic_sql hw_func_return_out -test: hw_package_function type_replace +test: hw_package_function type_replace type_with_event_trigger #show plan #test: plan_hint diff --git a/src/test/regress/parallel_schedule0B b/src/test/regress/parallel_schedule0B index aa8de33f0..0bd00fc71 100644 --- a/src/test/regress/parallel_schedule0B +++ b/src/test/regress/parallel_schedule0B @@ -50,7 +50,7 @@ test: hw_procedure_define #test: hw_anonymous_block #test: hw_procedure# test: hw_grant_all hw_dynamic_sql hw_func_return_out -test: hw_package_function type_replace +test: hw_package_function type_replace type_with_event_trigger #show plan #test: plan_hint diff --git a/src/test/regress/sql/type_with_event_trigger.sql b/src/test/regress/sql/type_with_event_trigger.sql new file mode 100644 index 000000000..03c7090c2 --- /dev/null +++ b/src/test/regress/sql/type_with_event_trigger.sql @@ -0,0 +1,10 @@ +create database type_with_event_trigger; + +\c type_with_event_trigger + +create publication pub_test for all tables with (ddl='all'); + +drop type type_not_exists cascade; + +\c regression +drop database type_with_event_trigger; \ No newline at end of file