diff options
Diffstat (limited to 'storage/innobase/btr/btr0sea.c')
-rw-r--r-- | storage/innobase/btr/btr0sea.c | 171 |
1 files changed, 84 insertions, 87 deletions
diff --git a/storage/innobase/btr/btr0sea.c b/storage/innobase/btr/btr0sea.c index bb089c4c417..2fe3606a390 100644 --- a/storage/innobase/btr/btr0sea.c +++ b/storage/innobase/btr/btr0sea.c @@ -74,7 +74,7 @@ btr_search_build_page_hash_index( ulint n_fields,/* in: hash this many full fields */ ulint n_bytes,/* in: hash this many bytes from the next field */ - ulint side); /* in: hash for searches from this side */ + ibool left_side);/* in: hash for searches from left side? */ /********************************************************************* This function should be called before reserving any btr search mutex, if @@ -157,10 +157,10 @@ btr_search_info_create( info = mem_heap_alloc(heap, sizeof(btr_search_t)); +#ifdef UNIV_DEBUG info->magic_n = BTR_SEARCH_MAGIC_N; +#endif /* UNIV_DEBUG */ - info->last_search = NULL; - info->n_direction = 0; info->root_guess = NULL; info->hash_analysis = 0; @@ -179,7 +179,7 @@ btr_search_info_create( info->n_fields = 1; info->n_bytes = 0; - info->side = BTR_SEARCH_LEFT_SIDE; + info->left_side = TRUE; return(info); } @@ -224,7 +224,7 @@ btr_search_info_update_hash( hash prefix */ if (info->n_fields >= n_unique && cursor->up_match >= n_unique) { - +increment_potential: info->n_hash_potential++; return; @@ -233,8 +233,7 @@ btr_search_info_update_hash( cmp = ut_pair_cmp(info->n_fields, info->n_bytes, cursor->low_match, cursor->low_bytes); - if ((info->side == BTR_SEARCH_LEFT_SIDE && cmp <= 0) - || (info->side == BTR_SEARCH_RIGHT_SIDE && cmp > 0)) { + if (info->left_side ? cmp <= 0 : cmp > 0) { goto set_new_recomm; } @@ -242,16 +241,11 @@ btr_search_info_update_hash( cmp = ut_pair_cmp(info->n_fields, info->n_bytes, cursor->up_match, cursor->up_bytes); - if ((info->side == BTR_SEARCH_LEFT_SIDE && cmp > 0) - || (info->side == BTR_SEARCH_RIGHT_SIDE && cmp <= 0)) { + if (info->left_side ? cmp <= 0 : cmp > 0) { - goto set_new_recomm; + goto increment_potential; } - info->n_hash_potential++; - - return; - set_new_recomm: /* We have to set a new recommendation; skip the hash analysis for a while to avoid unnecessary CPU time usage when there is no @@ -269,7 +263,7 @@ set_new_recomm: info->n_fields = 1; info->n_bytes = 0; - info->side = BTR_SEARCH_LEFT_SIDE; + info->left_side = TRUE; } else if (cmp > 0) { info->n_hash_potential = 1; @@ -288,7 +282,7 @@ set_new_recomm: info->n_bytes = cursor->low_bytes + 1; } - info->side = BTR_SEARCH_LEFT_SIDE; + info->left_side = TRUE; } else { info->n_hash_potential = 1; @@ -306,7 +300,7 @@ set_new_recomm: info->n_bytes = cursor->up_bytes + 1; } - info->side = BTR_SEARCH_RIGHT_SIDE; + info->left_side = FALSE; } } @@ -322,7 +316,8 @@ btr_search_update_block_hash_info( the block is recommended */ btr_search_t* info, /* in: search info */ buf_block_t* block, /* in: buffer block */ - btr_cur_t* cursor) /* in: cursor */ + btr_cur_t* cursor __attribute__((unused))) + /* in: cursor */ { #ifdef UNIV_SYNC_DEBUG ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_SHARED)); @@ -335,18 +330,18 @@ btr_search_update_block_hash_info( info->last_hash_succ = FALSE; ut_a(block->magic_n == BUF_BLOCK_MAGIC_N); - ut_a(info->magic_n == BTR_SEARCH_MAGIC_N); + ut_ad(info->magic_n == BTR_SEARCH_MAGIC_N); if ((block->n_hash_helps > 0) && (info->n_hash_potential > 0) && (block->n_fields == info->n_fields) && (block->n_bytes == info->n_bytes) - && (block->side == info->side)) { + && (block->left_side == info->left_side)) { if ((block->is_hashed) && (block->curr_n_fields == info->n_fields) && (block->curr_n_bytes == info->n_bytes) - && (block->curr_side == info->side)) { + && (block->curr_left_side == info->left_side)) { /* The search would presumably have succeeded using the hash index */ @@ -359,12 +354,14 @@ btr_search_update_block_hash_info( block->n_hash_helps = 1; block->n_fields = info->n_fields; block->n_bytes = info->n_bytes; - block->side = info->side; + block->left_side = info->left_side; } +#ifdef UNIV_DEBUG if (cursor->index->table->does_not_fit_in_memory) { block->n_hash_helps = 0; } +#endif /* UNIV_DEBUG */ if ((block->n_hash_helps > page_get_n_recs(block->frame) / BTR_SEARCH_PAGE_BUILD_LIMIT) @@ -375,7 +372,7 @@ btr_search_update_block_hash_info( > 2 * page_get_n_recs(block->frame)) || (block->n_fields != block->curr_n_fields) || (block->n_bytes != block->curr_n_bytes) - || (block->side != block->curr_side)) { + || (block->left_side != block->curr_left_side)) { /* Build a new hash index on the page */ @@ -404,7 +401,7 @@ btr_search_update_hash_ref( { ulint fold; rec_t* rec; - dulint tree_id; + dulint index_id; ut_ad(cursor->flag == BTR_CUR_HASH_FAIL); #ifdef UNIV_SYNC_DEBUG @@ -419,7 +416,7 @@ btr_search_update_hash_ref( && (info->n_hash_potential > 0) && (block->curr_n_fields == info->n_fields) && (block->curr_n_bytes == info->n_bytes) - && (block->curr_side == info->side)) { + && (block->curr_left_side == info->left_side)) { mem_heap_t* heap = NULL; ulint offsets_[REC_OFFS_NORMAL_SIZE]; *offsets_ = (sizeof offsets_) / sizeof *offsets_; @@ -431,12 +428,12 @@ btr_search_update_hash_ref( return; } - tree_id = ((cursor->index)->tree)->id; + index_id = cursor->index->id; fold = rec_fold(rec, rec_get_offsets(rec, cursor->index, offsets_, ULINT_UNDEFINED, &heap), block->curr_n_fields, - block->curr_n_bytes, tree_id); + block->curr_n_bytes, index_id); if (UNIV_LIKELY_NULL(heap)) { mem_heap_free(heap); } @@ -509,7 +506,7 @@ btr_search_info_update_slow( params = mem_alloc(3 * sizeof(ulint)); params[0] = block->n_fields; params[1] = block->n_bytes; - params[2] = block->side; + params[2] = block->left_side; /* Make sure the compiler cannot deduce the values and do optimizations */ @@ -618,8 +615,8 @@ btr_search_check_guess( prev_rec = page_rec_get_prev(rec); if (page_rec_is_infimum(prev_rec)) { - success = btr_page_get_prev - (buf_frame_align(prev_rec), mtr) == FIL_NULL; + success = btr_page_get_prev( + buf_frame_align(prev_rec), mtr) == FIL_NULL; goto exit_func; } @@ -643,8 +640,9 @@ btr_search_check_guess( next_rec = page_rec_get_next(rec); if (page_rec_is_supremum(next_rec)) { - if (btr_page_get_next - (buf_frame_align(next_rec), mtr) == FIL_NULL) { + if (btr_page_get_next( + buf_frame_align(next_rec), mtr) + == FIL_NULL) { cursor->up_match = 0; success = TRUE; @@ -702,7 +700,7 @@ btr_search_guess_on_hash( page_t* page; ulint fold; ulint tuple_n_fields; - dulint tree_id; + dulint index_id; ibool can_only_compare_to_cursor_rec = TRUE; #ifdef notdefined btr_cur_t cursor2; @@ -736,12 +734,12 @@ btr_search_guess_on_hash( return(FALSE); } - tree_id = (index->tree)->id; + index_id = index->id; #ifdef UNIV_SEARCH_PERF_STAT info->n_hash_succ++; #endif - fold = dtuple_fold(tuple, cursor->n_fields, cursor->n_bytes, tree_id); + fold = dtuple_fold(tuple, cursor->n_fields, cursor->n_bytes, index_id); cursor->fold = fold; cursor->flag = BTR_CUR_HASH; @@ -763,10 +761,11 @@ btr_search_guess_on_hash( if (UNIV_LIKELY(!has_search_latch)) { - if (UNIV_UNLIKELY - (!buf_page_get_known_nowait(latch_mode, page, - BUF_MAKE_YOUNG, - __FILE__, __LINE__, mtr))) { + if (UNIV_UNLIKELY( + !buf_page_get_known_nowait(latch_mode, page, + BUF_MAKE_YOUNG, + __FILE__, __LINE__, + mtr))) { goto failure_unlock; } @@ -801,7 +800,8 @@ btr_search_guess_on_hash( is positioned on. We cannot look at the next of the previous record to determine if our guess for the cursor position is right. */ - if (UNIV_EXPECT(ut_dulint_cmp(tree_id, btr_page_get_index_id(page)), 0) + if (UNIV_EXPECT( + ut_dulint_cmp(index_id, btr_page_get_index_id(page)), 0) || !btr_search_check_guess(cursor, can_only_compare_to_cursor_rec, tuple, mode, mtr)) { @@ -904,7 +904,7 @@ btr_search_drop_page_hash_index( rec_t* rec; ulint fold; ulint prev_fold; - dulint tree_id; + dulint index_id; ulint n_cached; ulint n_recs; ulint* folds; @@ -961,9 +961,9 @@ retry: rec = page_get_infimum_rec(page); rec = page_rec_get_next(rec); - tree_id = btr_page_get_index_id(page); + index_id = btr_page_get_index_id(page); - ut_a(0 == ut_dulint_cmp(tree_id, index->id)); + ut_a(0 == ut_dulint_cmp(index_id, index->id)); prev_fold = 0; @@ -971,12 +971,10 @@ retry: offsets = NULL; while (!page_rec_is_supremum(rec)) { - /* FIXME: in a mixed tree, not all records may have enough - ordering fields: */ offsets = rec_get_offsets(rec, index, offsets, n_fields + (n_bytes > 0), &heap); ut_a(rec_offs_n_fields(offsets) == n_fields + (n_bytes > 0)); - fold = rec_fold(rec, offsets, n_fields, n_bytes, tree_id); + fold = rec_fold(rec, offsets, n_fields, n_bytes, index_id); if (fold == prev_fold && prev_fold != 0) { @@ -1101,7 +1099,7 @@ btr_search_build_page_hash_index( ulint n_fields,/* in: hash this many full fields */ ulint n_bytes,/* in: hash this many bytes from the next field */ - ulint side) /* in: hash for searches from this side */ + ibool left_side)/* in: hash for searches from left side? */ { hash_table_t* table; buf_block_t* block; @@ -1109,7 +1107,7 @@ btr_search_build_page_hash_index( rec_t* next_rec; ulint fold; ulint next_fold; - dulint tree_id; + dulint index_id; ulint n_cached; ulint n_recs; ulint* folds; @@ -1135,7 +1133,7 @@ btr_search_build_page_hash_index( if (block->is_hashed && ((block->curr_n_fields != n_fields) || (block->curr_n_bytes != n_bytes) - || (block->curr_side != side))) { + || (block->curr_left_side != left_side))) { rw_lock_s_unlock(&btr_search_latch); @@ -1172,7 +1170,7 @@ btr_search_build_page_hash_index( n_cached = 0; - tree_id = btr_page_get_index_id(page); + index_id = btr_page_get_index_id(page); rec = page_get_infimum_rec(page); rec = page_rec_get_next(rec); @@ -1188,11 +1186,9 @@ btr_search_build_page_hash_index( } } - /* FIXME: in a mixed tree, all records may not have enough ordering - fields: */ - fold = rec_fold(rec, offsets, n_fields, n_bytes, tree_id); + fold = rec_fold(rec, offsets, n_fields, n_bytes, index_id); - if (side == BTR_SEARCH_LEFT_SIDE) { + if (left_side) { folds[n_cached] = fold; recs[n_cached] = rec; @@ -1204,7 +1200,7 @@ btr_search_build_page_hash_index( if (page_rec_is_supremum(next_rec)) { - if (side == BTR_SEARCH_RIGHT_SIDE) { + if (!left_side) { folds[n_cached] = fold; recs[n_cached] = rec; @@ -1217,12 +1213,12 @@ btr_search_build_page_hash_index( offsets = rec_get_offsets(next_rec, index, offsets, n_fields + (n_bytes > 0), &heap); next_fold = rec_fold(next_rec, offsets, n_fields, - n_bytes, tree_id); + n_bytes, index_id); if (fold != next_fold) { /* Insert an entry into the hash index */ - if (side == BTR_SEARCH_LEFT_SIDE) { + if (left_side) { folds[n_cached] = next_fold; recs[n_cached] = next_rec; @@ -1244,7 +1240,7 @@ btr_search_build_page_hash_index( if (block->is_hashed && ((block->curr_n_fields != n_fields) || (block->curr_n_bytes != n_bytes) - || (block->curr_side != side))) { + || (block->curr_left_side != left_side))) { goto exit_func; } @@ -1253,7 +1249,7 @@ btr_search_build_page_hash_index( block->curr_n_fields = n_fields; block->curr_n_bytes = n_bytes; - block->curr_side = side; + block->curr_left_side = left_side; block->index = index; for (i = 0; i < n_cached; i++) { @@ -1292,7 +1288,7 @@ btr_search_move_or_delete_hash_entries( buf_block_t* new_block; ulint n_fields; ulint n_bytes; - ulint side; + ibool left_side; block = buf_block_align(page); new_block = buf_block_align(new_page); @@ -1320,22 +1316,23 @@ btr_search_move_or_delete_hash_entries( n_fields = block->curr_n_fields; n_bytes = block->curr_n_bytes; - side = block->curr_side; + left_side = block->curr_left_side; new_block->n_fields = block->curr_n_fields; new_block->n_bytes = block->curr_n_bytes; - new_block->side = block->curr_side; + new_block->left_side = left_side; rw_lock_s_unlock(&btr_search_latch); ut_a(n_fields + n_bytes > 0); btr_search_build_page_hash_index(index, new_page, n_fields, - n_bytes, side); + n_bytes, left_side); +#if 1 /* TODO: safe to remove? */ ut_a(n_fields == block->curr_n_fields); ut_a(n_bytes == block->curr_n_bytes); - ut_a(side == block->curr_side); - + ut_a(left_side == block->curr_left_side); +#endif return; } @@ -1356,7 +1353,7 @@ btr_search_update_hash_on_delete( buf_block_t* block; rec_t* rec; ulint fold; - dulint tree_id; + dulint index_id; ibool found; ulint offsets_[REC_OFFS_NORMAL_SIZE]; mem_heap_t* heap = NULL; @@ -1380,10 +1377,10 @@ btr_search_update_hash_on_delete( table = btr_search_sys->hash_index; - tree_id = cursor->index->tree->id; + index_id = cursor->index->id; fold = rec_fold(rec, rec_get_offsets(rec, cursor->index, offsets_, ULINT_UNDEFINED, &heap), - block->curr_n_fields, block->curr_n_bytes, tree_id); + block->curr_n_fields, block->curr_n_bytes, index_id); if (UNIV_LIKELY_NULL(heap)) { mem_heap_free(heap); } @@ -1429,7 +1426,7 @@ btr_search_update_hash_node_on_insert( if ((cursor->flag == BTR_CUR_HASH) && (cursor->n_fields == block->curr_n_fields) && (cursor->n_bytes == block->curr_n_bytes) - && (block->curr_side == BTR_SEARCH_RIGHT_SIDE)) { + && !block->curr_left_side) { table = btr_search_sys->hash_index; @@ -1460,13 +1457,13 @@ btr_search_update_hash_on_insert( rec_t* rec; rec_t* ins_rec; rec_t* next_rec; - dulint tree_id; + dulint index_id; ulint fold; ulint ins_fold; ulint next_fold = 0; /* remove warning (??? bug ???) */ ulint n_fields; ulint n_bytes; - ulint side; + ibool left_side; ibool locked = FALSE; mem_heap_t* heap = NULL; ulint offsets_[REC_OFFS_NORMAL_SIZE]; @@ -1492,32 +1489,32 @@ btr_search_update_hash_on_insert( ut_a(block->index == cursor->index); - tree_id = ((cursor->index)->tree)->id; + index_id = cursor->index->id; n_fields = block->curr_n_fields; n_bytes = block->curr_n_bytes; - side = block->curr_side; + left_side = block->curr_left_side; ins_rec = page_rec_get_next(rec); next_rec = page_rec_get_next(ins_rec); offsets = rec_get_offsets(ins_rec, cursor->index, offsets, ULINT_UNDEFINED, &heap); - ins_fold = rec_fold(ins_rec, offsets, n_fields, n_bytes, tree_id); + ins_fold = rec_fold(ins_rec, offsets, n_fields, n_bytes, index_id); if (!page_rec_is_supremum(next_rec)) { offsets = rec_get_offsets(next_rec, cursor->index, offsets, n_fields + (n_bytes > 0), &heap); next_fold = rec_fold(next_rec, offsets, n_fields, - n_bytes, tree_id); + n_bytes, index_id); } if (!page_rec_is_infimum(rec)) { offsets = rec_get_offsets(rec, cursor->index, offsets, n_fields + (n_bytes > 0), &heap); - fold = rec_fold(rec, offsets, n_fields, n_bytes, tree_id); + fold = rec_fold(rec, offsets, n_fields, n_bytes, index_id); } else { - if (side == BTR_SEARCH_LEFT_SIDE) { + if (left_side) { rw_lock_x_lock(&btr_search_latch); @@ -1538,7 +1535,7 @@ btr_search_update_hash_on_insert( locked = TRUE; } - if (side == BTR_SEARCH_RIGHT_SIDE) { + if (!left_side) { ha_insert_for_fold(table, fold, rec); } else { ha_insert_for_fold(table, ins_fold, ins_rec); @@ -1548,7 +1545,7 @@ btr_search_update_hash_on_insert( check_next_rec: if (page_rec_is_supremum(next_rec)) { - if (side == BTR_SEARCH_RIGHT_SIDE) { + if (!left_side) { if (!locked) { rw_lock_x_lock(&btr_search_latch); @@ -1571,7 +1568,7 @@ check_next_rec: locked = TRUE; } - if (side == BTR_SEARCH_RIGHT_SIDE) { + if (!left_side) { ha_insert_for_fold(table, ins_fold, ins_rec); /* @@ -1659,17 +1656,17 @@ btr_search_validate(void) " node fold %lu, rec fold %lu\n", (ulong) buf_frame_get_page_no(page), node->data, - (ulong) ut_dulint_get_high - (btr_page_get_index_id(page)), - (ulong) ut_dulint_get_low - (btr_page_get_index_id(page)), + (ulong) ut_dulint_get_high( + btr_page_get_index_id(page)), + (ulong) ut_dulint_get_low( + btr_page_get_index_id(page)), (ulong) node->fold, (ulong) rec_fold((rec_t*)(node->data), offsets, block->curr_n_fields, block->curr_n_bytes, - btr_page_get_index_id - (page))); + btr_page_get_index_id( + page))); fputs("InnoDB: Record ", stderr); rec_print_new(stderr, (rec_t*)node->data, @@ -1681,7 +1678,7 @@ btr_search_validate(void) (void*) page, (ulong) block->is_hashed, (ulong) block->curr_n_fields, (ulong) block->curr_n_bytes, - (ulong) block->curr_side); + (ulong) block->curr_left_side); if (n_page_dumps < 20) { buf_page_print(page); |