diff --git a/storage/innobase/ibuf/ibuf0ibuf.cc b/storage/innobase/ibuf/ibuf0ibuf.cc index 5e9b72f..8a372f3 100644 --- a/storage/innobase/ibuf/ibuf0ibuf.cc +++ b/storage/innobase/ibuf/ibuf0ibuf.cc @@ -1578,7 +1578,22 @@ ibuf_build_entry_from_ibuf_rec_func( ibuf_rec_get_info(mtr, ibuf_rec, NULL, &comp, &info_len, NULL); - index = ibuf_dummy_index_create(n_fields, comp); + if (*pindex != NULL && + ((*pindex)->n_fields != n_fields + || dict_table_is_comp((*pindex)->table) != comp)) { + /* free the previous cached index and table object */ + ibuf_dummy_index_free(*pindex); + *pindex = NULL; + } + + if (*pindex == NULL) { + index = ibuf_dummy_index_create(n_fields, comp); + } else { + index = *pindex; + index->table->n_def = 0; + index->n_def = 0; + index->n_nullable = 0; + } len -= info_len; types += info_len; @@ -1707,7 +1722,7 @@ ibuf_rec_get_volume_func( } else if (comp) { dtuple_t* entry; ulint volume; - dict_index_t* dummy_index; + dict_index_t* dummy_index = NULL; mem_heap_t* heap = mem_heap_create(500); entry = ibuf_build_entry_from_ibuf_rec(mtr, ibuf_rec, @@ -2826,11 +2841,11 @@ ibuf_get_volume_buffered_hash( } #ifdef UNIV_DEBUG -# define ibuf_get_volume_buffered_count(mtr,rec,hash,size,n_recs) \ - ibuf_get_volume_buffered_count_func(mtr,rec,hash,size,n_recs) +# define ibuf_get_volume_buffered_count(mtr,rec,hash,size,n_recs, dummy_index, dummy_heap) \ + ibuf_get_volume_buffered_count_func(mtr,rec,hash,size,n_recs, dummy_index, dummy_heap) #else /* UNIV_DEBUG */ -# define ibuf_get_volume_buffered_count(mtr,rec,hash,size,n_recs) \ - ibuf_get_volume_buffered_count_func(rec,hash,size,n_recs) +# define ibuf_get_volume_buffered_count(mtr,rec,hash,size,n_recs, dummy_index, dummy_heap) \ + ibuf_get_volume_buffered_count_func(rec,hash,size,n_recs, dummy_index, dummy_heap) #endif /*********************************************************************//** Update the estimate of the number of records on a page, and @@ -2847,8 +2862,10 @@ ibuf_get_volume_buffered_count_func( const rec_t* rec, /*!< in: insert buffer record */ ulint* hash, /*!< in/out: hash array */ ulint size, /*!< in: number of elements in hash array */ - lint* n_recs) /*!< in/out: estimated number of records + lint* n_recs, /*!< in/out: estimated number of records on the page that rec points to */ + dict_index_t** dummy_index, /*!< in/out: dummy index for building tuple */ + mem_heap_t** dummy_heap) /*!< in/out: mem heap for creating tuple */ { ulint len; ibuf_op_t ibuf_op; @@ -2947,16 +2964,15 @@ get_volume_comp: { dtuple_t* entry; ulint volume; - dict_index_t* dummy_index; - mem_heap_t* heap = mem_heap_create(500); + + if (!(*dummy_heap)) { + *dummy_heap = mem_heap_create(1024); + } entry = ibuf_build_entry_from_ibuf_rec( - mtr, rec, heap, &dummy_index); + mtr, rec, *dummy_heap, dummy_index); - volume = rec_get_converted_size(dummy_index, entry, 0); - - ibuf_dummy_index_free(dummy_index); - mem_heap_free(heap); + volume = rec_get_converted_size(*dummy_index, entry, 0); return(volume + page_dir_calc_reserved_space(1)); } @@ -2993,6 +3009,8 @@ ibuf_get_volume_buffered( const page_t* next_page; /* bitmap of buffered recs */ ulint hash_bitmap[128 / sizeof(ulint)]; + mem_heap_t* dummy_heap = NULL; + dict_index_t* dummy_index = NULL; ut_ad((pcur->latch_mode == BTR_MODIFY_PREV) || (pcur->latch_mode == BTR_MODIFY_TREE)); @@ -3026,7 +3044,7 @@ ibuf_get_volume_buffered( volume += ibuf_get_volume_buffered_count( mtr, rec, - hash_bitmap, UT_ARR_SIZE(hash_bitmap), n_recs); + hash_bitmap, UT_ARR_SIZE(hash_bitmap), n_recs, &dummy_index, &dummy_heap); } /* Look at the previous page */ @@ -3067,7 +3085,8 @@ ibuf_get_volume_buffered( do not have the x-latch on it, and cannot acquire one because of the latching order: we have to give up */ - return(UNIV_PAGE_SIZE); + volume = UNIV_PAGE_SIZE; + goto func_exit; } if (page_no != ibuf_rec_get_page_no(mtr, rec) @@ -3078,7 +3097,7 @@ ibuf_get_volume_buffered( volume += ibuf_get_volume_buffered_count( mtr, rec, - hash_bitmap, UT_ARR_SIZE(hash_bitmap), n_recs); + hash_bitmap, UT_ARR_SIZE(hash_bitmap), n_recs, &dummy_index, &dummy_heap); } count_later: @@ -3093,12 +3112,12 @@ count_later: if (page_no != ibuf_rec_get_page_no(mtr, rec) || space != ibuf_rec_get_space(mtr, rec)) { - return(volume); + goto func_exit; } volume += ibuf_get_volume_buffered_count( mtr, rec, - hash_bitmap, UT_ARR_SIZE(hash_bitmap), n_recs); + hash_bitmap, UT_ARR_SIZE(hash_bitmap), n_recs, &dummy_index, &dummy_heap); } /* Look at the next page */ @@ -3107,7 +3126,7 @@ count_later: if (next_page_no == FIL_NULL) { - return(volume); + goto func_exit; } { @@ -3137,19 +3156,31 @@ count_later: /* We give up */ - return(UNIV_PAGE_SIZE); + volume = UNIV_PAGE_SIZE; + goto func_exit; } if (page_no != ibuf_rec_get_page_no(mtr, rec) || space != ibuf_rec_get_space(mtr, rec)) { - return(volume); + goto func_exit; } volume += ibuf_get_volume_buffered_count( mtr, rec, - hash_bitmap, UT_ARR_SIZE(hash_bitmap), n_recs); + hash_bitmap, UT_ARR_SIZE(hash_bitmap), n_recs, &dummy_index, &dummy_heap); + } + +func_exit: + if (dummy_heap) { + mem_heap_free(dummy_heap); } + + if (dummy_index) { + ibuf_dummy_index_free(dummy_index); + } + + return (volume); } /*********************************************************************//** @@ -4638,7 +4669,7 @@ loop: insertion is finished! */ dtuple_t* entry; trx_id_t max_trx_id; - dict_index_t* dummy_index; + dict_index_t* dummy_index = NULL; ibuf_op_t op = ibuf_rec_get_op_type(&mtr, rec); max_trx_id = page_get_max_trx_id(page_align(rec));