]> git.pld-linux.org Git - packages/mysql.git/blob - innodb_adaptive_hash_index_partitions.patch
- rel 0.5 (consider this to be test before rel 1); update percona patches; drop obsol...
[packages/mysql.git] / innodb_adaptive_hash_index_partitions.patch
1 # name       : innodb_adaptive_hash_index_num.patch
2 # introduced : XtraDB on 5.5 (-13?)
3 # maintainer : Yasufumi
4 #
5 #!!! notice !!!
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
11 @@ -954,7 +954,7 @@
12         }
13         ut_a(block);
14  
15 -       btr_search_drop_page_hash_index(block);
16 +       btr_search_drop_page_hash_index(block, NULL);
17  
18         header = buf_block_get_frame(block) + PAGE_HEADER + PAGE_BTR_SEG_TOP;
19  #ifdef UNIV_BTR_DEBUG
20 @@ -1023,7 +1023,7 @@
21  
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);
26         }
27  
28         block->check_index_page_at_flush = TRUE;
29 @@ -1188,7 +1188,7 @@
30         ut_a(!page_zip || page_zip_validate(page_zip, page));
31  #endif /* UNIV_ZIP_DEBUG */
32  
33 -       btr_search_drop_page_hash_index(block);
34 +       btr_search_drop_page_hash_index(block, index);
35  
36         /* Recreate the page: note that global data on page (possible
37         segment headers, next page-field, etc.) is preserved intact */
38 @@ -2497,7 +2497,7 @@
39                 mem_heap_free(heap);
40         }
41  
42 -       btr_search_drop_page_hash_index(block);
43 +       btr_search_drop_page_hash_index(block, index);
44  
45         /* Make the father empty */
46         btr_page_empty(father_block, father_page_zip, index, page_level, mtr);
47 @@ -2720,7 +2720,7 @@
48                         goto err_exit;
49                 }
50  
51 -               btr_search_drop_page_hash_index(block);
52 +               btr_search_drop_page_hash_index(block, index);
53  
54                 /* Remove the page from the level list */
55                 btr_level_list_remove(space, zip_size, page, mtr);
56 @@ -2761,7 +2761,7 @@
57                         goto err_exit;
58                 }
59  
60 -               btr_search_drop_page_hash_index(block);
61 +               btr_search_drop_page_hash_index(block, index);
62  
63  #ifdef UNIV_BTR_DEBUG
64                 if (UNIV_LIKELY_NULL(merge_page_zip)) {
65 @@ -2875,7 +2875,7 @@
66                 ut_a(btr_page_get_next(page, mtr) == FIL_NULL);
67  
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);
71  
72                 btr_page_get_father(index, block, mtr, &cursor);
73                 father = btr_cur_get_block(&cursor);
74 @@ -2980,7 +2980,7 @@
75  
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);
80  
81         if (left_page_no == FIL_NULL && !page_is_leaf(page)) {
82  
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
86 @@ -486,7 +486,7 @@
87  #ifdef UNIV_SEARCH_PERF_STAT
88         info->n_searches++;
89  #endif
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
94             && !estimate
95 @@ -522,7 +522,7 @@
96  
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));
101         }
102  
103         /* Store the position of the tree latch we push to mtr so that we
104 @@ -844,7 +844,7 @@
105  
106         if (has_search_latch) {
107  
108 -               rw_lock_s_lock(&btr_search_latch);
109 +               rw_lock_s_lock(btr_search_get_latch(cursor->index->id));
110         }
111  }
112  
113 @@ -2059,7 +2059,7 @@
114                         btr_search_update_hash_on_delete(cursor);
115                 }
116  
117 -               rw_lock_x_lock(&btr_search_latch);
118 +               rw_lock_x_lock(btr_search_get_latch(cursor->index->id));
119         }
120  
121         if (!(flags & BTR_KEEP_SYS_FLAG)) {
122 @@ -2073,7 +2073,7 @@
123         row_upd_rec_in_place(rec, index, offsets, update, page_zip);
124  
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));
128         }
129  
130         if (page_zip && !dict_index_is_clust(index)
131 @@ -2857,7 +2857,7 @@
132         block = btr_cur_get_block(cursor);
133  
134         if (block->is_hashed) {
135 -               rw_lock_x_lock(&btr_search_latch);
136 +               rw_lock_x_lock(btr_search_get_latch(index->id));
137         }
138  
139         page_zip = buf_block_get_page_zip(block);
140 @@ -2872,7 +2872,7 @@
141         }
142  
143         if (block->is_hashed) {
144 -               rw_lock_x_unlock(&btr_search_latch);
145 +               rw_lock_x_unlock(btr_search_get_latch(index->id));
146         }
147  
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));
151  
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));
155         }
156  
157         btr_rec_set_deleted_flag(rec, buf_block_get_page_zip(block), val);
158  
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));
162         }
163  
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
168 @@ -48,6 +48,8 @@
169  UNIV_INTERN char               btr_search_enabled      = TRUE;
170  UNIV_INTERN ibool              btr_search_fully_disabled = FALSE;
171  
172 +UNIV_INTERN ulint              btr_search_index_num    = 1;
173 +
174  /** Mutex protecting btr_search_enabled */
175  static mutex_t                 btr_search_enabled_mutex;
176  
177 @@ -79,7 +81,9 @@
178  
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;
183 +
184 +UNIV_INTERN rw_lock_t**                btr_search_latch_part;
185  
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. */
190  static
191  void
192 -btr_search_check_free_space_in_heap(void)
193 +btr_search_check_free_space_in_heap(
194  /*=====================================*/
195 +       index_id_t      key)
196  {
197         hash_table_t*   table;
198         mem_heap_t*     heap;
199  
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 */
206  
207 -       table = btr_search_sys->hash_index;
208 +       table = btr_search_get_hash_index(key);
209  
210         heap = table->heap;
211  
212 @@ -153,7 +158,7 @@
213         if (heap->free_block == NULL) {
214                 buf_block_t*    block = buf_block_alloc(NULL, 0);
215  
216 -               rw_lock_x_lock(&btr_search_latch);
217 +               rw_lock_x_lock(btr_search_get_latch(key));
218  
219                 if (heap->free_block == NULL) {
220                         heap->free_block = block;
221 @@ -161,7 +166,7 @@
222                         buf_block_free(block);
223                 }
224  
225 -               rw_lock_x_unlock(&btr_search_latch);
226 +               rw_lock_x_unlock(btr_search_get_latch(key));
227         }
228  }
229  
230 @@ -173,19 +178,30 @@
231  /*==================*/
232         ulint   hash_size)      /*!< in: hash index hash table size */
233  {
234 +       ulint i;
235         /* We allocate the search latch from dynamic memory:
236         see above at the global variable definition */
237  
238 -       btr_search_latch_temp = mem_alloc(sizeof(rw_lock_t));
239 +       //btr_search_latch_temp = mem_alloc(sizeof(rw_lock_t));
240  
241 -       rw_lock_create(btr_search_latch_key, &btr_search_latch,
242 -                      SYNC_SEARCH_SYS);
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);
247  
248         btr_search_sys = mem_alloc(sizeof(btr_search_sys_t));
249  
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));
256 +
257 +               rw_lock_create(btr_search_latch_key,
258 +                               btr_search_latch_part[i], SYNC_SEARCH_SYS);
259 +
260 +               btr_search_sys->hash_index[i] = ha_create(hash_size, 0, 0);
261 +       }
262  }
263  
264  /*****************************************************************//**
265 @@ -195,11 +211,20 @@
266  btr_search_sys_free(void)
267  /*=====================*/
268  {
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);
274 +       ulint i;
275 +
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]);
279 +
280 +               rw_lock_free(btr_search_latch_part[i]);
281 +
282 +               mem_free(btr_search_latch_part[i]);
283 +       }
284 +
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;
290  }
291 @@ -212,7 +237,7 @@
292  /*====================*/
293  {
294         mutex_enter(&btr_search_enabled_mutex);
295 -       rw_lock_x_lock(&btr_search_latch);
296 +       btr_search_x_lock_all();
297  
298         /* Disable access to hash index, also tell ha_insert_for_fold()
299         stop adding new nodes to hash index, but still allow updating
300 @@ -230,7 +255,7 @@
301         /* btr_search_enabled_mutex should guarantee this. */
302         ut_ad(!btr_search_enabled);
303  
304 -       rw_lock_x_unlock(&btr_search_latch);
305 +       btr_search_x_unlock_all();
306         mutex_exit(&btr_search_enabled_mutex);
307  }
308  
309 @@ -242,12 +267,12 @@
310  /*====================*/
311  {
312         mutex_enter(&btr_search_enabled_mutex);
313 -       rw_lock_x_lock(&btr_search_latch);
314 +       btr_search_x_lock_all();
315  
316         btr_search_enabled = TRUE;
317         btr_search_fully_disabled = FALSE;
318  
319 -       rw_lock_x_unlock(&btr_search_latch);
320 +       btr_search_x_unlock_all();
321         mutex_exit(&btr_search_enabled_mutex);
322  }
323  
324 @@ -300,20 +325,21 @@
325  ulint
326  btr_search_info_get_ref_count(
327  /*==========================*/
328 -       btr_search_t*   info)   /*!< in: search info. */
329 +       btr_search_t*   info,   /*!< in: search info. */
330 +       index_id_t      key)
331  {
332         ulint ret;
333  
334         ut_ad(info);
335  
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 */
342  
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));
348  
349         return(ret);
350  }
351 @@ -334,8 +360,8 @@
352         int             cmp;
353  
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 */
360  
361         index = cursor->index;
362 @@ -453,8 +479,8 @@
363                                 /*!< in: cursor */
364  {
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 */
373 @@ -538,7 +564,7 @@
374  
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 @@
383                         mem_heap_free(heap);
384                 }
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 */
389  
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,
392                                    block, rec);
393         }
394  }
395 @@ -601,8 +627,8 @@
396         ulint*          params2;
397  
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 */
404  
405         block = btr_cur_get_block(cursor);
406 @@ -623,7 +649,7 @@
407  
408         if (build_index || (cursor->flag == BTR_CUR_HASH_FAIL)) {
409  
410 -               btr_search_check_free_space_in_heap();
411 +               btr_search_check_free_space_in_heap(cursor->index->id);
412         }
413  
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 */
418  
419 -               rw_lock_x_lock(&btr_search_latch);
420 +               rw_lock_x_lock(btr_search_get_latch(cursor->index->id));
421  
422                 btr_search_update_hash_ref(info, block, cursor);
423  
424 -               rw_lock_x_unlock(&btr_search_latch);
425 +               rw_lock_x_unlock(btr_search_get_latch(cursor->index->id));
426         }
427  
428         if (build_index) {
429 @@ -881,17 +907,17 @@
430         cursor->flag = BTR_CUR_HASH;
431  
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));
435  
436                 if (UNIV_UNLIKELY(!btr_search_enabled)) {
437                         goto failure_unlock;
438                 }
439         }
440  
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);
445  
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);
448  
449         if (UNIV_UNLIKELY(!rec)) {
450                 goto failure_unlock;
451 @@ -909,7 +935,7 @@
452                         goto failure_unlock;
453                 }
454  
455 -               rw_lock_s_unlock(&btr_search_latch);
456 +               rw_lock_s_unlock(btr_search_get_latch(index_id));
457  
458                 buf_block_dbg_add_level(block, SYNC_TREE_NODE_FROM_HASH);
459         }
460 @@ -1006,7 +1032,7 @@
461         /*-------------------------------------------*/
462  failure_unlock:
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));
466         }
467  failure:
468         cursor->flag = BTR_CUR_HASH_FAIL;
469 @@ -1029,10 +1055,11 @@
470  void
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)
479  {
480         hash_table_t*           table;
481         ulint                   n_fields;
482 @@ -1051,22 +1078,60 @@
483         ulint*                  offsets;
484  
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));
488 +       if (index_in) {
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));
491 +       }
492  #endif /* UNIV_SYNC_DEBUG */
493  
494  retry:
495 -       rw_lock_s_lock(&btr_search_latch);
496 +       if (index_in) {
497 +               index = index_in;
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;
501 +
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) {
506 +                               goto retry;
507 +                       }
508 +                       return;
509 +               }
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);
513 +                       goto retry;
514 +               }
515 +               if (UNIV_LIKELY(!block->is_hashed)) {
516 +                       rw_lock_s_unlock(btr_search_latch);
517 +                       return;
518 +               }
519 +               index = block->index;
520 +               ut_a(btr_search_latch == btr_search_get_latch(index->id));
521 +       } else {
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]);
528 +                       return;
529 +               }
530 +               index = block->index;
531 +       }
532 +
533         page = block->frame;
534  
535         if (UNIV_LIKELY(!block->is_hashed)) {
536  
537 -               rw_lock_s_unlock(&btr_search_latch);
538 +               rw_lock_s_unlock(btr_search_get_latch(index->id));
539  
540                 return;
541         }
542  
543 -       table = btr_search_sys->hash_index;
544 +       table = btr_search_get_hash_index(index->id);
545  
546  #ifdef UNIV_SYNC_DEBUG
547         ut_ad(rw_lock_own(&(block->lock), RW_LOCK_SHARED)
548 @@ -1076,14 +1141,14 @@
549  
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));
555  
556         /* NOTE: The fields of block must not be accessed after
557         releasing btr_search_latch, as the index page might only
558         be s-latched! */
559  
560 -       rw_lock_s_unlock(&btr_search_latch);
561 +       rw_lock_s_unlock(btr_search_get_latch(index->id));
562  
563         ut_a(n_fields + n_bytes > 0);
564  
565 @@ -1133,7 +1198,7 @@
566                 mem_heap_free(heap);
567         }
568  
569 -       rw_lock_x_lock(&btr_search_latch);
570 +       rw_lock_x_lock(btr_search_get_latch(index->id));
571  
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 */
577  
578 -               rw_lock_x_unlock(&btr_search_latch);
579 +               rw_lock_x_unlock(btr_search_get_latch(index->id));
580  
581                 mem_free(folds);
582                 goto retry;
583 @@ -1165,6 +1230,7 @@
584  
585         block->is_hashed = FALSE;
586         block->index = NULL;
587 +       block->btr_search_latch = NULL;
588         
589  cleanup:
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));
597  
598                 btr_search_validate();
599         } else {
600 -               rw_lock_x_unlock(&btr_search_latch);
601 +               rw_lock_x_unlock(btr_search_get_latch(index->id));
602         }
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 */
607  
608         mem_free(folds);
609 @@ -1215,10 +1281,10 @@
610         mem_heap_t*     heap    = NULL;
611         ulint*          offsets;
612  
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();
616  
617 -       table = btr_search_sys->hash_index;
618 +       table = btr_search_get_hash_index(index->id);
619  
620         for (j = 0; j < srv_buf_pool_instances; j++) {
621                 buf_pool_t*     buf_pool;
622 @@ -1291,6 +1357,7 @@
623  
624                                 block->is_hashed = FALSE;
625                                 block->index = NULL;
626 +                               block->btr_search_latch = NULL;
627         
628  #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
629                                 if (UNIV_UNLIKELY(block->n_pointers)) {
630 @@ -1313,7 +1380,7 @@
631         }
632  
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));
636  
637         if (UNIV_LIKELY_NULL(heap)) {
638                 mem_heap_free(heap);
639 @@ -1360,7 +1427,7 @@
640  
641                 buf_block_dbg_add_level(block, SYNC_TREE_NODE_FROM_HASH);
642  
643 -               btr_search_drop_page_hash_index(block);
644 +               btr_search_drop_page_hash_index(block, NULL);
645         }
646  
647         mtr_commit(&mtr);
648 @@ -1402,26 +1469,26 @@
649         ut_ad(index);
650         ut_a(!dict_index_is_ibuf(index));
651  
652 -       table = btr_search_sys->hash_index;
653 +       table = btr_search_get_hash_index(index->id);
654         page = buf_block_get_frame(block);
655  
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 */
662  
663 -       rw_lock_s_lock(&btr_search_latch);
664 +       rw_lock_s_lock(btr_search_get_latch(index->id));
665  
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))) {
669  
670 -               rw_lock_s_unlock(&btr_search_latch);
671 +               rw_lock_s_unlock(btr_search_get_latch(index->id));
672  
673 -               btr_search_drop_page_hash_index(block);
674 +               btr_search_drop_page_hash_index(block, index);
675         } else {
676 -               rw_lock_s_unlock(&btr_search_latch);
677 +               rw_lock_s_unlock(btr_search_get_latch(index->id));
678         }
679  
680         n_recs = page_get_n_recs(page);
681 @@ -1515,9 +1582,9 @@
682                 fold = next_fold;
683         }
684  
685 -       btr_search_check_free_space_in_heap();
686 +       btr_search_check_free_space_in_heap(index->id);
687  
688 -       rw_lock_x_lock(&btr_search_latch);
689 +       rw_lock_x_lock(btr_search_get_latch(index->id));
690  
691         if (UNIV_UNLIKELY(btr_search_fully_disabled)) {
692                 goto exit_func;
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);
698  
699         for (i = 0; i < n_cached; i++) {
700  
701 @@ -1552,7 +1620,7 @@
702         }
703  
704  exit_func:
705 -       rw_lock_x_unlock(&btr_search_latch);
706 +       rw_lock_x_unlock(btr_search_get_latch(index->id));
707  
708         mem_free(folds);
709         mem_free(recs);
710 @@ -1591,13 +1659,13 @@
711         ut_a(!(new_block->is_hashed || block->is_hashed)
712              || !dict_index_is_ibuf(index));
713  
714 -       rw_lock_s_lock(&btr_search_latch);
715 +       rw_lock_s_lock(btr_search_get_latch(index->id));
716  
717         if (new_block->is_hashed) {
718  
719 -               rw_lock_s_unlock(&btr_search_latch);
720 +               rw_lock_s_unlock(btr_search_get_latch(index->id));
721  
722 -               btr_search_drop_page_hash_index(block);
723 +               btr_search_drop_page_hash_index(block, index);
724  
725                 return;
726         }
727 @@ -1612,7 +1680,7 @@
728                 new_block->n_bytes = block->curr_n_bytes;
729                 new_block->left_side = left_side;
730  
731 -               rw_lock_s_unlock(&btr_search_latch);
732 +               rw_lock_s_unlock(btr_search_get_latch(index->id));
733  
734                 ut_a(n_fields + n_bytes > 0);
735  
736 @@ -1624,7 +1692,7 @@
737                 return;
738         }
739  
740 -       rw_lock_s_unlock(&btr_search_latch);
741 +       rw_lock_s_unlock(btr_search_get_latch(index->id));
742  }
743  
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));
748  
749 -       table = btr_search_sys->hash_index;
750 +       table = btr_search_get_hash_index(cursor->index->id);
751  
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)) {
756                 mem_heap_free(heap);
757         }
758 -       rw_lock_x_lock(&btr_search_latch);
759 +       rw_lock_x_lock(btr_search_get_latch(cursor->index->id));
760  
761         ha_search_and_delete_if_found(table, fold, rec);
762  
763 -       rw_lock_x_unlock(&btr_search_latch);
764 +       rw_lock_x_unlock(btr_search_get_latch(cursor->index->id));
765  }
766  
767  /********************************************************************//**
768 @@ -1710,21 +1778,21 @@
769         ut_a(block->index == cursor->index);
770         ut_a(!dict_index_is_ibuf(cursor->index));
771  
772 -       rw_lock_x_lock(&btr_search_latch);
773 +       rw_lock_x_lock(btr_search_get_latch(cursor->index->id));
774  
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) {
779  
780 -               table = btr_search_sys->hash_index;
781 +               table = btr_search_get_hash_index(cursor->index->id);
782  
783                 ha_search_and_update_if_found(table, cursor->fold, rec,
784                                               block, page_rec_get_next(rec));
785  
786 -               rw_lock_x_unlock(&btr_search_latch);
787 +               rw_lock_x_unlock(btr_search_get_latch(cursor->index->id));
788         } else {
789 -               rw_lock_x_unlock(&btr_search_latch);
790 +               rw_lock_x_unlock(btr_search_get_latch(cursor->index->id));
791  
792                 btr_search_update_hash_on_insert(cursor);
793         }
794 @@ -1759,9 +1827,9 @@
795         ulint*          offsets         = offsets_;
796         rec_offs_init(offsets_);
797  
798 -       table = btr_search_sys->hash_index;
799 +       table = btr_search_get_hash_index(cursor->index->id);
800  
801 -       btr_search_check_free_space_in_heap();
802 +       btr_search_check_free_space_in_heap(cursor->index->id);
803  
804         rec = btr_cur_get_rec(cursor);
805  
806 @@ -1806,7 +1874,7 @@
807         } else {
808                 if (left_side) {
809  
810 -                       rw_lock_x_lock(&btr_search_latch);
811 +                       rw_lock_x_lock(btr_search_get_latch(index_id));
812  
813                         locked = TRUE;
814  
815 @@ -1820,7 +1888,7 @@
816  
817                 if (!locked) {
818  
819 -                       rw_lock_x_lock(&btr_search_latch);
820 +                       rw_lock_x_lock(btr_search_get_latch(index_id));
821  
822                         locked = TRUE;
823                 }
824 @@ -1838,7 +1906,7 @@
825                 if (!left_side) {
826  
827                         if (!locked) {
828 -                               rw_lock_x_lock(&btr_search_latch);
829 +                               rw_lock_x_lock(btr_search_get_latch(index_id));
830  
831                                 locked = TRUE;
832                         }
833 @@ -1853,7 +1921,7 @@
834  
835                 if (!locked) {
836  
837 -                       rw_lock_x_lock(&btr_search_latch);
838 +                       rw_lock_x_lock(btr_search_get_latch(index_id));
839  
840                         locked = TRUE;
841                 }
842 @@ -1876,7 +1944,7 @@
843                 mem_heap_free(heap);
844         }
845         if (locked) {
846 -               rw_lock_x_unlock(&btr_search_latch);
847 +               rw_lock_x_unlock(btr_search_get_latch(index_id));
848         }
849  }
850  
851 @@ -1892,7 +1960,7 @@
852         ha_node_t*      node;
853         ulint           n_page_dumps    = 0;
854         ibool           ok              = TRUE;
855 -       ulint           i;
856 +       ulint           i,j;
857         ulint           cell_count;
858         mem_heap_t*     heap            = NULL;
859         ulint           offsets_[REC_OFFS_NORMAL_SIZE];
860 @@ -1904,23 +1972,25 @@
861  
862         rec_offs_init(offsets_);
863  
864 -       rw_lock_x_lock(&btr_search_latch);
865 +       btr_search_x_lock_all();
866         buf_pool_page_hash_x_lock_all();
867  
868 -       cell_count = hash_get_n_cells(btr_search_sys->hash_index);
869 +       for (j = 0; j < btr_search_index_num; j++) {
870 +
871 +       cell_count = hash_get_n_cells(btr_search_sys->hash_index[j]);
872  
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();
880                         os_thread_yield();
881 -                       rw_lock_x_lock(&btr_search_latch);
882 +                       btr_search_x_lock_all();
883                         buf_pool_page_hash_x_lock_all();
884                 }
885  
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;
888  
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. */
893                 if (i != 0) {
894                         buf_pool_page_hash_x_unlock_all();
895 -                       rw_lock_x_unlock(&btr_search_latch);
896 +                       btr_search_x_unlock_all();
897                         os_thread_yield();
898 -                       rw_lock_x_lock(&btr_search_latch);
899 +                       btr_search_x_lock_all();
900                         buf_pool_page_hash_x_lock_all();
901                 }
902  
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)) {
905                         ok = FALSE;
906                 }
907         }
908  
909 +       } /*for (j = 0; j < btr_search_index_num; j++)*/
910 +
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)) {
915                 mem_heap_free(heap);
916         }
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
920 @@ -949,6 +949,7 @@
921  
922         block->check_index_page_at_flush = FALSE;
923         block->index = NULL;
924 +       block->btr_search_latch = NULL;
925  
926         block->is_hashed = FALSE;
927  
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. */
940                         
941 -                       btr_search_drop_page_hash_index(block);
942 +                       btr_search_drop_page_hash_index(block, NULL);
943                         
944                         rw_lock_x_unlock(&block->lock);
945                         
946 -                       rw_lock_x_lock(&btr_search_latch);
947 +                       btr_search_x_lock_all();
948                         
949                         ut_ad(!btr_search_enabled);
950                 }
951 @@ -1531,7 +1532,11 @@
952         ibool           released_search_latch;
953  
954  #ifdef UNIV_SYNC_DEBUG
955 -       ut_ad(rw_lock_own(&btr_search_latch, RW_LOCK_EX));
956 +       ulint   j;
957 +
958 +       for (j = 0; j < btr_search_index_num; j++) {
959 +               ut_ad(rw_lock_own(btr_search_latch_part[j], RW_LOCK_EX));
960 +       }
961  #endif /* UNIV_SYNC_DEBUG */
962         ut_ad(!btr_search_enabled);
963  
964 @@ -2635,6 +2640,7 @@
965  {
966         block->check_index_page_at_flush = FALSE;
967         block->index            = NULL;
968 +       block->btr_search_latch = NULL;
969  
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 @@
976  
977                 UNIV_MEM_VALID(((buf_block_t*) bpage)->frame,
978                                UNIV_PAGE_SIZE);
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,
982                                  UNIV_PAGE_SIZE);
983  
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 @@
988         zero. */
989  
990         for (;;) {
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) {
994                         break;
995                 }
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
999 @@ -102,7 +102,8 @@
1000         ut_ad(table);
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 */
1007  
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);
1015  
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);
1020 +
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
1035 @@ -85,7 +85,8 @@
1036  ulint
1037  btr_search_info_get_ref_count(
1038  /*==========================*/
1039 -       btr_search_t*   info);  /*!< in: search info. */
1040 +       btr_search_t*   info,   /*!< in: search info. */
1041 +       index_id_t      key);
1042  /*********************************************************************//**
1043  Updates the search info. */
1044  UNIV_INLINE
1045 @@ -136,10 +137,11 @@
1046  void
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 */
1057  UNIV_INTERN
1058 @@ -199,10 +201,47 @@
1059  # define btr_search_validate() TRUE
1060  #endif /* defined UNIV_AHI_DEBUG || defined UNIV_DEBUG */
1061  
1062 +/********************************************************************//**
1063 +New functions to control split btr_search_index */
1064 +UNIV_INLINE
1065 +hash_table_t*
1066 +btr_search_get_hash_index(
1067 +/*======================*/
1068 +       index_id_t      key);
1069 +
1070 +UNIV_INLINE
1071 +rw_lock_t*
1072 +btr_search_get_latch(
1073 +/*=================*/
1074 +       index_id_t      key);
1075 +
1076 +UNIV_INLINE
1077 +void
1078 +btr_search_x_lock_all(void);
1079 +/*========================*/
1080 +
1081 +UNIV_INLINE
1082 +void
1083 +btr_search_x_unlock_all(void);
1084 +/*==========================*/
1085 +
1086 +UNIV_INLINE
1087 +void
1088 +btr_search_s_lock_all(void);
1089 +/*========================*/
1090 +
1091 +UNIV_INLINE
1092 +void
1093 +btr_search_s_unlock_all(void);
1094 +/*==========================*/
1095 +
1096 +
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;
1100  
1101 +extern ulint   btr_search_index_num;
1102 +
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.
1106 @@ -269,7 +308,7 @@
1107  
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 */
1114  };
1115 @@ -290,10 +329,12 @@
1116  
1117  Bear in mind (3) and (4) when using the hash index.
1118  */
1119 -extern rw_lock_t*      btr_search_latch_temp;
1120 +//extern rw_lock_t*    btr_search_latch_temp;
1121 +
1122 +extern rw_lock_t**     btr_search_latch_part;
1123  
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)
1127  
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
1133 @@ -62,8 +62,8 @@
1134         btr_search_t*   info;
1135  
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 */
1142  
1143         info = btr_search_get_info(index);
1144 @@ -82,3 +82,72 @@
1145  
1146         btr_search_info_update_slow(info, cursor);
1147  }
1148 +
1149 +/*********************************************************************//**
1150 +New functions to control split btr_search_index */
1151 +UNIV_INLINE
1152 +hash_table_t*
1153 +btr_search_get_hash_index(
1154 +/*======================*/
1155 +       index_id_t      key)
1156 +{
1157 +       return(btr_search_sys->hash_index[key % btr_search_index_num]);
1158 +}
1159 +
1160 +UNIV_INLINE
1161 +rw_lock_t*
1162 +btr_search_get_latch(
1163 +/*=================*/
1164 +       index_id_t      key)
1165 +{
1166 +       return(btr_search_latch_part[key % btr_search_index_num]);
1167 +}
1168 +
1169 +UNIV_INLINE
1170 +void
1171 +btr_search_x_lock_all(void)
1172 +/*=======================*/
1173 +{
1174 +       ulint   i;
1175 +
1176 +       for (i = 0; i < btr_search_index_num; i++) {
1177 +               rw_lock_x_lock(btr_search_latch_part[i]);
1178 +       }
1179 +}
1180 +
1181 +UNIV_INLINE
1182 +void
1183 +btr_search_x_unlock_all(void)
1184 +/*==========================*/
1185 +{
1186 +       ulint   i;
1187 +
1188 +       for (i = 0; i < btr_search_index_num; i++) {
1189 +               rw_lock_x_unlock(btr_search_latch_part[i]);
1190 +       }
1191 +}
1192 +
1193 +UNIV_INLINE
1194 +void
1195 +btr_search_s_lock_all(void)
1196 +/*=======================*/
1197 +{
1198 +       ulint   i;
1199 +
1200 +       for (i = 0; i < btr_search_index_num; i++) {
1201 +               rw_lock_s_lock(btr_search_latch_part[i]);
1202 +       }
1203 +}
1204 +
1205 +UNIV_INLINE
1206 +void
1207 +btr_search_s_unlock_all(void)
1208 +/*=========================*/
1209 +{
1210 +       ulint   i;
1211 +
1212 +       for (i = 0; i < btr_search_index_num; i++) {
1213 +               rw_lock_s_unlock(btr_search_latch_part[i]);
1214 +       }
1215 +}
1216 +
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;
1234         /* @} */
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
1240 @@ -158,7 +158,7 @@
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);
1247         }
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
1252 @@ -218,7 +218,7 @@
1253         const ibool     is_hashed       = block->is_hashed;
1254  
1255         if (is_hashed) {
1256 -               rw_lock_x_lock(&btr_search_latch);
1257 +               rw_lock_x_lock(btr_search_get_latch(block->index->id));
1258         }
1259  
1260         ut_ad(!mtr || mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX));
1261 @@ -244,7 +244,7 @@
1262  
1263  #ifndef UNIV_HOTBACKUP
1264         if (is_hashed) {
1265 -               rw_lock_x_unlock(&btr_search_latch);
1266 +               rw_lock_x_unlock(btr_search_get_latch(block->index->id));
1267         }
1268  #endif /* !UNIV_HOTBACKUP */
1269  }
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 @@
1274  
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 */
1292  
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));
1300  
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) {
1304  
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. */
1310  
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));
1315                 }
1316  
1317                 found_flag = row_sel_try_search_shortcut(node, plan, &mtr);
1318 @@ -1417,7 +1417,7 @@
1319         }
1320  
1321         if (search_latch_locked) {
1322 -               rw_lock_s_unlock(&btr_search_latch);
1323 +               rw_lock_s_unlock(btr_search_get_latch(index->id));
1324  
1325                 search_latch_locked = FALSE;
1326         }
1327 @@ -1993,7 +1993,7 @@
1328  
1329  func_exit:
1330         if (search_latch_locked) {
1331 -               rw_lock_s_unlock(&btr_search_latch);
1332 +               rw_lock_s_unlock(btr_search_get_latch(index->id));
1333         }
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
1339         TRUE */
1340 +       ulint           i;
1341 +       ulint           should_release;
1342  #ifdef UNIV_SEARCH_DEBUG
1343         ulint           cnt                             = 0;
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 */
1348  
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);
1357 +               }
1358 +       }
1359 +
1360 +       if (should_release) {
1361  
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
1365                 calls from MySQL */
1366  
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);
1373 +                       }
1374 +               }
1375  
1376 +               if (!trx->has_search_latch) {
1377                 trx->search_latch_timeout = BTR_SEA_TIMEOUT;
1378 +               }
1379         }
1380  
1381         /* Reset the new record lock info if srv_locks_unsafe_for_binlog
1382 @@ -3603,9 +3619,11 @@
1383                         hash index semaphore! */
1384  
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);
1394                         }
1395  #endif
1396                         switch (row_sel_try_search_shortcut_for_mysql(
1397 @@ -3666,7 +3684,11 @@
1398  
1399                                         trx->search_latch_timeout--;
1400  
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]);
1405 +                                               }
1406 +                                       }
1407                                         trx->has_search_latch = FALSE;
1408                                 }
1409  
1410 @@ -3690,7 +3712,12 @@
1411         /* PHASE 3: Open or restore index cursor position */
1412  
1413         if (trx->has_search_latch) {
1414 -               rw_lock_s_unlock(&btr_search_latch);
1415 +
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]);
1419 +                       }
1420 +               }
1421                 trx->has_search_latch = FALSE;
1422         }
1423  
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);
1429         ibuf_print(file);
1430  
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));
1434 +       }
1435  
1436         fprintf(file,
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);
1446         } else {
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]);
1452                 }
1453         }
1454 +       btr_search_sys_subtotal *= btr_search_index_num;
1455  
1456         lock_sys_subtotal = 0;
1457         if (trx_sys) {
1458 @@ -2067,10 +2070,10 @@
1459                         "    Threads             %lu \t(%lu + %lu)\n",
1460  
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,
1469  
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:
1481         case SYNC_KERNEL:
1482 @@ -1204,6 +1203,7 @@
1483                         ut_error;
1484                 }
1485                 break;
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 */
1496  {
1497 +       ulint   i;
1498 +
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]);
1504 +                       }
1505 +               }
1506  
1507                 trx->has_search_latch = FALSE;
1508         }
This page took 0.256184 seconds and 4 git commands to generate.