Skip to content

Commit

Permalink
Add hook for vectoriztion execution.
Browse files Browse the repository at this point in the history
Enable setting larger spill mem threshold for optimizer.

Signed-off-by: Dongxiao Song <songdongxiao@hashdata.cn>
Co-authored-by: wuyifan <wuyifan@hashdata.cn>
  • Loading branch information
wuyifan authored and songdongxiaoa2 committed May 23, 2024
1 parent 4b26965 commit 1e560b5
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/backend/gpopt/utils/COptTasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,18 @@ COptTasks::SetCostModelParams(ICostModel *cost_model)
cost_param->GetLowerBoundVal() * optimizer_sort_factor,
cost_param->GetUpperBoundVal() * optimizer_sort_factor);
}
if (optimizer_spilling_mem_threshold > 0.0) {
ICostModelParams::SCostParam *cost_param =
cost_model->GetCostModelParams()->PcpLookup(
CCostModelParamsGPDB::EcpHJSpillingMemThreshold);

CDouble spill_mem_threshold(optimizer_spilling_mem_threshold);
cost_model->GetCostModelParams()->SetParam(
cost_param->Id(), spill_mem_threshold,
spill_mem_threshold - 0.0,
spill_mem_threshold + 0.0);
}

}


Expand Down
21 changes: 18 additions & 3 deletions src/backend/tcop/postgres.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ int client_connection_check_interval = 0;
*/
cancel_pending_hook_type cancel_pending_hook = NULL;

/*
* Hook for query execution.
*/
exec_simple_query_hook_type exec_simple_query_hook = NULL;

/* ----------------
* private typedefs etc
* ----------------
Expand Down Expand Up @@ -1647,7 +1652,7 @@ restore_guc_to_QE(void )
*
* Execute a "simple Query" protocol message.
*/
static void
void
exec_simple_query(const char *query_string)
{
CommandDest dest = whereToSendOutput;
Expand Down Expand Up @@ -5569,12 +5574,19 @@ PostgresMain(int argc, char *argv[],
if (am_walsender)
{
if (!exec_replication_command(query_string))
exec_simple_query(query_string);
{
if (exec_simple_query_hook)
exec_simple_query_hook(query_string);
else
exec_simple_query(query_string);
}
}
else if (am_ftshandler)
HandleFtsMessage(query_string);
else if (am_faulthandler)
HandleFaultMessage(query_string);
else if (exec_simple_query_hook)
exec_simple_query_hook(query_string);
else
exec_simple_query(query_string);

Expand Down Expand Up @@ -5735,7 +5747,10 @@ PostgresMain(int argc, char *argv[],
}
else
{
exec_simple_query(query_string);
if (exec_simple_query_hook)
exec_simple_query_hook(query_string);
else
exec_simple_query(query_string);
}
}
else
Expand Down
14 changes: 13 additions & 1 deletion src/backend/utils/misc/guc_gp.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ int optimizer_penalize_broadcast_threshold;
double optimizer_cost_threshold;
double optimizer_nestloop_factor;
double optimizer_sort_factor;
double optimizer_spilling_mem_threshold;

/* Optimizer hints */
int optimizer_join_arity_for_associativity_commutativity;
Expand Down Expand Up @@ -4412,7 +4413,7 @@ struct config_real ConfigureNamesReal_gp[] =
},

{
{"optimizer_sort_factor",PGC_USERSET, QUERY_TUNING_OTHER,
{"optimizer_sort_factor", PGC_USERSET, QUERY_TUNING_OTHER,
gettext_noop("Set the sort cost factor in the optimizer, 1.0 means same as default, > 1.0 means more costly than default, < 1.0 means means less costly than default"),
NULL,
GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
Expand All @@ -4422,6 +4423,17 @@ struct config_real ConfigureNamesReal_gp[] =
NULL, NULL, NULL
},

{
{"optimizer_spilling_mem_threshold", PGC_USERSET, QUERY_TUNING_OTHER,
gettext_noop("Set the optimizer factor for threshold of spilling to memory, 0.0 means unbounded"),
NULL,
GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
},
&optimizer_spilling_mem_threshold,
0.0, 0.0, DBL_MAX,
NULL, NULL, NULL
},

/* End-of-list marker */
{
{NULL, 0, 0, NULL, NULL}, NULL, 0.0, 0.0, 0.0, NULL, NULL
Expand Down
6 changes: 6 additions & 0 deletions src/include/tcop/tcopprot.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ extern int max_stack_depth;
extern int PostAuthDelay;
extern int client_connection_check_interval;

/* Hook for query execution.*/
typedef void (*exec_simple_query_hook_type) (const char *);
extern exec_simple_query_hook_type exec_simple_query_hook;

/* GUC-configurable parameters */

typedef enum
Expand Down Expand Up @@ -90,4 +94,6 @@ extern const char *get_stats_option_name(const char *arg);
extern void enable_client_wait_timeout_interrupt(void);
extern void disable_client_wait_timeout_interrupt(void);

extern void exec_simple_query(const char *query_string);

#endif /* TCOPPROT_H */
1 change: 1 addition & 0 deletions src/include/utils/guc.h
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ extern int optimizer_penalize_broadcast_threshold;
extern double optimizer_cost_threshold;
extern double optimizer_nestloop_factor;
extern double optimizer_sort_factor;
extern double optimizer_spilling_mem_threshold;

/* Optimizer hints */
extern int optimizer_array_expansion_threshold;
Expand Down
1 change: 1 addition & 0 deletions src/include/utils/unsync_guc_name.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@
"optimizer_sample_plans",
"optimizer_search_strategy_path",
"optimizer_segments",
"optimizer_spilling_mem_threshold",
"optimizer_sort_factor",
"optimizer_trace_fallback",
"optimizer_use_external_constant_expression_evaluation_for_ints",
Expand Down

0 comments on commit 1e560b5

Please # to comment.