• R/O
  • HTTP
  • SSH
  • HTTPS

pg_hint_plan: Commit

firtst release


Commit MetaInfo

Revision789d4d72e8142c3f8394f406ecba3bcbba207827 (tree)
Time2020-02-17 16:57:05
AuthorKyotaro Horiguchi <horikyota.ntt@gmai...>
CommiterKyotaro Horiguchi

Log Message

Use proper type for non-integer GUC options.

pg_hint_plan internally preserved numeric options into integer
variable regardless of their types, which leads to unintentional
change of the values. Handle double values in the proper way.

Change Summary

Incremental Difference

--- a/pg_hint_plan.c
+++ b/pg_hint_plan.c
@@ -353,8 +353,8 @@ struct HintState
353353 int init_scan_mask; /* enable_* mask */
354354 int init_nworkers; /* max_parallel_workers_per_gather */
355355 int init_min_para_size; /* min_parallel_relation_size*/
356- int init_paratup_cost; /* parallel_tuple_cost */
357- int init_parasetup_cost;/* parallel_setup_cost */
356+ double init_paratup_cost; /* parallel_tuple_cost */
357+ double init_parasetup_cost;/* parallel_setup_cost */
358358
359359 PlannerInfo *current_root; /* PlannerInfo for the followings */
360360 Index parent_relid; /* inherit parent of table relid */
@@ -503,6 +503,8 @@ static void setup_scan_method_enforcement(ScanMethodHint *scanhint,
503503 HintState *state);
504504 static int set_config_int32_option(const char *name, int32 value,
505505 GucContext context);
506+static int set_config_double_option(const char *name, double value,
507+ GucContext context);
506508
507509 /* GUC variables */
508510 static bool pg_hint_plan_enable_hint = true;
@@ -2640,6 +2642,23 @@ set_config_int32_option(const char *name, int32 value, GucContext context)
26402642 pg_hint_plan_parse_message_level);
26412643 }
26422644
2645+/*
2646+ * Sets GUC parameter of double type without throwing exceptions. Returns false
2647+ * if something wrong.
2648+ */
2649+static int
2650+set_config_double_option(const char *name, double value, GucContext context)
2651+{
2652+ char *buf = float8out_internal(value);
2653+ int result;
2654+
2655+ result = set_config_option_noerror(name, buf, context,
2656+ PGC_S_SESSION, GUC_ACTION_SAVE, true,
2657+ pg_hint_plan_parse_message_level);
2658+ pfree(buf);
2659+ return result;
2660+}
2661+
26432662 /* setup scan method enforcement according to given options */
26442663 static void
26452664 setup_guc_enforcement(SetHint **options, int noptions, GucContext context)
@@ -2687,16 +2706,16 @@ setup_parallel_plan_enforcement(ParallelHint *hint, HintState *state)
26872706 /* force means that enforce parallel as far as possible */
26882707 if (hint && hint->force_parallel)
26892708 {
2690- set_config_int32_option("parallel_tuple_cost", 0, state->context);
2691- set_config_int32_option("parallel_setup_cost", 0, state->context);
2709+ set_config_double_option("parallel_tuple_cost", 0.0, state->context);
2710+ set_config_double_option("parallel_setup_cost", 0.0, state->context);
26922711 set_config_int32_option("min_parallel_relation_size", 0,
26932712 state->context);
26942713 }
26952714 else
26962715 {
2697- set_config_int32_option("parallel_tuple_cost",
2716+ set_config_double_option("parallel_tuple_cost",
26982717 state->init_paratup_cost, state->context);
2699- set_config_int32_option("parallel_setup_cost",
2718+ set_config_double_option("parallel_setup_cost",
27002719 state->init_parasetup_cost, state->context);
27012720 set_config_int32_option("min_parallel_relation_size",
27022721 state->init_min_para_size, state->context);
Show on old repository browser