diff --git a/btr/btr0cur.c b/btr/btr0cur.c index 4259b800753..2a39074d4df 100644 --- a/btr/btr0cur.c +++ b/btr/btr0cur.c @@ -338,7 +338,8 @@ btr_cur_search_to_nth_level( Inserts should always be made using PAGE_CUR_LE to search the position! */ ulint latch_mode, /*!< in: BTR_SEARCH_LEAF, ..., ORed with - BTR_INSERT and BTR_ESTIMATE; + at most one of BTR_INSERT, BTR_DELETE_MARK, + BTR_DELETE, or BTR_ESTIMATE; cursor->left_block is used to store a pointer to the left neighbor page, in the cases BTR_SEARCH_PREV and BTR_MODIFY_PREV; @@ -773,35 +774,6 @@ retry_page_get: || mode != PAGE_CUR_LE); ut_ad(cursor->low_match != ULINT_UNDEFINED || mode != PAGE_CUR_LE); - - /* If this was a delete operation, the leaf page was - in the buffer pool, and a matching record was found in - the leaf page, attempt to delete it. If the deletion - fails, set the cursor flag accordingly. */ - if (UNIV_UNLIKELY(btr_op == BTR_DELETE_OP) - && low_match == dtuple_get_n_fields(tuple) - && !page_cur_is_before_first(page_cursor)) { - - /* Before attempting to purge a record, check - if it is safe to do so. */ - if (!row_purge_poss_sec(cursor->purge_node, - index, tuple)) { - - cursor->flag = BTR_CUR_DELETE_REF; - } else { - /* Only delete-marked records should - be purged. */ - ut_ad(REC_INFO_DELETED_FLAG - & rec_get_info_bits( - btr_cur_get_rec(cursor), - page_is_comp(page))); - - if (!btr_cur_optimistic_delete(cursor, mtr)) { - - cursor->flag = BTR_CUR_DELETE_FAILED; - } - } - } } func_exit: diff --git a/include/btr0btr.h b/include/btr0btr.h index 8764ac2e6de..cc4063cc32c 100644 --- a/include/btr0btr.h +++ b/include/btr0btr.h @@ -71,7 +71,8 @@ enum btr_latch_mode { /* BTR_INSERT, BTR_DELETE and BTR_DELETE_MARK are mutually exclusive. */ /** If this is ORed to btr_latch_mode, it means that the search tuple -will be inserted to the index, at the searched position */ +will be inserted to the index, at the searched position. +When the record is not in the buffer pool, try to use the insert buffer. */ #define BTR_INSERT 512 /** This flag ORed to btr_latch_mode says that we do the search in query @@ -84,11 +85,11 @@ the insert buffer to speed up inserts */ #define BTR_IGNORE_SEC_UNIQUE 2048 /** Try to delete mark the record at the searched position using the -insert/delete buffer. */ +insert/delete buffer when the record is not in the buffer pool. */ #define BTR_DELETE_MARK 4096 -/** Try to delete the record at the searched position using the insert/delete -buffer. */ +/** Try to purge the record at the searched position using the insert/delete +buffer when the record is not in the buffer pool. */ #define BTR_DELETE 8192 /**************************************************************//** diff --git a/include/btr0cur.h b/include/btr0cur.h index bd9f1f3c37f..136d2d068a1 100644 --- a/include/btr0cur.h +++ b/include/btr0cur.h @@ -138,7 +138,8 @@ btr_cur_search_to_nth_level( should always be made using PAGE_CUR_LE to search the position! */ ulint latch_mode, /*!< in: BTR_SEARCH_LEAF, ..., ORed with - BTR_INSERT and BTR_ESTIMATE; + at most one of BTR_INSERT, BTR_DELETE_MARK, + BTR_DELETE, or BTR_ESTIMATE; cursor->left_block is used to store a pointer to the left neighbor page, in the cases BTR_SEARCH_PREV and BTR_MODIFY_PREV; @@ -634,9 +635,7 @@ enum btr_cur_method { mark in the insert/delete buffer */ BTR_CUR_DELETE_IBUF, /*!< performed the intended delete in the insert/delete buffer */ - BTR_CUR_DELETE_REF, /*!< row_purge_poss_sec() failed */ - BTR_CUR_DELETE_FAILED /*!< an optimistic delete could not be - performed */ + BTR_CUR_DELETE_REF /*!< row_purge_poss_sec() failed */ }; /** The tree cursor: the definition appears here only for the compiler diff --git a/include/row0row.h b/include/row0row.h index 185dc0906a3..b40aa619f9f 100644 --- a/include/row0row.h +++ b/include/row0row.h @@ -269,8 +269,6 @@ enum row_search_result { enqueued in the insert/delete buffer */ ROW_NOT_DELETED_REF, /*!< BTR_DELETE was specified, and row_purge_poss_sec() failed */ - ROW_NOT_DELETED, /*!< BTR_DELETE was specified, and the - optimistic delete failed */ }; /***************************************************************//** diff --git a/row/row0purge.c b/row/row0purge.c index e8d8bdf81ce..92915fd42a4 100644 --- a/row/row0purge.c +++ b/row/row0purge.c @@ -297,7 +297,6 @@ row_purge_remove_sec_if_poss_tree( break; case ROW_BUFFERED: case ROW_NOT_DELETED_REF: - case ROW_NOT_DELETED: /* These are invalid outcomes, because the mode passed to row_search_index_entry() did not include any of the flags BTR_INSERT, BTR_DELETE, or BTR_DELETE_MARK. */ @@ -366,24 +365,40 @@ row_purge_remove_sec_if_poss_leaf( search_result = row_search_index_entry( index, entry, BTR_MODIFY_LEAF | BTR_DELETE, &pcur, &mtr); - btr_pcur_close(&pcur); - mtr_commit(&mtr); - switch (search_result) { - case ROW_NOT_DELETED: - /* The index entry could not be deleted. */ - return(FALSE); - + ibool success; + case ROW_FOUND: + /* Before attempting to purge a record, check + if it is safe to do so. */ + if (row_purge_poss_sec(node, index, entry)) { + btr_cur_t* btr_cur = btr_pcur_get_btr_cur(&pcur); + + /* Only delete-marked records should be purged. */ + ut_ad(REC_INFO_DELETED_FLAG + & rec_get_info_bits( + btr_cur_get_rec(btr_cur), + dict_table_is_comp(index->table))); + + if (!btr_cur_optimistic_delete(btr_cur, &mtr)) { + + /* The index entry could not be deleted. */ + success = FALSE; + goto func_exit; + } + } + /* fall through (the index entry is still needed, + or the deletion succeeded) */ case ROW_NOT_DELETED_REF: /* The index entry is still needed. */ - case ROW_NOT_FOUND: - /* The index entry does not exist, nothing to do. */ - case ROW_FOUND: - /* The index entry existed in the buffer pool - and was deleted because of the BTR_DELETE. */ case ROW_BUFFERED: /* The deletion was buffered. */ - return(TRUE); + case ROW_NOT_FOUND: + /* The index entry does not exist, nothing to do. */ + success = TRUE; + func_exit: + btr_pcur_close(&pcur); + mtr_commit(&mtr); + return(success); } ut_error; diff --git a/row/row0row.c b/row/row0row.c index 26a84f1332f..caac11ebc61 100644 --- a/row/row0row.c +++ b/row/row0row.c @@ -755,10 +755,6 @@ row_search_index_entry( ut_a(mode & BTR_DELETE); return(ROW_NOT_DELETED_REF); - case BTR_CUR_DELETE_FAILED: - ut_a(mode & BTR_DELETE); - return(ROW_NOT_DELETED); - case BTR_CUR_DEL_MARK_IBUF: case BTR_CUR_DELETE_IBUF: case BTR_CUR_INSERT_TO_IBUF: diff --git a/row/row0uins.c b/row/row0uins.c index 14432f88793..601cb23c372 100644 --- a/row/row0uins.c +++ b/row/row0uins.c @@ -168,7 +168,6 @@ row_undo_ins_remove_sec_low( case ROW_FOUND: break; case ROW_BUFFERED: - case ROW_NOT_DELETED: case ROW_NOT_DELETED_REF: /* These are invalid outcomes, because the mode passed to row_search_index_entry() did not include any of the diff --git a/row/row0umod.c b/row/row0umod.c index 83f02bba721..80f57870316 100644 --- a/row/row0umod.c +++ b/row/row0umod.c @@ -350,7 +350,6 @@ row_undo_mod_del_mark_or_remove_sec_low( case ROW_FOUND: break; case ROW_BUFFERED: - case ROW_NOT_DELETED: case ROW_NOT_DELETED_REF: /* These are invalid outcomes, because the mode passed to row_search_index_entry() did not include any of the @@ -487,7 +486,6 @@ row_undo_mod_del_unmark_sec_and_undo_update( switch (search_result) { case ROW_BUFFERED: - case ROW_NOT_DELETED: case ROW_NOT_DELETED_REF: /* These are invalid outcomes, because the mode passed to row_search_index_entry() did not include any of the diff --git a/row/row0upd.c b/row/row0upd.c index 99a83b78bd3..26a5a91c0e2 100644 --- a/row/row0upd.c +++ b/row/row0upd.c @@ -1476,7 +1476,6 @@ row_upd_sec_index_entry( rec = btr_cur_get_rec(btr_cur); switch (search_result) { - case ROW_NOT_DELETED: /* should only occur for BTR_DELETE */ case ROW_NOT_DELETED_REF: /* should only occur for BTR_DELETE */ ut_error; break;