Skip to content

Commit

Permalink
Cleanups
Browse files Browse the repository at this point in the history
- Avoid some realloc() during startup
- Ensure that file_key_management_plugin frees it's memory early, even if
  it's linked statically.
- Fixed compiler warnings from unused variables and missing destructors
- Fixed wrong indentation
  • Loading branch information
montywi committed Apr 28, 2016
1 parent dafed5b commit fabeab7
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 31 deletions.
2 changes: 1 addition & 1 deletion mysys/my_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ int my_load_defaults(const char *conf_file, const char **groups,
for (; *groups ; groups++)
group.count++;

if (my_init_dynamic_array(&args, sizeof(char*),*argc, 32, MYF(0)))
if (my_init_dynamic_array(&args, sizeof(char*), 128, 64, MYF(0)))
goto err;

ctx.alloc= &alloc;
Expand Down
7 changes: 6 additions & 1 deletion plugin/file_key_management/file_key_management_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ static int file_key_management_plugin_init(void *p)
return parser.parse(&keys);
}

static int file_key_management_plugin_deinit(void *p)
{
keys.free_memory();
}

/*
Plugin library descriptor
*/
Expand All @@ -181,7 +186,7 @@ maria_declare_plugin(file_key_management)
"File-based key management plugin",
PLUGIN_LICENSE_GPL,
file_key_management_plugin_init,
NULL,
file_key_management_plugin_deinit,
0x0100 /* 1.0 */,
NULL, /* status variables */
settings,
Expand Down
3 changes: 2 additions & 1 deletion sql/mysqld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9427,7 +9427,8 @@ static int get_options(int *argc_ptr, char ***argv_ptr)

/* prepare all_options array */
my_init_dynamic_array(&all_options, sizeof(my_option),
array_elements(my_long_options),
array_elements(my_long_options) +
sys_var_elements(),
array_elements(my_long_options)/4, MYF(0));
add_many_options(&all_options, my_long_options, array_elements(my_long_options));
sys_var_add_options(&all_options, 0);
Expand Down
9 changes: 5 additions & 4 deletions sql/rpl_rli.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,11 @@ class Relay_log_info : public Slave_reporting_capability

rpl_parallel parallel;
/*
The relay_log_state keeps track of the current binlog state of the execution
of the relay log. This is used to know where to resume current GTID position
if the slave thread is stopped and restarted.
It is only accessed from the SQL thread, so it does not need any locking.
The relay_log_state keeps track of the current binlog state of the
execution of the relay log. This is used to know where to resume
current GTID position if the slave thread is stopped and
restarted. It is only accessed from the SQL thread, so it does
not need any locking.
*/
rpl_binlog_state relay_log_state;
/*
Expand Down
7 changes: 6 additions & 1 deletion sql/set_var.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ int sys_var_init()
/* Must be already initialized. */
DBUG_ASSERT(system_charset_info != NULL);

