From 8e526985800678de20356cece1183f49f69c26f9 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Wed, 17 Apr 2013 22:33:33 +0300 Subject: [PATCH 1/4] Fixed compiler warnings and a not critical memory leak sql/keycaches.cc: Added free_all_rpl_filters() to be able to free all filters at cleanup sql/keycaches.h: Added prototype sql/rpl_rli.cc: Fixed compiler warning sql/slave.cc: Free all rpl_filters at cleanup sql/sp.cc: Fixed compiler warning when not all struct elements was initialized sql/sql_acl.cc: Fixed compiler warning when not all struct elements was initialized storage/perfschema/table_events_waits.cc: Fixed compiler warning when not all struct elements was initialized storage/perfschema/table_events_waits_summary.cc: Fixed compiler warning when not all struct elements was initialized storage/perfschema/table_ews_global_by_event_name.cc: Fixed compiler warning when not all struct elements was initialized storage/perfschema/table_file_instances.cc: Fixed compiler warning when not all struct elements was initialized storage/perfschema/table_file_summary.cc: Fixed compiler warning when not all struct elements was initialized storage/perfschema/table_performance_timers.cc: Fixed compiler warning when not all struct elements was initialized storage/perfschema/table_setup_consumers.cc: Fixed compiler warning when not all struct elements was initialized storage/perfschema/table_setup_instruments.cc: Fixed compiler warning when not all struct elements was initialized storage/perfschema/table_setup_timers.cc: Fixed compiler warning when not all struct elements was initialized storage/perfschema/table_sync_instances.cc: Fixed compiler warning when not all struct elements was initialized storage/perfschema/table_threads.cc: Fixed compiler warning when not all struct elements was initialized storage/xtradb/os/os0file.c: Fixed compiler warning when not all struct elements was initialized --- sql/keycaches.cc | 4 ++++ sql/keycaches.h | 1 + sql/rpl_rli.cc | 5 +++-- sql/slave.cc | 1 + sql/sp.cc | 2 +- sql/sql_acl.cc | 2 +- storage/perfschema/table_events_waits.cc | 2 +- storage/perfschema/table_events_waits_summary.cc | 4 ++-- storage/perfschema/table_ews_global_by_event_name.cc | 2 +- storage/perfschema/table_file_instances.cc | 2 +- storage/perfschema/table_file_summary.cc | 4 ++-- storage/perfschema/table_performance_timers.cc | 2 +- storage/perfschema/table_setup_consumers.cc | 2 +- storage/perfschema/table_setup_instruments.cc | 2 +- storage/perfschema/table_setup_timers.cc | 2 +- storage/perfschema/table_sync_instances.cc | 6 +++--- storage/perfschema/table_threads.cc | 2 +- storage/xtradb/os/os0file.c | 3 +-- 18 files changed, 27 insertions(+), 21 deletions(-) diff --git a/sql/keycaches.cc b/sql/keycaches.cc index 9e4b943dc83..120aa7e1029 100644 --- a/sql/keycaches.cc +++ b/sql/keycaches.cc @@ -225,3 +225,7 @@ void free_rpl_filter(const char *name, Rpl_filter *filter) delete filter; } +void free_all_rpl_filters() +{ + rpl_filters.delete_elements((void (*)(const char*, uchar*)) free_rpl_filter); +} diff --git a/sql/keycaches.h b/sql/keycaches.h index 2d52cb28973..32537339e2e 100644 --- a/sql/keycaches.h +++ b/sql/keycaches.h @@ -53,5 +53,6 @@ Rpl_filter *create_rpl_filter(const char *name, uint length); Rpl_filter *get_rpl_filter(LEX_STRING *filter_name); Rpl_filter *get_or_create_rpl_filter(const char *name, uint length); void free_rpl_filter(const char *name, Rpl_filter *filter); +void free_all_rpl_filters(void); #endif /* KEYCACHES_INCLUDED */ diff --git a/sql/rpl_rli.cc b/sql/rpl_rli.cc index 11c6e54c8f8..7733354b106 100644 --- a/sql/rpl_rli.cc +++ b/sql/rpl_rli.cc @@ -48,7 +48,8 @@ Relay_log_info::Relay_log_info(bool is_slave_recovery) no_storage(FALSE), replicate_same_server_id(::replicate_same_server_id), info_fd(-1), cur_log_fd(-1), relay_log(&sync_relaylog_period), sync_counter(0), is_relay_log_recovery(is_slave_recovery), - save_temporary_tables(0), cur_log_old_open_count(0), group_relay_log_pos(0), + save_temporary_tables(0), mi(0), + cur_log_old_open_count(0), group_relay_log_pos(0), event_relay_log_pos(0), #if HAVE_valgrind is_fake(FALSE), @@ -61,7 +62,7 @@ Relay_log_info::Relay_log_info(bool is_slave_recovery) gtid_sub_id(0), tables_to_lock(0), tables_to_lock_count(0), last_event_start_time(0), deferred_events(NULL),m_flags(0), row_stmt_start_timestamp(0), long_find_row_note_printed(false), - m_annotate_event(0), mi(0) + m_annotate_event(0) { DBUG_ENTER("Relay_log_info::Relay_log_info"); diff --git a/sql/slave.cc b/sql/slave.cc index 2e436d5e8b4..0a260272929 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -870,6 +870,7 @@ void end_slave() master_info_index= 0; active_mi= 0; mysql_mutex_unlock(&LOCK_active_mi); + free_all_rpl_filters(); DBUG_VOID_RETURN; } diff --git a/sql/sp.cc b/sql/sp.cc index b80fa968483..2aec9d19869 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -168,7 +168,7 @@ TABLE_FIELD_TYPE proc_table_fields[MYSQL_PROC_FIELD_COUNT] = }; static const TABLE_FIELD_DEF - proc_table_def= {MYSQL_PROC_FIELD_COUNT, proc_table_fields}; +proc_table_def= {MYSQL_PROC_FIELD_COUNT, proc_table_fields, 0, (uint*) 0 }; /*************************************************************************/ diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 7810bdb16e2..69290a64a29 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -171,7 +171,7 @@ TABLE_FIELD_TYPE mysql_db_table_fields[MYSQL_DB_FIELD_COUNT] = { }; const TABLE_FIELD_DEF - mysql_db_table_def= {MYSQL_DB_FIELD_COUNT, mysql_db_table_fields}; +mysql_db_table_def= {MYSQL_DB_FIELD_COUNT, mysql_db_table_fields, 0, (uint*) 0 }; static LEX_STRING native_password_plugin_name= { C_STRING_WITH_LEN("mysql_native_password") diff --git a/storage/perfschema/table_events_waits.cc b/storage/perfschema/table_events_waits.cc index 8408cc55975..864cecd32b5 100644 --- a/storage/perfschema/table_events_waits.cc +++ b/storage/perfschema/table_events_waits.cc @@ -113,7 +113,7 @@ static const TABLE_FIELD_TYPE field_types[]= TABLE_FIELD_DEF table_events_waits_current::m_field_def= -{ 16, field_types }; +{ 16, field_types, 0, (uint*) 0 }; PFS_engine_table_share table_events_waits_current::m_share= diff --git a/storage/perfschema/table_events_waits_summary.cc b/storage/perfschema/table_events_waits_summary.cc index 05f280f8521..15fe0d5202b 100644 --- a/storage/perfschema/table_events_waits_summary.cc +++ b/storage/perfschema/table_events_waits_summary.cc @@ -69,7 +69,7 @@ static const TABLE_FIELD_TYPE ews_by_thread_by_event_name_field_types[]= TABLE_FIELD_DEF table_events_waits_summary_by_thread_by_event_name::m_field_def= -{ 7, ews_by_thread_by_event_name_field_types }; +{ 7, ews_by_thread_by_event_name_field_types, 0, (uint*) 0 }; PFS_engine_table_share table_events_waits_summary_by_thread_by_event_name::m_share= @@ -381,7 +381,7 @@ static const TABLE_FIELD_TYPE ews_by_instance_field_types[]= TABLE_FIELD_DEF table_events_waits_summary_by_instance::m_field_def= -{ 7, ews_by_instance_field_types }; +{ 7, ews_by_instance_field_types, 0, (uint*) 0 }; PFS_engine_table_share table_events_waits_summary_by_instance::m_share= diff --git a/storage/perfschema/table_ews_global_by_event_name.cc b/storage/perfschema/table_ews_global_by_event_name.cc index 3177584231d..a880a96be4c 100644 --- a/storage/perfschema/table_ews_global_by_event_name.cc +++ b/storage/perfschema/table_ews_global_by_event_name.cc @@ -64,7 +64,7 @@ static const TABLE_FIELD_TYPE field_types[]= TABLE_FIELD_DEF table_ews_global_by_event_name::m_field_def= -{ 6, field_types }; +{ 6, field_types, 0, (uint*) 0 }; PFS_engine_table_share table_ews_global_by_event_name::m_share= diff --git a/storage/perfschema/table_file_instances.cc b/storage/perfschema/table_file_instances.cc index 9ae732a0e1c..2c116ce1eb2 100644 --- a/storage/perfschema/table_file_instances.cc +++ b/storage/perfschema/table_file_instances.cc @@ -49,7 +49,7 @@ static const TABLE_FIELD_TYPE field_types[]= TABLE_FIELD_DEF table_file_instances::m_field_def= -{ 3, field_types }; +{ 3, field_types, 0, (uint*) 0 }; PFS_engine_table_share table_file_instances::m_share= diff --git a/storage/perfschema/table_file_summary.cc b/storage/perfschema/table_file_summary.cc index a954db7ef4e..104fa0fbd36 100644 --- a/storage/perfschema/table_file_summary.cc +++ b/storage/perfschema/table_file_summary.cc @@ -59,7 +59,7 @@ static const TABLE_FIELD_TYPE fs_by_event_name_field_types[]= TABLE_FIELD_DEF table_file_summary_by_event_name::m_field_def= -{ 5, fs_by_event_name_field_types }; +{ 5, fs_by_event_name_field_types, 0, (uint*) 0 }; PFS_engine_table_share table_file_summary_by_event_name::m_share= @@ -222,7 +222,7 @@ static const TABLE_FIELD_TYPE fs_by_instance_field_types[]= TABLE_FIELD_DEF table_file_summary_by_instance::m_field_def= -{ 6, fs_by_instance_field_types }; +{ 6, fs_by_instance_field_types, 0, (uint*) 0 }; PFS_engine_table_share table_file_summary_by_instance::m_share= diff --git a/storage/perfschema/table_performance_timers.cc b/storage/perfschema/table_performance_timers.cc index acd379bc57b..3c5d5a09772 100644 --- a/storage/perfschema/table_performance_timers.cc +++ b/storage/perfschema/table_performance_timers.cc @@ -53,7 +53,7 @@ static const TABLE_FIELD_TYPE field_types[]= TABLE_FIELD_DEF table_performance_timers::m_field_def= -{ 4, field_types }; +{ 4, field_types, 0, (uint*) 0 }; PFS_engine_table_share table_performance_timers::m_share= diff --git a/storage/perfschema/table_setup_consumers.cc b/storage/perfschema/table_setup_consumers.cc index 601e0483b14..aa86b094c08 100644 --- a/storage/perfschema/table_setup_consumers.cc +++ b/storage/perfschema/table_setup_consumers.cc @@ -79,7 +79,7 @@ static const TABLE_FIELD_TYPE field_types[]= TABLE_FIELD_DEF table_setup_consumers::m_field_def= -{ 2, field_types }; +{ 2, field_types, 0, (uint*) 0 }; PFS_engine_table_share table_setup_consumers::m_share= diff --git a/storage/perfschema/table_setup_instruments.cc b/storage/perfschema/table_setup_instruments.cc index 480c0dbc13f..d3f39635bed 100644 --- a/storage/perfschema/table_setup_instruments.cc +++ b/storage/perfschema/table_setup_instruments.cc @@ -49,7 +49,7 @@ static const TABLE_FIELD_TYPE field_types[]= TABLE_FIELD_DEF table_setup_instruments::m_field_def= -{ 3, field_types }; +{ 3, field_types, 0, (uint*) 0 }; PFS_engine_table_share table_setup_instruments::m_share= diff --git a/storage/perfschema/table_setup_timers.cc b/storage/perfschema/table_setup_timers.cc index f8b1bfa4fe2..0bba71c7e2f 100644 --- a/storage/perfschema/table_setup_timers.cc +++ b/storage/perfschema/table_setup_timers.cc @@ -52,7 +52,7 @@ static const TABLE_FIELD_TYPE field_types[]= TABLE_FIELD_DEF table_setup_timers::m_field_def= -{ 2, field_types }; +{ 2, field_types, 0, (uint*) 0 }; PFS_engine_table_share table_setup_timers::m_share= diff --git a/storage/perfschema/table_sync_instances.cc b/storage/perfschema/table_sync_instances.cc index f2bd9fa1a28..584817d695d 100644 --- a/storage/perfschema/table_sync_instances.cc +++ b/storage/perfschema/table_sync_instances.cc @@ -50,7 +50,7 @@ static const TABLE_FIELD_TYPE mutex_field_types[]= TABLE_FIELD_DEF table_mutex_instances::m_field_def= -{ 3, mutex_field_types }; +{ 3, mutex_field_types, 0, (uint*) 0 }; PFS_engine_table_share table_mutex_instances::m_share= @@ -218,7 +218,7 @@ static const TABLE_FIELD_TYPE rwlock_field_types[]= TABLE_FIELD_DEF table_rwlock_instances::m_field_def= -{ 4, rwlock_field_types }; +{ 4, rwlock_field_types, 0, (uint*) 0 }; PFS_engine_table_share table_rwlock_instances::m_share= @@ -383,7 +383,7 @@ static const TABLE_FIELD_TYPE cond_field_types[]= TABLE_FIELD_DEF table_cond_instances::m_field_def= -{ 2, cond_field_types }; +{ 2, cond_field_types, 0, (uint*) 0 }; PFS_engine_table_share table_cond_instances::m_share= diff --git a/storage/perfschema/table_threads.cc b/storage/perfschema/table_threads.cc index 541ba860386..bbbfa28fa0f 100644 --- a/storage/perfschema/table_threads.cc +++ b/storage/perfschema/table_threads.cc @@ -47,7 +47,7 @@ static const TABLE_FIELD_TYPE field_types[]= TABLE_FIELD_DEF table_threads::m_field_def= -{ 3, field_types }; +{ 3, field_types, 0, (uint*) 0 }; PFS_engine_table_share table_threads::m_share= diff --git a/storage/xtradb/os/os0file.c b/storage/xtradb/os/os0file.c index 8f1b3e46bb2..8f7f8216782 100644 --- a/storage/xtradb/os/os0file.c +++ b/storage/xtradb/os/os0file.c @@ -1462,7 +1462,6 @@ os_file_set_nocache( #endif static int os_file_set_atomic_writes(os_file_t file, const char *name) { - static int first_time = 1; int atomic_option = 1; int ret = ioctl (file, DFS_IOCTL_ATOMIC_WRITE_SET, &atomic_option); @@ -2138,7 +2137,7 @@ os_file_set_size( "InnoDB: Error: preallocating data for" " file %s failed at\n" "InnoDB: offset 0 size %lld %lld. Operating system" - " error number %llu.\n" + " error number %d.\n" "InnoDB: Check that the disk is not full" " or a disk quota exceeded.\n" "InnoDB: Some operating system error numbers" From 8b714e507f9e2c216ad043a10db99ea558e9285b Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Wed, 17 Apr 2013 23:37:06 +0300 Subject: [PATCH 2/4] Changed the client library to only mark memory as THREAD_SPECIFIC if one has called mysql_options() with MYSQL_OPT_USE_THREAD_SPECIFIC_MEMORY include/mysql.h: Added MYSQL_OPT_USE_THREAD_SPECIFIC_MEMORY include/mysql.h.pp: Updated file sql-common/client.c: Marked client memory as THREAD_SPECIFIC sql/event_db_repository.cc: Fixed compiler warning sql/slave.cc: Marked client memory as THREAD_SPECIFIC storage/federatedx/federatedx_io_mysql.cc: Marked client memory as THREAD_SPECIFIC storage/federatedx/ha_federatedx.cc: Marked client memory as THREAD_SPECIFIC storage/sphinx/ha_sphinx.cc: Marked client memory as THREAD_SPECIFIC --- include/mysql.h | 4 ++-- include/mysql.h.pp | 6 +++--- sql-common/client.c | 11 +++++++++-- sql/event_db_repository.cc | 2 +- sql/slave.cc | 10 ++++++++-- storage/federatedx/federatedx_io_mysql.cc | 6 +++++- storage/federatedx/ha_federatedx.cc | 3 +++ storage/sphinx/ha_sphinx.cc | 12 ++++++++++-- 8 files changed, 41 insertions(+), 13 deletions(-) diff --git a/include/mysql.h b/include/mysql.h index fa62026b44a..122b5a2751f 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -169,7 +169,7 @@ enum mysql_option MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH, MYSQL_PROGRESS_CALLBACK, /* MariaDB options */ - MYSQL_OPT_NONBLOCK=6000 + MYSQL_OPT_NONBLOCK=6000, MYSQL_OPT_USE_THREAD_SPECIFIC_MEMORY }; /** @@ -194,7 +194,7 @@ struct st_mysql_options { unsigned long max_allowed_packet; my_bool use_ssl; /* if to use SSL or not */ my_bool compress,named_pipe; - my_bool unused1; + my_bool use_thread_specific_memory; my_bool unused2; my_bool unused3; my_bool unused4; diff --git a/include/mysql.h.pp b/include/mysql.h.pp index 331183180c0..b3a56dfd90b 100644 --- a/include/mysql.h.pp +++ b/include/mysql.h.pp @@ -83,7 +83,7 @@ enum enum_mysql_set_option my_bool my_net_init(NET *net, Vio* vio, unsigned int my_flags); void my_net_local_init(NET *net); void net_end(NET *net); - void net_clear(NET *net, my_bool clear_buffer); +void net_clear(NET *net, my_bool clear_buffer); my_bool net_realloc(NET *net, size_t length); my_bool net_flush(NET *net); my_bool my_net_write(NET *net,const unsigned char *packet, size_t len); @@ -263,7 +263,7 @@ enum mysql_option MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH, MYSQL_PROGRESS_CALLBACK, - MYSQL_OPT_NONBLOCK=6000 + MYSQL_OPT_NONBLOCK=6000, MYSQL_OPT_USE_THREAD_SPECIFIC_MEMORY }; struct st_mysql_options_extention; struct st_mysql_options { @@ -282,7 +282,7 @@ struct st_mysql_options { unsigned long max_allowed_packet; my_bool use_ssl; my_bool compress,named_pipe; - my_bool unused1; + my_bool use_thread_specific_memory; my_bool unused2; my_bool unused3; my_bool unused4; diff --git a/sql-common/client.c b/sql-common/client.c index 2d83f2ef215..507917b0722 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -892,7 +892,9 @@ void free_old_query(MYSQL *mysql) if (mysql->fields) free_root(&mysql->field_alloc,MYF(0)); /* Assume rowlength < 8192 */ - init_alloc_root(&mysql->field_alloc, 8192, 0, MYF(MY_THREAD_SPECIFIC)); + init_alloc_root(&mysql->field_alloc, 8192, 0, + MYF(mysql->options.use_thread_specific_memory ? + MY_THREAD_SPECIFIC : 0)); mysql->fields= 0; mysql->field_count= 0; /* For API */ mysql->warning_count= 0; @@ -1578,7 +1580,9 @@ MYSQL_DATA *cli_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, DBUG_RETURN(0); } /* Assume rowlength < 8192 */ - init_alloc_root(&result->alloc, 8192, 0, MYF(MY_THREAD_SPECIFIC)); + init_alloc_root(&result->alloc, 8192, 0, + MYF(mysql->options.use_thread_specific_memory ? + MY_THREAD_SPECIFIC : 0)); result->alloc.min_malloc=sizeof(MYSQL_ROWS); prev_ptr= &result->data; result->rows=0; @@ -4206,6 +4210,9 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const void *arg) case MYSQL_OPT_RECONNECT: mysql->reconnect= *(my_bool *) arg; break; + case MYSQL_OPT_USE_THREAD_SPECIFIC_MEMORY: + mysql->options.use_thread_specific_memory= *(my_bool *) arg; + break; case MYSQL_OPT_SSL_VERIFY_SERVER_CERT: if (*(my_bool*) arg) mysql->options.client_flag|= CLIENT_SSL_VERIFY_SERVER_CERT; diff --git a/sql/event_db_repository.cc b/sql/event_db_repository.cc index b7e82d8b4b9..edd4e248038 100644 --- a/sql/event_db_repository.cc +++ b/sql/event_db_repository.cc @@ -163,7 +163,7 @@ const TABLE_FIELD_TYPE event_table_fields[ET_FIELD_COUNT] = }; static const TABLE_FIELD_DEF - event_table_def= {ET_FIELD_COUNT, event_table_fields}; +event_table_def= {ET_FIELD_COUNT, event_table_fields, 0, (uint*) 0}; class Event_db_intact : public Table_check_intact { diff --git a/sql/slave.cc b/sql/slave.cc index 0a260272929..36d26e76dce 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -5004,6 +5004,7 @@ static int connect_to_master(THD* thd, MYSQL* mysql, Master_info* mi, int last_errno= -2; // impossible error ulong err_count=0; char llbuff[22]; + my_bool my_true= 1; DBUG_ENTER("connect_to_master"); #ifndef DBUG_OFF @@ -5015,6 +5016,8 @@ static int connect_to_master(THD* thd, MYSQL* mysql, Master_info* mi, mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (char *) &slave_net_timeout); mysql_options(mysql, MYSQL_OPT_READ_TIMEOUT, (char *) &slave_net_timeout); + mysql_options(mysql, MYSQL_OPT_USE_THREAD_SPECIFIC_MEMORY, + (char*) &my_true); #ifdef HAVE_OPENSSL if (mi->ssl) @@ -5130,14 +5133,15 @@ MYSQL *rpl_connect_master(MYSQL *mysql) { THD *thd= current_thd; Master_info *mi= my_pthread_getspecific_ptr(Master_info*, RPL_MASTER_INFO); + bool allocated= false; + my_bool my_true= 1; + if (!mi) { sql_print_error("'rpl_connect_master' must be called in slave I/O thread context."); return NULL; } - bool allocated= false; - if (!mysql) { if(!(mysql= mysql_init(NULL))) @@ -5157,6 +5161,8 @@ MYSQL *rpl_connect_master(MYSQL *mysql) */ mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (char *) &slave_net_timeout); mysql_options(mysql, MYSQL_OPT_READ_TIMEOUT, (char *) &slave_net_timeout); + mysql_options(mysql, MYSQL_OPT_USE_THREAD_SPECIFIC_MEMORY, + (char*) &my_true); #ifdef HAVE_OPENSSL if (mi->ssl) diff --git a/storage/federatedx/federatedx_io_mysql.cc b/storage/federatedx/federatedx_io_mysql.cc index effbe899e7f..cc45ae059ae 100644 --- a/storage/federatedx/federatedx_io_mysql.cc +++ b/storage/federatedx/federatedx_io_mysql.cc @@ -423,8 +423,10 @@ int federatedx_io_mysql::actual_query(const char *buffer, uint length) if (!mysql.net.vio) { + my_bool my_true= 1; + if (!(mysql_init(&mysql))) - DBUG_RETURN(-1); + DBUG_RETURN(-1); /* BUG# 17044 Federated Storage Engine is not UTF8 clean @@ -433,6 +435,8 @@ int federatedx_io_mysql::actual_query(const char *buffer, uint length) */ /* this sets the csname like 'set names utf8' */ mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, get_charsetname()); + mysql_options(&mysql, MYSQL_OPT_USE_THREAD_SPECIFIC_MEMORY, + (char*) &my_true); if (!mysql_real_connect(&mysql, get_hostname(), diff --git a/storage/federatedx/ha_federatedx.cc b/storage/federatedx/ha_federatedx.cc index d760fcf082f..c3f5e6add73 100644 --- a/storage/federatedx/ha_federatedx.cc +++ b/storage/federatedx/ha_federatedx.cc @@ -3593,12 +3593,15 @@ int ha_federatedx::discover_assisted(handlerton *hton, THD* thd, MYSQL_RES *res; MYSQL_ROW rdata; ulong *rlen; + my_bool my_true= 1; if (parse_url(thd->mem_root, &tmp_share, table_s, 1)) return HA_WRONG_CREATE_OPTION; mysql_init(&mysql); mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, cs->csname); + mysql_options(&mysql, MYSQL_OPT_USE_THREAD_SPECIFIC_MEMORY, + (char*) &my_true); if (!mysql_real_connect(&mysql, tmp_share.hostname, tmp_share.username, tmp_share.password, tmp_share.database, diff --git a/storage/sphinx/ha_sphinx.cc b/storage/sphinx/ha_sphinx.cc index 23bf21b6cbe..9f5097b59ce 100644 --- a/storage/sphinx/ha_sphinx.cc +++ b/storage/sphinx/ha_sphinx.cc @@ -2333,7 +2333,11 @@ int ha_sphinx::write_row ( byte * ) SPH_RET ( ER_OUT_OF_RESOURCES ); unsigned int uTimeout = 1; - mysql_options ( pConn, MYSQL_OPT_CONNECT_TIMEOUT, (const char*)&uTimeout ); + my_bool my_true= 1; + mysql_options(pConn, MYSQL_OPT_CONNECT_TIMEOUT, + (const char*) &uTimeout); + mysql_options(pConn, MYSQL_OPT_USE_THREAD_SPECIFIC_MEMORY, + (char*) &my_true); if ( !mysql_real_connect ( pConn, m_pShare->m_sHost, "root", "", "", m_pShare->m_iPort, m_pShare->m_sSocket, 0 ) ) SPH_RET ( HandleMysqlError ( pConn, ER_CONNECT_TO_FOREIGN_DATA_SOURCE ) ); @@ -2392,7 +2396,11 @@ int ha_sphinx::delete_row ( const byte * ) SPH_RET ( ER_OUT_OF_RESOURCES ); unsigned int uTimeout = 1; - mysql_options ( pConn, MYSQL_OPT_CONNECT_TIMEOUT, (const char*)&uTimeout ); + my_bool my_true= 1; + mysql_options(pConn, MYSQL_OPT_CONNECT_TIMEOUT, + (const char*) &uTimeout); + mysql_options(pConn, MYSQL_OPT_USE_THREAD_SPECIFIC_MEMORY, + (char*) &my_true); if ( !mysql_real_connect ( pConn, m_pShare->m_sHost, "root", "", "", m_pShare->m_iPort, m_pShare->m_sSocket, 0 ) ) SPH_RET ( HandleMysqlError ( pConn, ER_CONNECT_TO_FOREIGN_DATA_SOURCE ) ); From ac8333e46d63c87178e1844b95d89c87439e03e3 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Wed, 17 Apr 2013 16:15:22 -0700 Subject: [PATCH 3/4] Fixed a typo/bug that could lead to wrong selectivity numbers for tables retrieved by range scans. Added comments forgotten in the previous patch. --- mysql-test/r/selectivity.result | 4 +-- mysql-test/r/selectivity_innodb.result | 4 +-- sql/sql_select.cc | 37 +++++++++++++++++++++++--- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/mysql-test/r/selectivity.result b/mysql-test/r/selectivity.result index 8371b0eb0b6..79ff506d603 100644 --- a/mysql-test/r/selectivity.result +++ b/mysql-test/r/selectivity.result @@ -77,9 +77,9 @@ order by s_suppkey; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY supplier ALL PRIMARY NULL NULL NULL 10 100.00 Using filesort 1 PRIMARY ref key0 key0 5 dbt3_s001.supplier.s_suppkey 10 100.00 Using where -3 DERIVED lineitem range i_l_shipdate i_l_shipdate 4 NULL 268 0.20 Using where; Using temporary; Using filesort +3 DERIVED lineitem range i_l_shipdate i_l_shipdate 4 NULL 268 100.00 Using where; Using temporary; Using filesort 2 SUBQUERY ALL NULL NULL NULL NULL 268 100.00 -4 DERIVED lineitem range i_l_shipdate i_l_shipdate 4 NULL 268 0.20 Using where; Using temporary; Using filesort +4 DERIVED lineitem range i_l_shipdate i_l_shipdate 4 NULL 268 100.00 Using where; Using temporary; Using filesort Warnings: Note 1003 select `dbt3_s001`.`supplier`.`s_suppkey` AS `s_suppkey`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`revenue0`.`total_revenue` AS `total_revenue` from `dbt3_s001`.`supplier` join `dbt3_s001`.`revenue0` where ((`revenue0`.`supplier_no` = `dbt3_s001`.`supplier`.`s_suppkey`) and (`revenue0`.`total_revenue` = (select max(`revenue0`.`total_revenue`) from `dbt3_s001`.`revenue0`))) order by `dbt3_s001`.`supplier`.`s_suppkey` select s_suppkey, s_name, s_address, s_phone, total_revenue diff --git a/mysql-test/r/selectivity_innodb.result b/mysql-test/r/selectivity_innodb.result index eba0ed2f32a..e32eea8827d 100644 --- a/mysql-test/r/selectivity_innodb.result +++ b/mysql-test/r/selectivity_innodb.result @@ -80,9 +80,9 @@ order by s_suppkey; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY supplier index PRIMARY PRIMARY 4 NULL 10 100.00 1 PRIMARY ref key0 key0 5 dbt3_s001.supplier.s_suppkey 10 100.00 Using where -3 DERIVED lineitem range i_l_shipdate i_l_shipdate 4 NULL 228 0.14 Using where; Using temporary; Using filesort +3 DERIVED lineitem range i_l_shipdate i_l_shipdate 4 NULL 228 100.00 Using where; Using temporary; Using filesort 2 SUBQUERY ALL NULL NULL NULL NULL 228 100.00 -4 DERIVED lineitem range i_l_shipdate i_l_shipdate 4 NULL 228 0.14 Using where; Using temporary; Using filesort +4 DERIVED lineitem range i_l_shipdate i_l_shipdate 4 NULL 228 100.00 Using where; Using temporary; Using filesort Warnings: Note 1003 select `dbt3_s001`.`supplier`.`s_suppkey` AS `s_suppkey`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`revenue0`.`total_revenue` AS `total_revenue` from `dbt3_s001`.`supplier` join `dbt3_s001`.`revenue0` where ((`revenue0`.`supplier_no` = `dbt3_s001`.`supplier`.`s_suppkey`) and (`revenue0`.`total_revenue` = (select max(`revenue0`.`total_revenue`) from `dbt3_s001`.`revenue0`))) order by `dbt3_s001`.`supplier`.`s_suppkey` select s_suppkey, s_name, s_address, s_phone, total_revenue diff --git a/sql/sql_select.cc b/sql/sql_select.cc index be8ff20eb48..cc4b139fb2f 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -6905,6 +6905,18 @@ double JOIN::get_examined_rows() } +/** + @brief + Get the selectivity of equalities between columns when joining a table + + @param join The optimized join + @param idx The number of tables in the evaluated partual join + @param s The table to be joined for evaluation + @param rem_tables The bitmap of tables to be joined later + @param keyparts The number of key parts to used when joining s + @param ref_keyuse_steps Array of references to keyuses employed to join s +*/ + static double table_multi_eq_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s, table_map rem_tables, uint keyparts, @@ -7015,6 +7027,19 @@ double table_multi_eq_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s, return sel; } + +/** + @brief + Get the selectivity of conditions when joining a table + + @param join The optimized join + @param s The table to be joined for evaluation + @param rem_tables The bitmap of tables to be joined later + + @retval + selectivity of the conditions imposed on the rows of s +*/ + static double table_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s, table_map rem_tables) @@ -7034,7 +7059,7 @@ double table_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s, { if (pos->key == 0 && table_records > 0) { - sel*= table->quick_rows[s->quick->index]/table_records; + sel/= table->quick_rows[s->quick->index]/table_records; } } else if (pos->key != 0) @@ -7085,6 +7110,11 @@ double table_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s, } while (keyuse->table == table && keyuse->key == key); } + /* + If the field f from the table is equal to a field from one the + earlier joined tables then the selectivity of the range conditions + over the field f must be discounted. + */ for (Field **f_ptr=table->field ; (field= *f_ptr) ; f_ptr++) { if (!bitmap_is_set(read_set, field->field_index) || @@ -12275,9 +12305,9 @@ static COND *build_equal_items_for_cond(THD *thd, COND *cond, @endcode Thus, applying equalities from the where condition we basically can get more freedom in performing join operations. - Althogh we don't use this property now, it probably makes sense to use + Although we don't use this property now, it probably makes sense to use it in the future. - @param thd Thread handler + @param thd Thread handler @param cond condition to build the multiple equalities for @param inherited path to all inherited multiple equality items @param join_list list of join tables to which the condition @@ -12286,6 +12316,7 @@ static COND *build_equal_items_for_cond(THD *thd, COND *cond, for on expressions @param[out] cond_equal_ref pointer to the structure to place built equalities in + @param link_equal_items equal fields are to be linked @return pointer to the transformed condition containing multiple equalities From 71c211d48bafaf3e7fe1283b7a01b312ca8c8db1 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 18 Apr 2013 11:17:10 +0200 Subject: [PATCH 4/4] Fix race in test case. --- mysql-test/suite/multi_source/gtid.result | 2 +- mysql-test/suite/multi_source/gtid.test | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/mysql-test/suite/multi_source/gtid.result b/mysql-test/suite/multi_source/gtid.result index fb727aabae2..2aeec5835f7 100644 --- a/mysql-test/suite/multi_source/gtid.result +++ b/mysql-test/suite/multi_source/gtid.result @@ -14,9 +14,9 @@ Note 1937 SLAVE '' started include/wait_for_slave_to_start.inc SET GLOBAL gtid_domain_id= 1; SET SESSION gtid_domain_id= 1; +CREATE TABLE t3 (a INT PRIMARY KEY, b VARCHAR(10)) ENGINE=InnoDB; CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(10)); INSERT INTO t1 VALUES (1, "initial"); -CREATE TABLE t3 (a INT PRIMARY KEY, b VARCHAR(10)) ENGINE=InnoDB; INSERT INTO t3 VALUES (101, "initial 1"); SET GLOBAL gtid_domain_id= 2; SET SESSION gtid_domain_id= 2; diff --git a/mysql-test/suite/multi_source/gtid.test b/mysql-test/suite/multi_source/gtid.test index 06a0edf2ccc..d6b84fb7f3e 100644 --- a/mysql-test/suite/multi_source/gtid.test +++ b/mysql-test/suite/multi_source/gtid.test @@ -32,11 +32,17 @@ start all slaves; --connection master1 SET GLOBAL gtid_domain_id= 1; SET SESSION gtid_domain_id= 1; +CREATE TABLE t3 (a INT PRIMARY KEY, b VARCHAR(10)) ENGINE=InnoDB; CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(10)); INSERT INTO t1 VALUES (1, "initial"); -CREATE TABLE t3 (a INT PRIMARY KEY, b VARCHAR(10)) ENGINE=InnoDB; INSERT INTO t3 VALUES (101, "initial 1"); +# Make sure we have CREATE TABLE t3 from master1 before replicating INSERT INTO +# t3 from master2. +--connection slave1 +--let $wait_condition= SELECT COUNT(*)=1 FROM information_schema.tables WHERE table_name = "t3" AND table_schema = "test" +--source include/wait_condition.inc + --connection master2 SET GLOBAL gtid_domain_id= 2; SET SESSION gtid_domain_id= 2;