Skip to content

Commit

Permalink
ADBDEV-3730: Don't initialize ORCA on query executors (#523)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
RekGRpth authored Jun 27, 2023
1 parent 7189fef commit 4fa8a09
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/backend/utils/init/postinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

/*
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit 4fa8a09

Please sign in to comment.