Skip to content

Commit 2010cfa

Browse files
vuvovamontywi
authored andcommitted
remove GET_ADJUST_VALUE
avoid contaminating my_getopt with sysvar implementation details. adjust variable values after my_getopt, like it's done for others. this fixes --help to show correct values.
1 parent d10b3b0 commit 2010cfa

File tree

5 files changed

+46
-71
lines changed

5 files changed

+46
-71
lines changed

include/my_getopt.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ C_MODE_START
4040
#define GET_FLAGSET 15
4141
#define GET_BIT 16
4242

43-
#define GET_ADJUST_VALUE 256
4443
#define GET_ASK_ADDR 128
4544
#define GET_AUTO 64
4645
#define GET_TYPE_MASK 63
@@ -101,8 +100,6 @@ typedef my_bool (*my_get_one_option)(const struct my_option *, const char *, con
101100
typedef void *(*my_getopt_value)(const char *, uint, const struct my_option *,
102101
int *);
103102

104-
typedef void (*my_getopt_adjust)(const struct my_option *, void *);
105-
106103
extern char *disabled_my_option;
107104
extern char *autoset_my_option;
108105
extern my_bool my_getopt_print_errors;
@@ -111,7 +108,6 @@ extern my_bool my_getopt_prefix_matching;
111108
extern my_bool my_handle_options_init_variables;
112109
extern my_error_reporter my_getopt_error_reporter;
113110
extern my_getopt_value my_getopt_get_addr;
114-
extern my_getopt_adjust my_getopt_adjust_value;
115111

116112
extern int handle_options (int *argc, char ***argv,
117113
const struct my_option *longopts, my_get_one_option)

mysql-test/main/mysqld--help.result

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,29 +1739,29 @@ old-alter-table DEFAULT
17391739
old-mode UTF8_IS_UTF8MB3
17401740
old-passwords FALSE
17411741
old-style-user-limits FALSE
1742-
optimizer-disk-read-cost 0.01024
1742+
optimizer-disk-read-cost 10.24
17431743
optimizer-disk-read-ratio 0.02
17441744
optimizer-extra-pruning-depth 8
1745-
optimizer-index-block-copy-cost 3.56e-05
1746-
optimizer-key-compare-cost 1.1361e-05
1747-
optimizer-key-copy-cost 1.5685e-05
1748-
optimizer-key-lookup-cost 0.000435777
1749-
optimizer-key-next-find-cost 8.2347e-05
1745+
optimizer-index-block-copy-cost 0.0356
1746+
optimizer-key-compare-cost 0.011361
1747+
optimizer-key-copy-cost 0.015685
1748+
optimizer-key-lookup-cost 0.435777
1749+
optimizer-key-next-find-cost 0.082347
17501750
optimizer-max-sel-arg-weight 32000
17511751
optimizer-prune-level 2
1752-
optimizer-row-copy-cost 6.0866e-05
1753-
optimizer-row-lookup-cost 0.000130839
1754-
optimizer-row-next-find-cost 4.5916e-05
1755-
optimizer-rowid-compare-cost 2.653e-06
1756-
optimizer-rowid-copy-cost 2.653e-06
1757-
optimizer-scan-setup-cost 0.01
1752+
optimizer-row-copy-cost 0.060866
1753+
optimizer-row-lookup-cost 0.130839
1754+
optimizer-row-next-find-cost 0.045916
1755+
optimizer-rowid-compare-cost 0.002653
1756+
optimizer-rowid-copy-cost 0.002653
1757+
optimizer-scan-setup-cost 10
17581758
optimizer-search-depth 62
17591759
optimizer-selectivity-sampling-limit 100
17601760
optimizer-switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on,condition_pushdown_from_having=on
17611761
optimizer-trace
17621762
optimizer-trace-max-mem-size 1048576
17631763
optimizer-use-condition-selectivity 4
1764-
optimizer-where-cost 3.2e-05
1764+
optimizer-where-cost 0.032
17651765
performance-schema FALSE
17661766
performance-schema-accounts-size -1
17671767
performance-schema-consumer-events-stages-current FALSE

mysys/my_getopt.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ my_bool my_getopt_prefix_matching= 1;
8686
my_bool my_handle_options_init_variables = 1;
8787

8888
my_getopt_value my_getopt_get_addr= 0;
89-
my_getopt_adjust my_getopt_adjust_value= 0;
9089

9190
static void default_reporter(enum loglevel level, const char *format, ...)
9291
{
@@ -899,9 +898,6 @@ static int setval(const struct my_option *opts, void *value, char *argument,
899898
};
900899
}
901900

902-
if (opts->var_type & GET_ADJUST_VALUE)
903-
(*my_getopt_adjust_value)(opts, value);
904-
905901
validate_value(opts->name, argument, option_file);
906902

907903
DBUG_RETURN(0);

sql/mysqld.cc

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4863,6 +4863,25 @@ init_gtid_pos_auto_engines(void)
48634863
return 0;
48644864
}
48654865

