From: Marc Alff Date: March 20 2012 10:02am Subject: bzr push into mysql-trunk branch (marc.alff:3802) List-Archive: http://lists.mysql.com/commits/143248 Message-Id: <201203201002.q2KA2SiJ030546@acsmt356.oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 3802 Marc Alff 2012-03-20 [merge] Local merge modified: sql/mysqld.cc sql/unireg.cc === modified file 'storage/perfschema/pfs.cc' --- a/storage/perfschema/pfs.cc 2012-02-29 14:43:11 +0000 +++ b/storage/perfschema/pfs.cc 2012-03-19 19:29:28 +0000 @@ -3682,23 +3682,27 @@ static void end_table_io_wait_v1(PSI_tab DBUG_ASSERT(table != NULL); PFS_single_stat *stat; + PFS_table_io_stat *table_io_stat; DBUG_ASSERT((state->m_index < table->m_share->m_key_count) || - (state->m_index == MAX_KEY)); + (state->m_index == MAX_INDEXES)); + + table_io_stat= & table->m_table_stat.m_index_stat[state->m_index]; + table_io_stat->m_has_data= true; switch (state->m_io_operation) { case PSI_TABLE_FETCH_ROW: - stat= & table->m_table_stat.m_index_stat[state->m_index].m_fetch; + stat= & table_io_stat->m_fetch; break; case PSI_TABLE_WRITE_ROW: - stat= & table->m_table_stat.m_index_stat[state->m_index].m_insert; + stat= & table_io_stat->m_insert; break; case PSI_TABLE_UPDATE_ROW: - stat= & table->m_table_stat.m_index_stat[state->m_index].m_update; + stat= & table_io_stat->m_update; break; case PSI_TABLE_DELETE_ROW: - stat= & table->m_table_stat.m_index_stat[state->m_index].m_delete; + stat= & table_io_stat->m_delete; break; default: DBUG_ASSERT(false); === modified file 'storage/perfschema/pfs_instr.cc' --- a/storage/perfschema/pfs_instr.cc 2012-02-23 23:27:02 +0000 +++ b/storage/perfschema/pfs_instr.cc 2012-03-19 19:29:28 +0000 @@ -1329,12 +1329,24 @@ void PFS_table::sanitized_aggregate(void */ PFS_table_share *safe_share= sanitize_table_share(m_share); PFS_thread *safe_thread= sanitize_thread(m_thread_owner); - if ((safe_share != NULL && safe_thread != NULL) && - (m_has_io_stats || m_has_lock_stats)) + if ((safe_share != NULL && safe_thread != NULL)) { - safe_aggregate(& m_table_stat, safe_share, safe_thread); - m_has_io_stats= false; - m_has_lock_stats= false; + if (m_has_io_stats && m_has_lock_stats) + { + safe_aggregate(& m_table_stat, safe_share, safe_thread); + m_has_io_stats= false; + m_has_lock_stats= false; + } + else if (m_has_io_stats) + { + safe_aggregate_io(& m_table_stat, safe_share, safe_thread); + m_has_io_stats= false; + } + else if (m_has_lock_stats) + { + safe_aggregate_lock(& m_table_stat, safe_share, safe_thread); + m_has_lock_stats= false; + } } } @@ -1368,6 +1380,8 @@ void PFS_table::safe_aggregate(PFS_table DBUG_ASSERT(table_share != NULL); DBUG_ASSERT(thread != NULL); + uint key_count= sanitize_index_count(table_share->m_key_count); + if (flag_thread_instrumentation && thread->m_enabled) { PFS_single_stat *event_name_array; @@ -1379,7 +1393,7 @@ void PFS_table::safe_aggregate(PFS_table (for wait/io/table/sql/handler) */ index= global_table_io_class.m_event_name_index; - table_stat->sum_io(& event_name_array[index]); + table_stat->sum_io(& event_name_array[index], key_count); /* Aggregate to EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME @@ -1390,7 +1404,7 @@ void PFS_table::safe_aggregate(PFS_table } /* Aggregate to TABLE_IO_SUMMARY, TABLE_LOCK_SUMMARY */ - table_share->m_table_stat.aggregate(table_stat); + table_share->m_table_stat.aggregate(table_stat, key_count); table_stat->fast_reset(); } @@ -1402,6 +1416,8 @@ void PFS_table::safe_aggregate_io(PFS_ta DBUG_ASSERT(table_share != NULL); DBUG_ASSERT(thread != NULL); + uint key_count= sanitize_index_count(table_share->m_key_count); + if (flag_thread_instrumentation && thread->m_enabled) { PFS_single_stat *event_name_array; @@ -1413,11 +1429,11 @@ void PFS_table::safe_aggregate_io(PFS_ta (for wait/io/table/sql/handler) */ index= global_table_io_class.m_event_name_index; - table_stat->sum_io(& event_name_array[index]); + table_stat->sum_io(& event_name_array[index], key_count); } /* Aggregate to TABLE_IO_SUMMARY */ - table_share->m_table_stat.aggregate_io(table_stat); + table_share->m_table_stat.aggregate_io(table_stat, key_count); table_stat->fast_reset_io(); } === modified file 'storage/perfschema/pfs_instr.h' --- a/storage/perfschema/pfs_instr.h 2012-02-23 23:27:02 +0000 +++ b/storage/perfschema/pfs_instr.h 2012-03-19 19:29:28 +0000 @@ -196,11 +196,24 @@ public: */ void aggregate(void) { - if (likely((m_thread_owner != NULL) && (m_has_io_stats || m_has_lock_stats))) + if (likely(m_thread_owner != NULL)) { - safe_aggregate(& m_table_stat, m_share, m_thread_owner); - m_has_io_stats= false; - m_has_lock_stats= false; + if (m_has_io_stats && m_has_lock_stats) + { + safe_aggregate(& m_table_stat, m_share, m_thread_owner); + m_has_io_stats= false; + m_has_lock_stats= false; + } + else if (m_has_io_stats) + { + safe_aggregate_io(& m_table_stat, m_share, m_thread_owner); + m_has_io_stats= false; + } + else if (m_has_lock_stats) + { + safe_aggregate_lock(& m_table_stat, m_share, m_thread_owner); + m_has_lock_stats= false; + } } } === modified file 'storage/perfschema/pfs_instr_class.cc' --- a/storage/perfschema/pfs_instr_class.cc 2012-01-25 22:37:55 +0000 +++ b/storage/perfschema/pfs_instr_class.cc 2012-03-19 19:29:28 +0000 @@ -1193,7 +1193,7 @@ static void set_keys(PFS_table_share *pf pfs_key->m_name_length= len; } - pfs_key_last= pfs->m_keys + MAX_KEY; + pfs_key_last= pfs->m_keys + MAX_INDEXES; for ( ; pfs_key < pfs_key_last; pfs_key++) pfs_key->m_name_length= 0; } @@ -1353,9 +1353,10 @@ search: void PFS_table_share::aggregate_io(void) { + uint safe_key_count= sanitize_index_count(m_key_count); uint index= global_table_io_class.m_event_name_index; PFS_single_stat *table_io_total= & global_instr_class_waits_array[index]; - m_table_stat.sum_io(table_io_total); + m_table_stat.sum_io(table_io_total, safe_key_count); m_table_stat.fast_reset_io(); } === modified file 'storage/perfschema/pfs_instr_class.h' --- a/storage/perfschema/pfs_instr_class.h 2012-01-25 22:37:55 +0000 +++ b/storage/perfschema/pfs_instr_class.h 2012-03-19 19:29:28 +0000 @@ -316,13 +316,20 @@ public: /** Table statistics. */ PFS_table_stat m_table_stat; /** Index names. */ - PFS_table_key m_keys[MAX_KEY]; + PFS_table_key m_keys[MAX_INDEXES]; private: /** Number of opened table handles. */ int m_refcount; }; +inline uint sanitize_index_count(uint count) +{ + if (likely(count <= MAX_INDEXES)) + return count; + return 0; +} + /** Instrument controlling all table io. This instrument is used with table SETUP_OBJECTS. === modified file 'storage/perfschema/pfs_stat.h' --- a/storage/perfschema/pfs_stat.h 2012-01-06 09:03:53 +0000 +++ b/storage/perfschema/pfs_stat.h 2012-03-19 19:29:28 +0000 @@ -329,6 +329,7 @@ struct PFS_statement_stat /** Single table io statistic. */ struct PFS_table_io_stat { + bool m_has_data; /** FETCH statistics */ PFS_single_stat m_fetch; /** INSERT statistics */ @@ -338,8 +339,14 @@ struct PFS_table_io_stat /** DELETE statistics */ PFS_single_stat m_delete; + PFS_table_io_stat() + { + m_has_data= false; + } + inline void reset(void) { + m_has_data= false; m_fetch.reset(); m_insert.reset(); m_update.reset(); @@ -348,18 +355,25 @@ struct PFS_table_io_stat inline void aggregate(const PFS_table_io_stat *stat) { - m_fetch.aggregate(&stat->m_fetch); - m_insert.aggregate(&stat->m_insert); - m_update.aggregate(&stat->m_update); - m_delete.aggregate(&stat->m_delete); + if (stat->m_has_data) + { + m_has_data= true; + m_fetch.aggregate(&stat->m_fetch); + m_insert.aggregate(&stat->m_insert); + m_update.aggregate(&stat->m_update); + m_delete.aggregate(&stat->m_delete); + } } inline void sum(PFS_single_stat *result) { - result->aggregate(& m_fetch); - result->aggregate(& m_insert); - result->aggregate(& m_update); - result->aggregate(& m_delete); + if (m_has_data) + { + result->aggregate(& m_fetch); + result->aggregate(& m_insert); + result->aggregate(& m_update); + result->aggregate(& m_delete); + } } }; @@ -419,10 +433,10 @@ struct PFS_table_stat { /** Statistics, per index. - Each index stat is in [0, MAX_KEY-1], - stats when using no index are in [MAX_KEY]. + Each index stat is in [0, MAX_INDEXES-1], + stats when using no index are in [MAX_INDEXES]. */ - PFS_table_io_stat m_index_stat[MAX_KEY + 1]; + PFS_table_io_stat m_index_stat[MAX_INDEXES + 1]; /** Statistics, per lock type. @@ -433,7 +447,7 @@ struct PFS_table_stat inline void reset_io(void) { PFS_table_io_stat *stat= & m_index_stat[0]; - PFS_table_io_stat *stat_last= & m_index_stat[MAX_KEY + 1]; + PFS_table_io_stat *stat_last= & m_index_stat[MAX_INDEXES + 1]; for ( ; stat < stat_last ; stat++) stat->reset(); } @@ -466,13 +480,25 @@ struct PFS_table_stat memcpy(this, & g_reset_template, sizeof(*this)); } - inline void aggregate_io(const PFS_table_stat *stat) + inline void aggregate_io(const PFS_table_stat *stat, uint key_count) { - PFS_table_io_stat *to_stat= & m_index_stat[0]; - PFS_table_io_stat *to_stat_last= & m_index_stat[MAX_KEY + 1]; - const PFS_table_io_stat *from_stat= & stat->m_index_stat[0]; + PFS_table_io_stat *to_stat; + PFS_table_io_stat *to_stat_last; + const PFS_table_io_stat *from_stat; + + DBUG_ASSERT(key_count <= MAX_INDEXES); + + /* Aggregate stats for each index, if any */ + to_stat= & m_index_stat[0]; + to_stat_last= to_stat + key_count; + from_stat= & stat->m_index_stat[0]; for ( ; to_stat < to_stat_last ; from_stat++, to_stat++) to_stat->aggregate(from_stat); + + /* Aggregate stats for the table */ + to_stat= & m_index_stat[MAX_INDEXES]; + from_stat= & stat->m_index_stat[MAX_INDEXES]; + to_stat->aggregate(from_stat); } inline void aggregate_lock(const PFS_table_stat *stat) @@ -480,18 +506,27 @@ struct PFS_table_stat m_lock_stat.aggregate(& stat->m_lock_stat); } - inline void aggregate(const PFS_table_stat *stat) + inline void aggregate(const PFS_table_stat *stat, uint key_count) { - aggregate_io(stat); + aggregate_io(stat, key_count); aggregate_lock(stat); } - inline void sum_io(PFS_single_stat *result) + inline void sum_io(PFS_single_stat *result, uint key_count) { - PFS_table_io_stat *stat= & m_index_stat[0]; - PFS_table_io_stat *stat_last= & m_index_stat[MAX_KEY + 1]; + PFS_table_io_stat *stat; + PFS_table_io_stat *stat_last; + + DBUG_ASSERT(key_count <= MAX_INDEXES); + + /* Sum stats for each index, if any */ + stat= & m_index_stat[0]; + stat_last= stat + key_count; for ( ; stat < stat_last ; stat++) stat->sum(result); + + /* Sum stats for the table */ + m_index_stat[MAX_INDEXES].sum(result); } inline void sum_lock(PFS_single_stat *result) @@ -499,9 +534,9 @@ struct PFS_table_stat m_lock_stat.sum(result); } - inline void sum(PFS_single_stat *result) + inline void sum(PFS_single_stat *result, uint key_count) { - sum_io(result); + sum_io(result, key_count); sum_lock(result); } === modified file 'storage/perfschema/pfs_visitor.cc' --- a/storage/perfschema/pfs_visitor.cc 2011-09-02 20:03:36 +0000 +++ b/storage/perfschema/pfs_visitor.cc 2012-03-19 19:29:28 +0000 @@ -970,12 +970,18 @@ void PFS_object_wait_visitor::visit_glob void PFS_object_wait_visitor::visit_table_share(PFS_table_share *pfs) { - pfs->m_table_stat.sum(& m_stat); + uint safe_key_count= sanitize_index_count(pfs->m_key_count); + pfs->m_table_stat.sum(& m_stat, safe_key_count); } void PFS_object_wait_visitor::visit_table(PFS_table *pfs) { - pfs->m_table_stat.sum(& m_stat); + PFS_table_share *table_share= sanitize_table_share(pfs->m_share); + if (table_share != NULL) + { + uint safe_key_count= sanitize_index_count(table_share->m_key_count); + pfs->m_table_stat.sum(& m_stat, safe_key_count); + } } PFS_table_io_wait_visitor::PFS_table_io_wait_visitor() @@ -993,14 +999,15 @@ void PFS_table_io_wait_visitor::visit_gl void PFS_table_io_wait_visitor::visit_table_share(PFS_table_share *pfs) { PFS_table_io_stat io_stat; + uint safe_key_count= sanitize_index_count(pfs->m_key_count); uint index; /* Aggregate index stats */ - for (index= 0; index < pfs->m_key_count; index++) + for (index= 0; index < safe_key_count; index++) io_stat.aggregate(& pfs->m_table_stat.m_index_stat[index]); /* Aggregate global stats */ - io_stat.aggregate(& pfs->m_table_stat.m_index_stat[MAX_KEY]); + io_stat.aggregate(& pfs->m_table_stat.m_index_stat[MAX_INDEXES]); io_stat.sum(& m_stat); } @@ -1012,14 +1019,15 @@ void PFS_table_io_wait_visitor::visit_ta if (likely(safe_share != NULL)) { PFS_table_io_stat io_stat; + uint safe_key_count= sanitize_index_count(safe_share->m_key_count); uint index; /* Aggregate index stats */ - for (index= 0; index < safe_share->m_key_count; index++) + for (index= 0; index < safe_key_count; index++) io_stat.aggregate(& pfs->m_table_stat.m_index_stat[index]); /* Aggregate global stats */ - io_stat.aggregate(& pfs->m_table_stat.m_index_stat[MAX_KEY]); + io_stat.aggregate(& pfs->m_table_stat.m_index_stat[MAX_INDEXES]); io_stat.sum(& m_stat); } @@ -1035,14 +1043,15 @@ PFS_table_io_stat_visitor::~PFS_table_io void PFS_table_io_stat_visitor::visit_table_share(PFS_table_share *pfs) { + uint safe_key_count= sanitize_index_count(pfs->m_key_count); uint index; /* Aggregate index stats */ - for (index= 0; index < pfs->m_key_count; index++) + for (index= 0; index < safe_key_count; index++) m_stat.aggregate(& pfs->m_table_stat.m_index_stat[index]); /* Aggregate global stats */ - m_stat.aggregate(& pfs->m_table_stat.m_index_stat[MAX_KEY]); + m_stat.aggregate(& pfs->m_table_stat.m_index_stat[MAX_INDEXES]); } void PFS_table_io_stat_visitor::visit_table(PFS_table *pfs) @@ -1051,14 +1060,15 @@ void PFS_table_io_stat_visitor::visit_ta if (likely(safe_share != NULL)) { + uint safe_key_count= sanitize_index_count(safe_share->m_key_count); uint index; /* Aggregate index stats */ - for (index= 0; index < safe_share->m_key_count; index++) + for (index= 0; index < safe_key_count; index++) m_stat.aggregate(& pfs->m_table_stat.m_index_stat[index]); /* Aggregate global stats */ - m_stat.aggregate(& pfs->m_table_stat.m_index_stat[MAX_KEY]); + m_stat.aggregate(& pfs->m_table_stat.m_index_stat[MAX_INDEXES]); } } === modified file 'storage/perfschema/table_events_waits.cc' --- a/storage/perfschema/table_events_waits.cc 2012-01-24 23:42:36 +0000 +++ b/storage/perfschema/table_events_waits.cc 2012-03-19 19:29:28 +0000 @@ -239,7 +239,8 @@ int table_events_waits_common::make_tabl /* INDEX NAME */ safe_index= wait->m_index; - if (safe_index < MAX_KEY && safe_index < safe_table_share->m_key_count) + uint safe_key_count= sanitize_index_count(safe_table_share->m_key_count); + if (safe_index < safe_key_count) { PFS_table_key *key= & safe_table_share->m_keys[safe_index]; m_row.m_index_name_length= key->m_name_length; === modified file 'storage/perfschema/table_helper.cc' --- a/storage/perfschema/table_helper.cc 2012-02-23 23:27:02 +0000 +++ b/storage/perfschema/table_helper.cc 2012-03-19 19:29:28 +0000 @@ -199,7 +199,7 @@ int PFS_index_row::make_row(PFS_table_sh if (m_object_row.make_row(pfs)) return 1; - if (table_index < MAX_KEY) + if (table_index < MAX_INDEXES) { PFS_table_key *key= &pfs->m_keys[table_index]; m_index_name_length= key->m_name_length; === modified file 'storage/perfschema/table_os_global_by_type.cc' --- a/storage/perfschema/table_os_global_by_type.cc 2010-12-09 16:17:13 +0000 +++ b/storage/perfschema/table_os_global_by_type.cc 2012-03-19 19:29:28 +0000 @@ -174,6 +174,7 @@ void table_os_global_by_type::make_row(P { pfs_lock lock; PFS_single_stat cumulated_stat; + uint safe_key_count; m_row_exists= false; @@ -184,7 +185,11 @@ void table_os_global_by_type::make_row(P m_row.m_schema_name_length= share->m_schema_name_length; memcpy(m_row.m_object_name, share->m_table_name, share->m_table_name_length); m_row.m_object_name_length= share->m_table_name_length; - share->m_table_stat.sum(& cumulated_stat); + + /* This is a dirty read, some thread can write data while we are reading it */ + safe_key_count= sanitize_index_count(share->m_key_count); + + share->m_table_stat.sum(& cumulated_stat, safe_key_count); if (! share->m_lock.end_optimistic_lock(&lock)) return; @@ -204,7 +209,7 @@ void table_os_global_by_type::make_row(P If the opened table handle is for this table share, aggregate the table handle statistics. */ - table->m_table_stat.sum(& cumulated_stat); + table->m_table_stat.sum(& cumulated_stat, safe_key_count); } } } === modified file 'storage/perfschema/table_tiws_by_index_usage.cc' --- a/storage/perfschema/table_tiws_by_index_usage.cc 2012-01-24 23:42:36 +0000 +++ b/storage/perfschema/table_tiws_by_index_usage.cc 2012-03-19 19:29:28 +0000 @@ -290,15 +290,16 @@ int table_tiws_by_index_usage::rnd_next( table_share= &table_share_array[m_pos.m_index_1]; if (table_share->m_lock.is_populated()) { - if (m_pos.m_index_2 < table_share->m_key_count) + uint safe_key_count= sanitize_index_count(table_share->m_key_count); + if (m_pos.m_index_2 < safe_key_count) { make_row(table_share, m_pos.m_index_2); m_next_pos.set_after(&m_pos); return 0; } - if (m_pos.m_index_2 <= MAX_KEY) + if (m_pos.m_index_2 <= MAX_INDEXES) { - m_pos.m_index_2= MAX_KEY; + m_pos.m_index_2= MAX_INDEXES; make_row(table_share, m_pos.m_index_2); m_next_pos.set_after(&m_pos); return 0; @@ -319,12 +320,13 @@ table_tiws_by_index_usage::rnd_pos(const table_share= &table_share_array[m_pos.m_index_1]; if (table_share->m_lock.is_populated()) { - if (m_pos.m_index_2 < table_share->m_key_count) + uint safe_key_count= sanitize_index_count(table_share->m_key_count); + if (m_pos.m_index_2 < safe_key_count) { make_row(table_share, m_pos.m_index_2); return 0; } - if (m_pos.m_index_2 == MAX_KEY) + if (m_pos.m_index_2 == MAX_INDEXES) { make_row(table_share, m_pos.m_index_2); return 0; No bundle (reason: useless for push emails).