Commit 6d7f6baa authored by Marko Mäkelä's avatar Marko Mäkelä

Bug#12845774 OPTIMISTIC INSERT/UPDATE USES WRONG HEURISTICS FOR

COMPRESSED PAGE SIZE

This was submitted as MySQL Bug 61456 and a patch provided by
Facebook. This patch follows the same idea, but instead of adding a
parameter to btr_cur_pessimistic_insert(), we simply remove the
btr_cur_optimistic_insert() call there and add it to the only caller
that needs it.

btr_cur_pessimistic_insert(): Do not try btr_cur_optimistic_insert().

btr_insert_on_non_leaf_level_func(): Invoke btr_cur_optimistic_insert()
before invoking btr_cur_pessimistic_insert().

btr_cur_pessimistic_update(): Clarify in a comment why it is not
necessary to invoke btr_cur_optimistic_insert().

btr_root_raise_and_insert(): Assert that the root page is not empty.
This could happen if a pessimistic insert (involving a split or merge)
is performed without first attempting an optimistic (intra-page) insert.

rb:1219 approved by Sunny Bains
parent 95247de2
2012-08-16 The InnoDB Team
* btr/btr0btr.c, btr/btr0cur.c:
Fix Bug#12845774 OPTIMISTIC INSERT/UPDATE USES WRONG HEURISTICS FOR
COMPRESSED PAGE SIZE
2012-08-16 The InnoDB Team 2012-08-16 The InnoDB Team
* btr/btr0cur.c, page/page0page.c: * btr/btr0cur.c, page/page0page.c:
......
...@@ -1822,6 +1822,7 @@ btr_root_raise_and_insert( ...@@ -1822,6 +1822,7 @@ btr_root_raise_and_insert(
root = btr_cur_get_page(cursor); root = btr_cur_get_page(cursor);
root_block = btr_cur_get_block(cursor); root_block = btr_cur_get_block(cursor);
root_page_zip = buf_block_get_page_zip(root_block); root_page_zip = buf_block_get_page_zip(root_block);
ut_ad(page_get_n_recs(root) > 0);
#ifdef UNIV_ZIP_DEBUG #ifdef UNIV_ZIP_DEBUG
ut_a(!root_page_zip || page_zip_validate(root_page_zip, root)); ut_a(!root_page_zip || page_zip_validate(root_page_zip, root));
#endif /* UNIV_ZIP_DEBUG */ #endif /* UNIV_ZIP_DEBUG */
...@@ -2302,12 +2303,20 @@ btr_insert_on_non_leaf_level_func( ...@@ -2302,12 +2303,20 @@ btr_insert_on_non_leaf_level_func(
BTR_CONT_MODIFY_TREE, BTR_CONT_MODIFY_TREE,
&cursor, 0, file, line, mtr); &cursor, 0, file, line, mtr);
err = btr_cur_pessimistic_insert(BTR_NO_LOCKING_FLAG ut_ad(cursor.flag == BTR_CUR_BINARY);
| BTR_KEEP_SYS_FLAG
| BTR_NO_UNDO_LOG_FLAG, err = btr_cur_optimistic_insert(
&cursor, tuple, &rec, BTR_NO_LOCKING_FLAG | BTR_KEEP_SYS_FLAG
| BTR_NO_UNDO_LOG_FLAG, &cursor, tuple, &rec,
&dummy_big_rec, 0, NULL, mtr); &dummy_big_rec, 0, NULL, mtr);
if (err == DB_FAIL) {
err = btr_cur_pessimistic_insert(
BTR_NO_LOCKING_FLAG | BTR_KEEP_SYS_FLAG
| BTR_NO_UNDO_LOG_FLAG,
&cursor, tuple, &rec, &dummy_big_rec, 0, NULL, mtr);
ut_a(err == DB_SUCCESS); ut_a(err == DB_SUCCESS);
}
} }
/**************************************************************//** /**************************************************************//**
......
...@@ -1361,20 +1361,9 @@ btr_cur_pessimistic_insert( ...@@ -1361,20 +1361,9 @@ btr_cur_pessimistic_insert(
ut_ad(mtr_memo_contains(mtr, btr_cur_get_block(cursor), ut_ad(mtr_memo_contains(mtr, btr_cur_get_block(cursor),
MTR_MEMO_PAGE_X_FIX)); MTR_MEMO_PAGE_X_FIX));
/* Try first an optimistic insert; reset the cursor flag: we do not
assume anything of how it was positioned */
cursor->flag = BTR_CUR_BINARY; cursor->flag = BTR_CUR_BINARY;
err = btr_cur_optimistic_insert(flags, cursor, entry, rec, /* Check locks and write to undo log, if specified */
big_rec, n_ext, thr, mtr);
if (err != DB_FAIL) {
return(err);
}
/* Retry with a pessimistic insert. Check locks and write to undo log,
if specified */
err = btr_cur_ins_lock_and_undo(flags, cursor, entry, err = btr_cur_ins_lock_and_undo(flags, cursor, entry,
thr, mtr, &dummy_inh); thr, mtr, &dummy_inh);
...@@ -2365,8 +2354,10 @@ make_external: ...@@ -2365,8 +2354,10 @@ make_external:
record on its page? */ record on its page? */
was_first = page_cur_is_before_first(page_cursor); was_first = page_cur_is_before_first(page_cursor);
/* The first parameter means that no lock checking and undo logging /* Lock checks and undo logging were already performed by
is made in the insert */ btr_cur_upd_lock_and_undo(). We do not try
btr_cur_optimistic_insert() because
btr_cur_insert_if_possible() already failed above. */
err = btr_cur_pessimistic_insert(BTR_NO_UNDO_LOG_FLAG err = btr_cur_pessimistic_insert(BTR_NO_UNDO_LOG_FLAG
| BTR_NO_LOCKING_FLAG | BTR_NO_LOCKING_FLAG
......
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