March 13, 2013

[MySQL 5.6] 优化函数lock_number_of_rows_locked

lock_number_of_rows_locked是一个统计一个事务中占有多少记录锁的函数,通过执行show engine innodb status触发。 在我们的生产环境中,类似SHOW ENGINE INNODB STATUS这样的语句是被频繁执行的,而从perf top,也观察到过占用超过20%的cpu。 quoted code from lock_number_of_rows_locked: for (lock = UT_LIST_GET_FIRST(trx_lock->trx_locks); lock != NULL; lock = UT_LIST_GET_NEXT(trx_locks, lock)) { if (lock_get_type_low(lock) == LOCK_REC) { ulint n_bit; ulint n_bits = lock_rec_get_n_bits(lock); for (n_bit = 0; n_bit < n_bits; n_bit++) { if (lock_rec_get_nth_bit(lock, n_bit)) { n_records++; } } } }   […]