• R/O
  • HTTP
  • SSH
  • HTTPS

pg_hint_plan: Commit

firtst release


Commit MetaInfo

Revision0087813c357c66e695164216de795e1e0d8a3a27 (tree)
Time2020-02-17 16:56:14
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
@@ -359,8 +359,8 @@ struct HintState
359359 int init_min_para_tablescan_size;
360360 /* min_parallel_index_scan_size*/
361361 int init_min_para_indexscan_size;
362- int init_paratup_cost; /* parallel_tuple_cost */
363- int init_parasetup_cost;/* parallel_setup_cost */
362+ double init_paratup_cost; /* parallel_tuple_cost */
363+ double init_parasetup_cost;/* parallel_setup_cost */
364364
365365 PlannerInfo *current_root; /* PlannerInfo for the followings */
366366 Index parent_relid; /* inherit parent of table relid */
@@ -502,6 +502,8 @@ static void setup_scan_method_enforcement(ScanMethodHint *scanhint,
502502 HintState *state);
503503 static int set_config_int32_option(const char *name, int32 value,
504504 GucContext context);
505+static int set_config_double_option(const char *name, double value,
506+ GucContext context);
505507
506508 /* GUC variables */
507509 static bool pg_hint_plan_enable_hint = true;
@@ -2630,6 +2632,23 @@ set_config_int32_option(const char *name, int32 value, GucContext context)
26302632 pg_hint_plan_parse_message_level);
26312633 }
26322634
2635+/*
2636+ * Sets GUC parameter of double type without throwing exceptions. Returns false
2637+ * if something wrong.
2638+ */
2639+static int
2640+set_config_double_option(const char *name, double value, GucContext context)
2641+{
2642+ char *buf = float8out_internal(value);
2643+ int result;
2644+
2645+ result = set_config_option_noerror(name, buf, context,
2646+ PGC_S_SESSION, GUC_ACTION_SAVE, true,
2647+ pg_hint_plan_parse_message_level);
2648+ pfree(buf);
2649+ return result;
2650+}
2651+
26332652 /* setup scan method enforcement according to given options */
26342653 static void
26352654 setup_guc_enforcement(SetHint **options, int noptions, GucContext context)
@@ -2677,8 +2696,8 @@ setup_parallel_plan_enforcement(ParallelHint *hint, HintState *state)
26772696 /* force means that enforce parallel as far as possible */
26782697 if (hint && hint->force_parallel && hint->nworkers > 0)
26792698 {
2680- set_config_int32_option("parallel_tuple_cost", 0, state->context);
2681- set_config_int32_option("parallel_setup_cost", 0, state->context);
2699+ set_config_double_option("parallel_tuple_cost", 0.0, state->context);
2700+ set_config_double_option("parallel_setup_cost", 0.0, state->context);
26822701 set_config_int32_option("min_parallel_table_scan_size", 0,
26832702 state->context);
26842703 set_config_int32_option("min_parallel_index_scan_size", 0,
@@ -2686,9 +2705,9 @@ setup_parallel_plan_enforcement(ParallelHint *hint, HintState *state)
26862705 }
26872706 else
26882707 {
2689- set_config_int32_option("parallel_tuple_cost",
2708+ set_config_double_option("parallel_tuple_cost",
26902709 state->init_paratup_cost, state->context);
2691- set_config_int32_option("parallel_setup_cost",
2710+ set_config_double_option("parallel_setup_cost",
26922711 state->init_parasetup_cost, state->context);
26932712 set_config_int32_option("min_parallel_table_scan_size",
26942713 state->init_min_para_tablescan_size,
Show on old repository browser