Commit d9d61e92 authored by Marko Mäkelä's avatar Marko Mäkelä

btr_page_split_and_insert(): Avoid an infinite loop. (Bug #52964)

btr_page_tuple_smaller(): New function, refactored from
btr_page_split_and_insert().

btr_page_get_split_rec(): Renamed from btr_page_get_sure_split_rec().
Note that a NULL return may mean that the tuple is to be inserted into
either the lower or upper page, to be determined by btr_page_tuple_smaller().

btr_page_split_and_insert(): When btr_page_get_split_rec() returns NULL,
invoke btr_page_tuple_smaller() to determine which half-page the tuple
belongs to.

Reviewed by Sunny Bains
parent c129f738
2010-04-21 The InnoDB Team
* btr/btr0btr.c:
Fix Bug#52964 Infinite loop in btr_page_split_and_insert()
in ROW_FORMAT=COMPRESSED
2010-04-21 The InnoDB Team 2010-04-21 The InnoDB Team
* data/data0data.c: * data/data0data.c:
......
...@@ -1451,11 +1451,11 @@ Calculates a split record such that the tuple will certainly fit on ...@@ -1451,11 +1451,11 @@ Calculates a split record such that the tuple will certainly fit on
its half-page when the split is performed. We assume in this function its half-page when the split is performed. We assume in this function
only that the cursor page has at least one user record. only that the cursor page has at least one user record.
@return split record, or NULL if tuple will be the first record on @return split record, or NULL if tuple will be the first record on
upper half-page */ the lower or upper half-page (determined by btr_page_tuple_smaller()) */
static static
rec_t* rec_t*
btr_page_get_sure_split_rec( btr_page_get_split_rec(
/*========================*/ /*===================*/
btr_cur_t* cursor, /*!< in: cursor at which insert should be made */ btr_cur_t* cursor, /*!< in: cursor at which insert should be made */
const dtuple_t* tuple, /*!< in: tuple to insert */ const dtuple_t* tuple, /*!< in: tuple to insert */
ulint n_ext) /*!< in: number of externally stored columns */ ulint n_ext) /*!< in: number of externally stored columns */
...@@ -1831,6 +1831,37 @@ btr_attach_half_pages( ...@@ -1831,6 +1831,37 @@ btr_attach_half_pages(
btr_page_set_next(upper_page, upper_page_zip, next_page_no, mtr); btr_page_set_next(upper_page, upper_page_zip, next_page_no, mtr);
} }
/*************************************************************//**
Determine if a tuple is smaller than any record on the page.
@return TRUE if smaller */
static
ibool
btr_page_tuple_smaller(
/*===================*/
btr_cur_t* cursor, /*!< in: b-tree cursor */
const dtuple_t* tuple, /*!< in: tuple to consider */
ulint* offsets,/*!< in/out: temporary storage */
ulint n_uniq, /*!< in: number of unique fields
in the index page records */
mem_heap_t** heap) /*!< in/out: heap for offsets */
{
buf_block_t* block;
const rec_t* first_rec;
page_cur_t pcur;
/* Read the first user record in the page. */
block = btr_cur_get_block(cursor);
page_cur_set_before_first(block, &pcur);
page_cur_move_to_next(&pcur);
first_rec = page_cur_get_rec(&pcur);
offsets = rec_get_offsets(
first_rec, cursor->index, offsets,
n_uniq, heap);
return(cmp_dtuple_rec(tuple, first_rec, offsets) < 0);
}
/*************************************************************//** /*************************************************************//**
Splits an index page to halves and inserts the tuple. It is assumed Splits an index page to halves and inserts the tuple. It is assumed
that mtr holds an x-latch to the index tree. NOTE: the tree x-latch is that mtr holds an x-latch to the index tree. NOTE: the tree x-latch is
...@@ -1905,49 +1936,45 @@ func_start: ...@@ -1905,49 +1936,45 @@ func_start:
if (n_iterations > 0) { if (n_iterations > 0) {
direction = FSP_UP; direction = FSP_UP;
hint_page_no = page_no + 1; hint_page_no = page_no + 1;
split_rec = btr_page_get_sure_split_rec(cursor, tuple, n_ext); split_rec = btr_page_get_split_rec(cursor, tuple, n_ext);
if (UNIV_UNLIKELY(split_rec == NULL)) {
insert_left = btr_page_tuple_smaller(
cursor, tuple, offsets, n_uniq, &heap);
}
} else if (btr_page_get_split_rec_to_right(cursor, &split_rec)) { } else if (btr_page_get_split_rec_to_right(cursor, &split_rec)) {
direction = FSP_UP; direction = FSP_UP;
hint_page_no = page_no + 1; hint_page_no = page_no + 1;
insert_left = FALSE;
} else if (btr_page_get_split_rec_to_left(cursor, &split_rec)) { } else if (btr_page_get_split_rec_to_left(cursor, &split_rec)) {
direction = FSP_DOWN; direction = FSP_DOWN;
hint_page_no = page_no - 1; hint_page_no = page_no - 1;
ut_ad(split_rec);
} else { } else {
direction = FSP_UP; direction = FSP_UP;
hint_page_no = page_no + 1; hint_page_no = page_no + 1;
if (page_get_n_recs(page) == 1) { /* If there is only one record in the index page, we
page_cur_t pcur; can't split the node in the middle by default. We need
to determine whether the new record will be inserted
/* There is only one record in the index page to the left or right. */
therefore we can't split the node in the middle
by default. We need to determine whether the
new record will be inserted to the left or right. */
/* Read the first (and only) record in the page. */ if (page_get_n_recs(page) > 1) {
page_cur_set_before_first(block, &pcur);
page_cur_move_to_next(&pcur);
first_rec = page_cur_get_rec(&pcur);
offsets = rec_get_offsets(
first_rec, cursor->index, offsets,
n_uniq, &heap);
/* If the new record is less than the existing record
the split in the middle will copy the existing
record to the new node. */
if (cmp_dtuple_rec(tuple, first_rec, offsets) < 0) {
split_rec = page_get_middle_rec(page);
} else {
split_rec = NULL;
}
} else {
split_rec = page_get_middle_rec(page); split_rec = page_get_middle_rec(page);
} else if (btr_page_tuple_smaller(cursor, tuple,
offsets, n_uniq, &heap)) {
split_rec = page_rec_get_next(
page_get_infimum_rec(page));
} else {
split_rec = NULL;
insert_left = FALSE;
} }
} }
/* At this point, insert_left is initialized if split_rec == NULL
and may be uninitialized otherwise. */
/* 2. Allocate a new page to the index */ /* 2. Allocate a new page to the index */
new_block = btr_page_alloc(cursor->index, hint_page_no, direction, 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);
...@@ -1974,11 +2001,11 @@ func_start: ...@@ -1974,11 +2001,11 @@ func_start:
avoid further splits by inserting the record avoid further splits by inserting the record
to an empty page. */ to an empty page. */
split_rec = NULL; split_rec = NULL;
goto insert_right; goto insert_empty;
} }
} else { } else {
insert_right: insert_empty:
insert_left = FALSE; ut_ad(!split_rec);
buf = mem_alloc(rec_get_converted_size(cursor->index, buf = mem_alloc(rec_get_converted_size(cursor->index,
tuple, n_ext)); tuple, n_ext));
......
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