Skip to content

Commit

Permalink
Simplify row_undo_ins_remove_sec_low()
Browse files Browse the repository at this point in the history
Reduce the scope of some variables, remove a goto and a redundant
assertion.

For B-tree secondary indexes, this function can remove a delete-marked
purgeable record, in case a row rollback of the INSERT was initiated
due to an error in an earlier secondary index.
  • Loading branch information
dr-m committed Oct 17, 2019
1 parent b027830 commit fa929f7
Showing 1 changed file with 22 additions and 30 deletions.
52 changes: 22 additions & 30 deletions storage/innobase/row/row0uins.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 1997, 2017, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, 2018, MariaDB Corporation.
Copyright (c) 2017, 2019, 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
Expand Down Expand Up @@ -196,10 +196,8 @@ row_undo_ins_remove_sec_low(
que_thr_t* thr) /*!< in: query thread */
{
btr_pcur_t pcur;
btr_cur_t* btr_cur;
dberr_t err = DB_SUCCESS;
mtr_t mtr;
enum row_search_result search_result;
const bool modify_leaf = mode == BTR_MODIFY_LEAF;

row_mtr_start(&mtr, index, !modify_leaf);
Expand All @@ -224,12 +222,15 @@ row_undo_ins_remove_sec_low(
mode |= BTR_RTREE_UNDO_INS;
}

search_result = row_search_index_entry(index, entry, mode,
&pcur, &mtr);

switch (search_result) {
switch (row_search_index_entry(index, entry, mode, &pcur, &mtr)) {
case ROW_BUFFERED:
case ROW_NOT_DELETED_REF:
/* 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. */
ut_error;
case ROW_NOT_FOUND:
goto func_exit;
break;
case ROW_FOUND:
if (dict_index_is_spatial(index)
&& rec_get_deleted_flag(
Expand All @@ -239,31 +240,22 @@ row_undo_ins_remove_sec_low(
<< " is deleted marked on insert rollback.";
ut_ad(0);
}
break;

case ROW_BUFFERED:
case ROW_NOT_DELETED_REF:
/* 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. */
ut_error;
}

btr_cur = btr_pcur_get_btr_cur(&pcur);
btr_cur_t* btr_cur = btr_pcur_get_btr_cur(&pcur);

if (modify_leaf) {
err = btr_cur_optimistic_delete(btr_cur, 0, &mtr)
? DB_SUCCESS : DB_FAIL;
} else {
/* Passing rollback=false here, because we are
deleting a secondary index record: the distinction
only matters when deleting a record that contains
externally stored columns. */
ut_ad(!dict_index_is_clust(index));
btr_cur_pessimistic_delete(&err, FALSE, btr_cur, 0,
false, &mtr);
if (modify_leaf) {
err = btr_cur_optimistic_delete(btr_cur, 0, &mtr)
? DB_SUCCESS : DB_FAIL;
} else {
/* Passing rollback=false here, because we are
deleting a secondary index record: the distinction
only matters when deleting a record that contains
externally stored columns. */
btr_cur_pessimistic_delete(&err, FALSE, btr_cur, 0,
false, &mtr);
}
}
func_exit:

btr_pcur_close(&pcur);
func_exit_no_pcur:
mtr_commit(&mtr);
Expand Down

0 comments on commit fa929f7

Please sign in to comment.