Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: lazy initialize orca optimizer #191

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/backend/optimizer/plan/planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,15 @@
#include "storage/lmgr.h"
#include "utils/guc.h"

#ifdef USE_ORCA
extern void InitGPOPT();
#endif

/* GUC parameters */
double cursor_tuple_fraction = DEFAULT_CURSOR_TUPLE_FRACTION;
int force_parallel_mode = FORCE_PARALLEL_OFF;
bool parallel_leader_participation = false;
bool optimizer_init = false;

/* Hook for plugins to get control in planner() */
planner_hook_type planner_hook = NULL;
Expand Down Expand Up @@ -366,6 +370,20 @@ standard_planner(Query *parse, const char *query_string, int cursorOptions,
(cursorOptions & CURSOR_OPT_SKIP_FOREIGN_PARTITIONS) == 0 &&
(cursorOptions & CURSOR_OPT_PARALLEL_RETRIEVE) == 0)
{

#ifdef USE_ORCA
if (!optimizer_init) {
/* Initialize GPOPT */
OptimizerMemoryContext = AllocSetContextCreate(TopMemoryContext,
"GPORCA Top-level Memory Context",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
InitGPOPT();
optimizer_init = true;
}
#endif

if (gp_log_optimization_time)
INSTR_TIME_SET_CURRENT(starttime);

Expand Down
25 changes: 25 additions & 0 deletions src/backend/utils/adt/gp_optimizer_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

#include "funcapi.h"
#include "utils/builtins.h"
#include "optimizer/planner.h"

#ifdef USE_ORCA
extern void InitGPOPT();
#endif

extern Datum EnableXform(PG_FUNCTION_ARGS);

Expand All @@ -25,6 +30,16 @@ Datum
enable_xform(PG_FUNCTION_ARGS)
{
#ifdef USE_ORCA
if (!optimizer_init) {
/* Initialize GPOPT */
OptimizerMemoryContext = AllocSetContextCreate(TopMemoryContext,
"GPORCA Top-level Memory Context",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
InitGPOPT();
optimizer_init = true;
}
return EnableXform(fcinfo);
#else
return CStringGetTextDatum("Server has been compiled without ORCA");
Expand All @@ -40,6 +55,16 @@ Datum
disable_xform(PG_FUNCTION_ARGS)
{
#ifdef USE_ORCA
if (!optimizer_init) {
/* Initialize GPOPT */
OptimizerMemoryContext = AllocSetContextCreate(TopMemoryContext,
"GPORCA Top-level Memory Context",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
InitGPOPT();
optimizer_init = true;
}
return DisableXform(fcinfo);
#else
return CStringGetTextDatum("Server has been compiled without ORCA");
Expand Down
12 changes: 1 addition & 11 deletions src/backend/utils/init/postinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -676,17 +676,7 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
/* Initialize memory protection */
GPMemoryProtect_Init();

#ifdef USE_ORCA
/* Initialize GPOPT */
OptimizerMemoryContext = AllocSetContextCreate(TopMemoryContext,
"GPORCA Top-level Memory Context",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);

if (!bootstrap && Gp_role == GP_ROLE_DISPATCH)
InitGPOPT();
#endif


/*
* Initialize my entry in the shared-invalidation manager's array of
Expand Down
2 changes: 2 additions & 0 deletions src/include/optimizer/planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,6 @@ extern Path *get_cheapest_fractional_path(RelOptInfo *rel,

extern Expr *preprocess_phv_expression(PlannerInfo *root, Expr *expr);

extern bool optimizer_init;

#endif /* PLANNER_H */