From dcf54eaf2a32e186b6203672bc9be1d825725f37 Mon Sep 17 00:00:00 2001 From: SaitTalhaNisanci Date: Fri, 19 Feb 2021 13:42:19 +0300 Subject: [PATCH] Use PROCESS_UTILITY_QUERY in utility calls When we use PROCESS_UTILITY_TOPLEVEL it causes some problems when combined with other extensions such as pg_audit. With this commit we use PROCESS_UTILITY_QUERY in the codebase to fix those problems. --- src/backend/distributed/commands/alter_table.c | 4 ++-- .../cascade_table_operation_for_connected_relations.c | 2 +- src/backend/distributed/executor/local_executor.c | 2 +- src/backend/distributed/utils/role.c | 6 +++--- .../distributed/worker/worker_create_or_replace.c | 4 ++-- .../distributed/worker/worker_data_fetch_protocol.c | 10 +++++----- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/backend/distributed/commands/alter_table.c b/src/backend/distributed/commands/alter_table.c index eef98cae1..ade2fe0bd 100644 --- a/src/backend/distributed/commands/alter_table.c +++ b/src/backend/distributed/commands/alter_table.c @@ -673,7 +673,7 @@ ConvertTable(TableConversionState *con) Node *parseTree = ParseTreeNode(tableCreationSql); RelayEventExtendNames(parseTree, con->schemaName, con->hashOfName); - ProcessUtilityParseTree(parseTree, tableCreationSql, PROCESS_UTILITY_TOPLEVEL, + ProcessUtilityParseTree(parseTree, tableCreationSql, PROCESS_UTILITY_QUERY, NULL, None_Receiver, NULL); } @@ -728,7 +728,7 @@ ConvertTable(TableConversionState *con) Node *parseTree = ParseTreeNode(attachPartitionCommand); ProcessUtilityParseTree(parseTree, attachPartitionCommand, - PROCESS_UTILITY_TOPLEVEL, + PROCESS_UTILITY_QUERY, NULL, None_Receiver, NULL); } diff --git a/src/backend/distributed/commands/cascade_table_operation_for_connected_relations.c b/src/backend/distributed/commands/cascade_table_operation_for_connected_relations.c index ce6a1348f..472408548 100644 --- a/src/backend/distributed/commands/cascade_table_operation_for_connected_relations.c +++ b/src/backend/distributed/commands/cascade_table_operation_for_connected_relations.c @@ -510,6 +510,6 @@ ExecuteForeignKeyCreateCommand(const char *commandString, bool skip_validation) "command \"%s\"", commandString))); } - ProcessUtilityParseTree(parseTree, commandString, PROCESS_UTILITY_TOPLEVEL, + ProcessUtilityParseTree(parseTree, commandString, PROCESS_UTILITY_QUERY, NULL, None_Receiver, NULL); } diff --git a/src/backend/distributed/executor/local_executor.c b/src/backend/distributed/executor/local_executor.c index e447decd6..c1ace895f 100644 --- a/src/backend/distributed/executor/local_executor.c +++ b/src/backend/distributed/executor/local_executor.c @@ -406,7 +406,7 @@ ExecuteUtilityCommand(const char *taskQueryCommand) * process utility. */ ProcessUtilityParseTree(taskRawParseTree, taskQueryCommand, - PROCESS_UTILITY_TOPLEVEL, NULL, None_Receiver, + PROCESS_UTILITY_QUERY, NULL, None_Receiver, NULL); } } diff --git a/src/backend/distributed/utils/role.c b/src/backend/distributed/utils/role.c index 21ea68d5a..9a714b1d1 100644 --- a/src/backend/distributed/utils/role.c +++ b/src/backend/distributed/utils/role.c @@ -41,7 +41,7 @@ alter_role_if_exists(PG_FUNCTION_ARGS) Node *parseTree = ParseTreeNode(utilityQuery); - ProcessUtilityParseTree(parseTree, utilityQuery, PROCESS_UTILITY_TOPLEVEL, NULL, + ProcessUtilityParseTree(parseTree, utilityQuery, PROCESS_UTILITY_QUERY, NULL, None_Receiver, NULL); PG_RETURN_BOOL(true); @@ -98,7 +98,7 @@ worker_create_or_alter_role(PG_FUNCTION_ARGS) ProcessUtilityParseTree(parseTree, createRoleUtilityQuery, - PROCESS_UTILITY_TOPLEVEL, + PROCESS_UTILITY_QUERY, NULL, None_Receiver, NULL); @@ -126,7 +126,7 @@ worker_create_or_alter_role(PG_FUNCTION_ARGS) ProcessUtilityParseTree(parseTree, alterRoleUtilityQuery, - PROCESS_UTILITY_TOPLEVEL, + PROCESS_UTILITY_QUERY, NULL, None_Receiver, NULL); diff --git a/src/backend/distributed/worker/worker_create_or_replace.c b/src/backend/distributed/worker/worker_create_or_replace.c index 9c875e827..2bb34ea8c 100644 --- a/src/backend/distributed/worker/worker_create_or_replace.c +++ b/src/backend/distributed/worker/worker_create_or_replace.c @@ -111,12 +111,12 @@ worker_create_or_replace_object(PG_FUNCTION_ARGS) RenameStmt *renameStmt = CreateRenameStatement(&address, newName); const char *sqlRenameStmt = DeparseTreeNode((Node *) renameStmt); ProcessUtilityParseTree((Node *) renameStmt, sqlRenameStmt, - PROCESS_UTILITY_TOPLEVEL, + PROCESS_UTILITY_QUERY, NULL, None_Receiver, NULL); } /* apply create statement locally */ - ProcessUtilityParseTree(parseTree, sqlStatement, PROCESS_UTILITY_TOPLEVEL, NULL, + ProcessUtilityParseTree(parseTree, sqlStatement, PROCESS_UTILITY_QUERY, NULL, None_Receiver, NULL); /* type has been created */ diff --git a/src/backend/distributed/worker/worker_data_fetch_protocol.c b/src/backend/distributed/worker/worker_data_fetch_protocol.c index a56015a3e..964790061 100644 --- a/src/backend/distributed/worker/worker_data_fetch_protocol.c +++ b/src/backend/distributed/worker/worker_data_fetch_protocol.c @@ -396,7 +396,7 @@ worker_apply_shard_ddl_command(PG_FUNCTION_ARGS) /* extend names in ddl command and apply extended command */ RelayEventExtendNames(ddlCommandNode, schemaName, shardId); - ProcessUtilityParseTree(ddlCommandNode, ddlCommand, PROCESS_UTILITY_TOPLEVEL, NULL, + ProcessUtilityParseTree(ddlCommandNode, ddlCommand, PROCESS_UTILITY_QUERY, NULL, None_Receiver, NULL); PG_RETURN_VOID(); @@ -428,7 +428,7 @@ worker_apply_inter_shard_ddl_command(PG_FUNCTION_ARGS) RelayEventExtendNamesForInterShardCommands(ddlCommandNode, leftShardId, leftShardSchemaName, rightShardId, rightShardSchemaName); - ProcessUtilityParseTree(ddlCommandNode, ddlCommand, PROCESS_UTILITY_TOPLEVEL, NULL, + ProcessUtilityParseTree(ddlCommandNode, ddlCommand, PROCESS_UTILITY_QUERY, NULL, None_Receiver, NULL); PG_RETURN_VOID(); @@ -461,7 +461,7 @@ worker_apply_sequence_command(PG_FUNCTION_ARGS) } /* run the CREATE SEQUENCE command */ - ProcessUtilityParseTree(commandNode, commandString, PROCESS_UTILITY_TOPLEVEL, NULL, + ProcessUtilityParseTree(commandNode, commandString, PROCESS_UTILITY_QUERY, NULL, None_Receiver, NULL); CommandCounterIncrement(); @@ -669,7 +669,7 @@ worker_append_table_to_shard(PG_FUNCTION_ARGS) SetUserIdAndSecContext(CitusExtensionOwner(), SECURITY_LOCAL_USERID_CHANGE); ProcessUtilityParseTree((Node *) localCopyCommand, queryString->data, - PROCESS_UTILITY_TOPLEVEL, NULL, None_Receiver, NULL); + PROCESS_UTILITY_QUERY, NULL, None_Receiver, NULL); SetUserIdAndSecContext(savedUserId, savedSecurityContext); @@ -782,7 +782,7 @@ AlterSequenceMinMax(Oid sequenceId, char *schemaName, char *sequenceName, /* since the command is an AlterSeqStmt, a dummy command string works fine */ ProcessUtilityParseTree((Node *) alterSequenceStatement, dummyString, - PROCESS_UTILITY_TOPLEVEL, NULL, None_Receiver, NULL); + PROCESS_UTILITY_QUERY, NULL, None_Receiver, NULL); } }