Skip to content

Commit 04e51dd

Browse files
author
Krunal Bauskar krunal.bauskar@oracle.com
committedAug 27, 2014
- Bug #16479309: FUNCTION LOCK_NUMBER_OF_ROWS_LOCKED MAY BE INEFFICIENT
Locks held by a transaction are tracked using a bit-vector. For reporting, bit-vector is traversed to calculate number of locks held. This could be optimized by using a simple counter for tracking Approved: Sunny (rb#6478)
1 parent 81e0d4c commit 04e51dd

File tree

4 files changed

+14
-20
lines changed

4 files changed

+14
-20
lines changed
 

‎storage/innobase/include/lock0priv.ic

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ lock_rec_set_nth_bit(
9696
bit_index = i % 8;
9797

9898
((byte*) &lock[1])[byte_index] |= 1 << bit_index;
99+
100+
++lock->trx->lock.n_rec_locks;
99101
}
100102

101103
/*********************************************************************//**

‎storage/innobase/include/trx0trx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,7 @@ struct trx_lock_t {
774774
mutex to prevent recursive deadlocks.
775775
Protected by both the lock sys mutex
776776
and the trx_t::mutex. */
777+
ulint n_rec_locks; /*!< number of rec locks in this trx */
777778
};
778779

779780
#define TRX_MAGIC_N 91118598

‎storage/innobase/lock/lock0lock.cc

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,12 @@ lock_rec_reset_nth_bit(
963963
byte mask = 1 << (i & 7);
964964
byte bit = *b & mask;
965965
*b &= ~mask;
966+
967+
if (bit != 0) {
968+
ut_ad(lock->trx->lock.n_rec_locks > 0);
969+
--lock->trx->lock.n_rec_locks;
970+
}
971+
966972
return(bit);
967973
}
968974

@@ -1339,28 +1345,9 @@ lock_number_of_rows_locked(
13391345
/*=======================*/
13401346
const trx_lock_t* trx_lock) /*!< in: transaction locks */
13411347
{
1342-
const lock_t* lock;
1343-
ulint n_records = 0;
1344-
13451348
ut_ad(lock_mutex_own());
13461349

1347-
for (lock = UT_LIST_GET_FIRST(trx_lock->trx_locks);
1348-
lock != NULL;
1349-
lock = UT_LIST_GET_NEXT(trx_locks, lock)) {
1350-
1351-
if (lock_get_type_low(lock) == LOCK_REC) {
1352-
ulint n_bit;
1353-
ulint n_bits = lock_rec_get_n_bits(lock);
1354-
1355-
for (n_bit = 0; n_bit < n_bits; n_bit++) {
1356-
if (lock_rec_get_nth_bit(lock, n_bit)) {
1357-
n_records++;
1358-
}
1359-
}
1360-
}
1361-
}
1362-
1363-
return(n_records);
1350+
return(trx_lock->n_rec_locks);
13641351
}
13651352

13661353
/*********************************************************************//**
@@ -6386,6 +6373,8 @@ lock_trx_release_locks(
63866373

63876374
lock_release(trx);
63886375

6376+
trx->lock.n_rec_locks = 0;
6377+
63896378
lock_mutex_exit();
63906379

63916380
/* We don't remove the locks one by one from the vector for

‎storage/innobase/trx/trx0trx.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ trx_init(
118118

119119
trx->support_xa = true;
120120

121+
trx->lock.n_rec_locks = 0;
122+
121123
trx->search_latch_timeout = BTR_SEA_TIMEOUT;
122124

123125
trx->dict_operation = TRX_DICT_OP_NONE;

0 commit comments

Comments
 (0)
Please sign in to comment.