4866+
4867+
#define us_to_ms(X) if (X > 0) X/= 1000;
4868+
static int adjust_optimizer_costs(void *, OPTIMIZER_COSTS *oc, void *)
4869+
{
4870+
us_to_ms(oc->disk_read_cost);
4871+
us_to_ms(oc->index_block_copy_cost);
4872+
us_to_ms(oc->key_cmp_cost);
4873+
us_to_ms(oc->key_copy_cost);
4874+
us_to_ms(oc->key_lookup_cost);
4875+
us_to_ms(oc->key_next_find_cost);
4876+
us_to_ms(oc->row_copy_cost);
4877+
us_to_ms(oc->row_lookup_cost);
4878+
us_to_ms(oc->row_next_find_cost);
4879+
us_to_ms(oc->rowid_cmp_cost);
4880+
us_to_ms(oc->rowid_copy_cost);
4881+
return 0;
4882+
}
4883+
4884+
48664885
#define MYSQL_COMPATIBILITY_OPTION(option) \
48674886
{ option, OPT_MYSQL_COMPATIBILITY, \
48684887
0, 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0 }
@@ -5207,8 +5226,15 @@ static int init_server_components()
52075226

52085227
tc_log= 0; // ha_initialize_handlerton() needs that
52095228

5210-
if (!opt_abort && ddl_log_initialize())
5211-
unireg_abort(1);
5229+
if (!opt_abort)
5230+
{
5231+
if (ddl_log_initialize())
5232+
unireg_abort(1);
5233+
5234+
process_optimizer_costs((process_optimizer_costs_t)adjust_optimizer_costs, 0);
5235+
us_to_ms(global_system_variables.optimizer_where_cost);
5236+
us_to_ms(global_system_variables.optimizer_scan_setup_cost);
5237+
}
52125238

