From 4fa8a09d5babb471a36b8a06b499247d24d1f6ad Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Tue, 27 Jun 2023 15:24:55 +0500 Subject: [PATCH] ADBDEV-3730: Don't initialize ORCA on query executors (#523) Currently, the ORCA optimizer is initialized unconditionally in all backends. But we can reduce memory consumption by avoiding ORCA initialization on query executors where ORCA is never used. This can be done using the Gp_role variable, which is set to GP_ROLE_EXECUTE on the executors, and this happens before ORCA is initialized. --- src/backend/utils/init/postinit.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c index 923b7fc1fa8b..fade51a691f0 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -652,14 +652,17 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username, GPMemoryProtect_Init(); #ifdef USE_ORCA - /* Initialize GPOPT */ - OptimizerMemoryContext = AllocSetContextCreate(TopMemoryContext, - "GPORCA Top-level Memory Context", - ALLOCSET_DEFAULT_MINSIZE, - ALLOCSET_DEFAULT_INITSIZE, - ALLOCSET_DEFAULT_MAXSIZE); - - InitGPOPT(); + if (Gp_role == GP_ROLE_DISPATCH) + { + /* Initialize GPOPT */ + OptimizerMemoryContext = AllocSetContextCreate(TopMemoryContext, + "GPORCA Top-level Memory Context", + ALLOCSET_DEFAULT_MINSIZE, + ALLOCSET_DEFAULT_INITSIZE, + ALLOCSET_DEFAULT_MAXSIZE); + + InitGPOPT(); + } #endif /* @@ -1407,10 +1410,13 @@ ShutdownPostgres(int code, Datum arg) ReportOOMConsumption(); #ifdef USE_ORCA - TerminateGPOPT(); + if (Gp_role == GP_ROLE_DISPATCH) + { + TerminateGPOPT(); - if (OptimizerMemoryContext != NULL) - MemoryContextDelete(OptimizerMemoryContext); + if (OptimizerMemoryContext != NULL) + MemoryContextDelete(OptimizerMemoryContext); + } #endif /* Disable memory protection */