Skip to content

Commit

Permalink
Cleanup: Remove btr_pcur_t::old_stored
Browse files Browse the repository at this point in the history
The Boolean field btr_pcur_t::old_stored mostly duplicates old_rec.
Let us remove it.
  • Loading branch information
dr-m committed Nov 16, 2022
1 parent 8442bc6 commit 6b2d6a8
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 45 deletions.
11 changes: 3 additions & 8 deletions storage/innobase/btr/btr0pcur.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ btr_pcur_reset(
cursor->old_rec = NULL;
cursor->old_n_core_fields = 0;
cursor->old_n_fields = 0;
cursor->old_stored = false;

cursor->latch_mode = BTR_NO_LATCHES;
cursor->pos_state = BTR_PCUR_NOT_POSITIONED;
Expand Down Expand Up @@ -125,8 +124,6 @@ btr_pcur_store_position(
&& mtr->memo_contains_flagged(&index->lock, MTR_MEMO_X_LOCK
| MTR_MEMO_SX_LOCK)));

cursor->old_stored = true;

if (page_is_empty(block->page.frame)) {
/* It must be an empty index tree; NOTE that in this case
we do not store the modify_clock, but always do a search
Expand Down Expand Up @@ -301,7 +298,6 @@ btr_pcur_t::restore_position(ulint restore_latch_mode, mtr_t *mtr)
mem_heap_t* heap;

ut_ad(mtr->is_active());
//ut_ad(cursor->old_stored);
ut_ad(pos_state == BTR_PCUR_WAS_POSITIONED
|| pos_state == BTR_PCUR_IS_POSITIONED);

Expand Down Expand Up @@ -450,7 +446,6 @@ btr_pcur_t::restore_position(ulint restore_latch_mode, mtr_t *mtr)
block_when_stored.store(btr_pcur_get_block(this));
modify_clock= buf_block_get_modify_clock(
block_when_stored.block());
old_stored= true;

mem_heap_free(heap);

Expand Down Expand Up @@ -487,7 +482,7 @@ btr_pcur_move_to_next_page(
ut_ad(cursor->latch_mode != BTR_NO_LATCHES);
ut_ad(btr_pcur_is_after_last_on_page(cursor));

cursor->old_stored = false;
cursor->old_rec = nullptr;

const page_t* page = btr_pcur_get_page(cursor);
const uint32_t next_page_no = btr_page_get_next(page);
Expand Down Expand Up @@ -594,7 +589,7 @@ btr_pcur_move_backward_from_page(
}

cursor->latch_mode = latch_mode;
cursor->old_stored = false;
cursor->old_rec = nullptr;
return false;
}

Expand All @@ -612,7 +607,7 @@ btr_pcur_move_to_prev(
ut_ad(cursor->pos_state == BTR_PCUR_IS_POSITIONED);
ut_ad(cursor->latch_mode != BTR_NO_LATCHES);

cursor->old_stored = false;
cursor->old_rec = nullptr;

if (btr_pcur_is_before_first_on_page(cursor)) {
return (!btr_pcur_is_before_first_in_tree(cursor)
Expand Down
1 change: 0 additions & 1 deletion storage/innobase/fts/fts0fts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3347,7 +3347,6 @@ fts_add_doc_by_id(
is_id_cluster = (clust_index == fts_id_index);

mtr_start(&mtr);
btr_pcur_init(&pcur);

/* Search based on Doc ID. Here, we'll need to consider the case
when there is no primary index on Doc ID */
Expand Down
4 changes: 2 additions & 2 deletions storage/innobase/ibuf/ibuf0ibuf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2402,8 +2402,8 @@ ulint ibuf_contract()
/* Open a cursor to a randomly chosen leaf of the tree, at a random
position within the leaf */
pcur.pos_state = BTR_PCUR_IS_POSITIONED;
pcur.old_stored = false;
pcur.trx_if_known = NULL;
pcur.old_rec = nullptr;
pcur.trx_if_known = nullptr;
pcur.search_mode = PAGE_CUR_G;
pcur.latch_mode = BTR_SEARCH_LEAF;

Expand Down
4 changes: 1 addition & 3 deletions storage/innobase/include/btr0pcur.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,6 @@ struct btr_pcur_t{
we say then that the cursor is detached; it can be restored to
attached if the old position was stored in old_rec */
ulint latch_mode;
/** true if old_rec is stored */
bool old_stored;
/** if cursor position is stored, contains an initial segment of the
latest record cursor was positioned either on, before or after */
rec_t* old_rec;
Expand Down Expand Up @@ -416,7 +414,7 @@ struct btr_pcur_t{

btr_pcur_t() :
btr_cur(), latch_mode(RW_NO_LATCH),
old_stored(false), old_rec(NULL),
old_rec(NULL),
old_n_fields(0), rel_pos(btr_pcur_pos_t(0)),
block_when_stored(),
modify_clock(0), pos_state(BTR_PCUR_NOT_POSITIONED),
Expand Down
41 changes: 17 additions & 24 deletions storage/innobase/include/btr0pcur.inl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ btr_pcur_get_rel_pos(
{
ut_ad(cursor);
ut_ad(cursor->old_rec);
ut_ad(cursor->old_stored);
ut_ad(cursor->pos_state == BTR_PCUR_WAS_POSITIONED
|| cursor->pos_state == BTR_PCUR_IS_POSITIONED);

Expand Down Expand Up @@ -163,7 +162,7 @@ btr_pcur_move_to_next_on_page(
ut_ad(cursor->pos_state == BTR_PCUR_IS_POSITIONED);
ut_ad(cursor->latch_mode != BTR_NO_LATCHES);

cursor->old_stored = false;
cursor->old_rec = nullptr;
return page_cur_move_to_next(btr_pcur_get_page_cur(cursor));
}

Expand All @@ -177,7 +176,7 @@ btr_pcur_move_to_prev_on_page(
{
ut_ad(cursor->pos_state == BTR_PCUR_IS_POSITIONED);
ut_ad(cursor->latch_mode != BTR_NO_LATCHES);
cursor->old_stored = false;
cursor->old_rec = nullptr;

return page_cur_move_to_prev(btr_pcur_get_page_cur(cursor));
}
Expand All @@ -196,7 +195,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 = false;
cursor->old_rec = nullptr;
loop:
if (btr_pcur_is_after_last_on_page(cursor)) {
if (btr_pcur_is_after_last_in_tree(cursor)
Expand Down Expand Up @@ -230,7 +229,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= false;
cursor->old_rec= nullptr;

if (btr_pcur_is_after_last_on_page(cursor))
return !btr_pcur_is_after_last_in_tree(cursor) &&
Expand Down Expand Up @@ -294,7 +293,6 @@ btr_pcur_init(
/*==========*/
btr_pcur_t* pcur) /*!< in: persistent cursor */
{
pcur->old_stored = false;
pcur->old_rec_buf = NULL;
pcur->old_rec = NULL;

Expand Down Expand Up @@ -363,7 +361,6 @@ dberr_t btr_pcur_open_with_no_init(dict_index_t *index, const dtuple_t *tuple,
cursor->latch_mode= BTR_LATCH_MODE_WITHOUT_INTENTION(latch_mode);
cursor->search_mode= mode;
cursor->pos_state= BTR_PCUR_IS_POSITIONED;
cursor->old_stored= false;
cursor->trx_if_known= nullptr;

/* Search with the tree cursor */
Expand Down Expand Up @@ -402,7 +399,7 @@ btr_pcur_open_at_index_side(
btr_pcur_get_btr_cur(pcur), level, mtr);
pcur->pos_state = BTR_PCUR_IS_POSITIONED;

pcur->old_stored = false;
pcur->old_rec = nullptr;

pcur->trx_if_known = NULL;

Expand All @@ -425,25 +422,21 @@ btr_pcur_close(
/*===========*/
btr_pcur_t* cursor) /*!< in: persistent cursor */
{
ut_free(cursor->old_rec_buf);
ut_free(cursor->old_rec_buf);

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;
if (cursor->btr_cur.rtr_info)
rtr_clean_rtr_info(cursor->btr_cur.rtr_info, true);

cursor->old_rec = NULL;
cursor->old_stored = false;
cursor->btr_cur.rtr_info= nullptr;
cursor->old_rec = nullptr;
cursor->old_rec_buf = nullptr;
cursor->btr_cur.page_cur.rec = nullptr;
cursor->btr_cur.page_cur.block = nullptr;

cursor->latch_mode = BTR_NO_LATCHES;
cursor->pos_state = BTR_PCUR_NOT_POSITIONED;
cursor->latch_mode = BTR_NO_LATCHES;
cursor->pos_state = BTR_PCUR_NOT_POSITIONED;

cursor->trx_if_known = NULL;
cursor->trx_if_known = nullptr;
}

/*********************************************************//**
Expand All @@ -459,5 +452,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 = false;
cursor->old_rec = nullptr;
}
2 changes: 1 addition & 1 deletion storage/innobase/row/row0import.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,7 @@ dberr_t IndexPurge::next() noexcept
return DB_CORRUPTION;
}
/* The following is based on btr_pcur_move_to_next_user_rec(). */
m_pcur.old_stored = false;
m_pcur.old_rec = nullptr;
ut_ad(m_pcur.latch_mode == BTR_MODIFY_LEAF);
do {
if (btr_pcur_is_after_last_on_page(&m_pcur)) {
Expand Down
1 change: 1 addition & 0 deletions storage/innobase/row/row0ins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,7 @@ row_ins_foreign_check_on_constraint(

ref = row_build_row_ref(ROW_COPY_POINTERS, index, rec,
tmp_heap);
cascade->pcur->old_rec = nullptr;
err = btr_pcur_open_with_no_init(clust_index, ref,
PAGE_CUR_LE, BTR_SEARCH_LEAF,
cascade->pcur, mtr);
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/row/row0purge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,7 @@ purge_node_t::validate_pcur()
return(true);
}

if (!pcur.old_stored) {
if (!pcur.old_rec) {
return(true);
}

Expand Down
13 changes: 8 additions & 5 deletions storage/innobase/row/row0sel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ row_sel_get_clust_rec(
row_build_row_ref_fast(plan->clust_ref, plan->clust_map, rec, offsets);

index = dict_table_get_first_index(plan->table);

plan->clust_pcur.old_rec = nullptr;
dberr_t err = btr_pcur_open_with_no_init(index, plan->clust_ref,
PAGE_CUR_LE, BTR_SEARCH_LEAF,
&plan->clust_pcur, mtr);
Expand Down Expand Up @@ -1411,6 +1411,8 @@ row_sel_open_pcur(
cond = UT_LIST_GET_NEXT(cond_list, cond);
}

plan->pcur.old_rec = nullptr;

dberr_t err;

if (plan->tuple) {
Expand Down Expand Up @@ -3371,6 +3373,7 @@ Row_sel_get_clust_rec_for_mysql::operator()(
rec_t* old_vers;
trx_t* trx;

prebuilt->clust_pcur->old_rec = nullptr;
*out_rec = NULL;
trx = thr_get_trx(thr);

Expand Down Expand Up @@ -3965,6 +3968,7 @@ row_sel_try_search_shortcut_for_mysql(
ut_ad(!index->table->is_temporary());
ut_ad(!prebuilt->templ_contains_blob);
ut_ad(trx->read_view.is_open());
pcur->old_rec = nullptr;

if (btr_pcur_open_with_no_init(index, search_tuple, PAGE_CUR_GE,
BTR_SEARCH_LEAF, pcur, mtr)
Expand Down Expand Up @@ -4767,6 +4771,7 @@ row_search_mvcc(

} else if (dtuple_get_n_fields(search_tuple) > 0) {
pcur->btr_cur.thr = thr;
pcur->old_rec = nullptr;

if (dict_index_is_spatial(index)) {
if (!prebuilt->rtr_info) {
Expand Down Expand Up @@ -5020,7 +5025,7 @@ row_search_mvcc(

page_cur_set_after_last(btr_pcur_get_block(pcur),
btr_pcur_get_page_cur(pcur));
pcur->old_stored = false;
pcur->old_rec = nullptr;
goto next_rec;
}
}
Expand Down Expand Up @@ -5786,7 +5791,7 @@ row_search_mvcc(
/* This is based on btr_pcur_move_to_next() */
ut_ad(pcur->pos_state == BTR_PCUR_IS_POSITIONED);
ut_ad(pcur->latch_mode != BTR_NO_LATCHES);
pcur->old_stored = false;
pcur->old_rec = nullptr;
if (btr_pcur_is_after_last_on_page(pcur)) {
if (btr_pcur_is_after_last_in_tree(pcur)) {
goto not_moved;
Expand Down Expand Up @@ -6198,8 +6203,6 @@ dberr_t row_check_index(row_prebuilt_t *prebuilt, ulint *n_rows)
*n_rows= 0;
dict_index_t *const index= prebuilt->index;

prebuilt->fetch_direction= ROW_SEL_NEXT;

if (!index->is_btree())
return DB_CORRUPTION;

Expand Down

0 comments on commit 6b2d6a8

Please sign in to comment.