• R/O
  • HTTP
  • SSH
  • HTTPS

pg_hint_plan: Commit

firtst release


Commit MetaInfo

Revision7dcc96fd27a7f91545156887faba5907f35da068 (tree)
Time2020-02-17 16:55:02
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
@@ -38,6 +38,7 @@
3838 #include "partitioning/partbounds.h"
3939 #include "tcop/utility.h"
4040 #include "utils/builtins.h"
41+#include "utils/float.h"
4142 #include "utils/lsyscache.h"
4243 #include "utils/memutils.h"
4344 #include "utils/rel.h"
@@ -363,8 +364,8 @@ struct HintState
363364 int init_min_para_tablescan_size;
364365 /* min_parallel_index_scan_size*/
365366 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 */
368369
369370 PlannerInfo *current_root; /* PlannerInfo for the followings */
370371 Index parent_relid; /* inherit parent of table relid */
@@ -506,6 +507,8 @@ static void setup_scan_method_enforcement(ScanMethodHint *scanhint,
506507 HintState *state);
507508 static int set_config_int32_option(const char *name, int32 value,
508509 GucContext context);
510+static int set_config_double_option(const char *name, double value,
511+ GucContext context);
509512
510513 /* GUC variables */
511514 static bool pg_hint_plan_enable_hint = true;
@@ -2634,6 +2637,23 @@ set_config_int32_option(const char *name, int32 value, GucContext context)
26342637 pg_hint_plan_parse_message_level);
26352638 }
26362639
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+
26372657 /* setup scan method enforcement according to given options */
26382658 static void
26392659 setup_guc_enforcement(SetHint **options, int noptions, GucContext context)
@@ -2681,8 +2701,8 @@ setup_parallel_plan_enforcement(ParallelHint *hint, HintState *state)
26812701 /* force means that enforce parallel as far as possible */
26822702 if (hint && hint->force_parallel && hint->nworkers > 0)
26832703 {
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);
26862706 set_config_int32_option("min_parallel_table_scan_size", 0,
26872707 state->context);
26882708 set_config_int32_option("min_parallel_index_scan_size", 0,
@@ -2690,9 +2710,9 @@ setup_parallel_plan_enforcement(ParallelHint *hint, HintState *state)
26902710 }
26912711 else
26922712 {
2693- set_config_int32_option("parallel_tuple_cost",
2713+ set_config_double_option("parallel_tuple_cost",
26942714 state->init_paratup_cost, state->context);
2695- set_config_int32_option("parallel_setup_cost",
2715+ set_config_double_option("parallel_setup_cost",
26962716 state->init_parasetup_cost, state->context);
26972717 set_config_int32_option("min_parallel_table_scan_size",
26982718 state->init_min_para_tablescan_size,
Show on old repository browser