firtst release
Revision | 0087813c357c66e695164216de795e1e0d8a3a27 (tree) |
---|---|
Time | 2020-02-17 16:56:14 |
Author | Kyotaro Horiguchi <horikyota.ntt@gmai...> |
Commiter | Kyotaro Horiguchi |
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.
@@ -359,8 +359,8 @@ struct HintState | ||
359 | 359 | int init_min_para_tablescan_size; |
360 | 360 | /* min_parallel_index_scan_size*/ |
361 | 361 | 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 */ | |
364 | 364 | |
365 | 365 | PlannerInfo *current_root; /* PlannerInfo for the followings */ |
366 | 366 | Index parent_relid; /* inherit parent of table relid */ |
@@ -502,6 +502,8 @@ static void setup_scan_method_enforcement(ScanMethodHint *scanhint, | ||
502 | 502 | HintState *state); |
503 | 503 | static int set_config_int32_option(const char *name, int32 value, |
504 | 504 | GucContext context); |
505 | +static int set_config_double_option(const char *name, double value, | |
506 | + GucContext context); | |
505 | 507 | |
506 | 508 | /* GUC variables */ |
507 | 509 | static bool pg_hint_plan_enable_hint = true; |
@@ -2630,6 +2632,23 @@ set_config_int32_option(const char *name, int32 value, GucContext context) | ||
2630 | 2632 | pg_hint_plan_parse_message_level); |
2631 | 2633 | } |
2632 | 2634 | |
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 | + | |
2633 | 2652 | /* setup scan method enforcement according to given options */ |
2634 | 2653 | static void |
2635 | 2654 | setup_guc_enforcement(SetHint **options, int noptions, GucContext context) |
@@ -2677,8 +2696,8 @@ setup_parallel_plan_enforcement(ParallelHint *hint, HintState *state) | ||
2677 | 2696 | /* force means that enforce parallel as far as possible */ |
2678 | 2697 | if (hint && hint->force_parallel && hint->nworkers > 0) |
2679 | 2698 | { |
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); | |
2682 | 2701 | set_config_int32_option("min_parallel_table_scan_size", 0, |
2683 | 2702 | state->context); |
2684 | 2703 | set_config_int32_option("min_parallel_index_scan_size", 0, |
@@ -2686,9 +2705,9 @@ setup_parallel_plan_enforcement(ParallelHint *hint, HintState *state) | ||
2686 | 2705 | } |
2687 | 2706 | else |
2688 | 2707 | { |
2689 | - set_config_int32_option("parallel_tuple_cost", | |
2708 | + set_config_double_option("parallel_tuple_cost", | |
2690 | 2709 | state->init_paratup_cost, state->context); |
2691 | - set_config_int32_option("parallel_setup_cost", | |
2710 | + set_config_double_option("parallel_setup_cost", | |
2692 | 2711 | state->init_parasetup_cost, state->context); |
2693 | 2712 | set_config_int32_option("min_parallel_table_scan_size", |
2694 | 2713 | state->init_min_para_tablescan_size, |