!6221 修复开启ddl逻辑复制后,删除不存在type时报错不友好的问题
Merge pull request !6221 from wenger/bug_logical_ddl_type
This commit is contained in:
@ -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:
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
7
src/test/regress/expected/type_with_event_trigger.out
Normal file
7
src/test/regress/expected/type_with_event_trigger.out
Normal file
@ -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;
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
10
src/test/regress/sql/type_with_event_trigger.sql
Normal file
10
src/test/regress/sql/type_with_event_trigger.sql
Normal file
@ -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;
|
||||
Reference in New Issue
Block a user