52135239
if (plugin_init(&remaining_argc, remaining_argv,
52145240
(opt_noacl ? PLUGIN_INIT_SKIP_PLUGIN_TABLE : 0) |
@@ -8547,31 +8573,6 @@ mysql_getopt_value(const char *name, uint length,
85478573
}
85488574

85498575

8550-
static void
8551-
mariadb_getopt_adjust_value(const struct my_option *option, void *value)
8552-
{
8553-
switch (option->id) {
8554-
case OPT_COSTS_DISK_READ_COST:
8555-
case OPT_COSTS_INDEX_BLOCK_COPY_COST:
8556-
case OPT_COSTS_KEY_CMP_COST:
8557-
case OPT_COSTS_KEY_COPY_COST:
8558-
case OPT_COSTS_KEY_LOOKUP_COST:
8559-
case OPT_COSTS_KEY_NEXT_FIND_COST:
8560-
case OPT_COSTS_DISK_READ_RATIO:
8561-
case OPT_COSTS_ROW_COPY_COST:
8562-
case OPT_COSTS_ROW_LOOKUP_COST:
8563-
case OPT_COSTS_ROW_NEXT_FIND_COST:
8564-
case OPT_COSTS_ROWID_CMP_COST:
8565-
case OPT_COSTS_ROWID_COPY_COST:
8566-
/* Value from command is line given in usec. Convert to ms */
8567-
*(double*) value= *(double*) value/1000.0;
8568-
break;
8569-
default:
8570-
break;
8571-
}
8572-
}
8573-
8574-
85758576
static void option_error_reporter(enum loglevel level, const char *format, ...)
85768577
{
85778578
va_list args;
@@ -8610,7 +8611,6 @@ static int get_options(int *argc_ptr, char ***argv_ptr)
86108611

86118612
my_getopt_get_addr= mysql_getopt_value;
86128613
my_getopt_error_reporter= option_error_reporter;
8613-
my_getopt_adjust_value= mariadb_getopt_adjust_value;
86148614

86158615
/* prepare all_options array */
86168616
my_init_dynamic_array(PSI_INSTRUMENT_ME, &all_options, sizeof(my_option),

sql/sys_vars.inl

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,14 +1250,12 @@ public:
12501250
on_update_function on_update_func=0,
12511251
const char *substitute=0)
12521252
:Sys_var_double(name_arg, comment, flag_args, off, size, getopt,
1253-
min_val, max_val, def_val, lock,
1253+
min_val, max_val, def_val * arg_cost_adjust, lock,
12541254
binlog_status_arg,
12551255
on_check_func,
12561256
on_update_func,
12571257
substitute)
12581258
{
1259-
if (arg_cost_adjust == 1000)
1260-
option.var_type|= GET_ADJUST_VALUE;
12611259
cost_adjust= (double) arg_cost_adjust;
12621260
}
12631261
bool session_update(THD *thd, set_var *var)
@@ -1275,8 +1273,7 @@ public:
12751273

12761274
void global_save_default(THD *thd, set_var *var)
12771275
{
1278-
var->save_result.double_value= getopt_ulonglong2double(option.def_value)*
1279-
cost_adjust;
1276+
var->save_result.double_value= getopt_ulonglong2double(option.def_value);
12801277
}
12811278
const uchar *tmp_ptr(THD *thd) const
12821279
{
@@ -1312,33 +1309,20 @@ public:
13121309
#define COST_VAR(X) GLOBAL_VAR(default_optimizer_costs.X)
13131310
#define cost_var_ptr(KC, OFF) (((uchar*)(KC))+(OFF))
13141311
#define cost_var(KC, OFF) (*(double*)cost_var_ptr(KC, OFF))
1315-
typedef bool (*cost_update_function)(THD *, OPTIMIZER_COSTS *, ptrdiff_t,
1316-
double, double);
1317-
1318-
static bool update_cost(THD *thd, OPTIMIZER_COSTS *key_cache,
1319-
ptrdiff_t offset, double new_value, double cost_adjust)
1320-
{
1321-
cost_var(key_cache, offset)= new_value / cost_adjust;
1322-
return 0;
1323-
}
1324-
13251312

13261313
class Sys_var_engine_optimizer_cost: public Sys_var_optimizer_cost
13271314
{
1328-
cost_update_function cost_update;
13291315
public:
13301316
Sys_var_engine_optimizer_cost(const char *name_arg,
13311317
const char *comment, int flag_args, ptrdiff_t off, size_t size,
13321318
CMD_LINE getopt,
13331319
double min_val, double max_val, double def_val,
13341320
long cost_adjust, PolyLock *lock= 0,
1335-
cost_update_function on_update_func= update_cost,
13361321
const char *substitute=0)
13371322
: Sys_var_optimizer_cost(name_arg, comment, flag_args, off, size,
13381323
getopt, min_val, max_val, def_val, cost_adjust,
13391324
lock, VARIABLE_NOT_IN_BINLOG, 0,
1340-
0, substitute),
1341-
cost_update(on_update_func)
1325+
0, substitute)
13421326
{
13431327
option.var_type|= GET_ASK_ADDR;
13441328
option.value= (uchar**)1; // crash me, please
@@ -1351,7 +1335,6 @@ class Sys_var_engine_optimizer_cost: public Sys_var_optimizer_cost
13511335
double new_value= var->save_result.double_value;
13521336
LEX_CSTRING *base_name= &var->base;
13531337
OPTIMIZER_COSTS *optimizer_costs;
1354-
bool res;
13551338

13561339
/* If no basename, assume it's for the default costs */
13571340
if (!base_name->length)
@@ -1364,9 +1347,9 @@ class Sys_var_engine_optimizer_cost: public Sys_var_optimizer_cost
13641347
mysql_mutex_unlock(&LOCK_optimizer_costs);
13651348
return true;
13661349
}
1367-
res= cost_update(thd, optimizer_costs, offset, new_value, cost_adjust);
1350+
cost_var(optimizer_costs, offset)= new_value / cost_adjust;
13681351
mysql_mutex_unlock(&LOCK_optimizer_costs);
1369-
return res;
1352+
return 0;
13701353
}
13711354
const uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) const
13721355
{

0 commit comments

Comments
 (0)