diff options
Diffstat (limited to 'storage/innobase/include/btr0pcur.ic')
-rw-r--r-- | storage/innobase/include/btr0pcur.ic | 151 |
1 files changed, 108 insertions, 43 deletions
diff --git a/storage/innobase/include/btr0pcur.ic b/storage/innobase/include/btr0pcur.ic index 1cd13824542..6cd968b4682 100644 --- a/storage/innobase/include/btr0pcur.ic +++ b/storage/innobase/include/btr0pcur.ic @@ -1,6 +1,7 @@ /***************************************************************************** -Copyright (c) 1996, 2013, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1996, 2015, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2015, 2016, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -26,7 +27,7 @@ Created 2/23/1996 Heikki Tuuri /*********************************************************//** Gets the rel_pos field for a cursor whose position has been stored. -@return BTR_PCUR_ON, ... */ +@return BTR_PCUR_ON, ... */ UNIV_INLINE ulint btr_pcur_get_rel_pos( @@ -35,7 +36,7 @@ btr_pcur_get_rel_pos( { ut_ad(cursor); ut_ad(cursor->old_rec); - ut_ad(cursor->old_stored == BTR_PCUR_OLD_STORED); + ut_ad(cursor->old_stored); ut_ad(cursor->pos_state == BTR_PCUR_WAS_POSITIONED || cursor->pos_state == BTR_PCUR_IS_POSITIONED); @@ -45,7 +46,7 @@ btr_pcur_get_rel_pos( #ifdef UNIV_DEBUG /*********************************************************//** Returns the btr cursor component of a persistent cursor. -@return pointer to btr cursor component */ +@return pointer to btr cursor component */ UNIV_INLINE btr_cur_t* btr_pcur_get_btr_cur( @@ -58,7 +59,7 @@ btr_pcur_get_btr_cur( /*********************************************************//** Returns the page cursor component of a persistent cursor. -@return pointer to page cursor component */ +@return pointer to page cursor component */ UNIV_INLINE page_cur_t* btr_pcur_get_page_cur( @@ -70,7 +71,7 @@ btr_pcur_get_page_cur( /*********************************************************//** Returns the page of a persistent cursor. -@return pointer to the page */ +@return pointer to the page */ UNIV_INLINE page_t* btr_pcur_get_page( @@ -84,7 +85,7 @@ btr_pcur_get_page( /*********************************************************//** Returns the buffer block of a persistent cursor. -@return pointer to the block */ +@return pointer to the block */ UNIV_INLINE buf_block_t* btr_pcur_get_block( @@ -98,7 +99,7 @@ btr_pcur_get_block( /*********************************************************//** Returns the record of a persistent cursor. -@return pointer to the record */ +@return pointer to the record */ UNIV_INLINE rec_t* btr_pcur_get_rec( @@ -260,7 +261,7 @@ btr_pcur_move_to_next_on_page( page_cur_move_to_next(btr_pcur_get_page_cur(cursor)); - cursor->old_stored = BTR_PCUR_OLD_NOT_STORED; + cursor->old_stored = false; } /*********************************************************//** @@ -276,7 +277,7 @@ btr_pcur_move_to_prev_on_page( page_cur_move_to_prev(btr_pcur_get_page_cur(cursor)); - cursor->old_stored = BTR_PCUR_OLD_NOT_STORED; + cursor->old_stored = false; } /*********************************************************//** @@ -294,13 +295,13 @@ btr_pcur_move_to_last_on_page( page_cur_set_after_last(btr_pcur_get_block(cursor), btr_pcur_get_page_cur(cursor)); - cursor->old_stored = BTR_PCUR_OLD_NOT_STORED; + cursor->old_stored = false; } /*********************************************************//** Moves the persistent cursor to the next user record in the tree. If no user records are left, the cursor ends up 'after last in tree'. -@return TRUE if the cursor moved forward, ending on a user record */ +@return TRUE if the cursor moved forward, ending on a user record */ UNIV_INLINE ibool btr_pcur_move_to_next_user_rec( @@ -311,7 +312,7 @@ btr_pcur_move_to_next_user_rec( { ut_ad(cursor->pos_state == BTR_PCUR_IS_POSITIONED); ut_ad(cursor->latch_mode != BTR_NO_LATCHES); - cursor->old_stored = BTR_PCUR_OLD_NOT_STORED; + cursor->old_stored = false; loop: if (btr_pcur_is_after_last_on_page(cursor)) { @@ -336,7 +337,7 @@ loop: /*********************************************************//** Moves the persistent cursor to the next record in the tree. If no records are left, the cursor stays 'after last in tree'. -@return TRUE if the cursor was not after last in tree */ +@return TRUE if the cursor was not after last in tree */ UNIV_INLINE ibool btr_pcur_move_to_next( @@ -348,7 +349,7 @@ btr_pcur_move_to_next( ut_ad(cursor->pos_state == BTR_PCUR_IS_POSITIONED); ut_ad(cursor->latch_mode != BTR_NO_LATCHES); - cursor->old_stored = BTR_PCUR_OLD_NOT_STORED; + cursor->old_stored = false; if (btr_pcur_is_after_last_on_page(cursor)) { @@ -396,9 +397,21 @@ btr_pcur_init( /*==========*/ btr_pcur_t* pcur) /*!< in: persistent cursor */ { - pcur->old_stored = BTR_PCUR_OLD_NOT_STORED; + pcur->old_stored = false; pcur->old_rec_buf = NULL; pcur->old_rec = NULL; + + pcur->btr_cur.rtr_info = NULL; +} + +/** Free old_rec_buf. +@param[in] pcur Persistent cursor holding old_rec to be freed. */ +UNIV_INLINE +void +btr_pcur_free( + btr_pcur_t* pcur) +{ + ut_free(pcur->old_rec_buf); } /**************************************************************//** @@ -411,7 +424,7 @@ btr_pcur_open_low( dict_index_t* index, /*!< in: index */ ulint level, /*!< in: level in the btree */ const dtuple_t* tuple, /*!< in: tuple on which search done */ - ulint mode, /*!< in: PAGE_CUR_L, ...; + page_cur_mode_t mode, /*!< in: PAGE_CUR_L, ...; NOTE that if the search is made using a unique prefix of a record, mode should be PAGE_CUR_LE, not PAGE_CUR_GE, as the latter @@ -424,6 +437,7 @@ btr_pcur_open_low( mtr_t* mtr) /*!< in: mtr */ { btr_cur_t* btr_cursor; + dberr_t err = DB_SUCCESS; /* Initialize the cursor */ @@ -436,8 +450,33 @@ btr_pcur_open_low( btr_cursor = btr_pcur_get_btr_cur(cursor); - btr_cur_search_to_nth_level(index, level, tuple, mode, latch_mode, - btr_cursor, 0, file, line, mtr); + ut_ad(!dict_index_is_spatial(index)); + + if (dict_table_is_intrinsic(index->table)) { + ut_ad((latch_mode & BTR_MODIFY_LEAF) + || (latch_mode & BTR_SEARCH_LEAF) + || (latch_mode & BTR_MODIFY_TREE)); + err = btr_cur_search_to_nth_level_with_no_latch( + index, level, tuple, mode, btr_cursor, + file, line, mtr, + (((latch_mode & BTR_MODIFY_LEAF) + || (latch_mode & BTR_MODIFY_TREE)) ? true : false)); + } else { + err = btr_cur_search_to_nth_level( + index, level, tuple, mode, latch_mode, + btr_cursor, 0, file, line, mtr); + } + + if (err != DB_SUCCESS) { + ib::warn() << " Error code: " << err + << " btr_pcur_open_low " + << " level: " << level + << " called from file: " + << file << " line: " << line + << " table: " << index->table->name + << " index: " << index->name; + } + cursor->pos_state = BTR_PCUR_IS_POSITIONED; cursor->trx_if_known = NULL; @@ -452,7 +491,7 @@ btr_pcur_open_with_no_init_func( /*============================*/ dict_index_t* index, /*!< in: index */ const dtuple_t* tuple, /*!< in: tuple on which search done */ - ulint mode, /*!< in: PAGE_CUR_L, ...; + page_cur_mode_t mode, /*!< in: PAGE_CUR_L, ...; NOTE that if the search is made using a unique prefix of a record, mode should be PAGE_CUR_LE, not PAGE_CUR_GE, as the latter @@ -464,8 +503,9 @@ btr_pcur_open_with_no_init_func( page, but assume that the caller uses his btr search latch to protect the record! */ btr_pcur_t* cursor, /*!< in: memory buffer for persistent cursor */ - ulint has_search_latch,/*!< in: latch mode the caller - currently has on btr_search_latch: + ulint has_search_latch, + /*!< in: latch mode the caller + currently has on search system: RW_S_LATCH, or 0 */ const char* file, /*!< in: file name */ ulint line, /*!< in: line where called */ @@ -474,19 +514,29 @@ btr_pcur_open_with_no_init_func( btr_cur_t* btr_cursor; dberr_t err = DB_SUCCESS; - cursor->latch_mode = latch_mode; + cursor->latch_mode = BTR_LATCH_MODE_WITHOUT_INTENTION(latch_mode); cursor->search_mode = mode; /* Search with the tree cursor */ btr_cursor = btr_pcur_get_btr_cur(cursor); - err = btr_cur_search_to_nth_level(index, 0, tuple, mode, latch_mode, - btr_cursor, has_search_latch, - file, line, mtr); + if (dict_table_is_intrinsic(index->table)) { + ut_ad((latch_mode & BTR_MODIFY_LEAF) + || (latch_mode & BTR_SEARCH_LEAF)); + err = btr_cur_search_to_nth_level_with_no_latch( + index, 0, tuple, mode, btr_cursor, + file, line, mtr, + ((latch_mode & BTR_MODIFY_LEAF) ? true : false)); + } else { + err = btr_cur_search_to_nth_level( + index, 0, tuple, mode, latch_mode, btr_cursor, + has_search_latch, file, line, mtr); + } + cursor->pos_state = BTR_PCUR_IS_POSITIONED; - cursor->old_stored = BTR_PCUR_OLD_NOT_STORED; + cursor->old_stored = false; cursor->trx_if_known = NULL; return err; @@ -518,11 +568,18 @@ btr_pcur_open_at_index_side( btr_pcur_init(pcur); } - err = btr_cur_open_at_index_side(from_left, index, latch_mode, - btr_pcur_get_btr_cur(pcur), level, mtr); + if (dict_table_is_intrinsic(index->table)) { + err = btr_cur_open_at_index_side_with_no_latch( + from_left, index, + btr_pcur_get_btr_cur(pcur), level, mtr); + } else { + err = btr_cur_open_at_index_side( + from_left, index, latch_mode, + btr_pcur_get_btr_cur(pcur), level, mtr); + } pcur->pos_state = BTR_PCUR_IS_POSITIONED; - pcur->old_stored = BTR_PCUR_OLD_NOT_STORED; + pcur->old_stored = false; pcur->trx_if_known = NULL; @@ -530,9 +587,11 @@ btr_pcur_open_at_index_side( } /**********************************************************************//** -Positions a cursor at a randomly chosen position within a B-tree. */ +Positions a cursor at a randomly chosen position within a B-tree. +@return true if the index is available and we have put the cursor, false +if the index is unavailable */ UNIV_INLINE -void +bool btr_pcur_open_at_rnd_pos_func( /*==========================*/ dict_index_t* index, /*!< in: index */ @@ -549,13 +608,17 @@ btr_pcur_open_at_rnd_pos_func( btr_pcur_init(cursor); - btr_cur_open_at_rnd_pos_func(index, latch_mode, - btr_pcur_get_btr_cur(cursor), - file, line, mtr); + bool available; + + available = btr_cur_open_at_rnd_pos_func(index, latch_mode, + btr_pcur_get_btr_cur(cursor), + file, line, mtr); cursor->pos_state = BTR_PCUR_IS_POSITIONED; - cursor->old_stored = BTR_PCUR_OLD_NOT_STORED; + cursor->old_stored = false; cursor->trx_if_known = NULL; + + return(available); } /**************************************************************//** @@ -576,18 +639,20 @@ btr_pcur_close( /*===========*/ btr_pcur_t* cursor) /*!< in: persistent cursor */ { - if (cursor->old_rec_buf != NULL) { - - mem_free(cursor->old_rec_buf); + ut_free(cursor->old_rec_buf); - cursor->old_rec = NULL; - cursor->old_rec_buf = NULL; + if (cursor->btr_cur.rtr_info) { + rtr_clean_rtr_info(cursor->btr_cur.rtr_info, true); + cursor->btr_cur.rtr_info = NULL; } + cursor->old_rec = NULL; + cursor->old_rec_buf = NULL; cursor->btr_cur.page_cur.rec = NULL; cursor->btr_cur.page_cur.block = NULL; + cursor->old_rec = NULL; - cursor->old_stored = BTR_PCUR_OLD_NOT_STORED; + cursor->old_stored = false; cursor->latch_mode = BTR_NO_LATCHES; cursor->pos_state = BTR_PCUR_NOT_POSITIONED; @@ -608,5 +673,5 @@ btr_pcur_move_before_first_on_page( page_cur_set_before_first(btr_pcur_get_block(cursor), btr_pcur_get_page_cur(cursor)); - cursor->old_stored = BTR_PCUR_OLD_NOT_STORED; + cursor->old_stored = false; } |