enable local execution for DROP command on distributed & reference tables

improve-drop-trigger2
Onur Tirtir 2020-03-10 16:02:40 +03:00
parent 26cec16b16
commit 4042d21714
1 changed files with 33 additions and 7 deletions

View File

@ -396,6 +396,7 @@ DropShards(Oid relationId, char *schemaName, char *relationName,
List *dropTaskList = DropTaskList(relationId, schemaName, relationName, List *dropTaskList = DropTaskList(relationId, schemaName, relationName,
deletableShardIntervalList); deletableShardIntervalList);
bool shouldExecuteTasksLocally = ShouldExecuteTasksLocally(dropTaskList);
Task *task = NULL; Task *task = NULL;
foreach_ptr(task, dropTaskList) foreach_ptr(task, dropTaskList)
@ -423,6 +424,30 @@ DropShards(Oid relationId, char *schemaName, char *relationName,
continue; continue;
} }
/*
* If it is a local placement of a distributed table or a reference table,
* then execute the DROP command locally.
*/
if (isLocalShardPlacement && shouldExecuteTasksLocally)
{
List *singleTaskList = list_make1(task);
ExecuteLocalUtilityTaskList(singleTaskList);
}
else
{
/*
* Either it was not a local placement or we could not use
* local execution even if it was a local placement.
* If it is the second case, then it is possibly because in
* current transaction, some commands or queries connected
* to local group as well.
*
* Regardless of the node is a remote node or the current node,
* try to open a new connection (or use an existing one) to
* connect to that node to drop the shard placement over that
* remote connection.
*/
const char *dropShardPlacementCommand = TaskQueryString(task); const char *dropShardPlacementCommand = TaskQueryString(task);
ExecuteDropShardPlacementCommandRemotely(shardPlacement, ExecuteDropShardPlacementCommandRemotely(shardPlacement,
relationName, relationName,
@ -432,6 +457,7 @@ DropShards(Oid relationId, char *schemaName, char *relationName,
{ {
TransactionConnectedToLocalGroup = true; TransactionConnectedToLocalGroup = true;
} }
}
DeleteShardPlacementRow(shardPlacementId); DeleteShardPlacementRow(shardPlacementId);
} }