Commit d583b180 authored by marko's avatar marko

branches/zip: Eliminate many buf_block_align() calls.

Replace page_t* or page_zip_des_t* parameters in some functions with
buf_block_t*.

buf_frame_get_page_zip(): Disable unless #ifdef UNIV_DEBUG || UNIV_ZIP_DEBUG.

btr_cur_t: Add buf_block_t* page_block.

btr_pcur_get_block(), btr_cur_get_block(), btr_cur_get_page_zip():
New functions.

btr_cur_position(): Add the parameter block.
parent 8f077940
......@@ -78,18 +78,29 @@ make them consecutive on disk if possible. From the other file segment
we allocate pages for the non-leaf levels of the tree.
*/
/****************************************************************
Returns the upper level node pointer to a page. It is assumed that
mtr holds an x-latch on the tree. */
/******************************************************************
Gets the root node of a tree and x-latches it. */
static
rec_t*
btr_page_get_father_node_ptr(
/*=========================*/
/* out: pointer to node pointer record */
buf_block_t*
btr_root_block_get(
/*===============*/
/* out: root page, x-latched */
dict_index_t* index, /* in: index tree */
page_t* page, /* in: page: must contain at least one
user record */
mtr_t* mtr); /* in: mtr */
mtr_t* mtr) /* in: mtr */
{
ulint space;
ulint root_page_no;
buf_block_t* block;
space = dict_index_get_space(index);
root_page_no = dict_index_get_page(index);
block = btr_block_get(space, root_page_no, RW_X_LATCH, mtr);
ut_a((ibool)!!page_is_comp(buf_block_get_frame(block))
== dict_table_is_comp(index->table));
return(block);
}
/******************************************************************
Gets the root node of a tree and x-latches it. */
......@@ -101,17 +112,7 @@ btr_root_get(
dict_index_t* index, /* in: index tree */
mtr_t* mtr) /* in: mtr */
{
ulint space;
ulint root_page_no;
page_t* root;
space = dict_index_get_space(index);
root_page_no = dict_index_get_page(index);
root = btr_page_get(space, root_page_no, RW_X_LATCH, mtr);
ut_a((ibool)!!page_is_comp(root) == dict_table_is_comp(index->table));
return(root);
return(buf_block_get_frame(btr_root_block_get(index, mtr)));
}
/*****************************************************************
......@@ -511,7 +512,7 @@ btr_node_ptr_set_child_page_no(
/****************************************************************
Returns the child page of a node pointer and x-latches it. */
static
page_t*
buf_block_t*
btr_node_ptr_get_child(
/*===================*/
/* out: child page, x-latched */
......@@ -526,60 +527,59 @@ btr_node_ptr_get_child(
space = page_get_space_id(page_align(node_ptr));
page_no = btr_node_ptr_get_child_page_no(node_ptr, offsets);
return(btr_page_get(space, page_no, RW_X_LATCH, mtr));
return(btr_block_get(space, page_no, RW_X_LATCH, mtr));
}
/****************************************************************
Returns the upper level node pointer to a page. It is assumed that mtr holds
an x-latch on the tree. */
static
rec_t*
btr_page_get_father_for_rec(
/*========================*/
/* out: pointer to node pointer record,
ulint*
btr_page_get_father_node_ptr(
/*=========================*/
/* out: rec_get_offsets() of the
node pointer record */
ulint* offsets,/* in: work area for the return value */
mem_heap_t* heap, /* in: memory heap to use */
btr_cur_t* cursor, /* in: cursor pointing to user record,
out: cursor on node pointer record,
its page x-latched */
dict_index_t* index, /* in: index tree */
page_t* page, /* in: page: must contain at least one
user record */
rec_t* user_rec,/* in: user_record on page */
mtr_t* mtr) /* in: mtr */
{
mem_heap_t* heap;
dtuple_t* tuple;
btr_cur_t cursor;
rec_t* user_rec;
rec_t* node_ptr;
ulint offsets_[REC_OFFS_NORMAL_SIZE];
ulint* offsets = offsets_;
*offsets_ = (sizeof offsets_) / sizeof *offsets_;
ulint level;
ulint page_no;
dict_index_t* index;
page_no = buf_block_get_page_no(btr_cur_get_block(cursor));
index = btr_cur_get_index(cursor);
ut_ad(mtr_memo_contains(mtr, dict_index_get_lock(index),
MTR_MEMO_X_LOCK));
ut_a(page_rec_is_user_rec(user_rec));
ut_ad(dict_index_get_page(index) != page_get_page_no(page));
heap = mem_heap_create(100);
ut_ad(dict_index_get_page(index) != page_no);
tuple = dict_index_build_node_ptr(index, user_rec, 0, heap,
btr_page_get_level(page, mtr));
/* In the following, we choose just any index from the tree as the
first parameter for btr_cur_search_to_nth_level. */
level = btr_page_get_level(btr_cur_get_page(cursor), mtr);
user_rec = btr_cur_get_rec(cursor);
ut_a(page_rec_is_user_rec(user_rec));
tuple = dict_index_build_node_ptr(index, user_rec, 0, heap, level);
btr_cur_search_to_nth_level(index,
btr_page_get_level(page, mtr) + 1,
tuple, PAGE_CUR_LE,
BTR_CONT_MODIFY_TREE, &cursor, 0, mtr);
btr_cur_search_to_nth_level(index, level + 1, tuple, PAGE_CUR_LE,
BTR_CONT_MODIFY_TREE, cursor, 0, mtr);
node_ptr = btr_cur_get_rec(&cursor);
node_ptr = btr_cur_get_rec(cursor);
ut_ad(!page_rec_is_comp(node_ptr)
|| rec_get_status(node_ptr) == REC_STATUS_NODE_PTR);
offsets = rec_get_offsets(node_ptr, index, offsets,
ULINT_UNDEFINED, &heap);
if (UNIV_UNLIKELY(btr_node_ptr_get_child_page_no(node_ptr, offsets)
!= page_get_page_no(page))) {
!= page_no)) {
rec_t* print_rec;
fputs("InnoDB: Dump of the child page:\n", stderr);
buf_page_print(page_align(page), 0);
buf_page_print(page_align(user_rec), 0);
fputs("InnoDB: Dump of the parent page:\n", stderr);
buf_page_print(page_align(node_ptr), 0);
......@@ -591,8 +591,9 @@ btr_page_get_father_for_rec(
"InnoDB: father ptr page no %lu, child page no %lu\n",
(ulong)
btr_node_ptr_get_child_page_no(node_ptr, offsets),
(ulong) page_get_page_no(page));
print_rec = page_rec_get_next(page_get_infimum_rec(page));
(ulong) page_no);
print_rec = page_rec_get_next(
page_get_infimum_rec(page_align(user_rec)));
offsets = rec_get_offsets(print_rec, index,
offsets, ULINT_UNDEFINED, &heap);
page_rec_print(print_rec, offsets);
......@@ -612,27 +613,55 @@ btr_page_get_father_for_rec(
ut_error;
}
mem_heap_free(heap);
return(offsets);
}
return(node_ptr);
/****************************************************************
Returns the upper level node pointer to a page. It is assumed that mtr holds
an x-latch on the tree. */
static
ulint*
btr_page_get_father_block(
/*======================*/
/* out: rec_get_offsets() of the
node pointer record */
ulint* offsets,/* in: work area for the return value */
mem_heap_t* heap, /* in: memory heap to use */
dict_index_t* index, /* in: b-tree index */
buf_block_t* block, /* in: child page in the index */
mtr_t* mtr, /* in: mtr */
btr_cur_t* cursor) /* out: cursor on node pointer record,
its page x-latched */
{
rec_t* rec
= page_rec_get_next(page_get_infimum_rec(buf_block_get_frame(
block)));
btr_cur_position(index, rec, block, cursor);
return(btr_page_get_father_node_ptr(offsets, heap, cursor, mtr));
}
/****************************************************************
Returns the upper level node pointer to a page. It is assumed that
mtr holds an x-latch on the tree. */
Seeks to the upper level node pointer to a page.
It is assumed that mtr holds an x-latch on the tree. */
static
rec_t*
btr_page_get_father_node_ptr(
/*=========================*/
/* out: pointer to node pointer record */
dict_index_t* index, /* in: index tree */
page_t* page, /* in: page: must contain at least one
user record */
mtr_t* mtr) /* in: mtr */
void
btr_page_get_father(
/*================*/
dict_index_t* index, /* in: b-tree index */
buf_block_t* block, /* in: child page in the index */
mtr_t* mtr, /* in: mtr */
btr_cur_t* cursor) /* out: cursor on node pointer record,
its page x-latched */
{
return(btr_page_get_father_for_rec(
index, page,
page_rec_get_next(page_get_infimum_rec(page)), mtr));
mem_heap_t* heap;
rec_t* rec
= page_rec_get_next(page_get_infimum_rec(buf_block_get_frame(
block)));
btr_cur_position(index, rec, block, cursor);
heap = mem_heap_create(100);
btr_page_get_father_node_ptr(NULL, heap, cursor, mtr);
mem_heap_free(heap);
}
/****************************************************************
......@@ -832,12 +861,12 @@ btr_page_reorganize_low(
there cannot exist locks on the
page, and a hash index should not be
dropped: it cannot exist */
page_t* page, /* in/out: page to be reorganized */
page_zip_des_t* page_zip,/* in/out: compressed page, or NULL */
buf_block_t* block, /* in: page to be reorganized */
dict_index_t* index, /* in: record descriptor */
mtr_t* mtr) /* in: mtr */
{
buf_block_t* block;
page_t* page = buf_block_get_frame(block);
page_zip_des_t* page_zip = buf_block_get_page_zip(block);
buf_block_t* temp_block;
page_t* temp_page;
ulint log_mode;
......@@ -845,9 +874,8 @@ btr_page_reorganize_low(
ulint data_size2;
ulint max_ins_size1;
ulint max_ins_size2;
ibool success = FALSE;
ibool success = FALSE;
block = buf_block_align(page);
ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX));
ut_ad(!!page_is_comp(page) == dict_table_is_comp(index->table));
#ifdef UNIV_ZIP_DEBUG
......@@ -944,13 +972,11 @@ ibool
btr_page_reorganize(
/*================*/
/* out: TRUE on success, FALSE on failure */
page_t* page, /* in: page to be reorganized */
buf_block_t* block, /* in: page to be reorganized */
dict_index_t* index, /* in: record descriptor */
mtr_t* mtr) /* in: mtr */
{
return(btr_page_reorganize_low(FALSE, page,
buf_frame_get_page_zip(page),
index, mtr));
return(btr_page_reorganize_low(FALSE, block, index, mtr));
}
/***************************************************************
......@@ -964,16 +990,15 @@ btr_parse_page_reorganize(
byte* end_ptr __attribute__((unused)),
/* in: buffer end */
dict_index_t* index, /* in: record descriptor */
page_t* page, /* in/out: page to be reorganized, or NULL */
page_zip_des_t* page_zip,/* in/out: compressed page, or NULL */
buf_block_t* block, /* in: page to be reorganized, or NULL */
mtr_t* mtr) /* in: mtr or NULL */
{
ut_ad(ptr && end_ptr);
/* The record is empty, except for the record initial part */
if (UNIV_LIKELY(page != NULL)) {
btr_page_reorganize_low(TRUE, page, page_zip, index, mtr);
if (UNIV_LIKELY(block != NULL)) {
btr_page_reorganize_low(TRUE, block, index, mtr);
}
return(ptr);
......@@ -1048,7 +1073,7 @@ btr_root_raise_and_insert(
buf_block_t* new_block;
root = btr_cur_get_page(cursor);
root_block = buf_block_align(root);
root_block = btr_cur_get_block(cursor);
root_page_zip = buf_block_get_page_zip(root_block);
#ifdef UNIV_ZIP_DEBUG
ut_a(!root_page_zip || page_zip_validate(root_page_zip, root));
......@@ -1082,7 +1107,7 @@ btr_root_raise_and_insert(
/* Copy the records from root to the new page one by one. */
if (UNIV_UNLIKELY
(!page_copy_rec_list_end(new_page, new_page_zip,
(!page_copy_rec_list_end(new_block,
page_get_infimum_rec(root),
index, mtr))) {
ut_a(new_page_zip);
......@@ -1139,6 +1164,7 @@ btr_root_raise_and_insert(
/* Insert node pointer to the root */
ut_ad(buf_block_get_frame(btr_cur_get_block(cursor)) == root);
page_cur_set_before_first(root, page_cursor);
node_ptr_rec = page_cur_tuple_insert(page_cursor, root_page_zip,
......@@ -1160,6 +1186,7 @@ btr_root_raise_and_insert(
ibuf_reset_free_bits_with_type(index->type, new_block);
/* Reposition the cursor to the child node */
cursor->page_block = new_block;
page_cur_search(new_page, index, tuple,
PAGE_CUR_LE, page_cursor);
......@@ -1307,7 +1334,7 @@ btr_page_get_sure_split_rec(
insert_size = rec_get_converted_size(cursor->index, tuple, ext, n_ext);
free_space = page_get_free_space_of_empty(page_is_comp(page));
page_zip = buf_frame_get_page_zip(page);
page_zip = btr_cur_get_page_zip(cursor);
if (UNIV_LIKELY_NULL(page_zip)) {
/* Estimate the free space of an empty compressed page. */
ulint free_space_zip = page_zip_empty_size(
......@@ -1530,21 +1557,18 @@ void
btr_attach_half_pages(
/*==================*/
dict_index_t* index, /* in: the index tree */
page_t* page, /* in/out: page to be split */
page_zip_des_t* page_zip, /* in/out: compressed page, or NULL */
buf_block_t* block, /* in/out: page to be split */
rec_t* split_rec, /* in: first record on upper
half page */
page_t* new_page, /* in/out: the new half page */
page_zip_des_t* new_page_zip, /* in/out: compressed new_page,
or NULL */
buf_block_t* new_block, /* in/out: the new half page */
ulint direction, /* in: FSP_UP or FSP_DOWN */
mtr_t* mtr) /* in: mtr */
{
ulint space;
rec_t* node_ptr;
ulint prev_page_no;
ulint next_page_no;
ulint level;
page_t* page = buf_block_get_frame(block);
page_t* lower_page;
page_t* upper_page;
ulint lower_page_no;
......@@ -1554,9 +1578,8 @@ btr_attach_half_pages(
dtuple_t* node_ptr_upper;
mem_heap_t* heap;
ut_ad(mtr_memo_contains_page(mtr, page, MTR_MEMO_PAGE_X_FIX));
ut_ad(mtr_memo_contains_page(mtr, new_page, MTR_MEMO_PAGE_X_FIX));
ut_a(page_is_comp(page) == page_is_comp(new_page));
ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX));
ut_ad(mtr_memo_contains(mtr, new_block, MTR_MEMO_PAGE_X_FIX));
/* Create a memory heap where the data tuple is stored */
heap = mem_heap_create(1024);
......@@ -1564,37 +1587,39 @@ btr_attach_half_pages(
/* Based on split direction, decide upper and lower pages */
if (direction == FSP_DOWN) {
lower_page_no = page_get_page_no(new_page);
upper_page_no = page_get_page_no(page);
lower_page = new_page;
upper_page = page;
lower_page_zip = new_page_zip;
upper_page_zip = page_zip;
btr_cur_t cursor;
ulint* offsets;
lower_page = buf_block_get_frame(new_block);
lower_page_no = buf_block_get_page_no(new_block);
lower_page_zip = buf_block_get_page_zip(new_block);
upper_page = buf_block_get_frame(block);
upper_page_no = buf_block_get_page_no(block);
upper_page_zip = buf_block_get_page_zip(block);
/* Look up the index for the node pointer to page */
node_ptr = btr_page_get_father_node_ptr(index, page, mtr);
offsets = btr_page_get_father_block(NULL, heap, index,
block, mtr, &cursor);
/* Replace the address of the old child node (= page) with the
address of the new lower half */
btr_node_ptr_set_child_page_no(
node_ptr,
buf_frame_get_page_zip(node_ptr),
rec_get_offsets(node_ptr, index, NULL,
ULINT_UNDEFINED, &heap),
lower_page_no, mtr);
btr_cur_get_rec(&cursor),
btr_cur_get_page_zip(&cursor),
offsets, lower_page_no, mtr);
mem_heap_empty(heap);
} else {
lower_page_no = page_get_page_no(page);
upper_page_no = page_get_page_no(new_page);
lower_page = page;
upper_page = new_page;
lower_page_zip = page_zip;
upper_page_zip = new_page_zip;
lower_page = buf_block_get_frame(block);
lower_page_no = buf_block_get_page_no(block);
lower_page_zip = buf_block_get_page_zip(block);
upper_page = buf_block_get_frame(new_block);
upper_page_no = buf_block_get_page_no(new_block);
upper_page_zip = buf_block_get_page_zip(new_block);
}
/* Get the level of the split pages */
level = btr_page_get_level(page, mtr);
level = btr_page_get_level(buf_block_get_frame(block), mtr);
/* Build the node pointer (= node key and page address) for the upper
half */
......@@ -1614,7 +1639,7 @@ btr_attach_half_pages(
prev_page_no = btr_page_get_prev(page, mtr);
next_page_no = btr_page_get_next(page, mtr);
space = page_get_space_id(page);
space = buf_block_get_space(block);
/* Update page links of the level */
......@@ -1624,7 +1649,7 @@ btr_attach_half_pages(
#ifdef UNIV_BTR_DEBUG
ut_a(page_is_comp(prev_block->frame) == page_is_comp(page));
ut_a(btr_page_get_next(prev_block->frame, mtr)
== page_get_page_no(page));
== buf_block_get_page_no(block));
#endif /* UNIV_BTR_DEBUG */
btr_page_set_next(buf_block_get_frame(prev_block),
......@@ -1716,14 +1741,14 @@ btr_page_split_and_insert(
ut_ad(rw_lock_own(dict_index_get_lock(cursor->index), RW_LOCK_EX));
#endif /* UNIV_SYNC_DEBUG */
block = buf_block_align(btr_cur_get_rec(cursor));
block = btr_cur_get_block(cursor);
page = buf_block_get_frame(block);
page_zip = buf_block_get_page_zip(block);
ut_ad(mtr_memo_contains_page(mtr, page, MTR_MEMO_PAGE_X_FIX));
ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX));
ut_ad(page_get_n_recs(page) >= 1);
page_no = page_get_page_no(page);
page_no = buf_block_get_page_no(block);
/* 1. Decide the split record; split_rec == NULL means that the
tuple to be inserted should be the first record on the upper
......@@ -1750,7 +1775,7 @@ btr_page_split_and_insert(
/* 2. Allocate a new page to the index */
new_block = btr_page_alloc(cursor->index, hint_page_no, direction,
btr_page_get_level(page, mtr), mtr);
btr_page_get_level(page, mtr), mtr);
new_page = buf_block_get_frame(new_block);
new_page_zip = buf_block_get_page_zip(new_block);
btr_page_create(new_block, new_page_zip, cursor->index,
......@@ -1773,8 +1798,8 @@ btr_page_split_and_insert(
/* 4. Do first the modifications in the tree structure */
btr_attach_half_pages(cursor->index, page, page_zip, first_rec,
new_page, new_page_zip, direction, mtr);
btr_attach_half_pages(cursor->index, block,
first_rec, new_block, direction, mtr);
/* If the split is made on the leaf level and the insert will fit
on the appropriate half-page, we may release the tree x-latch.
......@@ -1808,8 +1833,7 @@ btr_page_split_and_insert(
/* fputs("Split left\n", stderr); */
if (UNIV_UNLIKELY
(!page_move_rec_list_start(new_page, new_page_zip,
move_limit, page_zip,
(!page_move_rec_list_start(new_block, move_limit, page_zip,
cursor->index, mtr))) {
/* For some reason, compressing new_page failed,
even though it should contain fewer records than
......@@ -1837,8 +1861,7 @@ btr_page_split_and_insert(
/* fputs("Split right\n", stderr); */
if (UNIV_UNLIKELY
(!page_move_rec_list_end(new_page, new_page_zip,
move_limit, page_zip,
(!page_move_rec_list_end(new_block, move_limit, page_zip,
cursor->index, mtr))) {
/* For some reason, compressing new_page failed,
even though it should contain fewer records than
......@@ -1889,6 +1912,7 @@ btr_page_split_and_insert(
/* 7. Reposition the cursor for insert and try insertion */
page_cursor = btr_cur_get_page_cur(cursor);
cursor->page_block = insert_block;
page_cur_search(insert_page, cursor->index, tuple,
PAGE_CUR_LE, page_cursor);
......@@ -1917,11 +1941,12 @@ btr_page_split_and_insert(
/* 8. If insert did not fit, try page reorganization */
if (UNIV_UNLIKELY
(!btr_page_reorganize(insert_page, cursor->index, mtr))) {
(!btr_page_reorganize(insert_block, cursor->index, mtr))) {
goto insert_failed;
}
ut_ad(cursor->page_block == insert_block);
page_cur_search(insert_page, cursor->index, tuple,
PAGE_CUR_LE, page_cursor);
rec = page_cur_tuple_insert(page_cursor, insert_page_zip,
......@@ -2099,20 +2124,18 @@ void
btr_node_ptr_delete(
/*================*/
dict_index_t* index, /* in: index tree */
page_t* page, /* in: page whose node pointer is deleted */
buf_block_t* block, /* in: page whose node pointer is deleted */
mtr_t* mtr) /* in: mtr */
{
rec_t* node_ptr;
btr_cur_t cursor;
ibool compressed;
ulint err;
ut_ad(mtr_memo_contains_page(mtr, page, MTR_MEMO_PAGE_X_FIX));
/* Delete node pointer on father page */
ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX));
node_ptr = btr_page_get_father_node_ptr(index, page, mtr);
/* Delete node pointer on father page */
btr_page_get_father(index, block, mtr, &cursor);
btr_cur_position(index, node_ptr, &cursor);
compressed = btr_cur_pessimistic_delete(&err, TRUE, &cursor, FALSE,
mtr);
ut_a(err == DB_SUCCESS);
......@@ -2136,6 +2159,7 @@ btr_lift_page_up(
record from the page should be removed */
mtr_t* mtr) /* in: mtr */
{
btr_cur_t father_cursor;
buf_block_t* father_block;
page_t* father_page;
ulint page_level;
......@@ -2145,14 +2169,11 @@ btr_lift_page_up(
ut_ad(btr_page_get_prev(page, mtr) == FIL_NULL);
ut_ad(btr_page_get_next(page, mtr) == FIL_NULL);
ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX));
father_block = buf_block_align(
btr_page_get_father_node_ptr(index, page, mtr));
btr_page_get_father(index, block, mtr, &father_cursor);
father_block = btr_cur_get_block(&father_cursor);
father_page_zip = buf_block_get_page_zip(father_block);
father_page = buf_block_get_frame(father_block);
#ifdef UNIV_ZIP_DEBUG
ut_a(!father_page_zip
|| page_zip_validate(father_page_zip, father_page));
#endif /* UNIV_ZIP_DEBUG */
page_level = btr_page_get_level(page, mtr);
......@@ -2167,7 +2188,7 @@ btr_lift_page_up(
/* Copy the records to the father page one by one. */
if (UNIV_UNLIKELY
(!page_copy_rec_list_end(father_page, father_page_zip,
(!page_copy_rec_list_end(father_block,
page_get_infimum_rec(page),
index, mtr))) {
ut_a(father_page_zip);
......@@ -2219,21 +2240,23 @@ btr_compress(
ibool is_left;
buf_block_t* block;
page_t* page;
rec_t* node_ptr;
btr_cur_t father_cursor;
mem_heap_t* heap;
ulint* offsets;
ulint data_size;
ulint n_recs;
ulint max_ins_size;
ulint max_ins_size_reorg;
ulint level;
block = buf_block_align(btr_cur_get_rec(cursor));
block = btr_cur_get_block(cursor);
page = buf_block_get_frame(block);
index = btr_cur_get_index(cursor);
ut_a((ibool) !!page_is_comp(page) == dict_table_is_comp(index->table));
ut_ad(mtr_memo_contains(mtr, dict_index_get_lock(index),
MTR_MEMO_X_LOCK));
ut_ad(mtr_memo_contains_page(mtr, page, MTR_MEMO_PAGE_X_FIX));
ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX));
level = btr_page_get_level(page, mtr);
space = dict_index_get_space(index);
......@@ -2245,10 +2268,9 @@ btr_compress(
left_page_no, right_page_no);
#endif
node_ptr = btr_page_get_father_node_ptr(index, page, mtr);
ut_ad(!page_is_comp(page)
|| rec_get_status(node_ptr) == REC_STATUS_NODE_PTR);
ut_a(page_is_comp(page) == page_rec_is_comp(node_ptr));
heap = mem_heap_create(100);
offsets = btr_page_get_father_block(NULL, heap, index, block, mtr,
&father_cursor);
/* Decide the page to which we try to merge and which will inherit
the locks */
......@@ -2261,8 +2283,7 @@ btr_compress(
mtr);
merge_page = buf_block_get_frame(merge_block);
#ifdef UNIV_BTR_DEBUG
ut_a(btr_page_get_next(merge_page, mtr)
== page_get_page_no(page));
ut_a(btr_page_get_next(merge_page, mtr) == block->offset);
#endif /* UNIV_BTR_DEBUG */
} else if (right_page_no != FIL_NULL) {
......@@ -2270,13 +2291,13 @@ btr_compress(
mtr);
merge_page = buf_block_get_frame(merge_block);
#ifdef UNIV_BTR_DEBUG
ut_a(btr_page_get_prev(merge_page, mtr)
== page_get_page_no(page));
ut_a(btr_page_get_prev(merge_page, mtr) == block->offset);
#endif /* UNIV_BTR_DEBUG */
} else {
/* The page is the only one on the level, lift the records
to the father */
btr_lift_page_up(index, block, mtr);
mem_heap_free(heap);
return(TRUE);
}
......@@ -2291,7 +2312,8 @@ btr_compress(
if (data_size > max_ins_size_reorg) {
/* No space for merge */
err_exit:
mem_heap_free(heap);
return(FALSE);
}
......@@ -2303,10 +2325,10 @@ btr_compress(
/* We have to reorganize merge_page */
if (UNIV_UNLIKELY(!btr_page_reorganize(merge_page,
if (UNIV_UNLIKELY(!btr_page_reorganize(merge_block,
index, mtr))) {
return(FALSE);
goto err_exit;
}
max_ins_size = page_get_max_insert_size(merge_page, n_recs);
......@@ -2319,7 +2341,7 @@ btr_compress(
/* Add fault tolerance, though this should
never happen */
return(FALSE);
goto err_exit;
}
}
......@@ -2327,35 +2349,31 @@ btr_compress(
#ifdef UNIV_ZIP_DEBUG
if (UNIV_LIKELY_NULL(merge_page_zip)) {
ut_a(page_zip_validate(merge_page_zip, merge_page));
ut_a(page_zip_validate(buf_frame_get_page_zip(page), page));
ut_a(page_zip_validate(buf_block_get_page_zip(block), page));
}
#endif /* UNIV_ZIP_DEBUG */
/* Move records to the merge page */
if (is_left) {
rec_t* orig_pred = page_copy_rec_list_start(
merge_page, merge_page_zip,
page_get_supremum_rec(page), index, mtr);
merge_block, page_get_supremum_rec(page), index, mtr);
if (UNIV_UNLIKELY(!orig_pred)) {
return(FALSE);
goto err_exit;
}
btr_search_drop_page_hash_index(buf_block_align(page));
btr_search_drop_page_hash_index(block);
/* Remove the page from the level list */
btr_level_list_remove(page, mtr);
btr_node_ptr_delete(index, page, mtr);
btr_node_ptr_delete(index, block, mtr);
lock_update_merge_left(merge_page, orig_pred, page);
} else {
mem_heap_t* heap = NULL;
ulint offsets_[REC_OFFS_NORMAL_SIZE];
rec_t* orig_succ;
#ifdef UNIV_BTR_DEBUG
byte fil_page_prev[4];
#endif /* UNIV_BTR_DEBUG */
*offsets_ = (sizeof offsets_) / sizeof *offsets_;
if (UNIV_LIKELY_NULL(merge_page_zip)) {
/* The function page_zip_compress(), which will be
......@@ -2371,7 +2389,7 @@ btr_compress(
memset(merge_page + FIL_PAGE_PREV, 0xff, 4);
}
orig_succ = page_copy_rec_list_end(merge_page, merge_page_zip,
orig_succ = page_copy_rec_list_end(merge_block,
page_get_infimum_rec(page),
cursor->index, mtr);
......@@ -2380,10 +2398,10 @@ btr_compress(
/* FIL_PAGE_PREV was restored from merge_page_zip. */
ut_ad(!memcmp(fil_page_prev,
merge_page + FIL_PAGE_PREV, 4));
return(FALSE);
goto err_exit;
}
btr_search_drop_page_hash_index(buf_block_align(page));
btr_search_drop_page_hash_index(block);
#ifdef UNIV_BTR_DEBUG
if (UNIV_LIKELY_NULL(merge_page_zip)) {
......@@ -2404,19 +2422,16 @@ btr_compress(
address of the merge page to the right */
btr_node_ptr_set_child_page_no(
node_ptr,
buf_frame_get_page_zip(node_ptr),
rec_get_offsets(node_ptr, index, offsets_,
ULINT_UNDEFINED, &heap),
right_page_no, mtr);
if (UNIV_LIKELY_NULL(heap)) {
mem_heap_free(heap);
}
btr_node_ptr_delete(index, merge_page, mtr);
btr_cur_get_rec(&father_cursor),
btr_cur_get_page_zip(&father_cursor),
offsets, right_page_no, mtr);
btr_node_ptr_delete(index, merge_block, mtr);
lock_update_merge_right(orig_succ, page);
}
mem_heap_free(heap);
/* We have added new records to merge_page: update its free bits */
ibuf_update_free_bits_if_full(index, merge_block,
UNIV_PAGE_SIZE, ULINT_UNDEFINED);
......@@ -2440,8 +2455,10 @@ btr_discard_only_page_on_level(
buf_block_t* block, /* in: page which is the only on its level */
mtr_t* mtr) /* in: mtr */
{
btr_cur_t father_cursor;
buf_block_t* father_block;
page_t* father_page;
page_zip_des_t* father_page_zip;
page_t* page = buf_block_get_frame(block);
ulint page_level;
......@@ -2450,16 +2467,16 @@ btr_discard_only_page_on_level(
ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX));
btr_search_drop_page_hash_index(block);
father_block = buf_block_align(
btr_page_get_father_node_ptr(index, page, mtr));
btr_page_get_father(index, block, mtr, &father_cursor);
father_block = btr_cur_get_block(&father_cursor);
father_page_zip = buf_block_get_page_zip(father_block);
father_page = buf_block_get_frame(father_block);
page_level = btr_page_get_level(page, mtr);
lock_update_discard(page_get_supremum_rec(father_page), page);
btr_page_set_level(father_page, buf_block_get_page_zip(father_block),
page_level, mtr);
btr_page_set_level(father_page, father_page_zip, page_level, mtr);
/* Free the file page */
btr_page_free(index, block, mtr);
......@@ -2468,9 +2485,7 @@ btr_discard_only_page_on_level(
== dict_index_get_page(index))) {
/* The father is the root page */
btr_page_empty(father_block,
buf_block_get_page_zip(father_block),
mtr, index);
btr_page_empty(father_block, father_page_zip, mtr, index);
/* We play safe and reset the free bits for the father */
ibuf_reset_free_bits_with_type(index->type, father_block);
......@@ -2502,34 +2517,31 @@ btr_discard_page(
page_t* page;
rec_t* node_ptr;
block = buf_block_align(btr_cur_get_rec(cursor));
page = buf_block_get_frame(block);
block = btr_cur_get_block(cursor);
index = btr_cur_get_index(cursor);
ut_ad(dict_index_get_page(index) != page_get_page_no(page));
ut_ad(dict_index_get_page(index) != block->offset);
ut_ad(mtr_memo_contains(mtr, dict_index_get_lock(index),
MTR_MEMO_X_LOCK));
ut_ad(mtr_memo_contains_page(mtr, page, MTR_MEMO_PAGE_X_FIX));
ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX));
space = dict_index_get_space(index);
/* Decide the page which will inherit the locks */
left_page_no = btr_page_get_prev(page, mtr);
right_page_no = btr_page_get_next(page, mtr);
left_page_no = btr_page_get_prev(buf_block_get_frame(block), mtr);
right_page_no = btr_page_get_next(buf_block_get_frame(block), mtr);
if (left_page_no != FIL_NULL) {
merge_page = btr_page_get(space, left_page_no, RW_X_LATCH,
mtr);
#ifdef UNIV_BTR_DEBUG
ut_a(btr_page_get_next(merge_page, mtr)
== page_get_page_no(page));
ut_a(btr_page_get_next(merge_page, mtr) == block->offset);
#endif /* UNIV_BTR_DEBUG */
} else if (right_page_no != FIL_NULL) {
merge_page = btr_page_get(space, right_page_no, RW_X_LATCH,
mtr);
#ifdef UNIV_BTR_DEBUG
ut_a(btr_page_get_prev(merge_page, mtr)
== page_get_page_no(page));
ut_a(btr_page_get_prev(merge_page, mtr) == block->offset);
#endif /* UNIV_BTR_DEBUG */
} else {
btr_discard_only_page_on_level(index, block, mtr);
......@@ -2537,8 +2549,9 @@ btr_discard_page(
return;
}
page = buf_block_get_frame(block);
ut_a(page_is_comp(merge_page) == page_is_comp(page));
btr_search_drop_page_hash_index(buf_block_align(page));
btr_search_drop_page_hash_index(block);
if (left_page_no == FIL_NULL && !page_is_leaf(page)) {
......@@ -2556,7 +2569,7 @@ btr_discard_page(
btr_set_min_rec_mark(node_ptr, mtr);
}
btr_node_ptr_delete(index, page, mtr);
btr_node_ptr_delete(index, block, mtr);
/* Remove the page from the level list */
btr_level_list_remove(page, mtr);
......@@ -2670,8 +2683,9 @@ btr_print_recursive(
*offsets = rec_get_offsets(node_ptr, index, *offsets,
ULINT_UNDEFINED, heap);
child = btr_node_ptr_get_child(node_ptr,
*offsets, &mtr2);
child = buf_block_get_frame(
btr_node_ptr_get_child(node_ptr,
*offsets, &mtr2));
btr_print_recursive(index, child, width,
heap, offsets, &mtr2);
mtr_commit(&mtr2);
......@@ -2730,32 +2744,32 @@ btr_check_node_ptr(
mtr_t* mtr) /* in: mtr */
{
mem_heap_t* heap;
rec_t* node_ptr;
dtuple_t* node_ptr_tuple;
dtuple_t* tuple;
ulint* offsets;
btr_cur_t cursor;
buf_block_t* block = buf_block_align(page);
ut_ad(mtr_memo_contains_page(mtr, page, MTR_MEMO_PAGE_X_FIX));
if (dict_index_get_page(index) == page_get_page_no(page)) {
ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX));
if (dict_index_get_page(index) == block->offset) {
return(TRUE);
}
node_ptr = btr_page_get_father_node_ptr(index, page, mtr);
heap = mem_heap_create(256);
offsets = btr_page_get_father_block(NULL, heap, index, block, mtr,
&cursor);
if (page_is_leaf(page)) {
return(TRUE);
goto func_exit;
}
heap = mem_heap_create(256);
node_ptr_tuple = dict_index_build_node_ptr(
tuple = dict_index_build_node_ptr(
index, page_rec_get_next(page_get_infimum_rec(page)), 0, heap,
btr_page_get_level(page, mtr));
ut_a(!cmp_dtuple_rec(node_ptr_tuple, node_ptr,
rec_get_offsets(node_ptr, index,
NULL, ULINT_UNDEFINED, &heap)));
ut_a(!cmp_dtuple_rec(tuple, btr_cur_get_rec(&cursor), offsets));
func_exit:
mem_heap_free(heap);
return(TRUE);
......@@ -2972,12 +2986,13 @@ btr_validate_level(
ulint level) /* in: level number */
{
ulint space;
buf_block_t* block;
page_t* page;
buf_block_t* right_block = 0; /* remove warning */
page_t* right_page = 0; /* remove warning */
page_t* father_page;
page_t* right_father_page;
rec_t* node_ptr;
rec_t* right_node_ptr;
btr_cur_t node_cur;
btr_cur_t right_node_cur;
rec_t* rec;
ulint right_page_no;
ulint left_page_no;
......@@ -2996,13 +3011,16 @@ btr_validate_level(
mtr_x_lock(dict_index_get_lock(index), &mtr);
page = btr_root_get(index, &mtr);
block = btr_root_block_get(index, &mtr);
page = buf_block_get_frame(block);
space = page_get_space_id(page);
while (level != btr_page_get_level(page, &mtr)) {
rec_t* node_ptr;
#ifdef UNIV_ZIP_DEBUG
page_zip = buf_frame_get_page_zip(page);
page_zip = buf_block_get_page_zip(block);
ut_a(!page_zip || page_zip_validate(page_zip, page));
#endif /* UNIV_ZIP_DEBUG */
ut_a(!page_is_leaf(page));
......@@ -3013,7 +3031,8 @@ btr_validate_level(
node_ptr = page_cur_get_rec(&cursor);
offsets = rec_get_offsets(node_ptr, index, offsets,
ULINT_UNDEFINED, &heap);
page = btr_node_ptr_get_child(node_ptr, offsets, &mtr);
block = btr_node_ptr_get_child(node_ptr, offsets, &mtr);
page = buf_block_get_frame(block);
}
/* Now we are on the desired level. Loop through the pages on that
......@@ -3029,7 +3048,7 @@ btr_validate_level(
mtr_x_lock(dict_index_get_lock(index), &mtr);
#ifdef UNIV_ZIP_DEBUG
page_zip = buf_frame_get_page_zip(page);
page_zip = buf_block_get_page_zip(block);
ut_a(!page_zip || page_zip_validate(page_zip, page));
#endif /* UNIV_ZIP_DEBUG */
......@@ -3060,8 +3079,9 @@ btr_validate_level(
if (right_page_no != FIL_NULL) {
rec_t* right_rec;
right_page = btr_page_get(space, right_page_no, RW_X_LATCH,
&mtr);
right_block = btr_block_get(space, right_page_no, RW_X_LATCH,
&mtr);
right_page = buf_block_get_frame(right_block);
if (UNIV_UNLIKELY(btr_page_get_prev(right_page, &mtr)
!= page_get_page_no(page))) {
btr_validate_report2(index, level, page, right_page);
......@@ -3124,21 +3144,27 @@ btr_validate_level(
page_is_comp(page)));
}
if (page_get_page_no(page) != dict_index_get_page(index)) {
if (buf_block_get_page_no(block) != dict_index_get_page(index)) {
/* Check father node pointers */
node_ptr = btr_page_get_father_node_ptr(index, page, &mtr);
father_page = page_align(node_ptr);
offsets = rec_get_offsets(node_ptr, index,
offsets, ULINT_UNDEFINED, &heap);
const rec_t* node_ptr;
offsets = btr_page_get_father_block(offsets, heap, index,
block, &mtr, &node_cur);
father_page = btr_cur_get_page(&node_cur);
node_ptr = btr_cur_get_rec(&node_cur);
btr_cur_position(
index, page_rec_get_prev(page_get_supremum_rec(page)),
block, &node_cur);
offsets = btr_page_get_father_node_ptr(offsets, heap,
&node_cur, &mtr);
if (btr_node_ptr_get_child_page_no(node_ptr, offsets)
!= page_get_page_no(page)
|| node_ptr != btr_page_get_father_for_rec(
index, page,
page_rec_get_prev(page_get_supremum_rec(page)),
&mtr)) {
if (UNIV_UNLIKELY(node_ptr != btr_cur_get_rec(&node_cur))
|| UNIV_UNLIKELY(btr_node_ptr_get_child_page_no(node_ptr,
offsets)
!= buf_block_get_page_no(block))) {
btr_validate_report1(index, level, page);
......@@ -3149,19 +3175,16 @@ btr_validate_level(
buf_page_print(page, 0);
fputs("InnoDB: node ptr ", stderr);
rec_print_new(stderr, node_ptr, offsets);
rec_print(stderr, node_ptr, index);
rec = btr_cur_get_rec(&node_cur);
fprintf(stderr, "\n"
"InnoDB: node ptr child page n:o %lu\n",
(ulong) btr_node_ptr_get_child_page_no(
node_ptr, offsets));
rec, offsets));
fputs("InnoDB: record on page ", stderr);
rec = btr_page_get_father_for_rec(
index, page,
page_rec_get_prev(page_get_supremum_rec(page)),
&mtr);
rec_print(stderr, rec, index);
rec_print_new(stderr, rec, offsets);
putc('\n', stderr);
ret = FALSE;
......@@ -3169,10 +3192,6 @@ btr_validate_level(
}
if (!page_is_leaf(page)) {
offsets = rec_get_offsets(node_ptr, index,
offsets, ULINT_UNDEFINED,
&heap);
node_ptr_tuple = dict_index_build_node_ptr(
index,
page_rec_get_next(page_get_infimum_rec(page)),
......@@ -3212,13 +3231,14 @@ btr_validate_level(
page_get_supremum_rec(father_page)));
ut_a(btr_page_get_next(father_page, &mtr) == FIL_NULL);
} else {
right_node_ptr = btr_page_get_father_node_ptr(
index, right_page, &mtr);
if (page_rec_get_next(node_ptr)
offsets = btr_page_get_father_block(
offsets, heap, index, right_block,
&mtr, &right_node_cur);
if (page_rec_get_next((rec_t*) node_ptr)
!= page_get_supremum_rec(father_page)) {
if (right_node_ptr
!= page_rec_get_next(node_ptr)) {
if (btr_cur_get_rec(&right_node_cur)
!= page_rec_get_next((rec_t*) node_ptr)) {
ret = FALSE;
fputs("InnoDB: node pointer to"
" the right page is wrong\n",
......@@ -3232,9 +3252,11 @@ btr_validate_level(
buf_page_print(right_page, 0);
}
} else {
right_father_page = page_align(right_node_ptr);
page_t* right_father_page
= btr_cur_get_page(&right_node_cur);
if (right_node_ptr != page_rec_get_next(
if (btr_cur_get_rec(&right_node_cur)
!= page_rec_get_next(
page_get_infimum_rec(
right_father_page))) {
ret = FALSE;
......@@ -3280,7 +3302,8 @@ btr_validate_level(
if (right_page_no != FIL_NULL) {
mtr_start(&mtr);
page = btr_page_get(space, right_page_no, RW_X_LATCH, &mtr);
block = btr_block_get(space, right_page_no, RW_X_LATCH, &mtr);
page = buf_block_get_frame(block);
goto loop;
}
......
......@@ -532,10 +532,12 @@ btr_cur_search_to_nth_level(
page_mode = mode;
}
cursor->page_block = block;
page_cur_search_with_match(page, index, tuple, page_mode,
&up_match, &up_bytes,
&low_match, &low_bytes,
page_cursor);
if (estimate) {
btr_cur_add_path_info(cursor, height, root_height);
}
......@@ -676,6 +678,7 @@ btr_cur_open_at_index_side(
btr_page_get_index_id(page)));
block->check_index_page_at_flush = TRUE;
cursor->page_block = block;
if (height == ULINT_UNDEFINED) {
/* We are in the root node */
......@@ -705,6 +708,7 @@ btr_cur_open_at_index_side(
}
}
ut_ad(buf_block_get_frame(btr_cur_get_block(cursor)) == page);
if (from_left) {
page_cur_set_before_first(page, page_cursor);
} else {
......@@ -804,6 +808,7 @@ btr_cur_open_at_rnd_pos(
latch_mode, cursor, mtr);
}
cursor->page_block = block;
page_cur_open_on_rnd_user_rec(page, page_cursor);
if (height == 0) {
......@@ -850,14 +855,14 @@ btr_cur_insert_if_possible(
mtr_t* mtr) /* in: mtr */
{
page_cur_t* page_cursor;
page_t* page;
buf_block_t* block;
rec_t* rec;
ut_ad(dtuple_check_typed(tuple));
page = btr_cur_get_page(cursor);
block = btr_cur_get_block(cursor);
ut_ad(mtr_memo_contains_page(mtr, page, MTR_MEMO_PAGE_X_FIX));
ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX));
page_cursor = btr_cur_get_page_cur(cursor);
/* Now, try the insert */
......@@ -867,9 +872,10 @@ btr_cur_insert_if_possible(
if (UNIV_UNLIKELY(!rec)) {
/* If record did not fit, reorganize */
if (btr_page_reorganize(page, cursor->index, mtr)) {
if (btr_page_reorganize(block, cursor->index, mtr)) {
page_cur_search(page, cursor->index, tuple,
page_cur_search(buf_block_get_frame(block),
cursor->index, tuple,
PAGE_CUR_LE, page_cursor);
rec = page_cur_tuple_insert(page_cursor, page_zip,
......@@ -910,7 +916,9 @@ btr_cur_ins_lock_and_undo(
rec = btr_cur_get_rec(cursor);
index = cursor->index;
err = lock_rec_insert_check_and_lock(flags, rec, index, thr, inherit);
err = lock_rec_insert_check_and_lock(flags, rec,
btr_cur_get_block(cursor),
index, thr, inherit);
if (err != DB_SUCCESS) {
......@@ -1045,7 +1053,7 @@ btr_cur_optimistic_insert(
*big_rec = NULL;
block = buf_block_align(btr_cur_get_rec(cursor));
block = btr_cur_get_block(cursor);
page = buf_block_get_frame(block);
index = cursor->index;
page_zip = buf_block_get_page_zip(block);
......@@ -1135,7 +1143,7 @@ btr_cur_optimistic_insert(
entry, index, ext, n_ext, mtr);
if (UNIV_UNLIKELY(!(*rec))) {
/* If the record did not fit, reorganize */
if (UNIV_UNLIKELY(!btr_page_reorganize(page, index, mtr))) {
if (UNIV_UNLIKELY(!btr_page_reorganize(block, index, mtr))) {
ut_a(page_zip);
goto fail;
......@@ -1233,7 +1241,7 @@ btr_cur_pessimistic_insert(
ulint zip_size = dict_table_zip_size(index->table);
big_rec_t* big_rec_vec = NULL;
mem_heap_t* heap = NULL;
page_t* page;
buf_block_t* block;
ulint err;
ibool dummy_inh;
ibool success;
......@@ -1244,12 +1252,12 @@ btr_cur_pessimistic_insert(
*big_rec = NULL;
page = btr_cur_get_page(cursor);
block = btr_cur_get_block(cursor);
ut_ad(mtr_memo_contains(mtr,
dict_index_get_lock(btr_cur_get_index(cursor)),
MTR_MEMO_X_LOCK));
ut_ad(mtr_memo_contains_page(mtr, page, MTR_MEMO_PAGE_X_FIX));
ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX));
/* Try first an optimistic insert; reset the cursor flag: we do not
assume anything of how it was positioned */
......@@ -1291,7 +1299,8 @@ btr_cur_pessimistic_insert(
if (page_zip_rec_needs_ext(rec_get_converted_size(index, entry,
ext, n_ext),
page_is_comp(page), zip_size)) {
dict_table_is_comp(index->table),
zip_size)) {
/* The record is so big that we have to store some fields
externally on separate database pages */
......@@ -1359,7 +1368,7 @@ btr_cur_pessimistic_insert(
}
}
if (dict_index_get_page(index) == page_get_page_no(page)) {
if (dict_index_get_page(index) == buf_block_get_page_no(block)) {
/* The page is the root page */
*rec = btr_root_raise_and_insert(cursor, entry,
......@@ -1373,7 +1382,7 @@ btr_cur_pessimistic_insert(
mem_heap_free(heap);
}
btr_cur_position(index, page_rec_get_prev(*rec), cursor);
btr_cur_position(index, page_rec_get_prev(*rec), block, cursor);
#ifdef BTR_CUR_ADAPT
btr_search_update_hash_on_insert(cursor);
......@@ -1424,8 +1433,9 @@ btr_cur_upd_lock_and_undo(
if (!dict_index_is_clust(index)) {
/* We do undo logging only when we update a clustered index
record */
return(lock_sec_rec_modify_check_and_lock(flags, rec, index,
thr));
return(lock_sec_rec_modify_check_and_lock(
flags, rec, btr_cur_get_block(cursor),
index, thr));
}
/* Check if we have to wait for a lock: enqueue an explicit lock
......@@ -1628,7 +1638,7 @@ btr_cur_update_in_place(
}
#endif /* UNIV_DEBUG */
block = buf_block_align(rec);
block = btr_cur_get_block(cursor);
/* Check that enough space is available on the compressed page. */
page_zip = buf_block_get_page_zip(block);
......@@ -1728,6 +1738,7 @@ btr_cur_optimistic_update(
dict_index_t* index;
page_cur_t* page_cursor;
ulint err;
buf_block_t* block;
page_t* page;
page_zip_des_t* page_zip;
rec_t* rec;
......@@ -1742,10 +1753,12 @@ btr_cur_optimistic_update(
ulint i;
ulint* offsets;
page = btr_cur_get_page(cursor);
block = btr_cur_get_block(cursor);
page = buf_block_get_frame(block);
orig_rec = rec = btr_cur_get_rec(cursor);
index = cursor->index;
ut_ad(!!page_rec_is_comp(rec) == dict_table_is_comp(index->table));
ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX));
heap = mem_heap_create(1024);
offsets = rec_get_offsets(rec, index, NULL, ULINT_UNDEFINED, &heap);
......@@ -1757,7 +1770,6 @@ btr_cur_optimistic_update(
}
#endif /* UNIV_DEBUG */
ut_ad(mtr_memo_contains_page(mtr, page, MTR_MEMO_PAGE_X_FIX));
if (!row_upd_changes_field_size_or_external(index, offsets, update)) {
/* The simplest and the most common case: the update does not
......@@ -1798,7 +1810,7 @@ btr_cur_optimistic_update(
old_rec_size = rec_offs_size(offsets);
new_rec_size = rec_get_converted_size(index, new_entry, NULL, 0);
page_zip = buf_frame_get_page_zip(page);
page_zip = buf_block_get_page_zip(block);
#ifdef UNIV_ZIP_DEBUG
ut_a(!page_zip || page_zip_validate(page_zip, page));
#endif /* UNIV_ZIP_DEBUG */
......@@ -1975,6 +1987,7 @@ btr_cur_pessimistic_update(
big_rec_t* big_rec_vec = NULL;
big_rec_t* dummy_big_rec;
dict_index_t* index;
buf_block_t* block;
page_t* page;
page_zip_des_t* page_zip;
rec_t* rec;
......@@ -1994,14 +2007,15 @@ btr_cur_pessimistic_update(
*big_rec = NULL;
page = btr_cur_get_page(cursor);
page_zip = buf_frame_get_page_zip(page);
block = btr_cur_get_block(cursor);
page = buf_block_get_frame(block);
page_zip = buf_block_get_page_zip(block);
rec = btr_cur_get_rec(cursor);
index = cursor->index;
ut_ad(mtr_memo_contains(mtr, dict_index_get_lock(index),
MTR_MEMO_X_LOCK));
ut_ad(mtr_memo_contains_page(mtr, page, MTR_MEMO_PAGE_X_FIX));
ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX));
#ifdef UNIV_ZIP_DEBUG
ut_a(!page_zip || page_zip_validate(page_zip, page));
#endif /* UNIV_ZIP_DEBUG */
......@@ -2374,8 +2388,6 @@ btr_cur_del_mark_set_clust_rec(
ut_ad(dict_index_is_clust(index));
ut_ad(!rec_get_deleted_flag(rec, rec_offs_comp(offsets)));
page_zip = buf_frame_get_page_zip(rec);
err = lock_clust_rec_modify_check_and_lock(flags,
rec, index, offsets, thr);
......@@ -2392,12 +2404,14 @@ btr_cur_del_mark_set_clust_rec(
goto func_exit;
}
block = buf_block_align(rec);
block = btr_cur_get_block(cursor);
if (block->is_hashed) {
rw_lock_x_lock(&btr_search_latch);
}
page_zip = buf_block_get_page_zip(block);
btr_rec_set_deleted_flag(rec, page_zip, val);
trx = thr_get_trx(thr);
......@@ -2512,10 +2526,10 @@ btr_cur_del_mark_set_sec_rec(
mtr_t* mtr) /* in: mtr */
{
buf_block_t* block;
page_zip_des_t* page_zip;
rec_t* rec;
ulint err;
block = btr_cur_get_block(cursor);
rec = btr_cur_get_rec(cursor);
#ifdef UNIV_DEBUG
......@@ -2526,23 +2540,22 @@ btr_cur_del_mark_set_sec_rec(
}
#endif /* UNIV_DEBUG */
err = lock_sec_rec_modify_check_and_lock(flags, rec, cursor->index,
thr);
err = lock_sec_rec_modify_check_and_lock(flags, rec,
btr_cur_get_block(cursor),
cursor->index, thr);
if (err != DB_SUCCESS) {
return(err);
}
block = buf_block_align(rec);
ut_ad(!!page_is_comp(buf_block_get_frame(block))
ut_ad(!!page_rec_is_comp(rec)
== dict_table_is_comp(cursor->index->table));
page_zip = buf_frame_get_page_zip(rec);
if (block->is_hashed) {
rw_lock_x_lock(&btr_search_latch);
}
btr_rec_set_deleted_flag(rec, page_zip, val);
btr_rec_set_deleted_flag(rec, buf_block_get_page_zip(block), val);
if (block->is_hashed) {
rw_lock_x_unlock(&btr_search_latch);
......@@ -2566,9 +2579,6 @@ btr_cur_del_unmark_for_ibuf(
/* We do not need to reserve btr_search_latch, as the page has just
been read to the buffer pool and there cannot be a hash index to it. */
/* The insert buffer is not used on compressed pages. */
ut_ad(!buf_frame_get_page_zip(rec));
btr_rec_set_deleted_flag(rec, NULL, FALSE);
btr_cur_del_mark_set_sec_rec_log(rec, FALSE, mtr);
......@@ -2595,8 +2605,8 @@ btr_cur_compress_if_useful(
ut_ad(mtr_memo_contains(mtr,
dict_index_get_lock(btr_cur_get_index(cursor)),
MTR_MEMO_X_LOCK));
ut_ad(mtr_memo_contains_page(mtr, btr_cur_get_rec(cursor),
MTR_MEMO_PAGE_X_FIX));
ut_ad(mtr_memo_contains(mtr, btr_cur_get_block(cursor),
MTR_MEMO_PAGE_X_FIX));
return(btr_cur_compress_recommendation(cursor, mtr)
&& btr_compress(cursor, mtr));
......@@ -2627,11 +2637,11 @@ btr_cur_optimistic_delete(
ibool no_compress_needed;
*offsets_ = (sizeof offsets_) / sizeof *offsets_;
ut_ad(mtr_memo_contains_page(mtr, btr_cur_get_rec(cursor),
MTR_MEMO_PAGE_X_FIX));
ut_ad(mtr_memo_contains(mtr, btr_cur_get_block(cursor),
MTR_MEMO_PAGE_X_FIX));
/* This is intended only for leaf page deletions */
block = buf_block_align(btr_cur_get_rec(cursor));
block = btr_cur_get_block(cursor);
ut_ad(page_is_leaf(buf_block_get_frame(block)));
......@@ -2702,6 +2712,7 @@ btr_cur_pessimistic_delete(
ibool in_rollback,/* in: TRUE if called in rollback */
mtr_t* mtr) /* in: mtr */
{
buf_block_t* block;
page_t* page;
page_zip_des_t* page_zip;
dict_index_t* index;
......@@ -2715,12 +2726,13 @@ btr_cur_pessimistic_delete(
mem_heap_t* heap;
ulint* offsets;
page = btr_cur_get_page(cursor);
block = btr_cur_get_block(cursor);
page = buf_block_get_frame(block);
index = btr_cur_get_index(cursor);
ut_ad(mtr_memo_contains(mtr, dict_index_get_lock(index),
MTR_MEMO_X_LOCK));
ut_ad(mtr_memo_contains_page(mtr, page, MTR_MEMO_PAGE_X_FIX));
ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX));
if (!has_reserved_extents) {
/* First reserve enough free space for the file segments
of the index tree, so that the node pointer updates will
......@@ -2741,7 +2753,7 @@ btr_cur_pessimistic_delete(
heap = mem_heap_create(1024);
rec = btr_cur_get_rec(cursor);
page_zip = buf_frame_get_page_zip(page);
page_zip = buf_block_get_page_zip(block);
#ifdef UNIV_ZIP_DEBUG
ut_a(!page_zip || page_zip_validate(page_zip, page));
#endif /* UNIV_ZIP_DEBUG */
......@@ -2764,7 +2776,7 @@ btr_cur_pessimistic_delete(
if (UNIV_UNLIKELY(page_get_n_recs(page) < 2)
&& UNIV_UNLIKELY(dict_index_get_page(btr_cur_get_index(cursor))
!= page_get_page_no(page))) {
!= buf_block_get_page_no(block))) {
/* If there is only one record, drop the whole page in
btr_discard_page, if this is not the root page */
......@@ -2804,7 +2816,7 @@ btr_cur_pessimistic_delete(
so that it is equal to the new leftmost node pointer
on the page */
btr_node_ptr_delete(index, page, mtr);
btr_node_ptr_delete(index, block, mtr);
node_ptr = dict_index_build_node_ptr(
index, next_rec, page_get_page_no(page),
......@@ -3593,11 +3605,12 @@ btr_store_big_rec_extern_fields(
ut_ad(mtr_memo_contains_page(local_mtr, rec, MTR_MEMO_PAGE_X_FIX));
ut_a(dict_index_is_clust(index));
space_id = page_get_space_id(page_align(rec));
page_zip = buf_frame_get_page_zip(rec);
rec_block = buf_block_align(rec);
page_zip = buf_block_get_page_zip(rec_block);
ut_a(dict_table_zip_size(index->table)
== (page_zip ? page_zip->size : 0));
== buf_block_get_zip_size(rec_block));
space_id = buf_block_get_space(rec_block);
if (UNIV_LIKELY_NULL(page_zip)) {
int err;
......@@ -3685,8 +3698,8 @@ btr_store_big_rec_extern_fields(
mlog_write_ulint(
prev_page + FIL_PAGE_NEXT,
page_no, MLOG_4BYTES, &mtr);
memcpy(buf_frame_get_page_zip(
prev_page)
memcpy(buf_block_get_page_zip(
prev_block)
->data + FIL_PAGE_NEXT,
prev_page + FIL_PAGE_NEXT, 4);
} else {
......@@ -3914,14 +3927,12 @@ btr_free_externally_stored_field(
mtr_t mtr;
#ifdef UNIV_DEBUG
buf_block_t* block = buf_block_align(field_ref);
#endif /* UNIV_DEBUG */
ut_ad(mtr_memo_contains(local_mtr, dict_index_get_lock(index),
MTR_MEMO_X_LOCK));
ut_ad(mtr_memo_contains(local_mtr, block, MTR_MEMO_PAGE_X_FIX));
ut_ad(!rec || rec_offs_validate(rec, index, offsets));
#ifdef UNIV_DEBUG
if (rec) {
ulint local_len;
byte* f = rec_get_nth_field(rec, offsets, i, &local_len);
......
......@@ -75,6 +75,7 @@ btr_pcur_store_position(
mtr_t* mtr) /* in: mtr */
{
page_cur_t* page_cursor;
buf_block_t* block;
rec_t* rec;
dict_index_t* index;
page_t* page;
......@@ -83,6 +84,7 @@ btr_pcur_store_position(
ut_a(cursor->pos_state == BTR_PCUR_IS_POSITIONED);
ut_ad(cursor->latch_mode != BTR_NO_LATCHES);
block = btr_pcur_get_block(cursor);
index = btr_cur_get_index(btr_pcur_get_btr_cur(cursor));
page_cursor = btr_pcur_get_page_cur(cursor);
......@@ -91,8 +93,8 @@ btr_pcur_store_position(
page = page_align(rec);
offs = page_offset(rec);
ut_ad(mtr_memo_contains_page(mtr, page, MTR_MEMO_PAGE_S_FIX)
|| mtr_memo_contains_page(mtr, page, MTR_MEMO_PAGE_X_FIX));
ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_S_FIX)
|| mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX));
ut_a(cursor->latch_mode != BTR_NO_LATCHES);
if (UNIV_UNLIKELY(page_get_n_recs(page) == 0)) {
......@@ -135,9 +137,8 @@ btr_pcur_store_position(
index, rec, &cursor->old_n_fields,
&cursor->old_rec_buf, &cursor->buf_size);
cursor->block_when_stored = buf_block_align(page);
cursor->modify_clock = buf_block_get_modify_clock(
cursor->block_when_stored);
cursor->block_when_stored = block;
cursor->modify_clock = buf_block_get_modify_clock(block);
}
/******************************************************************
......@@ -215,9 +216,9 @@ btr_pcur_restore_position(
ut_error;
}
if (UNIV_UNLIKELY(
cursor->rel_pos == BTR_PCUR_AFTER_LAST_IN_TREE
|| cursor->rel_pos == BTR_PCUR_BEFORE_FIRST_IN_TREE)) {
if (UNIV_UNLIKELY
(cursor->rel_pos == BTR_PCUR_AFTER_LAST_IN_TREE
|| cursor->rel_pos == BTR_PCUR_BEFORE_FIRST_IN_TREE)) {
/* In these cases we do not try an optimistic restoration,
but always do a search */
......@@ -226,8 +227,7 @@ btr_pcur_restore_position(
cursor->rel_pos == BTR_PCUR_BEFORE_FIRST_IN_TREE,
index, latch_mode, btr_pcur_get_btr_cur(cursor), mtr);
cursor->block_when_stored
= buf_block_align(btr_pcur_get_page(cursor));
cursor->block_when_stored = btr_pcur_get_block(cursor);
return(FALSE);
}
......@@ -235,7 +235,7 @@ btr_pcur_restore_position(
ut_a(cursor->old_rec);
ut_a(cursor->old_n_fields);
page = btr_cur_get_page(btr_pcur_get_btr_cur(cursor));
page = btr_pcur_get_page(cursor);
if (UNIV_LIKELY(latch_mode == BTR_SEARCH_LEAF)
|| UNIV_LIKELY(latch_mode == BTR_MODIFY_LEAF)) {
......@@ -247,7 +247,7 @@ btr_pcur_restore_position(
cursor->modify_clock, mtr))) {
cursor->pos_state = BTR_PCUR_IS_POSITIONED;
#ifdef UNIV_SYNC_DEBUG
buf_block_dbg_add_level(buf_block_align(page),
buf_block_dbg_add_level(btr_pcur_get_block(cursor),
SYNC_TREE_NODE);
#endif /* UNIV_SYNC_DEBUG */
if (cursor->rel_pos == BTR_PCUR_ON) {
......@@ -316,8 +316,7 @@ btr_pcur_restore_position(
the cursor can now be on a different page! But we can retain
the value of old_rec */
cursor->block_when_stored = buf_block_align(
btr_pcur_get_page(cursor));
cursor->block_when_stored = btr_pcur_get_block(cursor);
cursor->modify_clock = buf_block_get_modify_clock(
cursor->block_when_stored);
cursor->old_stored = BTR_PCUR_OLD_STORED;
......@@ -356,7 +355,7 @@ btr_pcur_release_leaf(
ut_a(cursor->pos_state == BTR_PCUR_IS_POSITIONED);
ut_ad(cursor->latch_mode != BTR_NO_LATCHES);
block = buf_block_align(btr_cur_get_rec(btr_pcur_get_btr_cur(cursor)));
block = btr_pcur_get_block(cursor);
btr_leaf_page_release(block, cursor->latch_mode, mtr);
......@@ -391,9 +390,8 @@ btr_pcur_move_to_next_page(
cursor->old_stored = BTR_PCUR_OLD_NOT_STORED;
page = btr_pcur_get_page(cursor);
next_page_no = btr_page_get_next(page, mtr);
space = page_get_space_id(page);
space = buf_block_get_space(btr_pcur_get_block(cursor));
ut_ad(next_page_no != FIL_NULL);
......@@ -402,12 +400,15 @@ btr_pcur_move_to_next_page(
next_page = buf_block_get_frame(next_block);
#ifdef UNIV_BTR_DEBUG
ut_a(page_is_comp(next_page) == page_is_comp(page));
ut_a(btr_page_get_prev(next_page, mtr) == page_get_page_no(page));
ut_a(btr_page_get_prev(next_page, mtr)
== buf_block_get_page_no(btr_pcur_get_block(cursor)));
#endif /* UNIV_BTR_DEBUG */
next_block->check_index_page_at_flush = TRUE;
btr_leaf_page_release(buf_block_align(page), cursor->latch_mode, mtr);
btr_leaf_page_release(btr_pcur_get_block(cursor),
cursor->latch_mode, mtr);
btr_pcur_get_btr_cur(cursor)->page_block = next_block;
page_cur_set_before_first(next_page, btr_pcur_get_page_cur(cursor));
page_check_dir(next_page);
......@@ -467,18 +468,21 @@ btr_pcur_move_backward_from_page(
page = btr_pcur_get_page(cursor);
prev_page_no = btr_page_get_prev(page, mtr);
space = page_get_space_id(page);
space = buf_block_get_space(btr_pcur_get_block(cursor));
if (btr_pcur_is_before_first_on_page(cursor, mtr)
&& (prev_page_no != FIL_NULL)) {
if (prev_page_no == FIL_NULL) {
} else if (btr_pcur_is_before_first_on_page(cursor, mtr)) {
prev_page = btr_pcur_get_btr_cur(cursor)->left_page;
btr_leaf_page_release(buf_block_align(page), latch_mode, mtr);
btr_leaf_page_release(btr_pcur_get_block(cursor),
latch_mode, mtr);
btr_pcur_get_btr_cur(cursor)->page_block
= buf_block_align(prev_page);
page_cur_set_after_last(prev_page,
btr_pcur_get_page_cur(cursor));
} else if (prev_page_no != FIL_NULL) {
} else {
/* The repositioned cursor did not end on an infimum record on
a page. Cursor repositioning acquired a latch also on the
......
......@@ -464,7 +464,7 @@ btr_search_info_update_slow(
ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_EX));
#endif /* UNIV_SYNC_DEBUG */
block = buf_block_align(btr_cur_get_rec(cursor));
block = btr_cur_get_block(cursor);
/* NOTE that the following two function calls do NOT protect
info or block->n_fields etc. with any semaphore, to save CPU time!
......@@ -789,7 +789,7 @@ btr_search_guess_on_hash(
ut_ad(block->state == BUF_BLOCK_FILE_PAGE);
ut_ad(page_rec_is_user_rec(rec));
btr_cur_position(index, rec, cursor);
btr_cur_position(index, rec, block, cursor);
/* Check the validity of the guess within the page */
......
......@@ -2875,14 +2875,14 @@ void
ibuf_insert_to_index_page(
/*======================*/
dtuple_t* entry, /* in: buffered entry to insert */
page_t* page, /* in/out: index page where the buffered entry
buf_block_t* block, /* in/out: index page where the buffered entry
should be placed */
page_zip_des_t* page_zip,/* in/out: compressed page, or NULL */
dict_index_t* index, /* in: record descriptor */
mtr_t* mtr) /* in: mtr */
{
page_cur_t page_cur;
ulint low_match;
page_t* page = buf_block_get_frame(block);
rec_t* rec;
page_t* bitmap_page;
ulint old_bits;
......@@ -2931,21 +2931,23 @@ ibuf_insert_to_index_page(
btr_cur_del_unmark_for_ibuf(rec, mtr);
} else {
rec = page_cur_tuple_insert(&page_cur, page_zip,
rec = page_cur_tuple_insert(&page_cur,
buf_block_get_page_zip(block),
entry, index, NULL, 0, mtr);
if (UNIV_UNLIKELY(rec == NULL)) {
/* If the record did not fit, reorganize */
btr_page_reorganize(page, index, mtr);
btr_page_reorganize(block, index, mtr);
page_cur_search(page, index, entry,
PAGE_CUR_LE, &page_cur);
/* This time the record must fit */
if (UNIV_UNLIKELY
(!page_cur_tuple_insert(&page_cur, page_zip, entry,
index, NULL, 0, mtr))) {
(!page_cur_tuple_insert(
&page_cur, buf_block_get_page_zip(block),
entry, index, NULL, 0, mtr))) {
ulint space;
ulint page_no;
......@@ -3345,7 +3347,7 @@ ibuf_merge_or_delete_for_page(
ut_a(volume <= 4 * UNIV_PAGE_SIZE
/ IBUF_PAGE_SIZE_PER_FREE_SPACE);
#endif
ibuf_insert_to_index_page(entry, page, page_zip,
ibuf_insert_to_index_page(entry, block,
dummy_index, &mtr);
ibuf_dummy_index_free(dummy_index);
}
......
......@@ -156,7 +156,7 @@ ulint
btr_node_ptr_get_child_page_no(
/*===========================*/
/* out: child node address */
rec_t* rec, /* in: node pointer record */
const rec_t* rec, /* in: node pointer record */
const ulint* offsets);/* in: array returned by rec_get_offsets() */
/****************************************************************
Creates the root node for a new index tree. */
......@@ -216,7 +216,7 @@ ibool
btr_page_reorganize(
/*================*/
/* out: TRUE on success, FALSE on failure */
page_t* page, /* in: page to be reorganized */
buf_block_t* block, /* in: page to be reorganized */
dict_index_t* index, /* in: record descriptor */
mtr_t* mtr); /* in: mtr */
/*****************************************************************
......@@ -290,7 +290,7 @@ void
btr_node_ptr_delete(
/*================*/
dict_index_t* index, /* in: index tree */
page_t* page, /* in: page whose node pointer is deleted */
buf_block_t* block, /* in: page whose node pointer is deleted */
mtr_t* mtr); /* in: mtr */
#ifdef UNIV_DEBUG
/****************************************************************
......@@ -357,8 +357,7 @@ btr_parse_page_reorganize(
byte* ptr, /* in: buffer */
byte* end_ptr,/* in: buffer end */
dict_index_t* index, /* in: record descriptor */
page_t* page, /* in/out: page to be reorganized, or NULL */
page_zip_des_t* page_zip,/* in/out: compressed page, or NULL */
buf_block_t* block, /* in: page to be reorganized, or NULL */
mtr_t* mtr); /* in: mtr or NULL */
/******************************************************************
Gets the number of pages in a B-tree. */
......
......@@ -229,17 +229,17 @@ ulint
btr_node_ptr_get_child_page_no(
/*===========================*/
/* out: child node address */
rec_t* rec, /* in: node pointer record */
const rec_t* rec, /* in: node pointer record */
const ulint* offsets)/* in: array returned by rec_get_offsets() */
{
byte* field;
ulint len;
ulint page_no;
const byte* field;
ulint len;
ulint page_no;
ut_ad(!rec_offs_comp(offsets) || rec_get_node_ptr_flag(rec));
/* The child address is in the last field */
field = rec_get_nth_field(rec, offsets,
field = rec_get_nth_field((rec_t*) rec, offsets,
rec_offs_n_fields(offsets) - 1, &len);
ut_ad(len == 4);
......@@ -251,7 +251,7 @@ btr_node_ptr_get_child_page_no(
"InnoDB: a nonsensical page number 0"
" in a node ptr record at offset %lu\n",
(ulong) page_offset(rec));
buf_page_print(page_align(rec), 0);
buf_page_print(page_align((rec_t*) rec), 0);
}
return(page_no);
......
......@@ -36,6 +36,14 @@ btr_cur_get_page_cur(
/* out: pointer to page cursor component */
btr_cur_t* cursor);/* in: tree cursor */
/*************************************************************
Returns the buffer block on which the tree cursor is positioned. */
UNIV_INLINE
buf_block_t*
btr_cur_get_block(
/*==============*/
/* out: pointer to buffer block */
btr_cur_t* cursor);/* in: tree cursor */
/*************************************************************
Returns the record pointer of a tree cursor. */
UNIV_INLINE
rec_t*
......@@ -44,6 +52,15 @@ btr_cur_get_rec(
/* out: pointer to record */
btr_cur_t* cursor);/* in: tree cursor */
/*************************************************************
Returns the compressed page on which the tree cursor is positioned. */
UNIV_INLINE
page_zip_des_t*
btr_cur_get_page_zip(
/*=================*/
/* out: pointer to compressed page,
or NULL if the page is not compressed */
btr_cur_t* cursor);/* in: tree cursor */
/*************************************************************
Invalidates a tree cursor by setting record pointer to NULL. */
UNIV_INLINE
void
......@@ -74,6 +91,7 @@ btr_cur_position(
/*=============*/
dict_index_t* index, /* in: index */
rec_t* rec, /* in: record in tree */
buf_block_t* block, /* in: buffer block of rec */
btr_cur_t* cursor);/* in: cursor */
/************************************************************************
Searches an index tree and positions a tree cursor on a given level.
......@@ -577,6 +595,9 @@ to know struct size! */
struct btr_cur_struct {
dict_index_t* index; /* index where positioned */
page_cur_t page_cur; /* page cursor */
buf_block_t* page_block; /* buffer pool block were
cursor is positioned; needed
to avoid buf_block_align() */
page_t* left_page; /* this field is used to store
a pointer to the left neighbor
page, in the cases
......
......@@ -19,6 +19,18 @@ btr_cur_get_page_cur(
{
return(&(cursor->page_cur));
}
/*************************************************************
Returns the buffer block on which the tree cursor is positioned. */
UNIV_INLINE
buf_block_t*
btr_cur_get_block(
/*==============*/
/* out: pointer to buffer block */
btr_cur_t* cursor) /* in: tree cursor */
{
ut_ad(page_align(cursor->page_cur.rec) == cursor->page_block->frame);
return(cursor->page_block);
}
/*************************************************************
Returns the record pointer of a tree cursor. */
......@@ -29,9 +41,23 @@ btr_cur_get_rec(
/* out: pointer to record */
btr_cur_t* cursor) /* in: tree cursor */
{
ut_ad(page_align(cursor->page_cur.rec) == cursor->page_block->frame);
return(page_cur_get_rec(&(cursor->page_cur)));
}
/*************************************************************
Returns the compressed page on which the tree cursor is positioned. */
UNIV_INLINE
page_zip_des_t*
btr_cur_get_page_zip(
/*=================*/
/* out: pointer to compressed page,
or NULL if the page is not compressed */
btr_cur_t* cursor) /* in: tree cursor */
{
return(buf_block_get_page_zip(btr_cur_get_block(cursor)));
}
/*************************************************************
Invalidates a tree cursor by setting record pointer to NULL. */
UNIV_INLINE
......@@ -41,6 +67,7 @@ btr_cur_invalidate(
btr_cur_t* cursor) /* in: tree cursor */
{
page_cur_invalidate(&(cursor->page_cur));
cursor->page_block = NULL;
}
/*************************************************************
......@@ -75,9 +102,13 @@ btr_cur_position(
/*=============*/
dict_index_t* index, /* in: index */
rec_t* rec, /* in: record in tree */
btr_cur_t* cursor) /* in: cursor */
buf_block_t* block, /* in: buffer block of rec */
btr_cur_t* cursor) /* out: cursor */
{
ut_ad(page_align(rec) == buf_block_get_frame(block));
page_cur_position(rec, btr_cur_get_page_cur(cursor));
cursor->page_block = block;
cursor->index = index;
}
......
......@@ -371,6 +371,14 @@ btr_pcur_get_page(
/* out: pointer to the page */
btr_pcur_t* cursor);/* in: persistent cursor */
/*************************************************************
Returns the buffer block of a persistent cursor. */
UNIV_INLINE
buf_block_t*
btr_pcur_get_block(
/*===============*/
/* out: pointer to the block */
btr_pcur_t* cursor);/* in: persistent cursor */
/*************************************************************
Returns the record of a persistent cursor. */
UNIV_INLINE
rec_t*
......
......@@ -88,7 +88,21 @@ btr_pcur_get_page(
{
ut_ad(cursor->pos_state == BTR_PCUR_IS_POSITIONED);
return(page_cur_get_page(btr_pcur_get_page_cur(cursor)));
return(btr_cur_get_page(btr_pcur_get_btr_cur(cursor)));
}
/*************************************************************
Returns the buffer block of a persistent cursor. */
UNIV_INLINE
buf_block_t*
btr_pcur_get_block(
/*===============*/
/* out: pointer to the block */
btr_pcur_t* cursor) /* in: persistent cursor */
{
ut_ad(cursor->pos_state == BTR_PCUR_IS_POSITIONED);
return(btr_cur_get_block(btr_pcur_get_btr_cur(cursor)));
}
/*************************************************************
......@@ -103,7 +117,7 @@ btr_pcur_get_rec(
ut_ad(cursor->pos_state == BTR_PCUR_IS_POSITIONED);
ut_ad(cursor->latch_mode != BTR_NO_LATCHES);
return(page_cur_get_rec(btr_pcur_get_page_cur(cursor)));
return(btr_cur_get_rec(btr_pcur_get_btr_cur(cursor)));
}
/******************************************************************
......@@ -296,7 +310,7 @@ btr_pcur_move_to_last_on_page(
UT_NOT_USED(mtr);
ut_ad(cursor->latch_mode != BTR_NO_LATCHES);
page_cur_set_after_last(page_align(btr_pcur_get_rec(cursor)),
page_cur_set_after_last(btr_pcur_get_page(cursor),
btr_pcur_get_page_cur(cursor));
cursor->old_stored = BTR_PCUR_OLD_NOT_STORED;
......@@ -619,6 +633,7 @@ btr_pcur_close(
cursor->old_rec_buf = NULL;
}
cursor->btr_cur.page_block = NULL;
cursor->btr_cur.page_cur.rec = NULL;
cursor->old_rec = NULL;
cursor->old_stored = BTR_PCUR_OLD_NOT_STORED;
......
......@@ -132,9 +132,9 @@ UNIV_INLINE
byte*
buf_frame_copy(
/*===========*/
/* out: buf */
byte* buf, /* in: buffer to copy to */
buf_frame_t* frame); /* in: buffer frame */
/* out: buf */
byte* buf, /* in: buffer to copy to */
const buf_frame_t* frame); /* in: buffer frame */
/******************************************************************
NOTE! The following macros should be used instead of buf_page_get_gen,
to improve debugging. Only values RW_S_LATCH and RW_X_LATCH are allowed
......@@ -618,6 +618,7 @@ buf_block_align(
/*============*/
/* out: pointer to block */
byte* ptr); /* in: pointer to a frame */
#if defined UNIV_DEBUG || defined UNIV_ZIP_DEBUG
/*************************************************************************
Gets the compressed page descriptor corresponding to an uncompressed page
if applicable. */
......@@ -628,6 +629,7 @@ buf_frame_get_page_zip(
/* out: compressed page descriptor, or NULL */
byte* ptr) /* in: pointer to the page */
__attribute((const));
#endif /* UNIV_DEBUG || UNIV_ZIP_DEBUG */
/************************************************************************
This function is used to get info if there is an io operation
going on on a buffer page. */
......
......@@ -261,6 +261,7 @@ buf_block_align(
return(block);
}
#if defined UNIV_DEBUG || defined UNIV_ZIP_DEBUG
/*************************************************************************
Gets the compressed page descriptor corresponding to an uncompressed page
if applicable. */
......@@ -273,6 +274,7 @@ buf_frame_get_page_zip(
{
return(buf_block_get_page_zip(buf_block_align(ptr)));
}
#endif /* UNIV_DEBUG || UNIV_ZIP_DEBUG */
/**************************************************************************
Gets the space id, page offset, and byte offset within page of a
......@@ -286,7 +288,7 @@ buf_ptr_get_fsp_addr(
fil_addr_t* addr) /* out: page offset and byte offset */
{
const page_t* page = ut_align_down((void*) ptr, UNIV_PAGE_SIZE);
ut_ad(buf_block_align(ptr));
ut_ad(buf_block_align((byte*) ptr));
*space = mach_read_from_4(page + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID);
addr->page = mach_read_from_4(page + FIL_PAGE_OFFSET);
......@@ -361,9 +363,9 @@ UNIV_INLINE
byte*
buf_frame_copy(
/*===========*/
/* out: buf */
byte* buf, /* in: buffer to copy to */
buf_frame_t* frame) /* in: buffer frame */
/* out: buf */
byte* buf, /* in: buffer to copy to */
const buf_frame_t* frame) /* in: buffer frame */
{
ut_ad(buf && frame);
......
......@@ -10,6 +10,7 @@ Created 5/7/1996 Heikki Tuuri
#define lock0lock_h
#include "univ.i"
#include "buf0types.h"
#include "trx0types.h"
#include "rem0types.h"
#include "dict0types.h"
......@@ -250,6 +251,7 @@ lock_rec_insert_check_and_lock(
ulint flags, /* in: if BTR_NO_LOCKING_FLAG bit is set,
does nothing */
rec_t* rec, /* in: record after which to insert */
buf_block_t* block, /* in: buffer block of rec */
dict_index_t* index, /* in: index */
que_thr_t* thr, /* in: query thread */
ibool* inherit);/* out: set to TRUE if the new inserted
......@@ -289,6 +291,7 @@ lock_sec_rec_modify_check_and_lock(
NOTE: as this is a secondary index, we
always have to modify the clustered index
record first: see the comment below */
buf_block_t* block, /* in: buffer block of rec */
dict_index_t* index, /* in: secondary index */
que_thr_t* thr); /* in: query thread */
/*************************************************************************
......
......@@ -698,12 +698,11 @@ page_copy_rec_list_end(
on new_page, or NULL on zip overflow
(new_page will be decompressed
from new_page_zip) */
page_t* new_page, /* in/out: index page to copy to */
page_zip_des_t* new_page_zip, /* in/out: compressed page, or NULL */
buf_block_t* new_block, /* in/out: index page to copy to */
rec_t* rec, /* in: record on page */
dict_index_t* index, /* in: record descriptor */
mtr_t* mtr) /* in: mtr */
__attribute__((warn_unused_result, nonnull(1, 3, 4, 5)));
__attribute__((warn_unused_result, nonnull));
/*****************************************************************
Copies records from page to new_page, up to the given record, NOT
including that record. Infimum and supremum records are not copied.
......@@ -717,12 +716,11 @@ page_copy_rec_list_start(
on new_page, or NULL on zip overflow
(new_page will be decompressed
from new_page_zip) */
page_t* new_page, /* in/out: index page to copy to */
page_zip_des_t* new_page_zip, /* in/out: compressed page, or NULL */
buf_block_t* new_block, /* in/out: index page to copy to */
rec_t* rec, /* in: record on page */
dict_index_t* index, /* in: record descriptor */
mtr_t* mtr) /* in: mtr */
__attribute__((warn_unused_result, nonnull(1, 3, 4, 5)));
__attribute__((warn_unused_result, nonnull));
/*****************************************************************
Deletes records from a page from a given record onward, including that record.
The infimum and supremum records are not deleted. */
......@@ -762,15 +760,13 @@ page_move_rec_list_end(
/* out: TRUE on success; FALSE on
compression failure (new_page will
be decompressed from new_page_zip) */
page_t* new_page, /* in: index page where to move */
page_zip_des_t* new_page_zip, /* in/out: compressed page of
new_page, or NULL */
buf_block_t* new_block, /* in/out: index page where to move */
rec_t* split_rec, /* in: first record to move */
page_zip_des_t* page_zip, /* in/out: compressed page of
split_rec, or NULL */
dict_index_t* index, /* in: record descriptor */
mtr_t* mtr) /* in: mtr */
__attribute__((nonnull(1, 3, 5, 6)));
__attribute__((nonnull(1, 2, 4, 5)));
/*****************************************************************
Moves record list start to another page. Moved records do not include
split_rec. */
......@@ -780,15 +776,13 @@ page_move_rec_list_start(
/*=====================*/
/* out: TRUE on success; FALSE on
compression failure */
page_t* new_page, /* in: index page where to move */
page_zip_des_t* new_page_zip, /* in/out: compressed page of
new_page, or NULL */
buf_block_t* new_block, /* in/out: index page where to move */
rec_t* split_rec, /* in: first record not to move */
page_zip_des_t* page_zip, /* in/out: compressed page of
split_rec, or NULL */
dict_index_t* index, /* in: record descriptor */
mtr_t* mtr) /* in: mtr */
__attribute__((nonnull(1, 3, 5, 6)));
__attribute__((nonnull(1, 2, 4, 5)));
/********************************************************************
Splits a directory slot which owns too many records. */
......
......@@ -16,6 +16,7 @@ Created June 2005 by Marko Makela
#include "mtr0types.h"
#include "page0types.h"
#include "buf0types.h"
#include "dict0types.h"
#include "ut0byte.h"
......@@ -335,9 +336,9 @@ page_zip_reorganize(
/* out: TRUE on success, FALSE on failure;
page and page_zip will be left intact
on failure. */
page_zip_des_t* page_zip,/* in: size; out: data, n_blobs,
m_start, m_end */
page_t* page, /* in/out: uncompressed page */
buf_block_t* block, /* in/out: page with compressed page;
on the compressed page, in: size;
out: data, n_blobs, m_start, m_end */
dict_index_t* index, /* in: index of the B-tree node */
mtr_t* mtr) /* in: mini-transaction */
__attribute__((warn_unused_result, nonnull));
......
......@@ -4926,6 +4926,7 @@ lock_rec_insert_check_and_lock(
ulint flags, /* in: if BTR_NO_LOCKING_FLAG bit is set,
does nothing */
rec_t* rec, /* in: record after which to insert */
buf_block_t* block, /* in: buffer block of rec */
dict_index_t* index, /* in: index */
que_thr_t* thr, /* in: query thread */
ibool* inherit)/* out: set to TRUE if the new inserted
......@@ -4968,7 +4969,7 @@ lock_rec_insert_check_and_lock(
if (!dict_index_is_clust(index)) {
/* Update the page max trx id field */
page_update_max_trx_id(page_align(rec),
buf_frame_get_page_zip(rec),
buf_block_get_page_zip(block),
thr_get_trx(thr)->id);
}
......@@ -5006,7 +5007,7 @@ lock_rec_insert_check_and_lock(
if ((err == DB_SUCCESS) && !dict_index_is_clust(index)) {
/* Update the page max trx id field */
page_update_max_trx_id(page_align(rec),
buf_frame_get_page_zip(rec),
buf_block_get_page_zip(block),
thr_get_trx(thr)->id);
}
......@@ -5142,6 +5143,7 @@ lock_sec_rec_modify_check_and_lock(
NOTE: as this is a secondary index, we
always have to modify the clustered index
record first: see the comment below */
buf_block_t* block, /* in: buffer block of rec */
dict_index_t* index, /* in: secondary index */
que_thr_t* thr) /* in: query thread */
{
......@@ -5186,7 +5188,7 @@ lock_sec_rec_modify_check_and_lock(
if (err == DB_SUCCESS) {
/* Update the page max trx id field */
page_update_max_trx_id(page_align(rec),
buf_frame_get_page_zip(rec),
buf_block_get_page_zip(block),
thr_get_trx(thr)->id);
}
......
......@@ -881,7 +881,7 @@ recv_parse_or_apply_log_rec_body(
|| (ibool)!!page_is_comp(page)
== dict_table_is_comp(index->table));
ptr = btr_parse_page_reorganize(ptr, end_ptr, index,
page, page_zip, mtr);
block, mtr);
}
break;
case MLOG_PAGE_CREATE: case MLOG_COMP_PAGE_CREATE:
......
......@@ -1130,11 +1130,14 @@ page_cur_insert_rec_low(
(!page_zip_compress(page_zip_orig, page, index, mtr))) {
/* Before trying to reorganize the page,
store the number of preceding records on the page. */
ulint insert_pos
ulint insert_pos
= page_rec_get_n_recs_before(insert_rec);
buf_block_t* block
= buf_block_align(page);
if (page_zip_reorganize(page_zip_orig, page,
index, mtr)) {
ut_ad(buf_block_get_page_zip(block) == page_zip_orig);
if (page_zip_reorganize(block, index, mtr)) {
/* The page was reorganized:
Seek to insert_pos to find insert_rec. */
insert_rec = page + PAGE_NEW_INFIMUM;
......
......@@ -579,15 +579,17 @@ page_copy_rec_list_end(
on new_page, or NULL on zip overflow
(new_page will be decompressed
from new_page_zip) */
page_t* new_page, /* in/out: index page to copy to */
page_zip_des_t* new_page_zip, /* in/out: compressed page, or NULL */
buf_block_t* new_block, /* in/out: index page to copy to */
rec_t* rec, /* in: record on page */
dict_index_t* index, /* in: record descriptor */
mtr_t* mtr) /* in: mtr */
{
page_t* page = page_align(rec);
rec_t* ret = page_rec_get_next(page_get_infimum_rec(new_page));
ulint log_mode= 0; /* remove warning */
page_t* new_page = buf_block_get_frame(new_block);
page_zip_des_t* new_page_zip = buf_block_get_page_zip(new_block);
page_t* page = page_align(rec);
rec_t* ret = page_rec_get_next(
page_get_infimum_rec(new_page));
ulint log_mode = 0; /* remove warning */
/* page_zip_validate() will fail here if btr_compress()
sets FIL_PAGE_PREV to FIL_NULL */
......@@ -616,8 +618,7 @@ page_copy_rec_list_end(
= page_rec_get_n_recs_before(ret);
if (UNIV_UNLIKELY
(!page_zip_reorganize(new_page_zip, new_page,
index, mtr))) {
(!page_zip_reorganize(new_block, index, mtr))) {
if (UNIV_UNLIKELY
(!page_zip_decompress(new_page_zip,
......@@ -663,12 +664,13 @@ page_copy_rec_list_start(
on new_page, or NULL on zip overflow
(new_page will be decompressed
from new_page_zip) */
page_t* new_page, /* in/out: index page to copy to */
page_zip_des_t* new_page_zip, /* in/out: compressed page, or NULL */
buf_block_t* new_block, /* in/out: index page to copy to */
rec_t* rec, /* in: record on page */
dict_index_t* index, /* in: record descriptor */
mtr_t* mtr) /* in: mtr */
{
page_t* new_page = buf_block_get_frame(new_block);
page_zip_des_t* new_page_zip = buf_block_get_page_zip(new_block);
page_cur_t cur1;
page_cur_t cur2;
page_t* page;
......@@ -726,8 +728,7 @@ page_copy_rec_list_start(
= page_rec_get_n_recs_before(ret);
if (UNIV_UNLIKELY
(!page_zip_reorganize(new_page_zip, new_page,
index, mtr))) {
(!page_zip_reorganize(new_block, index, mtr))) {
if (UNIV_UNLIKELY
(!page_zip_decompress(new_page_zip,
......@@ -1090,19 +1091,21 @@ page_move_rec_list_end(
/* out: TRUE on success; FALSE on
compression failure (new_page will
be decompressed from new_page_zip) */
page_t* new_page, /* in: index page where to move */
page_zip_des_t* new_page_zip, /* in/out: compressed page of
new_page, or NULL */
buf_block_t* new_block, /* in/out: index page where to move */
rec_t* split_rec, /* in: first record to move */
page_zip_des_t* page_zip, /* in/out: compressed page of
split_rec, or NULL */
dict_index_t* index, /* in: record descriptor */
mtr_t* mtr) /* in: mtr */
{
ulint old_data_size;
ulint new_data_size;
ulint old_n_recs;
ulint new_n_recs;
page_t* new_page = buf_block_get_frame(new_block);
#ifdef UNIV_ZIP_DEBUG
page_zip_des_t* new_page_zip = buf_block_get_page_zip(new_block);
#endif /* UNIV_ZIP_DEBUG */
ulint old_data_size;
ulint new_data_size;
ulint old_n_recs;
ulint new_n_recs;
old_data_size = page_get_data_size(new_page);
old_n_recs = page_get_n_recs(new_page);
......@@ -1111,8 +1114,8 @@ page_move_rec_list_end(
ut_a(!page_zip || page_zip_validate(page_zip, page_align(split_rec)));
#endif /* UNIV_ZIP_DEBUG */
if (UNIV_UNLIKELY(!page_copy_rec_list_end(new_page, new_page_zip,
split_rec, index, mtr))) {
if (UNIV_UNLIKELY(!page_copy_rec_list_end(new_block, split_rec,
index, mtr))) {
return(FALSE);
}
......@@ -1138,17 +1141,15 @@ page_move_rec_list_start(
/*=====================*/
/* out: TRUE on success; FALSE on
compression failure */
page_t* new_page, /* in: index page where to move */
page_zip_des_t* new_page_zip, /* in/out: compressed page of
new_page, or NULL */
buf_block_t* new_block, /* in/out: index page where to move */
rec_t* split_rec, /* in: first record not to move */
page_zip_des_t* page_zip, /* in/out: compressed page of
split_rec, or NULL */
dict_index_t* index, /* in: record descriptor */
mtr_t* mtr) /* in: mtr */
{
if (UNIV_UNLIKELY(!page_copy_rec_list_start(new_page, new_page_zip,
split_rec, index, mtr))) {
if (UNIV_UNLIKELY(!page_copy_rec_list_start(new_block, split_rec,
index, mtr))) {
return(FALSE);
}
......
......@@ -3504,13 +3504,14 @@ page_zip_reorganize(
/* out: TRUE on success, FALSE on failure;
page and page_zip will be left intact
on failure. */
page_zip_des_t* page_zip,/* in: size; out: data, n_blobs,
m_start, m_end */
page_t* page, /* in/out: uncompressed page */
buf_block_t* block, /* in/out: page with compressed page;
on the compressed page, in: size;
out: data, n_blobs, m_start, m_end */
dict_index_t* index, /* in: index of the B-tree node */
mtr_t* mtr) /* in: mini-transaction */
{
buf_block_t* block;
page_zip_des_t* page_zip = buf_block_get_page_zip(block);
page_t* page = buf_block_get_frame(block);
buf_block_t* temp_block;
page_t* temp_page;
ulint log_mode;
......@@ -3531,7 +3532,6 @@ page_zip_reorganize(
/* Recreate the page: note that global data on page (possible
segment headers, next page-field, etc.) is preserved intact */
block = buf_block_align(page);
page_create(block, mtr, dict_table_is_comp(index->table));
block->check_index_page_at_flush = TRUE;
......
......@@ -2084,7 +2084,8 @@ row_ins_index_entry_low(
if (modify == ROW_INS_NEXT) {
rec = page_rec_get_next(btr_cur_get_rec(&cursor));
btr_cur_position(index, rec, &cursor);
btr_cur_position(index, rec,
btr_cur_get_block(&cursor),&cursor);
}
if (dict_index_is_clust(index)) {
......
......@@ -3793,7 +3793,9 @@ row_search_for_mysql(
" buf block fix count %lu\n",
(void*) rec, (void*) buf_pool->frame_zero,
(void*) buf_pool->high_end,
(ulong)buf_block_align(rec)->buf_fix_count);
(ulong)
btr_cur_get_block(btr_pcur_get_btr_cur(pcur))
->buf_fix_count);
fprintf(stderr,
"InnoDB: Index corruption: rec offs %lu"
" next offs %lu, page no %lu,\n"
......
......@@ -1470,7 +1470,7 @@ row_upd_clust_rec_by_insert(
index = dict_table_get_first_index(table);
btr_cur_mark_extern_inherited_fields(
buf_frame_get_page_zip(rec),
btr_cur_get_page_zip(btr_cur),
rec, index,
rec_get_offsets(rec, index, offsets_,
ULINT_UNDEFINED, &heap),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment