From 11433ed35747e4362b92017932b2f56959e47824 Mon Sep 17 00:00:00 2001 From: Onur Tirtir Date: Mon, 21 Mar 2022 18:42:42 +0300 Subject: [PATCH] Create DDL job for create enum command in postprocess as we do for composite types Since now we don't throw an error for enums that user attempts creating in temp schema, the preprocess / DDL job that contains the prepared statement (to idempotently create the enum type) gets executed. As a result, we were emitting the following warning because of the error the underlying worker connection throws: ```sql WARNING: cannot PREPARE a transaction that has operated on temporary objects CONTEXT: while executing command on localhost:xxxxx WARNING: connection to the remote node localhost:xxxxx failed with the following error: another command is already in progress ERROR: cannot PREPARE a transaction that has operated on temporary objects CONTEXT: while executing command on localhost:xxxxx ``` --- src/backend/distributed/commands/type.c | 34 +++++++++---------- .../regress/expected/distributed_types.out | 5 --- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/backend/distributed/commands/type.c b/src/backend/distributed/commands/type.c index 461fd6d05..74718ea59 100644 --- a/src/backend/distributed/commands/type.c +++ b/src/backend/distributed/commands/type.c @@ -260,22 +260,7 @@ PreprocessCreateEnumStmt(Node *node, const char *queryString, /* enforce fully qualified typeName for correct deparsing and lookup */ QualifyTreeNode(node); - /* reconstruct creation statement in a portable fashion */ - const char *createEnumStmtSql = DeparseCreateEnumStmt(node); - createEnumStmtSql = WrapCreateOrReplace(createEnumStmtSql); - - /* - * when we allow propagation within a transaction block we should make sure to only - * allow this in sequential mode - */ - EnsureSequentialMode(OBJECT_TYPE); - - /* to prevent recursion with mx we disable ddl propagation */ - List *commands = list_make3(DISABLE_DDL_PROPAGATION, - (void *) createEnumStmtSql, - ENABLE_DDL_PROPAGATION); - - return NodeDDLTaskList(NON_COORDINATOR_NODES, commands); + return NIL; } @@ -305,9 +290,24 @@ PostprocessCreateEnumStmt(Node *node, const char *queryString) return NIL; } + /* + * when we allow propagation within a transaction block we should make sure to only + * allow this in sequential mode + */ + EnsureSequentialMode(OBJECT_TYPE); + EnsureDependenciesExistOnAllNodes(&typeAddress); - return NIL; + /* reconstruct creation statement in a portable fashion */ + const char *createEnumStmtSql = DeparseCreateEnumStmt(node); + createEnumStmtSql = WrapCreateOrReplace(createEnumStmtSql); + + /* to prevent recursion with mx we disable ddl propagation */ + List *commands = list_make3(DISABLE_DDL_PROPAGATION, + (void *) createEnumStmtSql, + ENABLE_DDL_PROPAGATION); + + return NodeDDLTaskList(NON_COORDINATOR_NODES, commands); } diff --git a/src/test/regress/expected/distributed_types.out b/src/test/regress/expected/distributed_types.out index 6996a6569..02d419d9b 100644 --- a/src/test/regress/expected/distributed_types.out +++ b/src/test/regress/expected/distributed_types.out @@ -604,11 +604,6 @@ DETAIL: "type temp_type" will be created only locally CREATE TYPE pg_temp.temp_enum AS ENUM ('one', 'two', 'three'); WARNING: "type temp_enum" has dependency on unsupported object "schema pg_temp_xxx" DETAIL: "type temp_enum" will be created only locally -WARNING: cannot PREPARE a transaction that has operated on temporary objects -CONTEXT: while executing command on localhost:xxxxx -WARNING: connection to the remote node localhost:xxxxx failed with the following error: another command is already in progress -ERROR: cannot PREPARE a transaction that has operated on temporary objects -CONTEXT: while executing command on localhost:xxxxx -- clear objects SET client_min_messages TO error; -- suppress cascading objects dropping DROP SCHEMA type_tests CASCADE;