• R/O
  • HTTP
  • SSH
  • HTTPS

pg_hint_plan: Commit

firtst release


Commit MetaInfo

Revisionef5e86487f2df6b551e75102ce1a187231e4c671 (tree)
Time2020-02-17 16:56:35
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
@@ -358,8 +358,8 @@ struct HintState
358358 int init_min_para_tablescan_size;
359359 /* min_parallel_index_scan_size*/
360360 int init_min_para_indexscan_size;
361- int init_paratup_cost; /* parallel_tuple_cost */
362- int init_parasetup_cost;/* parallel_setup_cost */
361+ double init_paratup_cost; /* parallel_tuple_cost */
362+ double init_parasetup_cost;/* parallel_setup_cost */
363363
364364 PlannerInfo *current_root; /* PlannerInfo for the followings */
365365 Index parent_relid; /* inherit parent of table relid */
@@ -511,6 +511,8 @@ static void setup_scan_method_enforcement(ScanMethodHint *scanhint,
511511 HintState *state);
512512 static int set_config_int32_option(const char *name, int32 value,
513513 GucContext context);
514+static int set_config_double_option(const char *name, double value,
515+ GucContext context);
514516
515517 /* GUC variables */
516518 static bool pg_hint_plan_enable_hint = true;
@@ -2639,6 +2641,23 @@ set_config_int32_option(const char *name, int32 value, GucContext context)
26392641 pg_hint_plan_parse_message_level);
26402642 }
26412643
2644+/*
2645+ * Sets GUC parameter of double type without throwing exceptions. Returns false
2646+ * if something wrong.
2647+ */
2648+static int
2649+set_config_double_option(const char *name, double value, GucContext context)
2650+{
2651+ char *buf = float8out_internal(value);
2652+ int result;
2653+
2654+ result = set_config_option_noerror(name, buf, context,
2655+ PGC_S_SESSION, GUC_ACTION_SAVE, true,
2656+ pg_hint_plan_parse_message_level);
2657+ pfree(buf);
2658+ return result;
2659+}
2660+
26422661 /* setup scan method enforcement according to given options */
26432662 static void
26442663 setup_guc_enforcement(SetHint **options, int noptions, GucContext context)
@@ -2686,8 +2705,8 @@ setup_parallel_plan_enforcement(ParallelHint *hint, HintState *state)
26862705 /* force means that enforce parallel as far as possible */
26872706 if (hint && hint->force_parallel)
26882707 {
2689- set_config_int32_option("parallel_tuple_cost", 0, state->context);
2690- set_config_int32_option("parallel_setup_cost", 0, state->context);
2708+ set_config_double_option("parallel_tuple_cost", 0.0, state->context);
2709+ set_config_double_option("parallel_setup_cost", 0.0, state->context);
26912710 set_config_int32_option("min_parallel_table_scan_size", 0,
26922711 state->context);
26932712 set_config_int32_option("min_parallel_index_scan_size", 0,
@@ -2695,9 +2714,9 @@ setup_parallel_plan_enforcement(ParallelHint *hint, HintState *state)
26952714 }
26962715 else
26972716 {
2698- set_config_int32_option("parallel_tuple_cost",
2717+ set_config_double_option("parallel_tuple_cost",
26992718 state->init_paratup_cost, state->context);
2700- set_config_int32_option("parallel_setup_cost",
2719+ set_config_double_option("parallel_setup_cost",
27012720 state->init_parasetup_cost, state->context);
27022721 set_config_int32_option("min_parallel_table_scan_size",
27032722 state->init_min_para_tablescan_size,
Show on old repository browser