if (my_hash_init(&system_variable_hash, system_charset_info, 100, 0,
if (my_hash_init(&system_variable_hash, system_charset_info, 700, 0,
0, (my_hash_get_key) get_sys_var_length, 0, HASH_UNIQUE))
goto error;

Expand All @@ -78,6 +78,11 @@ int sys_var_init()
DBUG_RETURN(1);
}

uint sys_var_elements()
{
return system_variable_hash.records;
}

int sys_var_add_options(DYNAMIC_ARRAY *long_options, int parse_flags)
{
uint saved_elements= long_options->elements;
Expand Down
1 change: 1 addition & 0 deletions sql/set_var.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ extern sys_var *Sys_autocommit_ptr;
CHARSET_INFO *get_old_charset_by_name(const char *old_name);

int sys_var_init();
uint sys_var_elements();
int sys_var_add_options(DYNAMIC_ARRAY *long_options, int parse_flags);
void sys_var_end(void);

Expand Down
5 changes: 5 additions & 0 deletions sql/sql_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ template <class Elem> class Dynamic_array
delete_dynamic(&array);
}

void free_memory()
{
delete_dynamic(&array);
}

typedef int (*CMP_FUNC)(const Elem *el1, const Elem *el2);

void sort(CMP_FUNC cmp_func)
Expand Down
10 changes: 7 additions & 3 deletions sql/sql_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1544,22 +1544,26 @@ int plugin_init(int *argc, char **argv, int flags)
init_alloc_root(&plugin_vars_mem_root, 4096, 4096, MYF(0));
init_alloc_root(&tmp_root, 4096, 4096, MYF(0));

if (my_hash_init(&bookmark_hash, &my_charset_bin, 16, 0, 0,
if (my_hash_init(&bookmark_hash, &my_charset_bin, 32, 0, 0,
get_bookmark_hash_key, NULL, HASH_UNIQUE))
goto err;


mysql_mutex_init(key_LOCK_plugin, &LOCK_plugin, MY_MUTEX_INIT_FAST);

/*
The 80 is from 2016-04-27 when we had 71 default plugins
Big enough to avoid many mallocs even in future
*/
if (my_init_dynamic_array(&plugin_dl_array,
sizeof(struct st_plugin_dl *), 16, 16, MYF(0)) ||
my_init_dynamic_array(&plugin_array,
sizeof(struct st_plugin_int *), 16, 16, MYF(0)))
sizeof(struct st_plugin_int *), 80, 32, MYF(0)))
goto err;

for (i= 0; i < MYSQL_MAX_PLUGIN_TYPE_NUM; i++)
{
if (my_hash_init(&plugin_hash[i], system_charset_info, 16, 0, 0,
if (my_hash_init(&plugin_hash[i], system_charset_info, 32, 0, 0,
get_plugin_hash_key, NULL, HASH_UNIQUE))
goto err;
}
Expand Down
35 changes: 17 additions & 18 deletions sql/sql_select.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2017,7 +2017,7 @@ JOIN::optimize_inner()
TODO: Explain the quick_group part of the test below.
*/
if ((ordered_index_usage != ordered_index_group_by) &&
(tmp_table_param.quick_group && !procedure ||
((tmp_table_param.quick_group && !procedure) ||
(tab->emb_sj_nest &&
best_positions[const_tables].sj_strategy == SJ_OPT_LOOSE_SCAN)))
{
Expand Down Expand Up @@ -3123,7 +3123,7 @@ void JOIN::save_explain_data(Explain_query *output, bool can_overwrite,
Explain_union *eu= output->get_union(nr);
explain= &eu->fake_select_lex_explain;
join_tab[0].tracker= eu->get_fake_select_lex_tracker();
for (int i=0 ; i < top_join_tab_count + aggr_tables; i++)
for (uint i=0 ; i < top_join_tab_count + aggr_tables; i++)
{
if (join_tab[i].filesort)
{
Expand Down Expand Up @@ -3360,23 +3360,25 @@ JOIN::destroy()

cleanup(1);

uint tables= table_count+aggr_tables;

if (join_tab) // We should not have tables > 0 and join_tab != NULL
for (JOIN_TAB *tab= first_linear_tab(this, WITH_BUSH_ROOTS, WITH_CONST_TABLES);
tab; tab= next_linear_tab(this, tab, WITH_BUSH_ROOTS))
if (join_tab)
{
if (tab->aggr)
DBUG_ASSERT(table_count+aggr_tables > 0);
for (JOIN_TAB *tab= first_linear_tab(this, WITH_BUSH_ROOTS,
WITH_CONST_TABLES);
tab; tab= next_linear_tab(this, tab, WITH_BUSH_ROOTS))
{
free_tmp_table(thd, tab->table);
delete tab->tmp_table_param;
tab->tmp_table_param= NULL;
tab->aggr= NULL;
if (tab->aggr)
{
free_tmp_table(thd, tab->table);
delete tab->tmp_table_param;
tab->tmp_table_param= NULL;
tab->aggr= NULL;
}
tab->table= NULL;
}

tab->table= NULL;
}
/* Cleanup items referencing temporary table columns */

/* Cleanup items referencing temporary table columns */
cleanup_item_list(tmp_all_fields1);
cleanup_item_list(tmp_all_fields3);
destroy_sj_tmp_tables(this);
Expand Down Expand Up @@ -24426,9 +24428,6 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
DBUG_ENTER("select_describe");

/* Update the QPF with latest values of using_temporary, using_filesort */
Explain_select *explain_sel;
uint select_nr= join->select_lex->select_number;

for (SELECT_LEX_UNIT *unit= join->select_lex->first_inner_unit();
unit;
unit= unit->next_unit())
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_show.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3044,7 +3044,7 @@ int add_status_vars(SHOW_VAR *list)
if (status_vars_inited)
mysql_mutex_lock(&LOCK_show_status);
if (!all_status_vars.buffer && // array is not allocated yet - do it now
my_init_dynamic_array(&all_status_vars, sizeof(SHOW_VAR), 200, 20, MYF(0)))
my_init_dynamic_array(&all_status_vars, sizeof(SHOW_VAR), 250, 50, MYF(0)))
{
res= 1;
goto err;
Expand Down
3 changes: 3 additions & 0 deletions sql/sql_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,8 @@ class Rowid_seq_cursor
uint ref_length;

public:
virtual ~Rowid_seq_cursor() {}

void init(READ_RECORD *info)
{
cache_start= info->cache_pos;
Expand Down Expand Up @@ -631,6 +633,7 @@ class Table_read_cursor : public Rowid_seq_cursor
*/
READ_RECORD *read_record;
public:
virtual ~Table_read_cursor() {}

void init(READ_RECORD *info)
{
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ class Window_frame : public Sql_alloc
class Window_spec : public Sql_alloc
{
bool window_names_are_checked;

public:
virtual ~Window_spec() {}

LEX_STRING *window_ref;

Expand Down

0 comments on commit fabeab7

Please sign in to comment.