firtst release
Revision | 7dcc96fd27a7f91545156887faba5907f35da068 (tree) |
---|---|
Time | 2020-02-17 16:55:02 |
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.
@@ -38,6 +38,7 @@ | ||
38 | 38 | #include "partitioning/partbounds.h" |
39 | 39 | #include "tcop/utility.h" |
40 | 40 | #include "utils/builtins.h" |
41 | +#include "utils/float.h" | |
41 | 42 | #include "utils/lsyscache.h" |
42 | 43 | #include "utils/memutils.h" |
43 | 44 | #include "utils/rel.h" |
@@ -363,8 +364,8 @@ struct HintState | ||
363 | 364 | int init_min_para_tablescan_size; |
364 | 365 | /* min_parallel_index_scan_size*/ |
365 | 366 | int init_min_para_indexscan_size; |
366 | - int init_paratup_cost; /* parallel_tuple_cost */ | |
367 | - int init_parasetup_cost;/* parallel_setup_cost */ | |
367 | + double init_paratup_cost; /* parallel_tuple_cost */ | |
368 | + double init_parasetup_cost;/* parallel_setup_cost */ | |
368 | 369 | |
369 | 370 | PlannerInfo *current_root; /* PlannerInfo for the followings */ |
370 | 371 | Index parent_relid; /* inherit parent of table relid */ |
@@ -506,6 +507,8 @@ static void setup_scan_method_enforcement(ScanMethodHint *scanhint, | ||
506 | 507 | HintState *state); |
507 | 508 | static int set_config_int32_option(const char *name, int32 value, |
508 | 509 | GucContext context); |
510 | +static int set_config_double_option(const char *name, double value, | |
511 | + GucContext context); | |
509 | 512 | |
510 | 513 | /* GUC variables */ |
511 | 514 | static bool pg_hint_plan_enable_hint = true; |
@@ -2634,6 +2637,23 @@ set_config_int32_option(const char *name, int32 value, GucContext context) | ||
2634 | 2637 | pg_hint_plan_parse_message_level); |
2635 | 2638 | } |
2636 | 2639 | |
2640 | +/* | |
2641 | + * Sets GUC parameter of double type without throwing exceptions. Returns false | |
2642 | + * if something wrong. | |
2643 | + */ | |
2644 | +static int | |
2645 | +set_config_double_option(const char *name, double value, GucContext context) | |
2646 | +{ | |
2647 | + char *buf = float8out_internal(value); | |
2648 | + int result; | |
2649 | + | |
2650 | + result = set_config_option_noerror(name, buf, context, | |
2651 | + PGC_S_SESSION, GUC_ACTION_SAVE, true, | |
2652 | + pg_hint_plan_parse_message_level); | |
2653 | + pfree(buf); | |
2654 | + return result; | |
2655 | +} | |
2656 | + | |
2637 | 2657 | /* setup scan method enforcement according to given options */ |
2638 | 2658 | static void |
2639 | 2659 | setup_guc_enforcement(SetHint **options, int noptions, GucContext context) |
@@ -2681,8 +2701,8 @@ setup_parallel_plan_enforcement(ParallelHint *hint, HintState *state) | ||
2681 | 2701 | /* force means that enforce parallel as far as possible */ |
2682 | 2702 | if (hint && hint->force_parallel && hint->nworkers > 0) |
2683 | 2703 | { |
2684 | - set_config_int32_option("parallel_tuple_cost", 0, state->context); | |
2685 | - set_config_int32_option("parallel_setup_cost", 0, state->context); | |
2704 | + set_config_double_option("parallel_tuple_cost", 0.0, state->context); | |
2705 | + set_config_double_option("parallel_setup_cost", 0.0, state->context); | |
2686 | 2706 | set_config_int32_option("min_parallel_table_scan_size", 0, |
2687 | 2707 | state->context); |
2688 | 2708 | set_config_int32_option("min_parallel_index_scan_size", 0, |
@@ -2690,9 +2710,9 @@ setup_parallel_plan_enforcement(ParallelHint *hint, HintState *state) | ||
2690 | 2710 | } |
2691 | 2711 | else |
2692 | 2712 | { |
2693 | - set_config_int32_option("parallel_tuple_cost", | |
2713 | + set_config_double_option("parallel_tuple_cost", | |
2694 | 2714 | state->init_paratup_cost, state->context); |
2695 | - set_config_int32_option("parallel_setup_cost", | |
2715 | + set_config_double_option("parallel_setup_cost", | |
2696 | 2716 | state->init_parasetup_cost, state->context); |
2697 | 2717 | set_config_int32_option("min_parallel_table_scan_size", |
2698 | 2718 | state->init_min_para_tablescan_size, |