1 # name : innodb_adaptive_hash_index_num.patch
2 # introduced : XtraDB on 5.5 (-13?)
3 # maintainer : Yasufumi
6 # Any small change to this file in the main branch
7 # should be done or reviewed by the maintainer!
8 diff -ruN a/storage/innobase/btr/btr0btr.c b/storage/innobase/btr/btr0btr.c
9 --- a/storage/innobase/btr/btr0btr.c 2010-12-04 15:52:23.355483176 +0900
10 +++ b/storage/innobase/btr/btr0btr.c 2010-12-04 16:12:48.639514256 +0900
15 - btr_search_drop_page_hash_index(block);
16 + btr_search_drop_page_hash_index(block, NULL);
18 header = buf_block_get_frame(block) + PAGE_HEADER + PAGE_BTR_SEG_TOP;
22 #ifndef UNIV_HOTBACKUP
23 if (UNIV_LIKELY(!recovery)) {
24 - btr_search_drop_page_hash_index(block);
25 + btr_search_drop_page_hash_index(block, index);
28 block->check_index_page_at_flush = TRUE;
30 ut_a(!page_zip || page_zip_validate(page_zip, page));
31 #endif /* UNIV_ZIP_DEBUG */
33 - btr_search_drop_page_hash_index(block);
34 + btr_search_drop_page_hash_index(block, index);
36 /* Recreate the page: note that global data on page (possible
37 segment headers, next page-field, etc.) is preserved intact */
42 - btr_search_drop_page_hash_index(block);
43 + btr_search_drop_page_hash_index(block, index);
45 /* Make the father empty */
46 btr_page_empty(father_block, father_page_zip, index, page_level, mtr);
51 - btr_search_drop_page_hash_index(block);
52 + btr_search_drop_page_hash_index(block, index);
54 /* Remove the page from the level list */
55 btr_level_list_remove(space, zip_size, page, mtr);
60 - btr_search_drop_page_hash_index(block);
61 + btr_search_drop_page_hash_index(block, index);
64 if (UNIV_LIKELY_NULL(merge_page_zip)) {
66 ut_a(btr_page_get_next(page, mtr) == FIL_NULL);
68 ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX));
69 - btr_search_drop_page_hash_index(block);
70 + btr_search_drop_page_hash_index(block, index);
72 btr_page_get_father(index, block, mtr, &cursor);
73 father = btr_cur_get_block(&cursor);
76 page = buf_block_get_frame(block);
77 ut_a(page_is_comp(merge_page) == page_is_comp(page));
78 - btr_search_drop_page_hash_index(block);
79 + btr_search_drop_page_hash_index(block, index);
81 if (left_page_no == FIL_NULL && !page_is_leaf(page)) {
83 diff -ruN a/storage/innobase/btr/btr0cur.c b/storage/innobase/btr/btr0cur.c
84 --- a/storage/innobase/btr/btr0cur.c 2010-12-04 15:52:23.359513820 +0900
85 +++ b/storage/innobase/btr/btr0cur.c 2010-12-04 16:12:48.643551837 +0900
87 #ifdef UNIV_SEARCH_PERF_STAT
90 - if (rw_lock_get_writer(&btr_search_latch) == RW_LOCK_NOT_LOCKED
91 + if (rw_lock_get_writer(btr_search_get_latch(cursor->index->id)) == RW_LOCK_NOT_LOCKED
92 && latch_mode <= BTR_MODIFY_LEAF
93 && info->last_hash_succ
97 if (has_search_latch) {
98 /* Release possible search latch to obey latching order */
99 - rw_lock_s_unlock(&btr_search_latch);
100 + rw_lock_s_unlock(btr_search_get_latch(cursor->index->id));
103 /* Store the position of the tree latch we push to mtr so that we
106 if (has_search_latch) {
108 - rw_lock_s_lock(&btr_search_latch);
109 + rw_lock_s_lock(btr_search_get_latch(cursor->index->id));
113 @@ -2059,7 +2059,7 @@
114 btr_search_update_hash_on_delete(cursor);
117 - rw_lock_x_lock(&btr_search_latch);
118 + rw_lock_x_lock(btr_search_get_latch(cursor->index->id));
121 if (!(flags & BTR_KEEP_SYS_FLAG)) {
122 @@ -2073,7 +2073,7 @@
123 row_upd_rec_in_place(rec, index, offsets, update, page_zip);
125 if (block->is_hashed) {
126 - rw_lock_x_unlock(&btr_search_latch);
127 + rw_lock_x_unlock(btr_search_get_latch(cursor->index->id));
130 if (page_zip && !dict_index_is_clust(index)
131 @@ -2857,7 +2857,7 @@
132 block = btr_cur_get_block(cursor);
134 if (block->is_hashed) {
135 - rw_lock_x_lock(&btr_search_latch);
136 + rw_lock_x_lock(btr_search_get_latch(index->id));
139 page_zip = buf_block_get_page_zip(block);
140 @@ -2872,7 +2872,7 @@
143 if (block->is_hashed) {
144 - rw_lock_x_unlock(&btr_search_latch);
145 + rw_lock_x_unlock(btr_search_get_latch(index->id));
148 btr_cur_del_mark_set_clust_rec_log(flags, rec, index, val, trx,
149 @@ -3003,13 +3003,13 @@
150 == dict_table_is_comp(cursor->index->table));
152 if (block->is_hashed) {
153 - rw_lock_x_lock(&btr_search_latch);
154 + rw_lock_x_lock(btr_search_get_latch(cursor->index->id));
157 btr_rec_set_deleted_flag(rec, buf_block_get_page_zip(block), val);
159 if (block->is_hashed) {
160 - rw_lock_x_unlock(&btr_search_latch);
161 + rw_lock_x_unlock(btr_search_get_latch(cursor->index->id));
164 btr_cur_del_mark_set_sec_rec_log(rec, val, mtr);
165 diff -ruN a/storage/innobase/btr/btr0sea.c b/storage/innobase/btr/btr0sea.c
166 --- a/storage/innobase/btr/btr0sea.c 2010-12-04 15:52:23.387513429 +0900
167 +++ b/storage/innobase/btr/btr0sea.c 2010-12-04 16:14:51.721884049 +0900
169 UNIV_INTERN char btr_search_enabled = TRUE;
170 UNIV_INTERN ibool btr_search_fully_disabled = FALSE;
172 +UNIV_INTERN ulint btr_search_index_num = 1;
174 /** Mutex protecting btr_search_enabled */
175 static mutex_t btr_search_enabled_mutex;
179 /* We will allocate the latch from dynamic memory to get it to the
180 same DRAM page as other hotspot semaphores */
181 -UNIV_INTERN rw_lock_t* btr_search_latch_temp;
182 +//UNIV_INTERN rw_lock_t* btr_search_latch_temp;
184 +UNIV_INTERN rw_lock_t** btr_search_latch_part;
186 /** padding to prevent other memory update hotspots from residing on
187 the same memory cache line */
188 @@ -131,18 +135,19 @@
189 will not guarantee success. */
192 -btr_search_check_free_space_in_heap(void)
193 +btr_search_check_free_space_in_heap(
194 /*=====================================*/
200 #ifdef UNIV_SYNC_DEBUG
201 - ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_SHARED));
202 - ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_EX));
203 + ut_ad(!rw_lock_own(btr_search_get_latch(key), RW_LOCK_SHARED));
204 + ut_ad(!rw_lock_own(btr_search_get_latch(key), RW_LOCK_EX));
205 #endif /* UNIV_SYNC_DEBUG */
207 - table = btr_search_sys->hash_index;
208 + table = btr_search_get_hash_index(key);
213 if (heap->free_block == NULL) {
214 buf_block_t* block = buf_block_alloc(NULL, 0);
216 - rw_lock_x_lock(&btr_search_latch);
217 + rw_lock_x_lock(btr_search_get_latch(key));
219 if (heap->free_block == NULL) {
220 heap->free_block = block;
222 buf_block_free(block);
225 - rw_lock_x_unlock(&btr_search_latch);
226 + rw_lock_x_unlock(btr_search_get_latch(key));
230 @@ -173,19 +178,30 @@
231 /*==================*/
232 ulint hash_size) /*!< in: hash index hash table size */
235 /* We allocate the search latch from dynamic memory:
236 see above at the global variable definition */
238 - btr_search_latch_temp = mem_alloc(sizeof(rw_lock_t));
239 + //btr_search_latch_temp = mem_alloc(sizeof(rw_lock_t));
241 - rw_lock_create(btr_search_latch_key, &btr_search_latch,
243 + //rw_lock_create(btr_search_latch_key, &btr_search_latch,
244 + // SYNC_SEARCH_SYS);
245 mutex_create(btr_search_enabled_mutex_key,
246 &btr_search_enabled_mutex, SYNC_SEARCH_SYS_CONF);
248 btr_search_sys = mem_alloc(sizeof(btr_search_sys_t));
250 - btr_search_sys->hash_index = ha_create(hash_size, 0, 0);
251 + /* btr_search_index_num should be <= 32. (bits of trx->has_search_latch) */
252 + btr_search_latch_part = mem_alloc(sizeof(rw_lock_t*) * btr_search_index_num);
253 + btr_search_sys->hash_index = mem_alloc(sizeof(hash_table_t*) * btr_search_index_num);
254 + for (i = 0; i < btr_search_index_num; i++) {
255 + btr_search_latch_part[i] = mem_alloc(sizeof(rw_lock_t));
257 + rw_lock_create(btr_search_latch_key,
258 + btr_search_latch_part[i], SYNC_SEARCH_SYS);
260 + btr_search_sys->hash_index[i] = ha_create(hash_size, 0, 0);
264 /*****************************************************************//**
265 @@ -195,11 +211,20 @@
266 btr_search_sys_free(void)
267 /*=====================*/
269 - rw_lock_free(&btr_search_latch);
270 - mem_free(btr_search_latch_temp);
271 - btr_search_latch_temp = NULL;
272 - mem_heap_free(btr_search_sys->hash_index->heap);
273 - hash_table_free(btr_search_sys->hash_index);
276 + for (i = 0; i < btr_search_index_num; i++) {
277 + mem_heap_free(btr_search_sys->hash_index[i]->heap);
278 + hash_table_free(btr_search_sys->hash_index[i]);
280 + rw_lock_free(btr_search_latch_part[i]);
282 + mem_free(btr_search_latch_part[i]);
285 + //rw_lock_free(&btr_search_latch);
286 + //mem_free(btr_search_latch_temp);
287 + //btr_search_latch_temp = NULL;
288 mem_free(btr_search_sys);
289 btr_search_sys = NULL;
292 /*====================*/
294 mutex_enter(&btr_search_enabled_mutex);
295 - rw_lock_x_lock(&btr_search_latch);
296 + btr_search_x_lock_all();
298 /* Disable access to hash index, also tell ha_insert_for_fold()
299 stop adding new nodes to hash index, but still allow updating
301 /* btr_search_enabled_mutex should guarantee this. */
302 ut_ad(!btr_search_enabled);
304 - rw_lock_x_unlock(&btr_search_latch);
305 + btr_search_x_unlock_all();
306 mutex_exit(&btr_search_enabled_mutex);
309 @@ -242,12 +267,12 @@
310 /*====================*/
312 mutex_enter(&btr_search_enabled_mutex);
313 - rw_lock_x_lock(&btr_search_latch);
314 + btr_search_x_lock_all();
316 btr_search_enabled = TRUE;
317 btr_search_fully_disabled = FALSE;
319 - rw_lock_x_unlock(&btr_search_latch);
320 + btr_search_x_unlock_all();
321 mutex_exit(&btr_search_enabled_mutex);
324 @@ -300,20 +325,21 @@
326 btr_search_info_get_ref_count(
327 /*==========================*/
328 - btr_search_t* info) /*!< in: search info. */
329 + btr_search_t* info, /*!< in: search info. */
336 #ifdef UNIV_SYNC_DEBUG
337 - ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_SHARED));
338 - ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_EX));
339 + ut_ad(!rw_lock_own(btr_search_get_latch(key), RW_LOCK_SHARED));
340 + ut_ad(!rw_lock_own(btr_search_get_latch(key), RW_LOCK_EX));
341 #endif /* UNIV_SYNC_DEBUG */
343 - rw_lock_s_lock(&btr_search_latch);
344 + rw_lock_s_lock(btr_search_get_latch(key));
345 ret = info->ref_count;
346 - rw_lock_s_unlock(&btr_search_latch);
347 + rw_lock_s_unlock(btr_search_get_latch(key));
354 #ifdef UNIV_SYNC_DEBUG
355 - ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_SHARED));
356 - ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_EX));
357 + ut_ad(!rw_lock_own(btr_search_get_latch(cursor->index->id), RW_LOCK_SHARED));
358 + ut_ad(!rw_lock_own(btr_search_get_latch(cursor->index->id), RW_LOCK_EX));
359 #endif /* UNIV_SYNC_DEBUG */
361 index = cursor->index;
365 #ifdef UNIV_SYNC_DEBUG
366 - ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_SHARED));
367 - ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_EX));
368 + ut_ad(!rw_lock_own(btr_search_get_latch(cursor->index->id), RW_LOCK_SHARED));
369 + ut_ad(!rw_lock_own(btr_search_get_latch(cursor->index->id), RW_LOCK_EX));
370 ut_ad(rw_lock_own(&block->lock, RW_LOCK_SHARED)
371 || rw_lock_own(&block->lock, RW_LOCK_EX));
372 #endif /* UNIV_SYNC_DEBUG */
375 ut_ad(cursor->flag == BTR_CUR_HASH_FAIL);
376 #ifdef UNIV_SYNC_DEBUG
377 - ut_ad(rw_lock_own(&btr_search_latch, RW_LOCK_EX));
378 + ut_ad(rw_lock_own(btr_search_get_latch(cursor->index->id), RW_LOCK_EX));
379 ut_ad(rw_lock_own(&(block->lock), RW_LOCK_SHARED)
380 || rw_lock_own(&(block->lock), RW_LOCK_EX));
381 #endif /* UNIV_SYNC_DEBUG */
382 @@ -578,10 +604,10 @@
385 #ifdef UNIV_SYNC_DEBUG
386 - ut_ad(rw_lock_own(&btr_search_latch, RW_LOCK_EX));
387 + ut_ad(rw_lock_own(btr_search_get_latch(cursor->index->id), RW_LOCK_EX));
388 #endif /* UNIV_SYNC_DEBUG */
390 - ha_insert_for_fold(btr_search_sys->hash_index, fold,
391 + ha_insert_for_fold(btr_search_get_hash_index(cursor->index->id), fold,
398 #ifdef UNIV_SYNC_DEBUG
399 - ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_SHARED));
400 - ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_EX));
401 + ut_ad(!rw_lock_own(btr_search_get_latch(cursor->index->id), RW_LOCK_SHARED));
402 + ut_ad(!rw_lock_own(btr_search_get_latch(cursor->index->id), RW_LOCK_EX));
403 #endif /* UNIV_SYNC_DEBUG */
405 block = btr_cur_get_block(cursor);
408 if (build_index || (cursor->flag == BTR_CUR_HASH_FAIL)) {
410 - btr_search_check_free_space_in_heap();
411 + btr_search_check_free_space_in_heap(cursor->index->id);
414 if (cursor->flag == BTR_CUR_HASH_FAIL) {
415 @@ -633,11 +659,11 @@
416 btr_search_n_hash_fail++;
417 #endif /* UNIV_SEARCH_PERF_STAT */
419 - rw_lock_x_lock(&btr_search_latch);
420 + rw_lock_x_lock(btr_search_get_latch(cursor->index->id));
422 btr_search_update_hash_ref(info, block, cursor);
424 - rw_lock_x_unlock(&btr_search_latch);
425 + rw_lock_x_unlock(btr_search_get_latch(cursor->index->id));
429 @@ -881,17 +907,17 @@
430 cursor->flag = BTR_CUR_HASH;
432 if (UNIV_LIKELY(!has_search_latch)) {
433 - rw_lock_s_lock(&btr_search_latch);
434 + rw_lock_s_lock(btr_search_get_latch(index_id));
436 if (UNIV_UNLIKELY(!btr_search_enabled)) {
441 - ut_ad(rw_lock_get_writer(&btr_search_latch) != RW_LOCK_EX);
442 - ut_ad(rw_lock_get_reader_count(&btr_search_latch) > 0);
443 + ut_ad(rw_lock_get_writer(btr_search_get_latch(index_id)) != RW_LOCK_EX);
444 + ut_ad(rw_lock_get_reader_count(btr_search_get_latch(index_id)) > 0);
446 - rec = ha_search_and_get_data(btr_search_sys->hash_index, fold);
447 + rec = ha_search_and_get_data(btr_search_get_hash_index(index_id), fold);
449 if (UNIV_UNLIKELY(!rec)) {
455 - rw_lock_s_unlock(&btr_search_latch);
456 + rw_lock_s_unlock(btr_search_get_latch(index_id));
458 buf_block_dbg_add_level(block, SYNC_TREE_NODE_FROM_HASH);
460 @@ -1006,7 +1032,7 @@
461 /*-------------------------------------------*/
463 if (UNIV_LIKELY(!has_search_latch)) {
464 - rw_lock_s_unlock(&btr_search_latch);
465 + rw_lock_s_unlock(btr_search_get_latch(index_id));
468 cursor->flag = BTR_CUR_HASH_FAIL;
469 @@ -1029,10 +1055,11 @@
471 btr_search_drop_page_hash_index(
472 /*============================*/
473 - buf_block_t* block) /*!< in: block containing index page,
474 + buf_block_t* block, /*!< in: block containing index page,
475 s- or x-latched, or an index page
476 for which we know that
477 block->buf_fix_count == 0 */
478 + dict_index_t* index_in)
482 @@ -1051,22 +1078,60 @@
485 #ifdef UNIV_SYNC_DEBUG
486 - ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_SHARED));
487 - ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_EX));
489 + ut_ad(!rw_lock_own(btr_search_get_latch(index_in->id), RW_LOCK_SHARED));
490 + ut_ad(!rw_lock_own(btr_search_get_latch(index_in->id), RW_LOCK_EX));
492 #endif /* UNIV_SYNC_DEBUG */
495 - rw_lock_s_lock(&btr_search_latch);
498 + rw_lock_s_lock(btr_search_get_latch(index->id));
499 + } else if (btr_search_index_num > 1) {
500 + rw_lock_t* btr_search_latch;
502 + /* FIXME: This may be optimistic implementation still. */
503 + btr_search_latch = (rw_lock_t*)(block->btr_search_latch);
504 + if (UNIV_LIKELY(!btr_search_latch)) {
505 + if (block->is_hashed) {
510 + rw_lock_s_lock(btr_search_latch);
511 + if (UNIV_LIKELY(btr_search_latch != block->btr_search_latch)) {
512 + rw_lock_s_unlock(btr_search_latch);
515 + if (UNIV_LIKELY(!block->is_hashed)) {
516 + rw_lock_s_unlock(btr_search_latch);
519 + index = block->index;
520 + ut_a(btr_search_latch == btr_search_get_latch(index->id));
522 + /* btr_search_index_num == 1 */
523 + /* btr_search_latch is only one and able to obtain
524 + before evaluating block->is_hashed. */
525 + rw_lock_s_lock(btr_search_latch_part[0]);
526 + if (UNIV_LIKELY(!block->is_hashed)) {
527 + rw_lock_s_unlock(btr_search_latch_part[0]);
530 + index = block->index;
535 if (UNIV_LIKELY(!block->is_hashed)) {
537 - rw_lock_s_unlock(&btr_search_latch);
538 + rw_lock_s_unlock(btr_search_get_latch(index->id));
543 - table = btr_search_sys->hash_index;
544 + table = btr_search_get_hash_index(index->id);
546 #ifdef UNIV_SYNC_DEBUG
547 ut_ad(rw_lock_own(&(block->lock), RW_LOCK_SHARED)
548 @@ -1076,14 +1141,14 @@
550 n_fields = block->curr_n_fields;
551 n_bytes = block->curr_n_bytes;
552 - index = block->index;
553 + ut_a(index == block->index);
554 ut_a(!dict_index_is_ibuf(index));
556 /* NOTE: The fields of block must not be accessed after
557 releasing btr_search_latch, as the index page might only
560 - rw_lock_s_unlock(&btr_search_latch);
561 + rw_lock_s_unlock(btr_search_get_latch(index->id));
563 ut_a(n_fields + n_bytes > 0);
565 @@ -1133,7 +1198,7 @@
569 - rw_lock_x_lock(&btr_search_latch);
570 + rw_lock_x_lock(btr_search_get_latch(index->id));
572 if (UNIV_UNLIKELY(!block->is_hashed)) {
573 /* Someone else has meanwhile dropped the hash index */
574 @@ -1149,7 +1214,7 @@
575 /* Someone else has meanwhile built a new hash index on the
576 page, with different parameters */
578 - rw_lock_x_unlock(&btr_search_latch);
579 + rw_lock_x_unlock(btr_search_get_latch(index->id));
583 @@ -1165,6 +1230,7 @@
585 block->is_hashed = FALSE;
587 + block->btr_search_latch = NULL;
590 #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
591 @@ -1177,14 +1243,14 @@
592 "InnoDB: the hash index to a page of %s,"
593 " still %lu hash nodes remain.\n",
594 index->name, (ulong) block->n_pointers);
595 - rw_lock_x_unlock(&btr_search_latch);
596 + rw_lock_x_unlock(btr_search_get_latch(index->id));
598 btr_search_validate();
600 - rw_lock_x_unlock(&btr_search_latch);
601 + rw_lock_x_unlock(btr_search_get_latch(index->id));
603 #else /* UNIV_AHI_DEBUG || UNIV_DEBUG */
604 - rw_lock_x_unlock(&btr_search_latch);
605 + rw_lock_x_unlock(btr_search_get_latch(index->id));
606 #endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
609 @@ -1215,10 +1281,10 @@
610 mem_heap_t* heap = NULL;
613 - rw_lock_x_lock(&btr_search_latch);
614 + rw_lock_x_lock(btr_search_get_latch(index->id));
615 //buf_pool_mutex_enter_all();
617 - table = btr_search_sys->hash_index;
618 + table = btr_search_get_hash_index(index->id);
620 for (j = 0; j < srv_buf_pool_instances; j++) {
621 buf_pool_t* buf_pool;
622 @@ -1291,6 +1357,7 @@
624 block->is_hashed = FALSE;
626 + block->btr_search_latch = NULL;
628 #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
629 if (UNIV_UNLIKELY(block->n_pointers)) {
630 @@ -1313,7 +1380,7 @@
633 //buf_pool_mutex_exit_all();
634 - rw_lock_x_unlock(&btr_search_latch);
635 + rw_lock_x_unlock(btr_search_get_latch(index->id));
637 if (UNIV_LIKELY_NULL(heap)) {
639 @@ -1360,7 +1427,7 @@
641 buf_block_dbg_add_level(block, SYNC_TREE_NODE_FROM_HASH);
643 - btr_search_drop_page_hash_index(block);
644 + btr_search_drop_page_hash_index(block, NULL);
648 @@ -1402,26 +1469,26 @@
650 ut_a(!dict_index_is_ibuf(index));
652 - table = btr_search_sys->hash_index;
653 + table = btr_search_get_hash_index(index->id);
654 page = buf_block_get_frame(block);
656 #ifdef UNIV_SYNC_DEBUG
657 - ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_EX));
658 + ut_ad(!rw_lock_own(btr_search_get_latch(index->id), RW_LOCK_EX));
659 ut_ad(rw_lock_own(&(block->lock), RW_LOCK_SHARED)
660 || rw_lock_own(&(block->lock), RW_LOCK_EX));
661 #endif /* UNIV_SYNC_DEBUG */
663 - rw_lock_s_lock(&btr_search_latch);
664 + rw_lock_s_lock(btr_search_get_latch(index->id));
666 if (block->is_hashed && ((block->curr_n_fields != n_fields)
667 || (block->curr_n_bytes != n_bytes)
668 || (block->curr_left_side != left_side))) {
670 - rw_lock_s_unlock(&btr_search_latch);
671 + rw_lock_s_unlock(btr_search_get_latch(index->id));
673 - btr_search_drop_page_hash_index(block);
674 + btr_search_drop_page_hash_index(block, index);
676 - rw_lock_s_unlock(&btr_search_latch);
677 + rw_lock_s_unlock(btr_search_get_latch(index->id));
680 n_recs = page_get_n_recs(page);
681 @@ -1515,9 +1582,9 @@
685 - btr_search_check_free_space_in_heap();
686 + btr_search_check_free_space_in_heap(index->id);
688 - rw_lock_x_lock(&btr_search_latch);
689 + rw_lock_x_lock(btr_search_get_latch(index->id));
691 if (UNIV_UNLIKELY(btr_search_fully_disabled)) {
693 @@ -1545,6 +1612,7 @@
694 block->curr_n_bytes = n_bytes;
695 block->curr_left_side = left_side;
696 block->index = index;
697 + block->btr_search_latch = btr_search_get_latch(index->id);
699 for (i = 0; i < n_cached; i++) {
701 @@ -1552,7 +1620,7 @@
705 - rw_lock_x_unlock(&btr_search_latch);
706 + rw_lock_x_unlock(btr_search_get_latch(index->id));
710 @@ -1591,13 +1659,13 @@
711 ut_a(!(new_block->is_hashed || block->is_hashed)
712 || !dict_index_is_ibuf(index));
714 - rw_lock_s_lock(&btr_search_latch);
715 + rw_lock_s_lock(btr_search_get_latch(index->id));
717 if (new_block->is_hashed) {
719 - rw_lock_s_unlock(&btr_search_latch);
720 + rw_lock_s_unlock(btr_search_get_latch(index->id));
722 - btr_search_drop_page_hash_index(block);
723 + btr_search_drop_page_hash_index(block, index);
727 @@ -1612,7 +1680,7 @@
728 new_block->n_bytes = block->curr_n_bytes;
729 new_block->left_side = left_side;
731 - rw_lock_s_unlock(&btr_search_latch);
732 + rw_lock_s_unlock(btr_search_get_latch(index->id));
734 ut_a(n_fields + n_bytes > 0);
736 @@ -1624,7 +1692,7 @@
740 - rw_lock_s_unlock(&btr_search_latch);
741 + rw_lock_s_unlock(btr_search_get_latch(index->id));
744 /********************************************************************//**
745 @@ -1663,7 +1731,7 @@
746 ut_a(block->curr_n_fields + block->curr_n_bytes > 0);
747 ut_a(!dict_index_is_ibuf(cursor->index));
749 - table = btr_search_sys->hash_index;
750 + table = btr_search_get_hash_index(cursor->index->id);
752 index_id = cursor->index->id;
753 fold = rec_fold(rec, rec_get_offsets(rec, cursor->index, offsets_,
754 @@ -1672,11 +1740,11 @@
755 if (UNIV_LIKELY_NULL(heap)) {
758 - rw_lock_x_lock(&btr_search_latch);
759 + rw_lock_x_lock(btr_search_get_latch(cursor->index->id));
761 ha_search_and_delete_if_found(table, fold, rec);
763 - rw_lock_x_unlock(&btr_search_latch);
764 + rw_lock_x_unlock(btr_search_get_latch(cursor->index->id));
767 /********************************************************************//**
768 @@ -1710,21 +1778,21 @@
769 ut_a(block->index == cursor->index);
770 ut_a(!dict_index_is_ibuf(cursor->index));
772 - rw_lock_x_lock(&btr_search_latch);
773 + rw_lock_x_lock(btr_search_get_latch(cursor->index->id));
775 if ((cursor->flag == BTR_CUR_HASH)
776 && (cursor->n_fields == block->curr_n_fields)
777 && (cursor->n_bytes == block->curr_n_bytes)
778 && !block->curr_left_side) {
780 - table = btr_search_sys->hash_index;
781 + table = btr_search_get_hash_index(cursor->index->id);
783 ha_search_and_update_if_found(table, cursor->fold, rec,
784 block, page_rec_get_next(rec));
786 - rw_lock_x_unlock(&btr_search_latch);
787 + rw_lock_x_unlock(btr_search_get_latch(cursor->index->id));
789 - rw_lock_x_unlock(&btr_search_latch);
790 + rw_lock_x_unlock(btr_search_get_latch(cursor->index->id));
792 btr_search_update_hash_on_insert(cursor);
794 @@ -1759,9 +1827,9 @@
795 ulint* offsets = offsets_;
796 rec_offs_init(offsets_);
798 - table = btr_search_sys->hash_index;
799 + table = btr_search_get_hash_index(cursor->index->id);
801 - btr_search_check_free_space_in_heap();
802 + btr_search_check_free_space_in_heap(cursor->index->id);
804 rec = btr_cur_get_rec(cursor);
806 @@ -1806,7 +1874,7 @@
810 - rw_lock_x_lock(&btr_search_latch);
811 + rw_lock_x_lock(btr_search_get_latch(index_id));
815 @@ -1820,7 +1888,7 @@
819 - rw_lock_x_lock(&btr_search_latch);
820 + rw_lock_x_lock(btr_search_get_latch(index_id));
824 @@ -1838,7 +1906,7 @@
828 - rw_lock_x_lock(&btr_search_latch);
829 + rw_lock_x_lock(btr_search_get_latch(index_id));
833 @@ -1853,7 +1921,7 @@
837 - rw_lock_x_lock(&btr_search_latch);
838 + rw_lock_x_lock(btr_search_get_latch(index_id));
842 @@ -1876,7 +1944,7 @@
846 - rw_lock_x_unlock(&btr_search_latch);
847 + rw_lock_x_unlock(btr_search_get_latch(index_id));
851 @@ -1892,7 +1960,7 @@
853 ulint n_page_dumps = 0;
858 mem_heap_t* heap = NULL;
859 ulint offsets_[REC_OFFS_NORMAL_SIZE];
860 @@ -1904,23 +1972,25 @@
862 rec_offs_init(offsets_);
864 - rw_lock_x_lock(&btr_search_latch);
865 + btr_search_x_lock_all();
866 buf_pool_page_hash_x_lock_all();
868 - cell_count = hash_get_n_cells(btr_search_sys->hash_index);
869 + for (j = 0; j < btr_search_index_num; j++) {
871 + cell_count = hash_get_n_cells(btr_search_sys->hash_index[j]);
873 for (i = 0; i < cell_count; i++) {
874 /* We release btr_search_latch every once in a while to
875 give other queries a chance to run. */
876 if ((i != 0) && ((i % chunk_size) == 0)) {
877 buf_pool_page_hash_x_unlock_all();
878 - rw_lock_x_unlock(&btr_search_latch);
879 + btr_search_x_unlock_all();
881 - rw_lock_x_lock(&btr_search_latch);
882 + btr_search_x_lock_all();
883 buf_pool_page_hash_x_lock_all();
886 - node = hash_get_nth_cell(btr_search_sys->hash_index, i)->node;
887 + node = hash_get_nth_cell(btr_search_sys->hash_index[j], i)->node;
889 for (; node != NULL; node = node->next) {
890 const buf_block_t* block
891 @@ -2029,19 +2099,21 @@
892 give other queries a chance to run. */
894 buf_pool_page_hash_x_unlock_all();
895 - rw_lock_x_unlock(&btr_search_latch);
896 + btr_search_x_unlock_all();
898 - rw_lock_x_lock(&btr_search_latch);
899 + btr_search_x_lock_all();
900 buf_pool_page_hash_x_lock_all();
903 - if (!ha_validate(btr_search_sys->hash_index, i, end_index)) {
904 + if (!ha_validate(btr_search_sys->hash_index[j], i, end_index)) {
909 + } /*for (j = 0; j < btr_search_index_num; j++)*/
911 buf_pool_page_hash_x_unlock_all();
912 - rw_lock_x_unlock(&btr_search_latch);
913 + btr_search_x_unlock_all();
914 if (UNIV_LIKELY_NULL(heap)) {
917 diff -ruN a/storage/innobase/buf/buf0buf.c b/storage/innobase/buf/buf0buf.c
918 --- a/storage/innobase/buf/buf0buf.c 2010-12-04 15:55:21.351597052 +0900
919 +++ b/storage/innobase/buf/buf0buf.c 2010-12-04 16:12:48.654550708 +0900
922 block->check_index_page_at_flush = FALSE;
924 + block->btr_search_latch = NULL;
926 block->is_hashed = FALSE;
928 @@ -1477,7 +1478,7 @@
929 /* To follow the latching order, we
930 have to release btr_search_latch
931 before acquiring block->latch. */
932 - rw_lock_x_unlock(&btr_search_latch);
933 + btr_search_x_unlock_all();
934 /* When we release the search latch,
935 we must rescan all blocks, because
936 some may become hashed again. */
937 @@ -1508,11 +1509,11 @@
938 anything. block->is_hashed can only
939 be set on uncompressed file pages. */
941 - btr_search_drop_page_hash_index(block);
942 + btr_search_drop_page_hash_index(block, NULL);
944 rw_lock_x_unlock(&block->lock);
946 - rw_lock_x_lock(&btr_search_latch);
947 + btr_search_x_lock_all();
949 ut_ad(!btr_search_enabled);
951 @@ -1531,7 +1532,11 @@
952 ibool released_search_latch;
954 #ifdef UNIV_SYNC_DEBUG
955 - ut_ad(rw_lock_own(&btr_search_latch, RW_LOCK_EX));
958 + for (j = 0; j < btr_search_index_num; j++) {
959 + ut_ad(rw_lock_own(btr_search_latch_part[j], RW_LOCK_EX));
961 #endif /* UNIV_SYNC_DEBUG */
962 ut_ad(!btr_search_enabled);
964 @@ -2635,6 +2640,7 @@
966 block->check_index_page_at_flush = FALSE;
968 + block->btr_search_latch = NULL;
970 block->n_hash_helps = 0;
971 block->is_hashed = FALSE;
972 diff -ruN a/storage/innobase/buf/buf0lru.c b/storage/innobase/buf/buf0lru.c
973 --- a/storage/innobase/buf/buf0lru.c 2010-12-04 15:35:29.137347521 +0900
974 +++ b/storage/innobase/buf/buf0lru.c 2010-12-04 16:12:48.658550840 +0900
975 @@ -1775,7 +1775,7 @@
977 UNIV_MEM_VALID(((buf_block_t*) bpage)->frame,
979 - btr_search_drop_page_hash_index((buf_block_t*) bpage);
980 + btr_search_drop_page_hash_index((buf_block_t*) bpage, NULL);
981 UNIV_MEM_INVALID(((buf_block_t*) bpage)->frame,
984 diff -ruN a/storage/innobase/dict/dict0dict.c b/storage/innobase/dict/dict0dict.c
985 --- a/storage/innobase/dict/dict0dict.c 2010-12-04 15:52:23.398513916 +0900
986 +++ b/storage/innobase/dict/dict0dict.c 2010-12-04 16:12:48.662550715 +0900
987 @@ -1802,7 +1802,7 @@
991 - ulint ref_count = btr_search_info_get_ref_count(info);
992 + ulint ref_count = btr_search_info_get_ref_count(info, index->id);
993 if (ref_count == 0) {
996 diff -ruN a/storage/innobase/ha/ha0ha.c b/storage/innobase/ha/ha0ha.c
997 --- a/storage/innobase/ha/ha0ha.c 2010-11-03 07:01:13.000000000 +0900
998 +++ b/storage/innobase/ha/ha0ha.c 2010-12-04 16:12:48.665593752 +0900
1001 ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
1002 #ifdef UNIV_SYNC_DEBUG
1003 - ut_ad(rw_lock_own(&btr_search_latch, RW_LOCK_EXCLUSIVE));
1004 + /* cannot identificate which btr_search_latch[i] for now */
1005 + //ut_ad(rw_lock_own(&btr_search_latch, RW_LOCK_EXCLUSIVE));
1006 #endif /* UNIV_SYNC_DEBUG */
1008 #ifndef UNIV_HOTBACKUP
1009 diff -ruN a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
1010 --- a/storage/innobase/handler/ha_innodb.cc 2010-12-04 16:12:20.185850734 +0900
1011 +++ b/storage/innobase/handler/ha_innodb.cc 2010-12-04 16:12:48.674552412 +0900
1012 @@ -11611,6 +11611,11 @@
1013 "Disable with --skip-innodb-adaptive-hash-index.",
1014 NULL, innodb_adaptive_hash_index_update, TRUE);
1016 +static MYSQL_SYSVAR_ULONG(adaptive_hash_index_partitions, btr_search_index_num,
1017 + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
1018 + "Number of InnoDB adaptive hash index partitions (default 1: disable partitioning)",
1019 + NULL, NULL, 1, 1, 32, 0);
1021 static MYSQL_SYSVAR_ULONG(replication_delay, srv_replication_delay,
1022 PLUGIN_VAR_RQCMDARG,
1023 "Replication thread delay (ms) on the slave server if "
1024 @@ -11963,6 +11968,7 @@
1025 MYSQL_SYSVAR(use_sys_stats_table),
1026 MYSQL_SYSVAR(stats_sample_pages),
1027 MYSQL_SYSVAR(adaptive_hash_index),
1028 + MYSQL_SYSVAR(adaptive_hash_index_partitions),
1029 MYSQL_SYSVAR(replication_delay),
1030 MYSQL_SYSVAR(status_file),
1031 MYSQL_SYSVAR(strict_mode),
1032 diff -ruN a/storage/innobase/include/btr0sea.h b/storage/innobase/include/btr0sea.h
1033 --- a/storage/innobase/include/btr0sea.h 2010-12-03 15:48:03.070987226 +0900
1034 +++ b/storage/innobase/include/btr0sea.h 2010-12-04 16:12:48.707551382 +0900
1037 btr_search_info_get_ref_count(
1038 /*==========================*/
1039 - btr_search_t* info); /*!< in: search info. */
1040 + btr_search_t* info, /*!< in: search info. */
1042 /*********************************************************************//**
1043 Updates the search info. */
1045 @@ -136,10 +137,11 @@
1047 btr_search_drop_page_hash_index(
1048 /*============================*/
1049 - buf_block_t* block); /*!< in: block containing index page,
1050 + buf_block_t* block, /*!< in: block containing index page,
1051 s- or x-latched, or an index page
1052 for which we know that
1053 block->buf_fix_count == 0 */
1054 + dict_index_t* index_in);
1055 /************************************************************************
1056 Drops a page hash index based on index */
1058 @@ -199,10 +201,47 @@
1059 # define btr_search_validate() TRUE
1060 #endif /* defined UNIV_AHI_DEBUG || defined UNIV_DEBUG */
1062 +/********************************************************************//**
1063 +New functions to control split btr_search_index */
1066 +btr_search_get_hash_index(
1067 +/*======================*/
1072 +btr_search_get_latch(
1073 +/*=================*/
1078 +btr_search_x_lock_all(void);
1079 +/*========================*/
1083 +btr_search_x_unlock_all(void);
1084 +/*==========================*/
1088 +btr_search_s_lock_all(void);
1089 +/*========================*/
1093 +btr_search_s_unlock_all(void);
1094 +/*==========================*/
1097 /** Flag: has the search system been enabled?
1098 Protected by btr_search_latch and btr_search_enabled_mutex. */
1099 extern char btr_search_enabled;
1101 +extern ulint btr_search_index_num;
1103 /** Flag: whether the search system has completed its disabling process,
1104 It is set to TRUE right after buf_pool_drop_hash_index() in
1105 btr_search_disable(), indicating hash index entries are cleaned up.
1108 /** The hash index system */
1109 struct btr_search_sys_struct{
1110 - hash_table_t* hash_index; /*!< the adaptive hash index,
1111 + hash_table_t** hash_index; /*!< the adaptive hash index,
1112 mapping dtuple_fold values
1113 to rec_t pointers on index pages */
1115 @@ -290,10 +329,12 @@
1117 Bear in mind (3) and (4) when using the hash index.
1119 -extern rw_lock_t* btr_search_latch_temp;
1120 +//extern rw_lock_t* btr_search_latch_temp;
1122 +extern rw_lock_t** btr_search_latch_part;
1124 /** The latch protecting the adaptive search system */
1125 -#define btr_search_latch (*btr_search_latch_temp)
1126 +//#define btr_search_latch (*btr_search_latch_temp)
1128 #ifdef UNIV_SEARCH_PERF_STAT
1129 /** Number of successful adaptive hash index lookups */
1130 diff -ruN a/storage/innobase/include/btr0sea.ic b/storage/innobase/include/btr0sea.ic
1131 --- a/storage/innobase/include/btr0sea.ic 2010-11-03 07:01:13.000000000 +0900
1132 +++ b/storage/innobase/include/btr0sea.ic 2010-12-04 16:12:48.709511202 +0900
1136 #ifdef UNIV_SYNC_DEBUG
1137 - ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_SHARED));
1138 - ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_EX));
1139 + ut_ad(!rw_lock_own(btr_search_get_latch(index->id), RW_LOCK_SHARED));
1140 + ut_ad(!rw_lock_own(btr_search_get_latch(index->id), RW_LOCK_EX));
1141 #endif /* UNIV_SYNC_DEBUG */
1143 info = btr_search_get_info(index);
1146 btr_search_info_update_slow(info, cursor);
1149 +/*********************************************************************//**
1150 +New functions to control split btr_search_index */
1153 +btr_search_get_hash_index(
1154 +/*======================*/
1157 + return(btr_search_sys->hash_index[key % btr_search_index_num]);
1162 +btr_search_get_latch(
1163 +/*=================*/
1166 + return(btr_search_latch_part[key % btr_search_index_num]);
1171 +btr_search_x_lock_all(void)
1172 +/*=======================*/
1176 + for (i = 0; i < btr_search_index_num; i++) {
1177 + rw_lock_x_lock(btr_search_latch_part[i]);
1183 +btr_search_x_unlock_all(void)
1184 +/*==========================*/
1188 + for (i = 0; i < btr_search_index_num; i++) {
1189 + rw_lock_x_unlock(btr_search_latch_part[i]);
1195 +btr_search_s_lock_all(void)
1196 +/*=======================*/
1200 + for (i = 0; i < btr_search_index_num; i++) {
1201 + rw_lock_s_lock(btr_search_latch_part[i]);
1207 +btr_search_s_unlock_all(void)
1208 +/*=========================*/
1212 + for (i = 0; i < btr_search_index_num; i++) {
1213 + rw_lock_s_unlock(btr_search_latch_part[i]);
1217 diff -ruN a/storage/innobase/include/buf0buf.h b/storage/innobase/include/buf0buf.h
1218 --- a/storage/innobase/include/buf0buf.h 2010-12-15 19:00:07.713604580 +0900
1219 +++ b/storage/innobase/include/buf0buf.h 2010-12-15 20:58:03.546839883 +0900
1220 @@ -1473,7 +1473,7 @@
1221 pointers in the adaptive hash index
1222 pointing to this frame */
1223 #endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
1224 - unsigned is_hashed:1; /*!< TRUE if hash index has
1225 + volatile unsigned is_hashed:1; /*!< TRUE if hash index has
1226 already been built on this
1227 page; note that it does not
1228 guarantee that the index is
1229 @@ -1487,6 +1487,7 @@
1230 unsigned curr_left_side:1;/*!< TRUE or FALSE in hash indexing */
1231 dict_index_t* index; /*!< Index for which the adaptive
1232 hash index has been created. */
1233 + volatile rw_lock_t* btr_search_latch;
1235 # ifdef UNIV_SYNC_DEBUG
1236 /** @name Debug fields */
1237 diff -ruN a/storage/innobase/include/row0upd.ic b/storage/innobase/include/row0upd.ic
1238 --- a/storage/innobase/include/row0upd.ic 2010-11-03 07:01:13.000000000 +0900
1239 +++ b/storage/innobase/include/row0upd.ic 2010-12-04 16:12:48.710551113 +0900
1241 ut_ad(dict_index_is_clust(index));
1242 ut_ad(rec_offs_validate(rec, index, offsets));
1243 #ifdef UNIV_SYNC_DEBUG
1244 - if (!rw_lock_own(&btr_search_latch, RW_LOCK_EX)) {
1245 + if (!rw_lock_own(btr_search_get_latch(index->id), RW_LOCK_EX)) {
1246 ut_ad(!buf_block_align(rec)->is_hashed);
1248 #endif /* UNIV_SYNC_DEBUG */
1249 diff -ruN a/storage/innobase/page/page0page.c b/storage/innobase/page/page0page.c
1250 --- a/storage/innobase/page/page0page.c 2010-11-03 07:01:13.000000000 +0900
1251 +++ b/storage/innobase/page/page0page.c 2010-12-04 16:12:48.712550963 +0900
1253 const ibool is_hashed = block->is_hashed;
1256 - rw_lock_x_lock(&btr_search_latch);
1257 + rw_lock_x_lock(btr_search_get_latch(block->index->id));
1260 ut_ad(!mtr || mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX));
1263 #ifndef UNIV_HOTBACKUP
1265 - rw_lock_x_unlock(&btr_search_latch);
1266 + rw_lock_x_unlock(btr_search_get_latch(block->index->id));
1268 #endif /* !UNIV_HOTBACKUP */
1270 diff -ruN a/storage/innobase/page/page0zip.c b/storage/innobase/page/page0zip.c
1271 --- a/storage/innobase/page/page0zip.c 2010-12-04 15:57:13.061494433 +0900
1272 +++ b/storage/innobase/page/page0zip.c 2010-12-04 16:12:48.716470334 +0900
1273 @@ -4445,7 +4445,7 @@
1275 #ifndef UNIV_HOTBACKUP
1276 temp_block = buf_block_alloc(buf_pool, 0);
1277 - btr_search_drop_page_hash_index(block);
1278 + btr_search_drop_page_hash_index(block, index);
1279 block->check_index_page_at_flush = TRUE;
1280 #else /* !UNIV_HOTBACKUP */
1281 ut_ad(block == back_block1);
1282 diff -ruN a/storage/innobase/row/row0sel.c b/storage/innobase/row/row0sel.c
1283 --- a/storage/innobase/row/row0sel.c 2010-12-04 16:09:53.204513572 +0900
1284 +++ b/storage/innobase/row/row0sel.c 2010-12-04 16:12:48.722551273 +0900
1285 @@ -1210,7 +1210,7 @@
1286 ut_ad(plan->unique_search);
1287 ut_ad(!plan->must_get_clust);
1288 #ifdef UNIV_SYNC_DEBUG
1289 - ut_ad(rw_lock_own(&btr_search_latch, RW_LOCK_SHARED));
1290 + ut_ad(rw_lock_own(btr_search_get_latch(index->id), RW_LOCK_SHARED));
1291 #endif /* UNIV_SYNC_DEBUG */
1293 row_sel_open_pcur(plan, TRUE, mtr);
1294 @@ -1381,10 +1381,10 @@
1295 && !plan->must_get_clust
1296 && !plan->table->big_rows) {
1297 if (!search_latch_locked) {
1298 - rw_lock_s_lock(&btr_search_latch);
1299 + rw_lock_s_lock(btr_search_get_latch(index->id));
1301 search_latch_locked = TRUE;
1302 - } else if (rw_lock_get_writer(&btr_search_latch) == RW_LOCK_WAIT_EX) {
1303 + } else if (rw_lock_get_writer(btr_search_get_latch(index->id)) == RW_LOCK_WAIT_EX) {
1305 /* There is an x-latch request waiting: release the
1306 s-latch for a moment; as an s-latch here is often
1307 @@ -1393,8 +1393,8 @@
1308 from acquiring an s-latch for a long time, lowering
1309 performance significantly in multiprocessors. */
1311 - rw_lock_s_unlock(&btr_search_latch);
1312 - rw_lock_s_lock(&btr_search_latch);
1313 + rw_lock_s_unlock(btr_search_get_latch(index->id));
1314 + rw_lock_s_lock(btr_search_get_latch(index->id));
1317 found_flag = row_sel_try_search_shortcut(node, plan, &mtr);
1318 @@ -1417,7 +1417,7 @@
1321 if (search_latch_locked) {
1322 - rw_lock_s_unlock(&btr_search_latch);
1323 + rw_lock_s_unlock(btr_search_get_latch(index->id));
1325 search_latch_locked = FALSE;
1327 @@ -1993,7 +1993,7 @@
1330 if (search_latch_locked) {
1331 - rw_lock_s_unlock(&btr_search_latch);
1332 + rw_lock_s_unlock(btr_search_get_latch(index->id));
1334 if (UNIV_LIKELY_NULL(heap)) {
1335 mem_heap_free(heap);
1336 @@ -3356,6 +3356,8 @@
1337 /* if the returned record was locked and we did a semi-consistent
1338 read (fetch the newest committed version), then this is set to
1341 + ulint should_release;
1342 #ifdef UNIV_SEARCH_DEBUG
1344 #endif /* UNIV_SEARCH_DEBUG */
1345 @@ -3441,18 +3443,32 @@
1346 /* PHASE 0: Release a possible s-latch we are holding on the
1347 adaptive hash index latch if there is someone waiting behind */
1349 - if (UNIV_UNLIKELY(rw_lock_get_writer(&btr_search_latch) != RW_LOCK_NOT_LOCKED)
1350 - && trx->has_search_latch) {
1351 + should_release = 0;
1352 + for (i = 0; i < btr_search_index_num; i++) {
1353 + if ((trx->has_search_latch & ((ulint)1 << i))
1354 + && rw_lock_get_writer(btr_search_latch_part[i])
1355 + != RW_LOCK_NOT_LOCKED) {
1356 + should_release |= ((ulint)1 << i);
1360 + if (should_release) {
1362 /* There is an x-latch request on the adaptive hash index:
1363 release the s-latch to reduce starvation and wait for
1364 BTR_SEA_TIMEOUT rounds before trying to keep it again over
1367 - rw_lock_s_unlock(&btr_search_latch);
1368 - trx->has_search_latch = FALSE;
1369 + for (i = 0; i < btr_search_index_num; i++) {
1370 + if (should_release & ((ulint)1 << i)) {
1371 + rw_lock_s_unlock(btr_search_latch_part[i]);
1372 + trx->has_search_latch &= ~((ulint)1 << i);
1376 + if (!trx->has_search_latch) {
1377 trx->search_latch_timeout = BTR_SEA_TIMEOUT;
1381 /* Reset the new record lock info if srv_locks_unsafe_for_binlog
1382 @@ -3603,9 +3619,11 @@
1383 hash index semaphore! */
1385 #ifndef UNIV_SEARCH_DEBUG
1386 - if (!trx->has_search_latch) {
1387 - rw_lock_s_lock(&btr_search_latch);
1388 - trx->has_search_latch = TRUE;
1389 + if (!(trx->has_search_latch
1390 + & ((ulint)1 << (index->id % btr_search_index_num)))) {
1391 + rw_lock_s_lock(btr_search_get_latch(index->id));
1392 + trx->has_search_latch |=
1393 + (ulint)1 << (index->id % btr_search_index_num);
1396 switch (row_sel_try_search_shortcut_for_mysql(
1397 @@ -3666,7 +3684,11 @@
1399 trx->search_latch_timeout--;
1401 - rw_lock_s_unlock(&btr_search_latch);
1402 + for (i = 0; i < btr_search_index_num; i++) {
1403 + if (trx->has_search_latch & ((ulint)1 << i)) {
1404 + rw_lock_s_unlock(btr_search_latch_part[i]);
1407 trx->has_search_latch = FALSE;
1410 @@ -3690,7 +3712,12 @@
1411 /* PHASE 3: Open or restore index cursor position */
1413 if (trx->has_search_latch) {
1414 - rw_lock_s_unlock(&btr_search_latch);
1416 + for (i = 0; i < btr_search_index_num; i++) {
1417 + if (trx->has_search_latch & ((ulint)1 << i)) {
1418 + rw_lock_s_unlock(btr_search_latch_part[i]);
1421 trx->has_search_latch = FALSE;
1424 diff -ruN a/storage/innobase/srv/srv0srv.c b/storage/innobase/srv/srv0srv.c
1425 --- a/storage/innobase/srv/srv0srv.c 2010-12-04 16:12:20.231484679 +0900
1426 +++ b/storage/innobase/srv/srv0srv.c 2010-12-04 16:12:48.726551018 +0900
1427 @@ -2008,7 +2008,9 @@
1428 "-------------------------------------\n", file);
1431 - ha_print_info(file, btr_search_sys->hash_index);
1432 + for (i = 0; i < btr_search_index_num; i++) {
1433 + ha_print_info(file, btr_search_get_hash_index((index_id_t)i));
1437 "%.2f hash searches/s, %.2f non-hash searches/s\n",
1438 @@ -2033,14 +2035,15 @@
1439 ut_total_allocated_memory,
1440 mem_pool_get_reserved(mem_comm_pool));
1441 /* Calcurate reserved memories */
1442 - if (btr_search_sys && btr_search_sys->hash_index->heap) {
1443 - btr_search_sys_subtotal = mem_heap_get_size(btr_search_sys->hash_index->heap);
1444 + if (btr_search_sys && btr_search_sys->hash_index[0]->heap) {
1445 + btr_search_sys_subtotal = mem_heap_get_size(btr_search_sys->hash_index[0]->heap);
1447 btr_search_sys_subtotal = 0;
1448 - for (i=0; i < btr_search_sys->hash_index->n_mutexes; i++) {
1449 - btr_search_sys_subtotal += mem_heap_get_size(btr_search_sys->hash_index->heaps[i]);
1450 + for (i=0; i < btr_search_sys->hash_index[0]->n_mutexes; i++) {
1451 + btr_search_sys_subtotal += mem_heap_get_size(btr_search_sys->hash_index[0]->heaps[i]);
1454 + btr_search_sys_subtotal *= btr_search_index_num;
1456 lock_sys_subtotal = 0;
1458 @@ -2067,10 +2070,10 @@
1459 " Threads %lu \t(%lu + %lu)\n",
1461 (ulong) (btr_search_sys
1462 - ? (btr_search_sys->hash_index->n_cells * sizeof(hash_cell_t)) : 0)
1463 + ? (btr_search_sys->hash_index[0]->n_cells * btr_search_index_num * sizeof(hash_cell_t)) : 0)
1464 + btr_search_sys_subtotal,
1465 (ulong) (btr_search_sys
1466 - ? (btr_search_sys->hash_index->n_cells * sizeof(hash_cell_t)) : 0),
1467 + ? (btr_search_sys->hash_index[0]->n_cells * btr_search_index_num * sizeof(hash_cell_t)) : 0),
1468 (ulong) btr_search_sys_subtotal,
1470 (ulong) (buf_pool_from_array(0)->page_hash->n_cells * sizeof(hash_cell_t)),
1471 diff -ruN a/storage/innobase/sync/sync0sync.c b/storage/innobase/sync/sync0sync.c
1472 --- a/storage/innobase/sync/sync0sync.c 2010-12-03 17:36:44.300986571 +0900
1473 +++ b/storage/innobase/sync/sync0sync.c 2010-12-04 16:12:48.729513564 +0900
1474 @@ -1183,7 +1183,6 @@
1475 case SYNC_ANY_LATCH:
1476 case SYNC_FILE_FORMAT_TAG:
1477 case SYNC_DOUBLEWRITE:
1478 - case SYNC_SEARCH_SYS:
1479 case SYNC_SEARCH_SYS_CONF:
1480 case SYNC_TRX_LOCK_HEAP:
1482 @@ -1204,6 +1203,7 @@
1486 + case SYNC_SEARCH_SYS:
1487 case SYNC_BUF_LRU_LIST:
1488 case SYNC_BUF_FLUSH_LIST:
1489 case SYNC_BUF_PAGE_HASH:
1490 diff -ruN a/storage/innobase/trx/trx0trx.c b/storage/innobase/trx/trx0trx.c
1491 --- a/storage/innobase/trx/trx0trx.c 2010-12-03 17:49:11.623953784 +0900
1492 +++ b/storage/innobase/trx/trx0trx.c 2010-12-04 16:12:48.731513275 +0900
1493 @@ -266,8 +266,14 @@
1494 /*=================================*/
1495 trx_t* trx) /*!< in: transaction */
1499 if (trx->has_search_latch) {
1500 - rw_lock_s_unlock(&btr_search_latch);
1501 + for (i = 0; i < btr_search_index_num; i++) {
1502 + if (trx->has_search_latch & ((ulint)1 << i)) {
1503 + rw_lock_s_unlock(btr_search_latch_part[i]);
1507 trx->has_search_latch = FALSE;