From 5dc454cdad9d0b8ca96aec411cc3a7ffd61a9c28 Mon Sep 17 00:00:00 2001 From: Onder Kalaci Date: Tue, 14 Jan 2020 10:09:16 +0100 Subject: [PATCH] Exclude localPlannedStatements from copy distributedPlan --- src/backend/distributed/executor/citus_custom_scan.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/backend/distributed/executor/citus_custom_scan.c b/src/backend/distributed/executor/citus_custom_scan.c index 4510e83ee..82d7f86e8 100644 --- a/src/backend/distributed/executor/citus_custom_scan.c +++ b/src/backend/distributed/executor/citus_custom_scan.c @@ -224,10 +224,21 @@ CitusGenerateDeferredQueryStrings(CustomScanState *node, EState *estate, int efl * We must not change the distributed plan since it may be reused across multiple * executions of a prepared statement. Instead we create a deep copy that we only * use for the current execution. + * + * We also exclude localPlannedStatements from the copyObject call for performance + * reasons, as they are immutable, so no need to have a deep copy. */ + DistributedPlan *originalDistributedPlan = scanState->distributedPlan; + List *localPlannedStatements = originalDistributedPlan->workerJob->localPlannedStatements; + originalDistributedPlan->workerJob->localPlannedStatements = NIL; + DistributedPlan *distributedPlan = copyObject(scanState->distributedPlan); scanState->distributedPlan = distributedPlan; + /* set back the immutable field */ + originalDistributedPlan->workerJob->localPlannedStatements = localPlannedStatements; + distributedPlan->workerJob->localPlannedStatements = localPlannedStatements; + Job *workerJob = distributedPlan->workerJob; Query *jobQuery = workerJob->jobQuery;