2005-10-27 07:29:40 +00:00
|
|
|
/******************************************************
|
|
|
|
The index tree cursor
|
|
|
|
|
|
|
|
All changes that row operations make to a B-tree or the records
|
|
|
|
there must go through this module! Undo log records are written here
|
|
|
|
of every modify or insert of a clustered index record.
|
|
|
|
|
|
|
|
NOTE!!!
|
|
|
|
To make sure we do not run out of disk space during a pessimistic
|
|
|
|
insert or update, we have to reserve 2 x the height of the index tree
|
|
|
|
many pages in the tablespace before we start the operation, because
|
|
|
|
if leaf splitting has been started, it is difficult to undo, except
|
|
|
|
by crashing the database and doing a roll-forward.
|
|
|
|
|
|
|
|
(c) 1994-2001 Innobase Oy
|
|
|
|
|
|
|
|
Created 10/16/1994 Heikki Tuuri
|
|
|
|
*******************************************************/
|
|
|
|
|
|
|
|
#include "btr0cur.h"
|
|
|
|
|
|
|
|
#ifdef UNIV_NONINL
|
|
|
|
#include "btr0cur.ic"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "page0page.h"
|
2005-10-27 11:48:10 +00:00
|
|
|
#include "page0zip.h"
|
2005-10-27 07:29:40 +00:00
|
|
|
#include "rem0rec.h"
|
|
|
|
#include "rem0cmp.h"
|
2007-01-16 13:23:10 +00:00
|
|
|
#include "buf0lru.h"
|
2005-10-27 07:29:40 +00:00
|
|
|
#include "btr0btr.h"
|
|
|
|
#include "btr0sea.h"
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
#include "row0purge.h"
|
2005-10-27 07:29:40 +00:00
|
|
|
#include "row0upd.h"
|
|
|
|
#include "trx0rec.h"
|
2008-08-09 00:15:46 +00:00
|
|
|
#include "trx0roll.h" /* trx_is_recv() */
|
2005-10-27 07:29:40 +00:00
|
|
|
#include "que0que.h"
|
|
|
|
#include "row0row.h"
|
|
|
|
#include "srv0srv.h"
|
|
|
|
#include "ibuf0ibuf.h"
|
|
|
|
#include "lock0lock.h"
|
2006-02-16 12:58:18 +00:00
|
|
|
#include "zlib.h"
|
|
|
|
|
2008-02-27 07:03:34 +00:00
|
|
|
/* Btree operation types, introduced as part of delete buffering. */
|
|
|
|
typedef enum btr_op_enum {
|
|
|
|
BTR_NO_OP = 0,
|
|
|
|
BTR_INSERT_OP,
|
|
|
|
BTR_DELETE_OP,
|
|
|
|
BTR_DELMARK_OP
|
|
|
|
} btr_op_t;
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
#ifdef UNIV_DEBUG
|
|
|
|
/* If the following is set to TRUE, this module prints a lot of
|
|
|
|
trace information of individual record operations */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN ibool btr_cur_print_record_ops = FALSE;
|
2005-10-27 07:29:40 +00:00
|
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN ulint btr_cur_n_non_sea = 0;
|
|
|
|
UNIV_INTERN ulint btr_cur_n_sea = 0;
|
|
|
|
UNIV_INTERN ulint btr_cur_n_non_sea_old = 0;
|
|
|
|
UNIV_INTERN ulint btr_cur_n_sea_old = 0;
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/* In the optimistic insert, if the insert does not fit, but this much space
|
|
|
|
can be released by page reorganize, then it is reorganized */
|
|
|
|
|
|
|
|
#define BTR_CUR_PAGE_REORGANIZE_LIMIT (UNIV_PAGE_SIZE / 32)
|
|
|
|
|
|
|
|
/* The structure of a BLOB part header */
|
|
|
|
/*--------------------------------------*/
|
|
|
|
#define BTR_BLOB_HDR_PART_LEN 0 /* BLOB part len on this
|
|
|
|
page */
|
|
|
|
#define BTR_BLOB_HDR_NEXT_PAGE_NO 4 /* next BLOB part page no,
|
|
|
|
FIL_NULL if none */
|
|
|
|
/*--------------------------------------*/
|
|
|
|
#define BTR_BLOB_HDR_SIZE 8
|
|
|
|
|
2007-11-27 09:11:45 +00:00
|
|
|
/* A BLOB field reference full of zero, for use in assertions and tests.
|
|
|
|
Initially, BLOB field references are set to zero, in
|
|
|
|
dtuple_convert_big_rec(). */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN const byte field_ref_zero[BTR_EXTERN_FIELD_REF_SIZE];
|
2007-11-27 09:11:45 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/***********************************************************************
|
|
|
|
Marks all extern fields in a record as owned by the record. This function
|
|
|
|
should be called if the delete mark of a record is removed: a not delete
|
|
|
|
marked record always owns all its extern fields. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
btr_cur_unmark_extern_fields(
|
|
|
|
/*=========================*/
|
2006-02-10 15:06:17 +00:00
|
|
|
page_zip_des_t* page_zip,/* in/out: compressed page whose uncompressed
|
|
|
|
part will be updated, or NULL */
|
|
|
|
rec_t* rec, /* in/out: record in a clustered index */
|
|
|
|
dict_index_t* index, /* in: index of the page */
|
|
|
|
const ulint* offsets,/* in: array returned by rec_get_offsets() */
|
|
|
|
mtr_t* mtr); /* in: mtr, or NULL if not logged */
|
2005-10-27 07:29:40 +00:00
|
|
|
/***********************************************************************
|
|
|
|
Adds path information to the cursor for the current page, for which
|
|
|
|
the binary search has been performed. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
btr_cur_add_path_info(
|
|
|
|
/*==================*/
|
|
|
|
btr_cur_t* cursor, /* in: cursor positioned on a page */
|
|
|
|
ulint height, /* in: height of the page in tree;
|
|
|
|
0 means leaf node */
|
|
|
|
ulint root_height); /* in: root node height in tree */
|
|
|
|
/***************************************************************
|
|
|
|
Frees the externally stored fields for a record, if the field is mentioned
|
|
|
|
in the update vector. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
btr_rec_free_updated_extern_fields(
|
|
|
|
/*===============================*/
|
|
|
|
dict_index_t* index, /* in: index of rec; the index tree MUST be
|
|
|
|
X-latched */
|
|
|
|
rec_t* rec, /* in: record */
|
2006-02-10 15:06:17 +00:00
|
|
|
page_zip_des_t* page_zip,/* in: compressed page whose uncompressed
|
|
|
|
part will be updated, or NULL */
|
2005-10-27 07:29:40 +00:00
|
|
|
const ulint* offsets,/* in: rec_get_offsets(rec, index) */
|
2007-06-19 12:44:45 +00:00
|
|
|
const upd_t* update, /* in: update vector */
|
2008-08-09 00:15:46 +00:00
|
|
|
enum trx_rb_ctx rb_ctx, /* in: rollback context */
|
2005-10-27 07:29:40 +00:00
|
|
|
mtr_t* mtr); /* in: mini-transaction handle which contains
|
|
|
|
an X-latch to record page and to the tree */
|
|
|
|
/***************************************************************
|
2006-02-16 12:58:18 +00:00
|
|
|
Frees the externally stored fields for a record. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
btr_rec_free_externally_stored_fields(
|
|
|
|
/*==================================*/
|
|
|
|
dict_index_t* index, /* in: index of the data, the index
|
|
|
|
tree MUST be X-latched */
|
|
|
|
rec_t* rec, /* in: record */
|
|
|
|
const ulint* offsets,/* in: rec_get_offsets(rec, index) */
|
|
|
|
page_zip_des_t* page_zip,/* in: compressed page whose uncompressed
|
|
|
|
part will be updated, or NULL */
|
2008-08-09 00:15:46 +00:00
|
|
|
enum trx_rb_ctx rb_ctx, /* in: rollback context */
|
2006-02-16 12:58:18 +00:00
|
|
|
mtr_t* mtr); /* in: mini-transaction handle which contains
|
|
|
|
an X-latch to record page and to the index
|
|
|
|
tree */
|
|
|
|
/***************************************************************
|
2005-10-27 07:29:40 +00:00
|
|
|
Gets the externally stored size of a record, in units of a database page. */
|
|
|
|
static
|
|
|
|
ulint
|
|
|
|
btr_rec_get_externally_stored_len(
|
|
|
|
/*==============================*/
|
|
|
|
/* out: externally stored part,
|
|
|
|
in units of a database page */
|
|
|
|
rec_t* rec, /* in: record */
|
|
|
|
const ulint* offsets);/* in: array returned by rec_get_offsets() */
|
|
|
|
|
2005-10-27 11:48:10 +00:00
|
|
|
/**********************************************************
|
|
|
|
The following function is used to set the deleted bit of a record. */
|
|
|
|
UNIV_INLINE
|
2006-02-10 15:06:17 +00:00
|
|
|
void
|
2005-10-27 11:48:10 +00:00
|
|
|
btr_rec_set_deleted_flag(
|
|
|
|
/*=====================*/
|
|
|
|
/* out: TRUE on success;
|
|
|
|
FALSE on page_zip overflow */
|
|
|
|
rec_t* rec, /* in/out: physical record */
|
2008-09-17 19:31:42 +00:00
|
|
|
page_zip_des_t* page_zip,/* in/out: compressed page (or NULL) */
|
2005-10-27 11:48:10 +00:00
|
|
|
ulint flag) /* in: nonzero if delete marked */
|
|
|
|
{
|
|
|
|
if (page_rec_is_comp(rec)) {
|
|
|
|
rec_set_deleted_flag_new(rec, page_zip, flag);
|
|
|
|
} else {
|
|
|
|
ut_ad(!page_zip);
|
|
|
|
rec_set_deleted_flag_old(rec, flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/*==================== B-TREE SEARCH =========================*/
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/************************************************************************
|
|
|
|
Latches the leaf page or pages requested. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
btr_cur_latch_leaves(
|
|
|
|
/*=================*/
|
|
|
|
page_t* page, /* in: leaf page where the search
|
|
|
|
converged */
|
|
|
|
ulint space, /* in: space id */
|
2007-01-18 09:59:00 +00:00
|
|
|
ulint zip_size, /* in: compressed page size in bytes
|
|
|
|
or 0 for uncompressed pages */
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint page_no, /* in: page number of the leaf */
|
|
|
|
ulint latch_mode, /* in: BTR_SEARCH_LEAF, ... */
|
2006-02-23 19:25:29 +00:00
|
|
|
btr_cur_t* cursor, /* in: cursor */
|
2005-10-27 07:29:40 +00:00
|
|
|
mtr_t* mtr) /* in: mtr */
|
|
|
|
{
|
2006-10-12 18:39:43 +00:00
|
|
|
ulint mode;
|
|
|
|
ulint left_page_no;
|
|
|
|
ulint right_page_no;
|
|
|
|
buf_block_t* get_block;
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
ut_ad(page && mtr);
|
|
|
|
|
2006-10-12 18:39:43 +00:00
|
|
|
switch (latch_mode) {
|
|
|
|
case BTR_SEARCH_LEAF:
|
|
|
|
case BTR_MODIFY_LEAF:
|
|
|
|
mode = latch_mode == BTR_SEARCH_LEAF ? RW_S_LATCH : RW_X_LATCH;
|
2007-01-18 09:59:00 +00:00
|
|
|
get_block = btr_block_get(space, zip_size, page_no, mode, mtr);
|
2006-10-18 17:43:04 +00:00
|
|
|
#ifdef UNIV_BTR_DEBUG
|
2006-10-12 18:39:43 +00:00
|
|
|
ut_a(page_is_comp(get_block->frame) == page_is_comp(page));
|
2006-10-18 17:43:04 +00:00
|
|
|
#endif /* UNIV_BTR_DEBUG */
|
2006-10-12 18:39:43 +00:00
|
|
|
get_block->check_index_page_at_flush = TRUE;
|
|
|
|
return;
|
|
|
|
case BTR_MODIFY_TREE:
|
2005-10-27 07:29:40 +00:00
|
|
|
/* x-latch also brothers from left to right */
|
|
|
|
left_page_no = btr_page_get_prev(page, mtr);
|
|
|
|
|
|
|
|
if (left_page_no != FIL_NULL) {
|
2007-01-18 09:59:00 +00:00
|
|
|
get_block = btr_block_get(space, zip_size,
|
|
|
|
left_page_no,
|
2006-10-12 18:39:43 +00:00
|
|
|
RW_X_LATCH, mtr);
|
2006-05-11 17:00:43 +00:00
|
|
|
#ifdef UNIV_BTR_DEBUG
|
2006-10-12 18:39:43 +00:00
|
|
|
ut_a(page_is_comp(get_block->frame)
|
|
|
|
== page_is_comp(page));
|
|
|
|
ut_a(btr_page_get_next(get_block->frame, mtr)
|
2006-10-12 07:02:36 +00:00
|
|
|
== page_get_page_no(page));
|
2006-05-11 17:00:43 +00:00
|
|
|
#endif /* UNIV_BTR_DEBUG */
|
2006-10-12 18:39:43 +00:00
|
|
|
get_block->check_index_page_at_flush = TRUE;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2007-01-18 09:59:00 +00:00
|
|
|
get_block = btr_block_get(space, zip_size, page_no,
|
|
|
|
RW_X_LATCH, mtr);
|
2006-10-18 17:43:04 +00:00
|
|
|
#ifdef UNIV_BTR_DEBUG
|
2006-10-12 18:39:43 +00:00
|
|
|
ut_a(page_is_comp(get_block->frame) == page_is_comp(page));
|
2006-10-18 17:43:04 +00:00
|
|
|
#endif /* UNIV_BTR_DEBUG */
|
2006-10-12 18:39:43 +00:00
|
|
|
get_block->check_index_page_at_flush = TRUE;
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
right_page_no = btr_page_get_next(page, mtr);
|
|
|
|
|
|
|
|
if (right_page_no != FIL_NULL) {
|
2007-01-18 09:59:00 +00:00
|
|
|
get_block = btr_block_get(space, zip_size,
|
|
|
|
right_page_no,
|
2006-10-12 18:39:43 +00:00
|
|
|
RW_X_LATCH, mtr);
|
2006-05-11 17:00:43 +00:00
|
|
|
#ifdef UNIV_BTR_DEBUG
|
2006-10-12 18:39:43 +00:00
|
|
|
ut_a(page_is_comp(get_block->frame)
|
|
|
|
== page_is_comp(page));
|
|
|
|
ut_a(btr_page_get_prev(get_block->frame, mtr)
|
2006-10-12 07:02:36 +00:00
|
|
|
== page_get_page_no(page));
|
2006-05-11 17:00:43 +00:00
|
|
|
#endif /* UNIV_BTR_DEBUG */
|
2006-10-12 18:39:43 +00:00
|
|
|
get_block->check_index_page_at_flush = TRUE;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2006-10-12 18:39:43 +00:00
|
|
|
return;
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-10-12 18:39:43 +00:00
|
|
|
case BTR_SEARCH_PREV:
|
|
|
|
case BTR_MODIFY_PREV:
|
|
|
|
mode = latch_mode == BTR_SEARCH_PREV ? RW_S_LATCH : RW_X_LATCH;
|
|
|
|
/* latch also left brother */
|
2005-10-27 07:29:40 +00:00
|
|
|
left_page_no = btr_page_get_prev(page, mtr);
|
|
|
|
|
|
|
|
if (left_page_no != FIL_NULL) {
|
2007-01-18 09:59:00 +00:00
|
|
|
get_block = btr_block_get(space, zip_size,
|
|
|
|
left_page_no, mode, mtr);
|
2006-10-18 17:43:04 +00:00
|
|
|
cursor->left_block = get_block;
|
2006-05-11 17:00:43 +00:00
|
|
|
#ifdef UNIV_BTR_DEBUG
|
2006-10-18 17:43:04 +00:00
|
|
|
ut_a(page_is_comp(get_block->frame)
|
2006-08-29 09:30:31 +00:00
|
|
|
== page_is_comp(page));
|
2006-10-18 17:43:04 +00:00
|
|
|
ut_a(btr_page_get_next(get_block->frame, mtr)
|
2006-10-12 07:02:36 +00:00
|
|
|
== page_get_page_no(page));
|
2006-05-11 17:00:43 +00:00
|
|
|
#endif /* UNIV_BTR_DEBUG */
|
2006-10-12 18:39:43 +00:00
|
|
|
get_block->check_index_page_at_flush = TRUE;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2007-01-18 09:59:00 +00:00
|
|
|
get_block = btr_block_get(space, zip_size, page_no, mode, mtr);
|
2006-10-18 17:43:04 +00:00
|
|
|
#ifdef UNIV_BTR_DEBUG
|
2006-10-12 18:39:43 +00:00
|
|
|
ut_a(page_is_comp(get_block->frame) == page_is_comp(page));
|
2006-10-18 17:43:04 +00:00
|
|
|
#endif /* UNIV_BTR_DEBUG */
|
2006-10-12 18:39:43 +00:00
|
|
|
get_block->check_index_page_at_flush = TRUE;
|
|
|
|
return;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
2006-10-12 18:39:43 +00:00
|
|
|
|
|
|
|
ut_error;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
Searches an index tree and positions a tree cursor on a given level.
|
|
|
|
NOTE: n_fields_cmp in tuple must be set so that it cannot be compared
|
|
|
|
to node pointer page number fields on the upper levels of the tree!
|
|
|
|
Note that if mode is PAGE_CUR_LE, which is used in inserts, then
|
|
|
|
cursor->up_match and cursor->low_match both will have sensible values.
|
2006-08-29 09:30:31 +00:00
|
|
|
If mode is PAGE_CUR_GE, then up_match will a have a sensible value.
|
|
|
|
|
|
|
|
If mode is PAGE_CUR_LE , cursor is left at the place where an insert of the
|
|
|
|
search tuple should be performed in the B-tree. InnoDB does an insert
|
|
|
|
immediately after the cursor. Thus, the cursor may end up on a user record,
|
|
|
|
or on a page infimum record. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
void
|
|
|
|
btr_cur_search_to_nth_level(
|
|
|
|
/*========================*/
|
|
|
|
dict_index_t* index, /* in: index */
|
|
|
|
ulint level, /* in: the tree level of search */
|
2006-10-20 08:30:07 +00:00
|
|
|
const dtuple_t* tuple, /* in: data tuple; NOTE: n_fields_cmp in
|
2005-10-27 07:29:40 +00:00
|
|
|
tuple must be set so that it cannot get
|
|
|
|
compared to the node ptr page number field! */
|
|
|
|
ulint mode, /* in: PAGE_CUR_L, ...;
|
|
|
|
Inserts should always be made using
|
|
|
|
PAGE_CUR_LE to search the position! */
|
|
|
|
ulint latch_mode, /* in: BTR_SEARCH_LEAF, ..., ORed with
|
|
|
|
BTR_INSERT and BTR_ESTIMATE;
|
2006-10-18 17:43:04 +00:00
|
|
|
cursor->left_block is used to store a pointer
|
2005-10-27 07:29:40 +00:00
|
|
|
to the left neighbor page, in the cases
|
|
|
|
BTR_SEARCH_PREV and BTR_MODIFY_PREV;
|
|
|
|
NOTE that if has_search_latch
|
|
|
|
is != 0, we maybe do not have a latch set
|
|
|
|
on the cursor page, we assume
|
|
|
|
the caller uses his search latch
|
|
|
|
to protect the record! */
|
|
|
|
btr_cur_t* cursor, /* in/out: tree cursor; the cursor page is
|
|
|
|
s- or x-latched, but see also above! */
|
|
|
|
ulint has_search_latch,/* in: info on the latch mode the
|
|
|
|
caller currently has on btr_search_latch:
|
|
|
|
RW_S_LATCH, or 0 */
|
|
|
|
mtr_t* mtr) /* in: mtr */
|
|
|
|
{
|
|
|
|
page_t* page;
|
2008-02-27 07:03:34 +00:00
|
|
|
buf_block_t* block;
|
|
|
|
ulint space;
|
2006-10-23 19:34:45 +00:00
|
|
|
buf_block_t* guess;
|
2008-02-27 07:03:34 +00:00
|
|
|
ulint height;
|
2005-10-27 07:29:40 +00:00
|
|
|
rec_t* node_ptr;
|
|
|
|
ulint page_no;
|
|
|
|
ulint up_match;
|
|
|
|
ulint up_bytes;
|
|
|
|
ulint low_match;
|
2006-02-23 19:25:29 +00:00
|
|
|
ulint low_bytes;
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint savepoint;
|
|
|
|
ulint rw_latch;
|
|
|
|
ulint page_mode;
|
|
|
|
ulint buf_mode;
|
|
|
|
ulint estimate;
|
2008-02-27 07:03:34 +00:00
|
|
|
ulint zip_size;
|
|
|
|
page_cur_t* page_cursor;
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint ignore_sec_unique;
|
2008-02-27 07:03:34 +00:00
|
|
|
btr_op_t btr_op = BTR_NO_OP;
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint root_height = 0; /* remove warning */
|
2008-02-27 07:03:34 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
#ifdef BTR_CUR_ADAPT
|
|
|
|
btr_search_t* info;
|
|
|
|
#endif
|
|
|
|
mem_heap_t* heap = NULL;
|
|
|
|
ulint offsets_[REC_OFFS_NORMAL_SIZE];
|
|
|
|
ulint* offsets = offsets_;
|
2007-09-28 07:05:57 +00:00
|
|
|
rec_offs_init(offsets_);
|
2005-10-27 07:29:40 +00:00
|
|
|
/* Currently, PAGE_CUR_LE is the only search mode used for searches
|
|
|
|
ending to upper levels */
|
|
|
|
|
|
|
|
ut_ad(level == 0 || mode == PAGE_CUR_LE);
|
2006-09-19 10:14:07 +00:00
|
|
|
ut_ad(dict_index_check_search_tuple(index, tuple));
|
2008-01-25 08:13:12 +00:00
|
|
|
ut_ad(!dict_index_is_ibuf(index) || ibuf_inside());
|
2005-10-27 07:29:40 +00:00
|
|
|
ut_ad(dtuple_check_typed(tuple));
|
|
|
|
|
|
|
|
#ifdef UNIV_DEBUG
|
|
|
|
cursor->up_match = ULINT_UNDEFINED;
|
|
|
|
cursor->low_match = ULINT_UNDEFINED;
|
2006-02-23 19:25:29 +00:00
|
|
|
#endif
|
2008-02-27 07:03:34 +00:00
|
|
|
|
2008-06-16 03:11:30 +00:00
|
|
|
/* These flags are mutually exclusive, they are lumped together
|
2008-02-27 07:03:34 +00:00
|
|
|
with the latch mode for historical reasons. It's possible for
|
|
|
|
none of the flags to be set. */
|
2008-12-12 10:08:00 +00:00
|
|
|
switch (UNIV_EXPECT(latch_mode
|
|
|
|
& (BTR_INSERT | BTR_DELETE | BTR_DELETE_MARK),
|
|
|
|
0)) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case BTR_INSERT:
|
2008-02-27 07:03:34 +00:00
|
|
|
btr_op = BTR_INSERT_OP;
|
2008-12-12 10:08:00 +00:00
|
|
|
break;
|
|
|
|
case BTR_DELETE:
|
2008-02-27 07:03:34 +00:00
|
|
|
btr_op = BTR_DELETE_OP;
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
ut_a(cursor->purge_node);
|
2008-12-12 10:08:00 +00:00
|
|
|
break;
|
|
|
|
case BTR_DELETE_MARK:
|
2008-02-27 07:03:34 +00:00
|
|
|
btr_op = BTR_DELMARK_OP;
|
2008-12-12 10:08:00 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* only one of BTR_INSERT, BTR_DELETE, BTR_DELETE_MARK
|
|
|
|
should be specified at a time */
|
|
|
|
ut_error;
|
2008-02-27 07:03:34 +00:00
|
|
|
}
|
|
|
|
|
2008-12-10 14:06:12 +00:00
|
|
|
/* Operations on the insert buffer tree cannot be buffered. */
|
|
|
|
ut_ad(btr_op == BTR_NO_OP || !dict_index_is_ibuf(index));
|
|
|
|
/* Operations on the clustered index cannot be buffered. */
|
|
|
|
ut_ad(btr_op == BTR_NO_OP || !dict_index_is_clust(index));
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
estimate = latch_mode & BTR_ESTIMATE;
|
|
|
|
ignore_sec_unique = latch_mode & BTR_IGNORE_SEC_UNIQUE;
|
|
|
|
|
2008-02-27 07:03:34 +00:00
|
|
|
/* Turn the flags unrelated to the latch mode off. */
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
latch_mode &= ~(BTR_INSERT
|
|
|
|
| BTR_DELETE_MARK
|
|
|
|
| BTR_DELETE
|
|
|
|
| BTR_ESTIMATE
|
|
|
|
| BTR_IGNORE_SEC_UNIQUE);
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
cursor->flag = BTR_CUR_BINARY;
|
|
|
|
cursor->index = index;
|
|
|
|
|
2008-02-27 07:03:34 +00:00
|
|
|
cursor->ibuf_cnt = ULINT_UNDEFINED;
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
#ifndef BTR_CUR_ADAPT
|
|
|
|
guess = NULL;
|
|
|
|
#else
|
|
|
|
info = btr_search_get_info(index);
|
|
|
|
|
|
|
|
guess = info->root_guess;
|
|
|
|
|
|
|
|
#ifdef BTR_CUR_HASH_ADAPT
|
|
|
|
|
|
|
|
#ifdef UNIV_SEARCH_PERF_STAT
|
|
|
|
info->n_searches++;
|
2006-02-23 19:25:29 +00:00
|
|
|
#endif
|
2008-02-27 07:03:34 +00:00
|
|
|
|
|
|
|
/* Ibuf does not use adaptive hash; this is prevented by the
|
|
|
|
latch_mode check below. */
|
2005-10-27 07:29:40 +00:00
|
|
|
if (btr_search_latch.writer == RW_LOCK_NOT_LOCKED
|
2008-02-27 07:03:34 +00:00
|
|
|
&& latch_mode <= BTR_MODIFY_LEAF
|
|
|
|
&& info->last_hash_succ
|
2006-08-29 09:30:31 +00:00
|
|
|
&& !estimate
|
2005-10-27 07:29:40 +00:00
|
|
|
#ifdef PAGE_CUR_LE_OR_EXTENDS
|
2006-08-29 09:30:31 +00:00
|
|
|
&& mode != PAGE_CUR_LE_OR_EXTENDS
|
2005-10-27 07:29:40 +00:00
|
|
|
#endif /* PAGE_CUR_LE_OR_EXTENDS */
|
2006-11-21 14:40:14 +00:00
|
|
|
&& !UNIV_UNLIKELY(btr_search_disabled)
|
2006-08-29 09:30:31 +00:00
|
|
|
&& btr_search_guess_on_hash(index, info, tuple, mode,
|
|
|
|
latch_mode, cursor,
|
|
|
|
has_search_latch, mtr)) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/* Search using the hash index succeeded */
|
|
|
|
|
|
|
|
ut_ad(cursor->up_match != ULINT_UNDEFINED
|
2006-08-29 09:30:31 +00:00
|
|
|
|| mode != PAGE_CUR_GE);
|
2005-10-27 07:29:40 +00:00
|
|
|
ut_ad(cursor->up_match != ULINT_UNDEFINED
|
2006-08-29 09:30:31 +00:00
|
|
|
|| mode != PAGE_CUR_LE);
|
2005-10-27 07:29:40 +00:00
|
|
|
ut_ad(cursor->low_match != ULINT_UNDEFINED
|
2006-08-29 09:30:31 +00:00
|
|
|
|| mode != PAGE_CUR_LE);
|
2005-10-27 07:29:40 +00:00
|
|
|
btr_cur_n_sea++;
|
|
|
|
|
2006-02-23 19:25:29 +00:00
|
|
|
return;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
2008-02-27 07:03:34 +00:00
|
|
|
#endif /* BTR_CUR_HASH_ADAPT */
|
|
|
|
#endif /* BTR_CUR_ADAPT */
|
2005-10-27 07:29:40 +00:00
|
|
|
btr_cur_n_non_sea++;
|
|
|
|
|
|
|
|
/* If the hash search did not succeed, do binary search down the
|
|
|
|
tree */
|
|
|
|
|
|
|
|
if (has_search_latch) {
|
|
|
|
/* Release possible search latch to obey latching order */
|
|
|
|
rw_lock_s_unlock(&btr_search_latch);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Store the position of the tree latch we push to mtr so that we
|
|
|
|
know how to release it when we have latched leaf node(s) */
|
|
|
|
|
|
|
|
savepoint = mtr_set_savepoint(mtr);
|
|
|
|
|
|
|
|
if (latch_mode == BTR_MODIFY_TREE) {
|
2006-09-19 10:14:07 +00:00
|
|
|
mtr_x_lock(dict_index_get_lock(index), mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
} else if (latch_mode == BTR_CONT_MODIFY_TREE) {
|
|
|
|
/* Do nothing */
|
2006-09-19 10:14:07 +00:00
|
|
|
ut_ad(mtr_memo_contains(mtr, dict_index_get_lock(index),
|
2006-08-29 09:30:31 +00:00
|
|
|
MTR_MEMO_X_LOCK));
|
2005-10-27 07:29:40 +00:00
|
|
|
} else {
|
2006-09-19 10:14:07 +00:00
|
|
|
mtr_s_lock(dict_index_get_lock(index), mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
page_cursor = btr_cur_get_page_cur(cursor);
|
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
space = dict_index_get_space(index);
|
|
|
|
page_no = dict_index_get_page(index);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
up_match = 0;
|
|
|
|
up_bytes = 0;
|
|
|
|
low_match = 0;
|
|
|
|
low_bytes = 0;
|
|
|
|
|
|
|
|
height = ULINT_UNDEFINED;
|
|
|
|
|
|
|
|
/* We use these modified search modes on non-leaf levels of the
|
|
|
|
B-tree. These let us end up in the right B-tree leaf. In that leaf
|
|
|
|
we use the original search mode. */
|
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case PAGE_CUR_GE:
|
|
|
|
page_mode = PAGE_CUR_L;
|
|
|
|
break;
|
|
|
|
case PAGE_CUR_G:
|
|
|
|
page_mode = PAGE_CUR_LE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
#ifdef PAGE_CUR_LE_OR_EXTENDS
|
|
|
|
ut_ad(mode == PAGE_CUR_L || mode == PAGE_CUR_LE
|
2006-08-29 09:30:31 +00:00
|
|
|
|| mode == PAGE_CUR_LE_OR_EXTENDS);
|
2005-10-27 07:29:40 +00:00
|
|
|
#else /* PAGE_CUR_LE_OR_EXTENDS */
|
|
|
|
ut_ad(mode == PAGE_CUR_L || mode == PAGE_CUR_LE);
|
|
|
|
#endif /* PAGE_CUR_LE_OR_EXTENDS */
|
|
|
|
page_mode = mode;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Loop and search until we arrive at the desired level */
|
|
|
|
|
2008-02-27 07:03:34 +00:00
|
|
|
search_loop:
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
buf_mode = BUF_GET;
|
|
|
|
rw_latch = RW_NO_LATCH;
|
2008-02-27 07:03:34 +00:00
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
if (height != 0) {
|
|
|
|
/* We are about to fetch the root or a non-leaf page. */
|
|
|
|
} else if (dict_index_is_ibuf(index)) {
|
|
|
|
/* We're doing a search on an ibuf tree and we're one
|
|
|
|
level above the leaf page. */
|
2008-02-27 07:03:34 +00:00
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
ulint is_min_rec;
|
2008-02-27 07:03:34 +00:00
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
ut_ad(level == 0);
|
2008-02-27 07:03:34 +00:00
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
is_min_rec = rec_get_info_bits(node_ptr, 0)
|
|
|
|
& REC_INFO_MIN_REC_FLAG;
|
2008-02-27 07:03:34 +00:00
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
if (!is_min_rec) {
|
|
|
|
cursor->ibuf_cnt = ibuf_rec_get_counter(node_ptr);
|
2008-02-27 07:03:34 +00:00
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
ut_a(cursor->ibuf_cnt <= 0xFFFF
|
|
|
|
|| cursor->ibuf_cnt == ULINT_UNDEFINED);
|
2008-02-27 07:03:34 +00:00
|
|
|
}
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
} else if (latch_mode <= BTR_MODIFY_LEAF) {
|
|
|
|
rw_latch = latch_mode;
|
2008-02-27 07:03:34 +00:00
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
if (btr_op != BTR_NO_OP
|
|
|
|
&& ibuf_should_try(index, ignore_sec_unique)) {
|
2007-01-18 09:59:00 +00:00
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
/* Try to buffer the operation if the leaf
|
|
|
|
page is not in the buffer pool. */
|
2008-02-27 07:03:34 +00:00
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
buf_mode = btr_op == BTR_DELETE_OP
|
|
|
|
? BUF_GET_IF_IN_POOL_OR_WATCH
|
|
|
|
: BUF_GET_IF_IN_POOL;
|
|
|
|
}
|
2008-02-27 07:03:34 +00:00
|
|
|
}
|
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
zip_size = dict_table_zip_size(index->table);
|
|
|
|
|
|
|
|
retry_page_get:
|
2008-02-27 07:03:34 +00:00
|
|
|
block = buf_page_get_gen(
|
|
|
|
space, zip_size, page_no, rw_latch, guess, buf_mode,
|
|
|
|
__FILE__, __LINE__, mtr);
|
|
|
|
|
2008-12-04 21:56:21 +00:00
|
|
|
if (block == NULL) {
|
2008-02-27 07:03:34 +00:00
|
|
|
/* This must be a search to perform an insert/delete
|
|
|
|
mark/ delete; try using the insert/delete buffer */
|
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
ut_ad(height == 0);
|
2008-02-27 07:03:34 +00:00
|
|
|
ut_ad(cursor->thr);
|
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
switch (btr_op) {
|
|
|
|
case BTR_INSERT_OP:
|
|
|
|
ut_ad(buf_mode == BUF_GET_IF_IN_POOL);
|
2008-02-27 07:03:34 +00:00
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
if (ibuf_insert(IBUF_OP_INSERT, tuple, index,
|
|
|
|
space, zip_size, page_no,
|
|
|
|
cursor->thr)) {
|
2008-02-27 07:03:34 +00:00
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
cursor->flag = BTR_CUR_INSERT_TO_IBUF;
|
2008-02-27 07:03:34 +00:00
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
goto func_exit;
|
|
|
|
}
|
|
|
|
break;
|
2008-02-27 07:03:34 +00:00
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
case BTR_DELMARK_OP:
|
|
|
|
ut_ad(buf_mode == BUF_GET_IF_IN_POOL);
|
2008-02-27 07:03:34 +00:00
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
if (ibuf_insert(IBUF_OP_DELETE_MARK, tuple,
|
|
|
|
index, space, zip_size,
|
|
|
|
page_no, cursor->thr)) {
|
2008-02-27 07:03:34 +00:00
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
cursor->flag = BTR_CUR_DEL_MARK_IBUF;
|
2008-02-27 07:03:34 +00:00
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
goto func_exit;
|
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
break;
|
2005-10-27 07:29:40 +00:00
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
case BTR_DELETE_OP:
|
|
|
|
ut_ad(buf_mode == BUF_GET_IF_IN_POOL_OR_WATCH);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
if (!row_purge_poss_sec(cursor->purge_node,
|
|
|
|
index, tuple)) {
|
2008-02-27 07:03:34 +00:00
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
/* The record cannot be purged yet. */
|
|
|
|
cursor->flag = BTR_CUR_DELETE_REF;
|
|
|
|
} else if (ibuf_insert(IBUF_OP_DELETE, tuple,
|
|
|
|
index, space, zip_size,
|
|
|
|
page_no,
|
|
|
|
cursor->thr)) {
|
|
|
|
|
|
|
|
/* The purge was buffered. */
|
|
|
|
cursor->flag = BTR_CUR_DELETE_IBUF;
|
|
|
|
} else {
|
|
|
|
/* The purge could not be buffered. */
|
|
|
|
buf_pool_watch_clear();
|
2008-02-27 07:03:34 +00:00
|
|
|
break;
|
|
|
|
}
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
|
|
|
|
buf_pool_watch_clear();
|
|
|
|
goto func_exit;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ut_error;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2008-02-27 07:03:34 +00:00
|
|
|
/* Insert to the insert/delete buffer did not succeed, we
|
|
|
|
must read the page from disk. */
|
|
|
|
|
|
|
|
buf_mode = BUF_GET;
|
|
|
|
|
|
|
|
goto retry_page_get;
|
|
|
|
}
|
|
|
|
|
|
|
|
block->check_index_page_at_flush = TRUE;
|
|
|
|
page = buf_block_get_frame(block);
|
|
|
|
|
|
|
|
if (rw_latch != RW_NO_LATCH) {
|
2008-12-12 14:18:52 +00:00
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
|
|
|
const page_zip_des_t* page_zip
|
|
|
|
= buf_block_get_page_zip(block);
|
2008-02-27 07:03:34 +00:00
|
|
|
ut_a(!page_zip || page_zip_validate(page_zip, page));
|
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2008-02-27 07:03:34 +00:00
|
|
|
buf_block_dbg_add_level(block, SYNC_TREE_NODE);
|
|
|
|
}
|
2008-09-22 07:57:34 +00:00
|
|
|
|
2008-02-27 07:03:34 +00:00
|
|
|
ut_ad(0 == ut_dulint_cmp(index->id, btr_page_get_index_id(page)));
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-02-27 07:03:34 +00:00
|
|
|
if (UNIV_UNLIKELY(height == ULINT_UNDEFINED)) {
|
|
|
|
/* We are in the root node */
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-02-27 07:03:34 +00:00
|
|
|
height = btr_page_get_level(page, mtr);
|
|
|
|
root_height = height;
|
|
|
|
cursor->tree_height = root_height + 1;
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
#ifdef BTR_CUR_ADAPT
|
2008-02-27 07:03:34 +00:00
|
|
|
if (block != guess) {
|
|
|
|
info->root_guess = block;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
2008-02-27 07:03:34 +00:00
|
|
|
#endif
|
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2008-02-27 07:03:34 +00:00
|
|
|
if (height == 0) {
|
|
|
|
if (rw_latch == RW_NO_LATCH) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-02-27 07:03:34 +00:00
|
|
|
btr_cur_latch_leaves(
|
|
|
|
page, space, zip_size, page_no, latch_mode,
|
|
|
|
cursor, mtr);
|
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-02-27 07:03:34 +00:00
|
|
|
if (latch_mode != BTR_MODIFY_TREE
|
|
|
|
&& latch_mode != BTR_CONT_MODIFY_TREE) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-02-27 07:03:34 +00:00
|
|
|
/* Release the tree s-latch */
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-02-27 07:03:34 +00:00
|
|
|
mtr_release_s_latch_at_savepoint(
|
|
|
|
mtr, savepoint, dict_index_get_lock(index));
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2008-02-27 07:03:34 +00:00
|
|
|
page_mode = mode;
|
|
|
|
}
|
2006-10-18 11:39:31 +00:00
|
|
|
|
2008-02-27 07:03:34 +00:00
|
|
|
page_cur_search_with_match(
|
|
|
|
block, index, tuple, page_mode, &up_match, &up_bytes,
|
|
|
|
&low_match, &low_bytes, page_cursor);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-02-27 07:03:34 +00:00
|
|
|
if (estimate) {
|
|
|
|
btr_cur_add_path_info(cursor, height, root_height);
|
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-02-27 07:03:34 +00:00
|
|
|
/* If this is the desired level, leave the loop */
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-02-27 07:03:34 +00:00
|
|
|
ut_ad(height == btr_page_get_level(page_cur_get_page(page_cursor),
|
|
|
|
mtr));
|
2005-10-27 07:29:40 +00:00
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
if (level != height) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
ut_ad(height > 0);
|
2005-10-27 11:48:10 +00:00
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
height--;
|
|
|
|
guess = NULL;
|
2005-10-27 07:29:40 +00:00
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
node_ptr = page_cur_get_rec(page_cursor);
|
2008-10-15 10:18:28 +00:00
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
offsets = rec_get_offsets(
|
|
|
|
node_ptr, index, offsets, ULINT_UNDEFINED, &heap);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
/* Go to the child node */
|
|
|
|
page_no = btr_node_ptr_get_child_page_no(node_ptr, offsets);
|
2008-02-27 07:03:34 +00:00
|
|
|
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
goto search_loop;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2008-12-12 12:28:49 +00:00
|
|
|
if (level != 0) {
|
|
|
|
/* x-latch the page */
|
|
|
|
page = btr_page_get(
|
|
|
|
space, zip_size, page_no, RW_X_LATCH, mtr);
|
|
|
|
|
|
|
|
ut_a((ibool)!!page_is_comp(page)
|
|
|
|
== dict_table_is_comp(index->table));
|
|
|
|
} else {
|
2005-10-27 07:29:40 +00:00
|
|
|
cursor->low_match = low_match;
|
|
|
|
cursor->low_bytes = low_bytes;
|
|
|
|
cursor->up_match = up_match;
|
|
|
|
cursor->up_bytes = up_bytes;
|
|
|
|
|
2006-02-23 19:25:29 +00:00
|
|
|
#ifdef BTR_CUR_ADAPT
|
2006-11-21 14:40:14 +00:00
|
|
|
if (!UNIV_UNLIKELY(btr_search_disabled)) {
|
|
|
|
|
|
|
|
btr_search_info_update(index, cursor);
|
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
#endif
|
|
|
|
ut_ad(cursor->up_match != ULINT_UNDEFINED
|
2006-08-29 09:30:31 +00:00
|
|
|
|| mode != PAGE_CUR_GE);
|
2005-10-27 07:29:40 +00:00
|
|
|
ut_ad(cursor->up_match != ULINT_UNDEFINED
|
2006-08-29 09:30:31 +00:00
|
|
|
|| mode != PAGE_CUR_LE);
|
2005-10-27 07:29:40 +00:00
|
|
|
ut_ad(cursor->low_match != ULINT_UNDEFINED
|
2006-08-29 09:30:31 +00:00
|
|
|
|| mode != PAGE_CUR_LE);
|
branches/innodb+: Clean up the buffering of purges. Instead of
traversing the index B-tree twice (first in BTR_WATCH_LEAF mode and
then in BTR_DELETE mode), let BTR_DELETE take care of checking that
the record can be purged, and either buffering or performing the
purge.
row_purge_poss_sec(): New function, to check if it is possible to
purge a secondary index record. Refactored from
row_purge_remove_sec_if_poss_low().
row_purge_remove_sec_if_poss_nonbuffered(): Rename to
row_purge_remove_sec_if_poss_tree(). Remove the parameter mode
(always use BTR_MODIFY_TREE). Use row_purge_poss_sec().
row_purge_remove_sec_if_poss_low(): Rename to
row_purge_remove_sec_if_poss_leaf(). Remove the parameter mode
(always use BTR_MODIFY_LEAF). Let row_search_index_entry() do all the
hard work.
btr_cur_t: Add purge_node, which will be needed by
btr_cur_search_to_nth_level() for BTR_DELETE. Replace the flag value
BTR_CUR_ABORTED with BTR_CUR_DELETE_REF and BTR_CUR_DELETE_FAILED.
enum row_search_result, row_search_index_entry(): Replace
ROW_NOT_IN_POOL with ROW_NOT_DELETED_REF and ROW_NOT_DELETED.
btr_cur_search_to_nth_level(): Remove BTR_WATCH_LEAF. As a side
effect, the adaptive hash index can be used in purge as well. If
BTR_DELETE cannot be buffered, attempt btr_cur_optimistic_delete().
Either way, check row_purge_poss_sec(). Move the code to set
cursor->ibuf_count to get rid of another if (height == 0)
check. Eliminate the label loop_end. Do not call ibuf_should_try()
twice.
ibuf_should_try(): Now that the successful calls to this function will
be halved, halve the magic constant that ibuf_flush_count will be
compared to, accordingly.
The changes regarding ibuf_should_try() were merged from branches/zip
r3515.
rb://60 approved by Heikki over IM
2008-12-12 12:59:48 +00:00
|
|
|
|
|
|
|
/* If this was a delete operation, the leaf page was
|
|
|
|
in the buffer pool, and a matching record was found in
|
|
|
|
the leaf page, attempt to delete it. If the deletion
|
|
|
|
fails, set the cursor flag accordingly. */
|
|
|
|
if (UNIV_UNLIKELY(btr_op == BTR_DELETE_OP)
|
|
|
|
&& low_match == dtuple_get_n_fields(tuple)
|
|
|
|
&& !page_cur_is_before_first(page_cursor)) {
|
|
|
|
|
|
|
|
/* Before attempting to purge a record, check
|
|
|
|
if it is safe to do so. */
|
|
|
|
if (!row_purge_poss_sec(cursor->purge_node,
|
|
|
|
index, tuple)) {
|
|
|
|
|
|
|
|
cursor->flag = BTR_CUR_DELETE_REF;
|
|
|
|
} else {
|
|
|
|
/* Only delete-marked records should
|
|
|
|
be purged. */
|
|
|
|
ut_ad(REC_INFO_DELETED_FLAG
|
|
|
|
& rec_get_info_bits(
|
|
|
|
btr_cur_get_rec(cursor),
|
|
|
|
page_is_comp(page)));
|
|
|
|
|
|
|
|
if (!btr_cur_optimistic_delete(cursor, mtr)) {
|
|
|
|
|
|
|
|
cursor->flag = BTR_CUR_DELETE_FAILED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2006-06-13 20:23:26 +00:00
|
|
|
func_exit:
|
2008-02-27 07:03:34 +00:00
|
|
|
|
|
|
|
if (UNIV_LIKELY_NULL(heap)) {
|
|
|
|
mem_heap_free(heap);
|
|
|
|
}
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
if (has_search_latch) {
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
rw_lock_s_lock(&btr_search_latch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
Opens a cursor at either end of an index. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
void
|
|
|
|
btr_cur_open_at_index_side(
|
|
|
|
/*=======================*/
|
|
|
|
ibool from_left, /* in: TRUE if open to the low end,
|
|
|
|
FALSE if to the high end */
|
|
|
|
dict_index_t* index, /* in: index */
|
|
|
|
ulint latch_mode, /* in: latch mode */
|
|
|
|
btr_cur_t* cursor, /* in: cursor */
|
|
|
|
mtr_t* mtr) /* in: mtr */
|
|
|
|
{
|
|
|
|
page_cur_t* page_cursor;
|
|
|
|
ulint page_no;
|
|
|
|
ulint space;
|
2007-01-18 09:59:00 +00:00
|
|
|
ulint zip_size;
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint height;
|
|
|
|
ulint root_height = 0; /* remove warning */
|
|
|
|
rec_t* node_ptr;
|
|
|
|
ulint estimate;
|
2006-02-23 19:25:29 +00:00
|
|
|
ulint savepoint;
|
2005-10-27 07:29:40 +00:00
|
|
|
mem_heap_t* heap = NULL;
|
|
|
|
ulint offsets_[REC_OFFS_NORMAL_SIZE];
|
|
|
|
ulint* offsets = offsets_;
|
2007-09-28 07:05:57 +00:00
|
|
|
rec_offs_init(offsets_);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
estimate = latch_mode & BTR_ESTIMATE;
|
|
|
|
latch_mode = latch_mode & ~BTR_ESTIMATE;
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/* Store the position of the tree latch we push to mtr so that we
|
|
|
|
know how to release it when we have latched the leaf node */
|
|
|
|
|
|
|
|
savepoint = mtr_set_savepoint(mtr);
|
|
|
|
|
|
|
|
if (latch_mode == BTR_MODIFY_TREE) {
|
2006-09-19 10:14:07 +00:00
|
|
|
mtr_x_lock(dict_index_get_lock(index), mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
} else {
|
2006-09-19 10:14:07 +00:00
|
|
|
mtr_s_lock(dict_index_get_lock(index), mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
page_cursor = btr_cur_get_page_cur(cursor);
|
|
|
|
cursor->index = index;
|
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
space = dict_index_get_space(index);
|
2007-01-18 09:59:00 +00:00
|
|
|
zip_size = dict_table_zip_size(index->table);
|
2006-09-19 10:14:07 +00:00
|
|
|
page_no = dict_index_get_page(index);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
height = ULINT_UNDEFINED;
|
|
|
|
|
|
|
|
for (;;) {
|
2006-10-12 11:05:22 +00:00
|
|
|
buf_block_t* block;
|
|
|
|
page_t* page;
|
2007-01-18 09:59:00 +00:00
|
|
|
block = buf_page_get_gen(space, zip_size, page_no,
|
|
|
|
RW_NO_LATCH, NULL, BUF_GET,
|
2008-02-27 07:03:34 +00:00
|
|
|
__FILE__, __LINE__, mtr);
|
2006-10-12 11:05:22 +00:00
|
|
|
page = buf_block_get_frame(block);
|
2006-09-19 10:14:07 +00:00
|
|
|
ut_ad(0 == ut_dulint_cmp(index->id,
|
2006-08-29 09:30:31 +00:00
|
|
|
btr_page_get_index_id(page)));
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-10-12 11:05:22 +00:00
|
|
|
block->check_index_page_at_flush = TRUE;
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (height == ULINT_UNDEFINED) {
|
|
|
|
/* We are in the root node */
|
|
|
|
|
|
|
|
height = btr_page_get_level(page, mtr);
|
|
|
|
root_height = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (height == 0) {
|
2007-01-18 09:59:00 +00:00
|
|
|
btr_cur_latch_leaves(page, space, zip_size, page_no,
|
2006-08-29 09:30:31 +00:00
|
|
|
latch_mode, cursor, mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/* In versions <= 3.23.52 we had forgotten to
|
|
|
|
release the tree latch here. If in an index scan
|
|
|
|
we had to scan far to find a record visible to the
|
|
|
|
current transaction, that could starve others
|
|
|
|
waiting for the tree latch. */
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
if ((latch_mode != BTR_MODIFY_TREE)
|
2006-08-29 09:30:31 +00:00
|
|
|
&& (latch_mode != BTR_CONT_MODIFY_TREE)) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/* Release the tree s-latch */
|
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
mtr_release_s_latch_at_savepoint(
|
|
|
|
mtr, savepoint,
|
|
|
|
dict_index_get_lock(index));
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
if (from_left) {
|
2006-10-20 12:45:53 +00:00
|
|
|
page_cur_set_before_first(block, page_cursor);
|
2005-10-27 07:29:40 +00:00
|
|
|
} else {
|
2006-10-20 12:45:53 +00:00
|
|
|
page_cur_set_after_last(block, page_cursor);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (height == 0) {
|
2006-02-23 19:25:29 +00:00
|
|
|
if (estimate) {
|
|
|
|
btr_cur_add_path_info(cursor, height,
|
2006-08-29 09:30:31 +00:00
|
|
|
root_height);
|
2006-02-23 19:25:29 +00:00
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ut_ad(height > 0);
|
|
|
|
|
|
|
|
if (from_left) {
|
|
|
|
page_cur_move_to_next(page_cursor);
|
|
|
|
} else {
|
|
|
|
page_cur_move_to_prev(page_cursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (estimate) {
|
|
|
|
btr_cur_add_path_info(cursor, height, root_height);
|
|
|
|
}
|
|
|
|
|
|
|
|
height--;
|
|
|
|
|
|
|
|
node_ptr = page_cur_get_rec(page_cursor);
|
|
|
|
offsets = rec_get_offsets(node_ptr, cursor->index, offsets,
|
2006-08-29 09:30:31 +00:00
|
|
|
ULINT_UNDEFINED, &heap);
|
2005-10-27 07:29:40 +00:00
|
|
|
/* Go to the child node */
|
|
|
|
page_no = btr_node_ptr_get_child_page_no(node_ptr, offsets);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (UNIV_LIKELY_NULL(heap)) {
|
|
|
|
mem_heap_free(heap);
|
|
|
|
}
|
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/**************************************************************************
|
|
|
|
Positions a cursor at a randomly chosen position within a B-tree. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
void
|
|
|
|
btr_cur_open_at_rnd_pos(
|
|
|
|
/*====================*/
|
|
|
|
dict_index_t* index, /* in: index */
|
|
|
|
ulint latch_mode, /* in: BTR_SEARCH_LEAF, ... */
|
|
|
|
btr_cur_t* cursor, /* in/out: B-tree cursor */
|
|
|
|
mtr_t* mtr) /* in: mtr */
|
|
|
|
{
|
|
|
|
page_cur_t* page_cursor;
|
|
|
|
ulint page_no;
|
|
|
|
ulint space;
|
2007-01-18 09:59:00 +00:00
|
|
|
ulint zip_size;
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint height;
|
|
|
|
rec_t* node_ptr;
|
|
|
|
mem_heap_t* heap = NULL;
|
|
|
|
ulint offsets_[REC_OFFS_NORMAL_SIZE];
|
|
|
|
ulint* offsets = offsets_;
|
2007-09-28 07:05:57 +00:00
|
|
|
rec_offs_init(offsets_);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (latch_mode == BTR_MODIFY_TREE) {
|
2006-09-19 10:14:07 +00:00
|
|
|
mtr_x_lock(dict_index_get_lock(index), mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
} else {
|
2006-09-19 10:14:07 +00:00
|
|
|
mtr_s_lock(dict_index_get_lock(index), mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
page_cursor = btr_cur_get_page_cur(cursor);
|
|
|
|
cursor->index = index;
|
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
space = dict_index_get_space(index);
|
2007-01-18 09:59:00 +00:00
|
|
|
zip_size = dict_table_zip_size(index->table);
|
2006-09-19 10:14:07 +00:00
|
|
|
page_no = dict_index_get_page(index);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
height = ULINT_UNDEFINED;
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
for (;;) {
|
2006-10-12 11:05:22 +00:00
|
|
|
buf_block_t* block;
|
|
|
|
page_t* page;
|
|
|
|
|
2007-01-18 09:59:00 +00:00
|
|
|
block = buf_page_get_gen(space, zip_size, page_no,
|
|
|
|
RW_NO_LATCH, NULL, BUF_GET,
|
2008-09-19 13:34:12 +00:00
|
|
|
__FILE__, __LINE__, mtr);
|
2006-10-12 11:05:22 +00:00
|
|
|
page = buf_block_get_frame(block);
|
2006-09-19 10:14:07 +00:00
|
|
|
ut_ad(0 == ut_dulint_cmp(index->id,
|
2006-08-29 09:30:31 +00:00
|
|
|
btr_page_get_index_id(page)));
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (height == ULINT_UNDEFINED) {
|
|
|
|
/* We are in the root node */
|
|
|
|
|
|
|
|
height = btr_page_get_level(page, mtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (height == 0) {
|
2007-01-18 09:59:00 +00:00
|
|
|
btr_cur_latch_leaves(page, space, zip_size, page_no,
|
2006-08-29 09:30:31 +00:00
|
|
|
latch_mode, cursor, mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2006-10-20 12:45:53 +00:00
|
|
|
page_cur_open_on_rnd_user_rec(block, page_cursor);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (height == 0) {
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ut_ad(height > 0);
|
|
|
|
|
|
|
|
height--;
|
|
|
|
|
|
|
|
node_ptr = page_cur_get_rec(page_cursor);
|
|
|
|
offsets = rec_get_offsets(node_ptr, cursor->index, offsets,
|
2006-08-29 09:30:31 +00:00
|
|
|
ULINT_UNDEFINED, &heap);
|
2005-10-27 07:29:40 +00:00
|
|
|
/* Go to the child node */
|
|
|
|
page_no = btr_node_ptr_get_child_page_no(node_ptr, offsets);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (UNIV_LIKELY_NULL(heap)) {
|
|
|
|
mem_heap_free(heap);
|
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/*==================== B-TREE INSERT =========================*/
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
Inserts a record if there is enough space, or if enough space can
|
2008-09-17 19:52:30 +00:00
|
|
|
be freed by reorganizing. Differs from btr_cur_optimistic_insert because
|
2005-10-27 07:29:40 +00:00
|
|
|
no heuristics is applied to whether it pays to use CPU time for
|
|
|
|
reorganizing the page or not. */
|
|
|
|
static
|
|
|
|
rec_t*
|
|
|
|
btr_cur_insert_if_possible(
|
|
|
|
/*=======================*/
|
|
|
|
/* out: pointer to inserted record if succeed,
|
|
|
|
else NULL */
|
|
|
|
btr_cur_t* cursor, /* in: cursor on page after which to insert;
|
|
|
|
cursor stays valid */
|
2006-10-20 08:30:07 +00:00
|
|
|
const dtuple_t* tuple, /* in: tuple to insert; the size info need not
|
2005-10-27 07:29:40 +00:00
|
|
|
have been stored to tuple */
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
ulint n_ext, /* in: number of externally stored columns */
|
2005-10-27 07:29:40 +00:00
|
|
|
mtr_t* mtr) /* in: mtr */
|
|
|
|
{
|
|
|
|
page_cur_t* page_cursor;
|
2006-10-18 11:39:31 +00:00
|
|
|
buf_block_t* block;
|
2005-10-27 07:29:40 +00:00
|
|
|
rec_t* rec;
|
|
|
|
|
|
|
|
ut_ad(dtuple_check_typed(tuple));
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2006-10-18 11:39:31 +00:00
|
|
|
block = btr_cur_get_block(cursor);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-10-18 11:39:31 +00:00
|
|
|
ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX));
|
2005-10-27 07:29:40 +00:00
|
|
|
page_cursor = btr_cur_get_page_cur(cursor);
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/* Now, try the insert */
|
2006-10-20 12:45:53 +00:00
|
|
|
rec = page_cur_tuple_insert(page_cursor, tuple,
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
cursor->index, n_ext, mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2007-02-28 11:08:59 +00:00
|
|
|
if (UNIV_UNLIKELY(!rec)) {
|
|
|
|
/* If record did not fit, reorganize */
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-10-18 11:39:31 +00:00
|
|
|
if (btr_page_reorganize(block, cursor->index, mtr)) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-10-20 12:45:53 +00:00
|
|
|
page_cur_search(block, cursor->index, tuple,
|
2006-08-29 09:30:31 +00:00
|
|
|
PAGE_CUR_LE, page_cursor);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-10-20 12:45:53 +00:00
|
|
|
rec = page_cur_tuple_insert(page_cursor, tuple,
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
cursor->index, n_ext, mtr);
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return(rec);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
For an insert, checks the locks and does the undo logging if desired. */
|
|
|
|
UNIV_INLINE
|
|
|
|
ulint
|
|
|
|
btr_cur_ins_lock_and_undo(
|
|
|
|
/*======================*/
|
|
|
|
/* out: DB_SUCCESS, DB_WAIT_LOCK,
|
|
|
|
DB_FAIL, or error number */
|
|
|
|
ulint flags, /* in: undo logging and locking flags: if
|
|
|
|
not zero, the parameters index and thr
|
|
|
|
should be specified */
|
|
|
|
btr_cur_t* cursor, /* in: cursor on page after which to insert */
|
2006-10-20 08:30:07 +00:00
|
|
|
const dtuple_t* entry, /* in: entry to insert */
|
2005-10-27 07:29:40 +00:00
|
|
|
que_thr_t* thr, /* in: query thread or NULL */
|
|
|
|
ibool* inherit)/* out: TRUE if the inserted new record maybe
|
|
|
|
should inherit LOCK_GAP type locks from the
|
|
|
|
successor record */
|
|
|
|
{
|
|
|
|
dict_index_t* index;
|
|
|
|
ulint err;
|
|
|
|
rec_t* rec;
|
|
|
|
dulint roll_ptr;
|
|
|
|
|
|
|
|
/* Check if we have to wait for a lock: enqueue an explicit lock
|
|
|
|
request if yes */
|
|
|
|
|
|
|
|
rec = btr_cur_get_rec(cursor);
|
|
|
|
index = cursor->index;
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2006-10-18 11:39:31 +00:00
|
|
|
err = lock_rec_insert_check_and_lock(flags, rec,
|
|
|
|
btr_cur_get_block(cursor),
|
|
|
|
index, thr, inherit);
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
2008-01-25 08:13:12 +00:00
|
|
|
if (dict_index_is_clust(index) && !dict_index_is_ibuf(index)) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
err = trx_undo_report_row_operation(flags, TRX_UNDO_INSERT_OP,
|
2006-08-29 09:30:31 +00:00
|
|
|
thr, index, entry,
|
|
|
|
NULL, 0, NULL,
|
|
|
|
&roll_ptr);
|
2005-10-27 07:29:40 +00:00
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now we can fill in the roll ptr field in entry */
|
|
|
|
|
|
|
|
if (!(flags & BTR_KEEP_SYS_FLAG)) {
|
|
|
|
|
|
|
|
row_upd_index_entry_sys_field(entry, index,
|
2006-08-29 09:30:31 +00:00
|
|
|
DATA_ROLL_PTR, roll_ptr);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(DB_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef UNIV_DEBUG
|
|
|
|
/*****************************************************************
|
|
|
|
Report information about a transaction. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
btr_cur_trx_report(
|
|
|
|
/*===============*/
|
|
|
|
trx_t* trx, /* in: transaction */
|
|
|
|
const dict_index_t* index, /* in: index */
|
|
|
|
const char* op) /* in: operation */
|
|
|
|
{
|
2007-12-20 14:08:16 +00:00
|
|
|
fprintf(stderr, "Trx with id " TRX_ID_FMT " going to ",
|
|
|
|
TRX_ID_PREP_PRINTF(trx->id));
|
2005-10-27 07:29:40 +00:00
|
|
|
fputs(op, stderr);
|
|
|
|
dict_index_name_print(stderr, trx, index);
|
|
|
|
putc('\n', stderr);
|
|
|
|
}
|
|
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
Tries to perform an insert to a page in an index tree, next to cursor.
|
|
|
|
It is assumed that mtr holds an x-latch on the page. The operation does
|
|
|
|
not succeed if there is too little space on the page. If there is just
|
|
|
|
one record on the page, the insert will always succeed; this is to
|
|
|
|
prevent trying to split a page with just one record. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint
|
|
|
|
btr_cur_optimistic_insert(
|
|
|
|
/*======================*/
|
|
|
|
/* out: DB_SUCCESS, DB_WAIT_LOCK,
|
|
|
|
DB_FAIL, or error number */
|
|
|
|
ulint flags, /* in: undo logging and locking flags: if not
|
|
|
|
zero, the parameters index and thr should be
|
|
|
|
specified */
|
|
|
|
btr_cur_t* cursor, /* in: cursor on page after which to insert;
|
|
|
|
cursor stays valid */
|
2006-10-20 08:30:07 +00:00
|
|
|
dtuple_t* entry, /* in/out: entry to insert */
|
2005-10-27 07:29:40 +00:00
|
|
|
rec_t** rec, /* out: pointer to inserted record if
|
|
|
|
succeed */
|
|
|
|
big_rec_t** big_rec,/* out: big rec vector whose fields have to
|
|
|
|
be stored externally by the caller, or
|
|
|
|
NULL */
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
ulint n_ext, /* in: number of externally stored columns */
|
2005-10-27 07:29:40 +00:00
|
|
|
que_thr_t* thr, /* in: query thread or NULL */
|
2007-05-16 12:01:31 +00:00
|
|
|
mtr_t* mtr) /* in: mtr; if this function returns
|
|
|
|
DB_SUCCESS on a leaf page of a secondary
|
|
|
|
index in a compressed tablespace, the
|
|
|
|
mtr must be committed before latching
|
|
|
|
any further pages */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
|
|
|
big_rec_t* big_rec_vec = NULL;
|
|
|
|
dict_index_t* index;
|
|
|
|
page_cur_t* page_cursor;
|
2006-10-13 07:45:52 +00:00
|
|
|
buf_block_t* block;
|
2005-10-27 07:29:40 +00:00
|
|
|
page_t* page;
|
|
|
|
ulint max_size;
|
|
|
|
rec_t* dummy_rec;
|
2007-05-16 12:01:31 +00:00
|
|
|
ibool leaf;
|
2005-10-27 07:29:40 +00:00
|
|
|
ibool reorg;
|
|
|
|
ibool inherit;
|
branches/zip: Enable the insert buffer on compressed tablespaces.
page_zip_max_ins_size(): New function.
btr_cur_optimistic_insert(), btr_cur_optimistic_delete(),
btr_page_split_and_insert(), btr_compress(): Do not update the
ibuf free bits for non-leaf pages or pages belonging to a clustered index.
The insert buffer only covers operations on leaf pages of secondary indexes.
For pages covered by the insert buffer, limit the max_ins_size to
page_zip_max_ins_size().
buf_page_get_gen(): Merge the insert buffer after decompressing the page.
buf_page_io_complete(): Relax the assertion about ibuf_count. For
compressed-only pages, the insert buffer merge takes place
in buf_page_get_gen().
ibuf_index_page_calc_free_bits(), ibuf_index_page_calc_free_from_bits(),
ibuf_index_page_calc_free(), ibuf_update_free_bits_if_full(),
ibuf_update_free_bits_low(), ibuf_update_free_bits_for_two_pages_low(),
ibuf_set_free_bits_low(): Add the parameter zip_size. Limit the maximum
insert size to page_zip_max_ins_size().
2007-02-19 20:32:06 +00:00
|
|
|
ulint zip_size;
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint rec_size;
|
2006-02-13 14:28:00 +00:00
|
|
|
mem_heap_t* heap = NULL;
|
2006-02-23 19:25:29 +00:00
|
|
|
ulint err;
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
*big_rec = NULL;
|
|
|
|
|
2006-10-18 11:39:31 +00:00
|
|
|
block = btr_cur_get_block(cursor);
|
2006-10-13 07:45:52 +00:00
|
|
|
page = buf_block_get_frame(block);
|
2005-10-27 07:29:40 +00:00
|
|
|
index = cursor->index;
|
branches/zip: Enable the insert buffer on compressed tablespaces.
page_zip_max_ins_size(): New function.
btr_cur_optimistic_insert(), btr_cur_optimistic_delete(),
btr_page_split_and_insert(), btr_compress(): Do not update the
ibuf free bits for non-leaf pages or pages belonging to a clustered index.
The insert buffer only covers operations on leaf pages of secondary indexes.
For pages covered by the insert buffer, limit the max_ins_size to
page_zip_max_ins_size().
buf_page_get_gen(): Merge the insert buffer after decompressing the page.
buf_page_io_complete(): Relax the assertion about ibuf_count. For
compressed-only pages, the insert buffer merge takes place
in buf_page_get_gen().
ibuf_index_page_calc_free_bits(), ibuf_index_page_calc_free_from_bits(),
ibuf_index_page_calc_free(), ibuf_update_free_bits_if_full(),
ibuf_update_free_bits_low(), ibuf_update_free_bits_for_two_pages_low(),
ibuf_set_free_bits_low(): Add the parameter zip_size. Limit the maximum
insert size to page_zip_max_ins_size().
2007-02-19 20:32:06 +00:00
|
|
|
zip_size = buf_block_get_zip_size(block);
|
2007-10-31 14:27:59 +00:00
|
|
|
#ifdef UNIV_DEBUG_VALGRIND
|
|
|
|
if (zip_size) {
|
|
|
|
UNIV_MEM_ASSERT_RW(page, UNIV_PAGE_SIZE);
|
2007-10-31 16:14:18 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(block->page.zip.data, zip_size);
|
2007-10-31 14:27:59 +00:00
|
|
|
}
|
|
|
|
#endif /* UNIV_DEBUG_VALGRIND */
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (!dtuple_check_typed_no_assert(entry)) {
|
|
|
|
fputs("InnoDB: Error in a tuple to insert into ", stderr);
|
|
|
|
dict_index_name_print(stderr, thr_get_trx(thr), index);
|
|
|
|
}
|
|
|
|
#ifdef UNIV_DEBUG
|
|
|
|
if (btr_cur_print_record_ops && thr) {
|
|
|
|
btr_cur_trx_report(thr_get_trx(thr), index, "insert into ");
|
|
|
|
dtuple_print(stderr, entry);
|
|
|
|
}
|
|
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
|
2006-10-13 07:45:52 +00:00
|
|
|
ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX));
|
2005-10-27 07:29:40 +00:00
|
|
|
max_size = page_get_max_insert_size_after_reorganize(page, 1);
|
2007-05-16 12:01:31 +00:00
|
|
|
leaf = page_is_leaf(page);
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/* Calculate the record size when entry is converted to a record */
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
rec_size = rec_get_converted_size(index, entry, n_ext);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-09-17 19:52:30 +00:00
|
|
|
if (page_zip_rec_needs_ext(rec_size, page_is_comp(page),
|
|
|
|
dtuple_get_n_fields(entry), zip_size)) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/* The record is so big that we have to store some fields
|
|
|
|
externally on separate database pages */
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
big_rec_vec = dtuple_convert_big_rec(index, entry, &n_ext);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-08-31 10:53:00 +00:00
|
|
|
if (UNIV_UNLIKELY(big_rec_vec == NULL)) {
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
return(DB_TOO_BIG_RECORD);
|
|
|
|
}
|
2007-01-31 14:12:57 +00:00
|
|
|
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
rec_size = rec_get_converted_size(index, entry, n_ext);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2008-09-17 19:52:30 +00:00
|
|
|
if (UNIV_UNLIKELY(zip_size)) {
|
|
|
|
/* Estimate the free space of an empty compressed page.
|
|
|
|
Subtract one byte for the encoded heap_no in the
|
|
|
|
modification log. */
|
|
|
|
ulint free_space_zip = page_zip_empty_size(
|
|
|
|
cursor->index->n_fields, zip_size) - 1;
|
|
|
|
ulint n_uniq = dict_index_get_n_unique_in_tree(index);
|
|
|
|
|
|
|
|
ut_ad(dict_table_is_comp(index->table));
|
|
|
|
|
|
|
|
/* There should be enough room for two node pointer
|
|
|
|
records on an empty non-leaf page. This prevents
|
|
|
|
infinite page splits. */
|
|
|
|
|
|
|
|
if (UNIV_LIKELY(entry->n_fields >= n_uniq)
|
2008-10-11 19:37:21 +00:00
|
|
|
&& UNIV_UNLIKELY(REC_NODE_PTR_SIZE
|
|
|
|
+ rec_get_converted_size_comp_prefix(
|
|
|
|
index, entry->fields, n_uniq,
|
|
|
|
NULL)
|
2008-09-17 19:52:30 +00:00
|
|
|
/* On a compressed page, there is
|
|
|
|
a two-byte entry in the dense
|
|
|
|
page directory for every record.
|
|
|
|
But there is no record header. */
|
|
|
|
- (REC_N_NEW_EXTRA_BYTES - 2)
|
|
|
|
> free_space_zip / 2)) {
|
|
|
|
|
|
|
|
if (big_rec_vec) {
|
|
|
|
dtuple_convert_back_big_rec(
|
|
|
|
index, entry, big_rec_vec);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (heap) {
|
|
|
|
mem_heap_free(heap);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(DB_TOO_BIG_RECORD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/* If there have been many consecutive inserts, and we are on the leaf
|
|
|
|
level, check if we have to split the page to reserve enough free space
|
|
|
|
for future updates of records. */
|
|
|
|
|
2007-01-31 14:12:57 +00:00
|
|
|
if (dict_index_is_clust(index)
|
2006-08-29 09:30:31 +00:00
|
|
|
&& (page_get_n_recs(page) >= 2)
|
2007-05-16 12:01:31 +00:00
|
|
|
&& UNIV_LIKELY(leaf)
|
2007-01-31 14:12:57 +00:00
|
|
|
&& (dict_index_get_space_reserve() + rec_size > max_size)
|
2006-08-29 09:30:31 +00:00
|
|
|
&& (btr_page_get_split_rec_to_right(cursor, &dummy_rec)
|
|
|
|
|| btr_page_get_split_rec_to_left(cursor, &dummy_rec))) {
|
2006-09-05 12:49:35 +00:00
|
|
|
fail:
|
2007-02-12 12:04:49 +00:00
|
|
|
err = DB_FAIL;
|
|
|
|
fail_err:
|
|
|
|
|
2006-02-23 19:25:29 +00:00
|
|
|
if (big_rec_vec) {
|
2005-10-27 07:29:40 +00:00
|
|
|
dtuple_convert_back_big_rec(index, entry, big_rec_vec);
|
|
|
|
}
|
|
|
|
|
2007-02-12 12:04:49 +00:00
|
|
|
if (UNIV_LIKELY_NULL(heap)) {
|
|
|
|
mem_heap_free(heap);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(err);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2007-01-31 14:12:57 +00:00
|
|
|
if (UNIV_UNLIKELY(max_size < BTR_CUR_PAGE_REORGANIZE_LIMIT
|
|
|
|
|| max_size < rec_size)
|
|
|
|
&& UNIV_LIKELY(page_get_n_recs(page) > 1)
|
|
|
|
&& page_get_max_insert_size(page, 1) < rec_size) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-09-05 12:49:35 +00:00
|
|
|
goto fail;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2006-02-23 19:25:29 +00:00
|
|
|
/* Check locks and write to the undo log, if specified */
|
|
|
|
err = btr_cur_ins_lock_and_undo(flags, cursor, entry, thr, &inherit);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2007-02-12 12:04:49 +00:00
|
|
|
if (UNIV_UNLIKELY(err != DB_SUCCESS)) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2007-02-12 12:04:49 +00:00
|
|
|
goto fail_err;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
page_cursor = btr_cur_get_page_cur(cursor);
|
|
|
|
|
|
|
|
/* Now, try the insert */
|
|
|
|
|
2007-02-20 13:36:17 +00:00
|
|
|
{
|
|
|
|
const rec_t* page_cursor_rec = page_cur_get_rec(page_cursor);
|
|
|
|
*rec = page_cur_tuple_insert(page_cursor, entry, index,
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
n_ext, mtr);
|
2007-02-20 13:36:17 +00:00
|
|
|
reorg = page_cursor_rec != page_cur_get_rec(page_cursor);
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2007-02-20 13:36:17 +00:00
|
|
|
if (UNIV_UNLIKELY(reorg)) {
|
|
|
|
ut_a(zip_size);
|
|
|
|
ut_a(*rec);
|
|
|
|
}
|
|
|
|
}
|
2007-02-20 11:30:13 +00:00
|
|
|
|
2007-02-28 11:08:59 +00:00
|
|
|
if (UNIV_UNLIKELY(!*rec) && UNIV_LIKELY(!reorg)) {
|
|
|
|
/* If the record did not fit, reorganize */
|
2007-02-20 13:36:17 +00:00
|
|
|
if (UNIV_UNLIKELY(!btr_page_reorganize(block, index, mtr))) {
|
2007-02-28 11:08:59 +00:00
|
|
|
ut_a(zip_size);
|
|
|
|
|
|
|
|
goto fail;
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2007-02-28 13:19:13 +00:00
|
|
|
ut_ad(zip_size
|
|
|
|
|| page_get_max_insert_size(page, 1) == max_size);
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
reorg = TRUE;
|
|
|
|
|
2006-10-20 12:45:53 +00:00
|
|
|
page_cur_search(block, index, entry, PAGE_CUR_LE, page_cursor);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-10-20 12:45:53 +00:00
|
|
|
*rec = page_cur_tuple_insert(page_cursor, entry, index,
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
n_ext, mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (UNIV_UNLIKELY(!*rec)) {
|
2007-02-28 11:08:59 +00:00
|
|
|
if (UNIV_LIKELY(zip_size != 0)) {
|
|
|
|
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
fputs("InnoDB: Error: cannot insert tuple ", stderr);
|
|
|
|
dtuple_print(stderr, entry);
|
|
|
|
fputs(" into ", stderr);
|
|
|
|
dict_index_name_print(stderr, thr_get_trx(thr), index);
|
|
|
|
fprintf(stderr, "\nInnoDB: max insert size %lu\n",
|
|
|
|
(ulong) max_size);
|
|
|
|
ut_error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-13 14:28:00 +00:00
|
|
|
if (UNIV_LIKELY_NULL(heap)) {
|
|
|
|
mem_heap_free(heap);
|
|
|
|
}
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
#ifdef BTR_CUR_HASH_ADAPT
|
2007-05-16 12:01:31 +00:00
|
|
|
if (!reorg && leaf && (cursor->flag == BTR_CUR_HASH)) {
|
2005-10-27 07:29:40 +00:00
|
|
|
btr_search_update_hash_node_on_insert(cursor);
|
|
|
|
} else {
|
|
|
|
btr_search_update_hash_on_insert(cursor);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!(flags & BTR_NO_LOCKING_FLAG) && inherit) {
|
|
|
|
|
2006-10-24 06:45:52 +00:00
|
|
|
lock_update_insert(block, *rec);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2006-08-29 09:30:31 +00:00
|
|
|
#if 0
|
|
|
|
fprintf(stderr, "Insert into page %lu, max ins size %lu,"
|
2005-10-27 07:29:40 +00:00
|
|
|
" rec %lu ind type %lu\n",
|
2006-10-23 18:26:10 +00:00
|
|
|
buf_block_get_page_no(block), max_size,
|
2007-01-31 14:12:57 +00:00
|
|
|
rec_size + PAGE_DIR_SLOT_SIZE, index->type);
|
2006-08-29 09:30:31 +00:00
|
|
|
#endif
|
2007-05-16 12:01:31 +00:00
|
|
|
if (!dict_index_is_clust(index) && leaf) {
|
branches/zip: Document and obey the rules for modifying the free bits in
the insert buffer bitmap.
ibuf_set_free_bits_func(): Never disable redo logging.
ibuf_update_free_bits_zip(): Remove.
btr_page_reorganize_low(), page_zip_reorganize(): Do not update the insert
buffer bitmap. Instead, document that callers will have to take care of it,
and adapt the callers.
btr_compress(): On error, reset the insert buffer free bits.
btr_cur_insert_if_possible(): Do not modify the insert buffer bitmap.
btr_compress(), btr_cur_optimistic_insert(): On compressed pages,
reset the insert buffer bitmap. Document why.
btr_cur_update_alloc_zip(): Document why it is necessary and sufficient
to reset the insert buffer free bits.
btr_cur_update_in_place(), btr_cur_optimistic_update(),
btr_cur_pessimistic_update(): Update the free bits in the same
mini-transaction. Document that the mini-transaction must be
committed before latching any further pages. Verify that this
is the case in all execution paths.
row_ins_sec_index_entry_by_modify(), row_ins_clust_index_entry_by_modify(),
row_undo_mod_clust_low(): Because these functions call
btr_cur_update_in_place(), btr_cur_optimistic_update(), or
btr_cur_pessimistic_update(), document that the mini-transaction must be
committed before latching any further pages. Verify that this is the case
in all execution paths.
2007-05-16 09:23:53 +00:00
|
|
|
/* Update the free bits of the B-tree page in the
|
2007-05-16 12:01:31 +00:00
|
|
|
insert buffer bitmap. */
|
branches/zip: Document and obey the rules for modifying the free bits in
the insert buffer bitmap.
ibuf_set_free_bits_func(): Never disable redo logging.
ibuf_update_free_bits_zip(): Remove.
btr_page_reorganize_low(), page_zip_reorganize(): Do not update the insert
buffer bitmap. Instead, document that callers will have to take care of it,
and adapt the callers.
btr_compress(): On error, reset the insert buffer free bits.
btr_cur_insert_if_possible(): Do not modify the insert buffer bitmap.
btr_compress(), btr_cur_optimistic_insert(): On compressed pages,
reset the insert buffer bitmap. Document why.
btr_cur_update_alloc_zip(): Document why it is necessary and sufficient
to reset the insert buffer free bits.
btr_cur_update_in_place(), btr_cur_optimistic_update(),
btr_cur_pessimistic_update(): Update the free bits in the same
mini-transaction. Document that the mini-transaction must be
committed before latching any further pages. Verify that this
is the case in all execution paths.
row_ins_sec_index_entry_by_modify(), row_ins_clust_index_entry_by_modify(),
row_undo_mod_clust_low(): Because these functions call
btr_cur_update_in_place(), btr_cur_optimistic_update(), or
btr_cur_pessimistic_update(), document that the mini-transaction must be
committed before latching any further pages. Verify that this is the case
in all execution paths.
2007-05-16 09:23:53 +00:00
|
|
|
|
|
|
|
/* The free bits in the insert buffer bitmap must
|
|
|
|
never exceed the free space on a page. It is safe to
|
|
|
|
decrement or reset the bits in the bitmap in a
|
|
|
|
mini-transaction that is committed before the
|
|
|
|
mini-transaction that affects the free space. */
|
|
|
|
|
|
|
|
/* It is unsafe to increment the bits in a separately
|
|
|
|
committed mini-transaction, because in crash recovery,
|
|
|
|
the free bits could momentarily be set too high. */
|
|
|
|
|
2007-02-28 13:19:13 +00:00
|
|
|
if (zip_size) {
|
2007-05-16 12:01:31 +00:00
|
|
|
/* Update the bits in the same mini-transaction. */
|
2007-10-12 13:25:12 +00:00
|
|
|
ibuf_update_free_bits_zip(block, mtr);
|
2007-02-28 13:19:13 +00:00
|
|
|
} else {
|
2007-05-16 12:01:31 +00:00
|
|
|
/* Decrement the bits in a separate
|
|
|
|
mini-transaction. */
|
2007-02-28 13:19:13 +00:00
|
|
|
ibuf_update_free_bits_if_full(
|
2007-05-06 12:39:46 +00:00
|
|
|
block, max_size,
|
2007-02-28 13:19:13 +00:00
|
|
|
rec_size + PAGE_DIR_SLOT_SIZE);
|
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*big_rec = big_rec_vec;
|
|
|
|
|
|
|
|
return(DB_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
Performs an insert on a page of an index tree. It is assumed that mtr
|
|
|
|
holds an x-latch on the tree and on the cursor page. If the insert is
|
|
|
|
made on the leaf level, to avoid deadlocks, mtr must also own x-latches
|
|
|
|
to brothers of page, if those brothers exist. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint
|
|
|
|
btr_cur_pessimistic_insert(
|
|
|
|
/*=======================*/
|
|
|
|
/* out: DB_SUCCESS or error number */
|
|
|
|
ulint flags, /* in: undo logging and locking flags: if not
|
|
|
|
zero, the parameter thr should be
|
|
|
|
specified; if no undo logging is specified,
|
|
|
|
then the caller must have reserved enough
|
|
|
|
free extents in the file space so that the
|
|
|
|
insertion will certainly succeed */
|
|
|
|
btr_cur_t* cursor, /* in: cursor after which to insert;
|
|
|
|
cursor stays valid */
|
2006-10-20 08:30:07 +00:00
|
|
|
dtuple_t* entry, /* in/out: entry to insert */
|
2005-10-27 07:29:40 +00:00
|
|
|
rec_t** rec, /* out: pointer to inserted record if
|
|
|
|
succeed */
|
|
|
|
big_rec_t** big_rec,/* out: big rec vector whose fields have to
|
|
|
|
be stored externally by the caller, or
|
|
|
|
NULL */
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
ulint n_ext, /* in: number of externally stored columns */
|
2005-10-27 07:29:40 +00:00
|
|
|
que_thr_t* thr, /* in: query thread or NULL */
|
|
|
|
mtr_t* mtr) /* in: mtr */
|
|
|
|
{
|
|
|
|
dict_index_t* index = cursor->index;
|
2006-08-17 11:57:51 +00:00
|
|
|
ulint zip_size = dict_table_zip_size(index->table);
|
2005-10-27 07:29:40 +00:00
|
|
|
big_rec_t* big_rec_vec = NULL;
|
2006-02-21 10:24:32 +00:00
|
|
|
mem_heap_t* heap = NULL;
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint err;
|
|
|
|
ibool dummy_inh;
|
|
|
|
ibool success;
|
|
|
|
ulint n_extents = 0;
|
|
|
|
ulint n_reserved;
|
2006-02-21 10:24:32 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
ut_ad(dtuple_check_typed(entry));
|
|
|
|
|
|
|
|
*big_rec = NULL;
|
|
|
|
|
|
|
|
ut_ad(mtr_memo_contains(mtr,
|
2006-09-19 10:14:07 +00:00
|
|
|
dict_index_get_lock(btr_cur_get_index(cursor)),
|
2006-08-29 09:30:31 +00:00
|
|
|
MTR_MEMO_X_LOCK));
|
2006-10-23 11:38:32 +00:00
|
|
|
ut_ad(mtr_memo_contains(mtr, btr_cur_get_block(cursor),
|
|
|
|
MTR_MEMO_PAGE_X_FIX));
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/* Try first an optimistic insert; reset the cursor flag: we do not
|
|
|
|
assume anything of how it was positioned */
|
|
|
|
|
|
|
|
cursor->flag = BTR_CUR_BINARY;
|
|
|
|
|
2006-04-03 11:19:01 +00:00
|
|
|
err = btr_cur_optimistic_insert(flags, cursor, entry, rec,
|
2007-11-27 07:57:03 +00:00
|
|
|
big_rec, n_ext, thr, mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
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, thr, &dummy_inh);
|
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
2006-02-23 19:25:29 +00:00
|
|
|
if (!(flags & BTR_NO_UNDO_LOG_FLAG)) {
|
2005-10-27 07:29:40 +00:00
|
|
|
/* First reserve enough free space for the file segments
|
|
|
|
of the index tree, so that the insert will not fail because
|
|
|
|
of lack of space */
|
|
|
|
|
|
|
|
n_extents = cursor->tree_height / 16 + 3;
|
|
|
|
|
|
|
|
success = fsp_reserve_free_extents(&n_reserved, index->space,
|
2006-08-29 09:30:31 +00:00
|
|
|
n_extents, FSP_NORMAL, mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
if (!success) {
|
2007-11-09 15:38:48 +00:00
|
|
|
return(DB_OUT_OF_FILE_SPACE);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
if (page_zip_rec_needs_ext(rec_get_converted_size(index, entry, n_ext),
|
2006-10-18 11:39:31 +00:00
|
|
|
dict_table_is_comp(index->table),
|
2008-09-17 19:52:30 +00:00
|
|
|
dict_index_get_n_fields(index),
|
2006-10-18 11:39:31 +00:00
|
|
|
zip_size)) {
|
2005-10-27 07:29:40 +00:00
|
|
|
/* The record is so big that we have to store some fields
|
|
|
|
externally on separate database pages */
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2006-08-31 10:53:00 +00:00
|
|
|
if (UNIV_LIKELY_NULL(big_rec_vec)) {
|
|
|
|
/* This should never happen, but we handle
|
|
|
|
the situation in a robust manner. */
|
|
|
|
ut_ad(0);
|
|
|
|
dtuple_convert_back_big_rec(index, entry, big_rec_vec);
|
|
|
|
}
|
|
|
|
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
big_rec_vec = dtuple_convert_big_rec(index, entry, &n_ext);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (big_rec_vec == NULL) {
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
if (n_extents > 0) {
|
2006-02-23 19:25:29 +00:00
|
|
|
fil_space_release_free_extents(index->space,
|
2006-08-29 09:30:31 +00:00
|
|
|
n_reserved);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
return(DB_TOO_BIG_RECORD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-23 11:38:32 +00:00
|
|
|
if (dict_index_get_page(index)
|
|
|
|
== buf_block_get_page_no(btr_cur_get_block(cursor))) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/* The page is the root page */
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
*rec = btr_root_raise_and_insert(cursor, entry, n_ext, mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
} else {
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
*rec = btr_page_split_and_insert(cursor, entry, n_ext, mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2006-02-21 10:24:32 +00:00
|
|
|
if (UNIV_LIKELY_NULL(heap)) {
|
|
|
|
mem_heap_free(heap);
|
|
|
|
}
|
|
|
|
|
2006-10-23 11:38:32 +00:00
|
|
|
ut_ad(page_rec_get_next(btr_cur_get_rec(cursor)) == *rec);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
#ifdef BTR_CUR_ADAPT
|
|
|
|
btr_search_update_hash_on_insert(cursor);
|
|
|
|
#endif
|
|
|
|
if (!(flags & BTR_NO_LOCKING_FLAG)) {
|
|
|
|
|
2006-10-24 06:45:52 +00:00
|
|
|
lock_update_insert(btr_cur_get_block(cursor), *rec);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (n_extents > 0) {
|
|
|
|
fil_space_release_free_extents(index->space, n_reserved);
|
|
|
|
}
|
|
|
|
|
|
|
|
*big_rec = big_rec_vec;
|
|
|
|
|
2007-11-09 15:38:48 +00:00
|
|
|
return(DB_SUCCESS);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*==================== B-TREE UPDATE =========================*/
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
For an update, checks the locks and does the undo logging. */
|
|
|
|
UNIV_INLINE
|
|
|
|
ulint
|
|
|
|
btr_cur_upd_lock_and_undo(
|
|
|
|
/*======================*/
|
|
|
|
/* out: DB_SUCCESS, DB_WAIT_LOCK, or error
|
|
|
|
number */
|
|
|
|
ulint flags, /* in: undo logging and locking flags */
|
|
|
|
btr_cur_t* cursor, /* in: cursor on record to update */
|
2007-06-19 12:44:45 +00:00
|
|
|
const upd_t* update, /* in: update vector */
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint cmpl_info,/* in: compiler info on secondary index
|
|
|
|
updates */
|
|
|
|
que_thr_t* thr, /* in: query thread */
|
|
|
|
dulint* roll_ptr)/* out: roll pointer */
|
|
|
|
{
|
|
|
|
dict_index_t* index;
|
|
|
|
rec_t* rec;
|
|
|
|
ulint err;
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
ut_ad(cursor && update && thr && roll_ptr);
|
|
|
|
|
|
|
|
rec = btr_cur_get_rec(cursor);
|
|
|
|
index = cursor->index;
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2006-03-09 17:26:02 +00:00
|
|
|
if (!dict_index_is_clust(index)) {
|
2005-10-27 07:29:40 +00:00
|
|
|
/* We do undo logging only when we update a clustered index
|
|
|
|
record */
|
2006-10-18 11:39:31 +00:00
|
|
|
return(lock_sec_rec_modify_check_and_lock(
|
2006-10-24 06:45:52 +00:00
|
|
|
flags, btr_cur_get_block(cursor), rec,
|
2006-10-18 11:39:31 +00:00
|
|
|
index, thr));
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we have to wait for a lock: enqueue an explicit lock
|
|
|
|
request if yes */
|
|
|
|
|
|
|
|
err = DB_SUCCESS;
|
|
|
|
|
|
|
|
if (!(flags & BTR_NO_LOCKING_FLAG)) {
|
|
|
|
mem_heap_t* heap = NULL;
|
|
|
|
ulint offsets_[REC_OFFS_NORMAL_SIZE];
|
2007-09-28 07:05:57 +00:00
|
|
|
rec_offs_init(offsets_);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
err = lock_clust_rec_modify_check_and_lock(
|
2006-10-24 06:45:52 +00:00
|
|
|
flags, btr_cur_get_block(cursor), rec, index,
|
2006-09-19 10:14:07 +00:00
|
|
|
rec_get_offsets(rec, index, offsets_,
|
|
|
|
ULINT_UNDEFINED, &heap), thr);
|
2005-10-27 07:29:40 +00:00
|
|
|
if (UNIV_LIKELY_NULL(heap)) {
|
|
|
|
mem_heap_free(heap);
|
|
|
|
}
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Append the info about the update in the undo log */
|
|
|
|
|
|
|
|
err = trx_undo_report_row_operation(flags, TRX_UNDO_MODIFY_OP, thr,
|
2006-08-29 09:30:31 +00:00
|
|
|
index, NULL, update,
|
|
|
|
cmpl_info, rec, roll_ptr);
|
2005-10-27 07:29:40 +00:00
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************
|
|
|
|
Writes a redo log record of updating a record in-place. */
|
|
|
|
UNIV_INLINE
|
|
|
|
void
|
|
|
|
btr_cur_update_in_place_log(
|
|
|
|
/*========================*/
|
|
|
|
ulint flags, /* in: flags */
|
|
|
|
rec_t* rec, /* in: record */
|
|
|
|
dict_index_t* index, /* in: index where cursor positioned */
|
2007-06-19 12:44:45 +00:00
|
|
|
const upd_t* update, /* in: update vector */
|
2005-10-27 07:29:40 +00:00
|
|
|
trx_t* trx, /* in: transaction */
|
|
|
|
dulint roll_ptr, /* in: roll ptr */
|
|
|
|
mtr_t* mtr) /* in: mtr */
|
|
|
|
{
|
|
|
|
byte* log_ptr;
|
2006-09-19 10:14:07 +00:00
|
|
|
page_t* page = page_align(rec);
|
2005-10-27 07:29:40 +00:00
|
|
|
ut_ad(flags < 256);
|
2006-02-27 09:33:26 +00:00
|
|
|
ut_ad(!!page_is_comp(page) == dict_table_is_comp(index->table));
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
log_ptr = mlog_open_and_write_index(mtr, rec, index, page_is_comp(page)
|
2006-08-29 09:30:31 +00:00
|
|
|
? MLOG_COMP_REC_UPDATE_IN_PLACE
|
|
|
|
: MLOG_REC_UPDATE_IN_PLACE,
|
|
|
|
1 + DATA_ROLL_PTR_LEN + 14 + 2
|
|
|
|
+ MLOG_BUF_MARGIN);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (!log_ptr) {
|
|
|
|
/* Logging in mtr is switched off during crash recovery */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The code below assumes index is a clustered index: change index to
|
|
|
|
the clustered index if we are updating a secondary index record (or we
|
|
|
|
could as well skip writing the sys col values to the log in this case
|
|
|
|
because they are not needed for a secondary index record update) */
|
|
|
|
|
|
|
|
index = dict_table_get_first_index(index->table);
|
|
|
|
|
|
|
|
mach_write_to_1(log_ptr, flags);
|
|
|
|
log_ptr++;
|
|
|
|
|
|
|
|
log_ptr = row_upd_write_sys_vals_to_log(index, trx, roll_ptr, log_ptr,
|
2006-08-29 09:30:31 +00:00
|
|
|
mtr);
|
2006-09-19 10:14:07 +00:00
|
|
|
mach_write_to_2(log_ptr, page_offset(rec));
|
2005-10-27 07:29:40 +00:00
|
|
|
log_ptr += 2;
|
|
|
|
|
|
|
|
row_upd_index_write_log(update, log_ptr, mtr);
|
2006-02-23 19:25:29 +00:00
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/***************************************************************
|
|
|
|
Parses a redo log record of updating a record in-place. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
byte*
|
|
|
|
btr_cur_parse_update_in_place(
|
|
|
|
/*==========================*/
|
|
|
|
/* out: end of log record or NULL */
|
|
|
|
byte* ptr, /* in: buffer */
|
|
|
|
byte* end_ptr,/* in: buffer end */
|
2005-10-27 11:48:10 +00:00
|
|
|
page_t* page, /* in/out: page or NULL */
|
|
|
|
page_zip_des_t* page_zip,/* in/out: compressed page, or NULL */
|
2005-10-27 07:29:40 +00:00
|
|
|
dict_index_t* index) /* in: index corresponding to page */
|
|
|
|
{
|
|
|
|
ulint flags;
|
|
|
|
rec_t* rec;
|
|
|
|
upd_t* update;
|
|
|
|
ulint pos;
|
|
|
|
dulint trx_id;
|
|
|
|
dulint roll_ptr;
|
|
|
|
ulint rec_offset;
|
|
|
|
mem_heap_t* heap;
|
|
|
|
ulint* offsets;
|
|
|
|
|
|
|
|
if (end_ptr < ptr + 1) {
|
|
|
|
|
|
|
|
return(NULL);
|
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
flags = mach_read_from_1(ptr);
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
ptr = row_upd_parse_sys_vals(ptr, end_ptr, &pos, &trx_id, &roll_ptr);
|
|
|
|
|
|
|
|
if (ptr == NULL) {
|
|
|
|
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (end_ptr < ptr + 2) {
|
|
|
|
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
rec_offset = mach_read_from_2(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
|
|
|
|
ut_a(rec_offset <= UNIV_PAGE_SIZE);
|
|
|
|
|
|
|
|
heap = mem_heap_create(256);
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
ptr = row_upd_index_parse(ptr, end_ptr, heap, &update);
|
|
|
|
|
|
|
|
if (!ptr || !page) {
|
|
|
|
|
|
|
|
goto func_exit;
|
|
|
|
}
|
|
|
|
|
2006-02-27 09:33:26 +00:00
|
|
|
ut_a((ibool)!!page_is_comp(page) == dict_table_is_comp(index->table));
|
2005-10-27 07:29:40 +00:00
|
|
|
rec = page + rec_offset;
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/* We do not need to reserve btr_search_latch, as the page is only
|
|
|
|
being recovered, and there cannot be a hash index to it. */
|
|
|
|
|
|
|
|
offsets = rec_get_offsets(rec, index, NULL, ULINT_UNDEFINED, &heap);
|
|
|
|
|
|
|
|
if (!(flags & BTR_KEEP_SYS_FLAG)) {
|
2005-10-27 11:48:10 +00:00
|
|
|
row_upd_rec_sys_fields_in_recovery(rec, page_zip, offsets,
|
2006-08-29 09:30:31 +00:00
|
|
|
pos, trx_id, roll_ptr);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2006-03-06 21:00:05 +00:00
|
|
|
row_upd_rec_in_place(rec, index, offsets, update, page_zip);
|
2005-10-27 11:48:10 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
func_exit:
|
|
|
|
mem_heap_free(heap);
|
|
|
|
|
|
|
|
return(ptr);
|
|
|
|
}
|
|
|
|
|
2007-02-26 09:35:02 +00:00
|
|
|
/*****************************************************************
|
|
|
|
See if there is enough place in the page modification log to log
|
|
|
|
an update-in-place. */
|
|
|
|
static
|
|
|
|
ibool
|
|
|
|
btr_cur_update_alloc_zip(
|
|
|
|
/*=====================*/
|
|
|
|
/* out: TRUE if enough place */
|
|
|
|
page_zip_des_t* page_zip,/* in/out: compressed page */
|
|
|
|
buf_block_t* block, /* in/out: buffer page */
|
|
|
|
dict_index_t* index, /* in: the index corresponding to the block */
|
|
|
|
ulint length, /* in: size needed */
|
|
|
|
mtr_t* mtr) /* in: mini-transaction */
|
|
|
|
{
|
|
|
|
ut_a(page_zip == buf_block_get_page_zip(block));
|
|
|
|
ut_ad(page_zip);
|
|
|
|
|
|
|
|
if (page_zip_available(page_zip, dict_index_is_clust(index),
|
|
|
|
length, 0)) {
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!page_zip->m_nonempty) {
|
|
|
|
/* The page has been freshly compressed, so
|
|
|
|
recompressing it will not help. */
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!page_zip_compress(page_zip, buf_block_get_frame(block),
|
|
|
|
index, mtr)) {
|
|
|
|
/* Unable to compress the page */
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
branches/zip: Document and obey the rules for modifying the free bits in
the insert buffer bitmap.
ibuf_set_free_bits_func(): Never disable redo logging.
ibuf_update_free_bits_zip(): Remove.
btr_page_reorganize_low(), page_zip_reorganize(): Do not update the insert
buffer bitmap. Instead, document that callers will have to take care of it,
and adapt the callers.
btr_compress(): On error, reset the insert buffer free bits.
btr_cur_insert_if_possible(): Do not modify the insert buffer bitmap.
btr_compress(), btr_cur_optimistic_insert(): On compressed pages,
reset the insert buffer bitmap. Document why.
btr_cur_update_alloc_zip(): Document why it is necessary and sufficient
to reset the insert buffer free bits.
btr_cur_update_in_place(), btr_cur_optimistic_update(),
btr_cur_pessimistic_update(): Update the free bits in the same
mini-transaction. Document that the mini-transaction must be
committed before latching any further pages. Verify that this
is the case in all execution paths.
row_ins_sec_index_entry_by_modify(), row_ins_clust_index_entry_by_modify(),
row_undo_mod_clust_low(): Because these functions call
btr_cur_update_in_place(), btr_cur_optimistic_update(), or
btr_cur_pessimistic_update(), document that the mini-transaction must be
committed before latching any further pages. Verify that this is the case
in all execution paths.
2007-05-16 09:23:53 +00:00
|
|
|
/* After recompressing a page, we must make sure that the free
|
|
|
|
bits in the insert buffer bitmap will not exceed the free
|
|
|
|
space on the page. Because this function will not attempt
|
|
|
|
recompression unless page_zip_available() fails above, it is
|
|
|
|
safe to reset the free bits if page_zip_available() fails
|
|
|
|
again, below. The free bits can safely be reset in a separate
|
|
|
|
mini-transaction. If page_zip_available() succeeds below, we
|
|
|
|
can be sure that the page_zip_compress() above did not reduce
|
|
|
|
the free space available on the page. */
|
|
|
|
|
2007-02-27 07:25:24 +00:00
|
|
|
if (!page_zip_available(page_zip, dict_index_is_clust(index),
|
|
|
|
length, 0)) {
|
branches/zip: Document and obey the rules for modifying the free bits in
the insert buffer bitmap.
ibuf_set_free_bits_func(): Never disable redo logging.
ibuf_update_free_bits_zip(): Remove.
btr_page_reorganize_low(), page_zip_reorganize(): Do not update the insert
buffer bitmap. Instead, document that callers will have to take care of it,
and adapt the callers.
btr_compress(): On error, reset the insert buffer free bits.
btr_cur_insert_if_possible(): Do not modify the insert buffer bitmap.
btr_compress(), btr_cur_optimistic_insert(): On compressed pages,
reset the insert buffer bitmap. Document why.
btr_cur_update_alloc_zip(): Document why it is necessary and sufficient
to reset the insert buffer free bits.
btr_cur_update_in_place(), btr_cur_optimistic_update(),
btr_cur_pessimistic_update(): Update the free bits in the same
mini-transaction. Document that the mini-transaction must be
committed before latching any further pages. Verify that this
is the case in all execution paths.
row_ins_sec_index_entry_by_modify(), row_ins_clust_index_entry_by_modify(),
row_undo_mod_clust_low(): Because these functions call
btr_cur_update_in_place(), btr_cur_optimistic_update(), or
btr_cur_pessimistic_update(), document that the mini-transaction must be
committed before latching any further pages. Verify that this is the case
in all execution paths.
2007-05-16 09:23:53 +00:00
|
|
|
/* Out of space: reset the free bits. */
|
|
|
|
if (!dict_index_is_clust(index)
|
|
|
|
&& page_is_leaf(buf_block_get_frame(block))) {
|
2007-05-06 12:39:46 +00:00
|
|
|
ibuf_reset_free_bits(block);
|
2007-02-27 07:25:24 +00:00
|
|
|
}
|
|
|
|
return(FALSE);
|
|
|
|
}
|
2007-02-26 09:35:02 +00:00
|
|
|
|
2007-02-27 07:25:24 +00:00
|
|
|
return(TRUE);
|
2007-02-26 09:35:02 +00:00
|
|
|
}
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/*****************************************************************
|
|
|
|
Updates a record when the update causes no size changes in its fields.
|
|
|
|
We assume here that the ordering fields of the record do not change. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint
|
|
|
|
btr_cur_update_in_place(
|
|
|
|
/*====================*/
|
|
|
|
/* out: DB_SUCCESS or error number */
|
|
|
|
ulint flags, /* in: undo logging and locking flags */
|
|
|
|
btr_cur_t* cursor, /* in: cursor on the record to update;
|
|
|
|
cursor stays valid and positioned on the
|
|
|
|
same record */
|
2007-06-19 12:44:45 +00:00
|
|
|
const upd_t* update, /* in: update vector */
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint cmpl_info,/* in: compiler info on secondary index
|
|
|
|
updates */
|
|
|
|
que_thr_t* thr, /* in: query thread */
|
branches/zip: Document and obey the rules for modifying the free bits in
the insert buffer bitmap.
ibuf_set_free_bits_func(): Never disable redo logging.
ibuf_update_free_bits_zip(): Remove.
btr_page_reorganize_low(), page_zip_reorganize(): Do not update the insert
buffer bitmap. Instead, document that callers will have to take care of it,
and adapt the callers.
btr_compress(): On error, reset the insert buffer free bits.
btr_cur_insert_if_possible(): Do not modify the insert buffer bitmap.
btr_compress(), btr_cur_optimistic_insert(): On compressed pages,
reset the insert buffer bitmap. Document why.
btr_cur_update_alloc_zip(): Document why it is necessary and sufficient
to reset the insert buffer free bits.
btr_cur_update_in_place(), btr_cur_optimistic_update(),
btr_cur_pessimistic_update(): Update the free bits in the same
mini-transaction. Document that the mini-transaction must be
committed before latching any further pages. Verify that this
is the case in all execution paths.
row_ins_sec_index_entry_by_modify(), row_ins_clust_index_entry_by_modify(),
row_undo_mod_clust_low(): Because these functions call
btr_cur_update_in_place(), btr_cur_optimistic_update(), or
btr_cur_pessimistic_update(), document that the mini-transaction must be
committed before latching any further pages. Verify that this is the case
in all execution paths.
2007-05-16 09:23:53 +00:00
|
|
|
mtr_t* mtr) /* in: mtr; must be committed before
|
|
|
|
latching any further pages */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
|
|
|
dict_index_t* index;
|
|
|
|
buf_block_t* block;
|
2005-10-27 11:48:10 +00:00
|
|
|
page_zip_des_t* page_zip;
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint err;
|
|
|
|
rec_t* rec;
|
|
|
|
dulint roll_ptr = ut_dulint_zero;
|
|
|
|
trx_t* trx;
|
|
|
|
ulint was_delete_marked;
|
|
|
|
mem_heap_t* heap = NULL;
|
|
|
|
ulint offsets_[REC_OFFS_NORMAL_SIZE];
|
|
|
|
ulint* offsets = offsets_;
|
2007-09-28 07:05:57 +00:00
|
|
|
rec_offs_init(offsets_);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
rec = btr_cur_get_rec(cursor);
|
|
|
|
index = cursor->index;
|
2006-02-27 09:33:26 +00:00
|
|
|
ut_ad(!!page_rec_is_comp(rec) == dict_table_is_comp(index->table));
|
2005-10-27 07:29:40 +00:00
|
|
|
trx = thr_get_trx(thr);
|
|
|
|
offsets = rec_get_offsets(rec, index, offsets, ULINT_UNDEFINED, &heap);
|
|
|
|
#ifdef UNIV_DEBUG
|
|
|
|
if (btr_cur_print_record_ops && thr) {
|
|
|
|
btr_cur_trx_report(trx, index, "update ");
|
|
|
|
rec_print_new(stderr, rec, offsets);
|
|
|
|
}
|
|
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
|
2006-10-18 11:39:31 +00:00
|
|
|
block = btr_cur_get_block(cursor);
|
2007-02-26 09:35:02 +00:00
|
|
|
page_zip = buf_block_get_page_zip(block);
|
2006-02-10 15:06:17 +00:00
|
|
|
|
|
|
|
/* Check that enough space is available on the compressed page. */
|
|
|
|
if (UNIV_LIKELY_NULL(page_zip)
|
2007-02-26 09:35:02 +00:00
|
|
|
&& !btr_cur_update_alloc_zip(page_zip, block, index,
|
|
|
|
rec_offs_size(offsets), mtr)) {
|
2006-02-10 15:06:17 +00:00
|
|
|
return(DB_ZIP_OVERFLOW);
|
|
|
|
}
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/* Do lock checking and undo logging */
|
|
|
|
err = btr_cur_upd_lock_and_undo(flags, cursor, update, cmpl_info,
|
2006-08-29 09:30:31 +00:00
|
|
|
thr, &roll_ptr);
|
2005-10-27 07:29:40 +00:00
|
|
|
if (UNIV_UNLIKELY(err != DB_SUCCESS)) {
|
|
|
|
|
|
|
|
if (UNIV_LIKELY_NULL(heap)) {
|
|
|
|
mem_heap_free(heap);
|
|
|
|
}
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (block->is_hashed) {
|
|
|
|
/* The function row_upd_changes_ord_field_binary works only
|
|
|
|
if the update vector was built for a clustered index, we must
|
|
|
|
NOT call it if index is secondary */
|
|
|
|
|
2006-03-09 17:26:02 +00:00
|
|
|
if (!dict_index_is_clust(index)
|
2006-08-29 09:30:31 +00:00
|
|
|
|| row_upd_changes_ord_field_binary(NULL, index, update)) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-02-23 19:25:29 +00:00
|
|
|
/* Remove possible hash index pointer to this record */
|
|
|
|
btr_search_update_hash_on_delete(cursor);
|
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
rw_lock_x_lock(&btr_search_latch);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(flags & BTR_KEEP_SYS_FLAG)) {
|
2005-10-27 11:48:10 +00:00
|
|
|
row_upd_rec_sys_fields(rec, NULL,
|
2006-08-29 09:30:31 +00:00
|
|
|
index, offsets, trx, roll_ptr);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
was_delete_marked = rec_get_deleted_flag(
|
|
|
|
rec, page_is_comp(buf_block_get_frame(block)));
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-03-06 21:00:05 +00:00
|
|
|
row_upd_rec_in_place(rec, index, offsets, update, page_zip);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (block->is_hashed) {
|
|
|
|
rw_lock_x_unlock(&btr_search_latch);
|
|
|
|
}
|
|
|
|
|
2007-03-01 11:28:30 +00:00
|
|
|
if (page_zip && !dict_index_is_clust(index)
|
|
|
|
&& page_is_leaf(buf_block_get_frame(block))) {
|
2007-02-27 07:25:24 +00:00
|
|
|
/* Update the free bits in the insert buffer. */
|
2007-10-12 13:25:12 +00:00
|
|
|
ibuf_update_free_bits_zip(block, mtr);
|
2007-02-27 07:25:24 +00:00
|
|
|
}
|
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
btr_cur_update_in_place_log(flags, rec, index, update,
|
2006-08-29 09:30:31 +00:00
|
|
|
trx, roll_ptr, mtr);
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
if (was_delete_marked
|
|
|
|
&& !rec_get_deleted_flag(rec, page_is_comp(
|
|
|
|
buf_block_get_frame(block)))) {
|
2005-10-27 07:29:40 +00:00
|
|
|
/* The new updated record owns its possible externally
|
|
|
|
stored fields */
|
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
btr_cur_unmark_extern_fields(page_zip,
|
|
|
|
rec, index, offsets, mtr);
|
2005-10-27 11:48:10 +00:00
|
|
|
}
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
if (UNIV_LIKELY_NULL(heap)) {
|
|
|
|
mem_heap_free(heap);
|
|
|
|
}
|
|
|
|
return(DB_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
Tries to update a record on a page in an index tree. It is assumed that mtr
|
|
|
|
holds an x-latch on the page. The operation does not succeed if there is too
|
|
|
|
little space on the page or if the update would result in too empty a page,
|
|
|
|
so that tree compression is recommended. We assume here that the ordering
|
|
|
|
fields of the record do not change. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint
|
|
|
|
btr_cur_optimistic_update(
|
|
|
|
/*======================*/
|
|
|
|
/* out: DB_SUCCESS, or DB_OVERFLOW if the
|
|
|
|
updated record does not fit, DB_UNDERFLOW
|
2006-02-10 15:06:17 +00:00
|
|
|
if the page would become too empty, or
|
|
|
|
DB_ZIP_OVERFLOW if there is not enough
|
|
|
|
space left on the compressed page */
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint flags, /* in: undo logging and locking flags */
|
|
|
|
btr_cur_t* cursor, /* in: cursor on the record to update;
|
|
|
|
cursor stays valid and positioned on the
|
|
|
|
same record */
|
2007-06-19 12:44:45 +00:00
|
|
|
const upd_t* update, /* in: update vector; this must also
|
2005-10-27 07:29:40 +00:00
|
|
|
contain trx id and roll ptr fields */
|
|
|
|
ulint cmpl_info,/* in: compiler info on secondary index
|
|
|
|
updates */
|
|
|
|
que_thr_t* thr, /* in: query thread */
|
branches/zip: Document and obey the rules for modifying the free bits in
the insert buffer bitmap.
ibuf_set_free_bits_func(): Never disable redo logging.
ibuf_update_free_bits_zip(): Remove.
btr_page_reorganize_low(), page_zip_reorganize(): Do not update the insert
buffer bitmap. Instead, document that callers will have to take care of it,
and adapt the callers.
btr_compress(): On error, reset the insert buffer free bits.
btr_cur_insert_if_possible(): Do not modify the insert buffer bitmap.
btr_compress(), btr_cur_optimistic_insert(): On compressed pages,
reset the insert buffer bitmap. Document why.
btr_cur_update_alloc_zip(): Document why it is necessary and sufficient
to reset the insert buffer free bits.
btr_cur_update_in_place(), btr_cur_optimistic_update(),
btr_cur_pessimistic_update(): Update the free bits in the same
mini-transaction. Document that the mini-transaction must be
committed before latching any further pages. Verify that this
is the case in all execution paths.
row_ins_sec_index_entry_by_modify(), row_ins_clust_index_entry_by_modify(),
row_undo_mod_clust_low(): Because these functions call
btr_cur_update_in_place(), btr_cur_optimistic_update(), or
btr_cur_pessimistic_update(), document that the mini-transaction must be
committed before latching any further pages. Verify that this is the case
in all execution paths.
2007-05-16 09:23:53 +00:00
|
|
|
mtr_t* mtr) /* in: mtr; must be committed before
|
|
|
|
latching any further pages */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
|
|
|
dict_index_t* index;
|
|
|
|
page_cur_t* page_cursor;
|
|
|
|
ulint err;
|
2006-10-18 11:39:31 +00:00
|
|
|
buf_block_t* block;
|
2005-10-27 07:29:40 +00:00
|
|
|
page_t* page;
|
2005-10-27 11:48:10 +00:00
|
|
|
page_zip_des_t* page_zip;
|
2005-10-27 07:29:40 +00:00
|
|
|
rec_t* rec;
|
2005-10-27 11:48:10 +00:00
|
|
|
rec_t* orig_rec;
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint max_size;
|
|
|
|
ulint new_rec_size;
|
|
|
|
ulint old_rec_size;
|
|
|
|
dtuple_t* new_entry;
|
|
|
|
dulint roll_ptr;
|
|
|
|
trx_t* trx;
|
|
|
|
mem_heap_t* heap;
|
|
|
|
ulint i;
|
2007-10-17 12:13:29 +00:00
|
|
|
ulint n_ext;
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint* offsets;
|
|
|
|
|
2006-10-18 11:39:31 +00:00
|
|
|
block = btr_cur_get_block(cursor);
|
|
|
|
page = buf_block_get_frame(block);
|
2005-10-27 11:48:10 +00:00
|
|
|
orig_rec = rec = btr_cur_get_rec(cursor);
|
2005-10-27 07:29:40 +00:00
|
|
|
index = cursor->index;
|
2006-02-27 09:33:26 +00:00
|
|
|
ut_ad(!!page_rec_is_comp(rec) == dict_table_is_comp(index->table));
|
2006-10-18 11:39:31 +00:00
|
|
|
ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX));
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
heap = mem_heap_create(1024);
|
|
|
|
offsets = rec_get_offsets(rec, index, NULL, ULINT_UNDEFINED, &heap);
|
|
|
|
|
|
|
|
#ifdef UNIV_DEBUG
|
|
|
|
if (btr_cur_print_record_ops && thr) {
|
|
|
|
btr_cur_trx_report(thr_get_trx(thr), index, "update ");
|
|
|
|
rec_print_new(stderr, rec, offsets);
|
|
|
|
}
|
|
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
|
|
|
|
if (!row_upd_changes_field_size_or_external(index, offsets, update)) {
|
|
|
|
|
|
|
|
/* The simplest and the most common case: the update does not
|
|
|
|
change the size of any field and none of the updated fields is
|
2006-02-10 15:06:17 +00:00
|
|
|
externally stored in rec or update, and there is enough space
|
|
|
|
on the compressed page to log the update. */
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
mem_heap_free(heap);
|
|
|
|
return(btr_cur_update_in_place(flags, cursor, update,
|
2006-08-29 09:30:31 +00:00
|
|
|
cmpl_info, thr, mtr));
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2007-02-27 07:25:24 +00:00
|
|
|
if (rec_offs_any_extern(offsets)) {
|
branches/zip: Document and obey the rules for modifying the free bits in
the insert buffer bitmap.
ibuf_set_free_bits_func(): Never disable redo logging.
ibuf_update_free_bits_zip(): Remove.
btr_page_reorganize_low(), page_zip_reorganize(): Do not update the insert
buffer bitmap. Instead, document that callers will have to take care of it,
and adapt the callers.
btr_compress(): On error, reset the insert buffer free bits.
btr_cur_insert_if_possible(): Do not modify the insert buffer bitmap.
btr_compress(), btr_cur_optimistic_insert(): On compressed pages,
reset the insert buffer bitmap. Document why.
btr_cur_update_alloc_zip(): Document why it is necessary and sufficient
to reset the insert buffer free bits.
btr_cur_update_in_place(), btr_cur_optimistic_update(),
btr_cur_pessimistic_update(): Update the free bits in the same
mini-transaction. Document that the mini-transaction must be
committed before latching any further pages. Verify that this
is the case in all execution paths.
row_ins_sec_index_entry_by_modify(), row_ins_clust_index_entry_by_modify(),
row_undo_mod_clust_low(): Because these functions call
btr_cur_update_in_place(), btr_cur_optimistic_update(), or
btr_cur_pessimistic_update(), document that the mini-transaction must be
committed before latching any further pages. Verify that this is the case
in all execution paths.
2007-05-16 09:23:53 +00:00
|
|
|
any_extern:
|
2007-02-27 07:25:24 +00:00
|
|
|
/* Externally stored fields are treated in pessimistic
|
|
|
|
update */
|
|
|
|
|
|
|
|
mem_heap_free(heap);
|
|
|
|
return(DB_OVERFLOW);
|
|
|
|
}
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
for (i = 0; i < upd_get_n_fields(update); i++) {
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
if (dfield_is_ext(&upd_get_nth_field(update, i)->new_val)) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
branches/zip: Document and obey the rules for modifying the free bits in
the insert buffer bitmap.
ibuf_set_free_bits_func(): Never disable redo logging.
ibuf_update_free_bits_zip(): Remove.
btr_page_reorganize_low(), page_zip_reorganize(): Do not update the insert
buffer bitmap. Instead, document that callers will have to take care of it,
and adapt the callers.
btr_compress(): On error, reset the insert buffer free bits.
btr_cur_insert_if_possible(): Do not modify the insert buffer bitmap.
btr_compress(), btr_cur_optimistic_insert(): On compressed pages,
reset the insert buffer bitmap. Document why.
btr_cur_update_alloc_zip(): Document why it is necessary and sufficient
to reset the insert buffer free bits.
btr_cur_update_in_place(), btr_cur_optimistic_update(),
btr_cur_pessimistic_update(): Update the free bits in the same
mini-transaction. Document that the mini-transaction must be
committed before latching any further pages. Verify that this
is the case in all execution paths.
row_ins_sec_index_entry_by_modify(), row_ins_clust_index_entry_by_modify(),
row_undo_mod_clust_low(): Because these functions call
btr_cur_update_in_place(), btr_cur_optimistic_update(), or
btr_cur_pessimistic_update(), document that the mini-transaction must be
committed before latching any further pages. Verify that this is the case
in all execution paths.
2007-05-16 09:23:53 +00:00
|
|
|
goto any_extern;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
page_cursor = btr_cur_get_page_cur(cursor);
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2007-10-17 12:13:29 +00:00
|
|
|
new_entry = row_rec_to_index_entry(ROW_COPY_DATA, rec, index, offsets,
|
|
|
|
&n_ext, heap);
|
|
|
|
/* We checked above that there are no externally stored fields. */
|
|
|
|
ut_a(!n_ext);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-01-14 10:04:45 +00:00
|
|
|
/* The page containing the clustered index record
|
|
|
|
corresponding to new_entry is latched in mtr.
|
|
|
|
Thus the following call is safe. */
|
2005-10-27 07:29:40 +00:00
|
|
|
row_upd_index_replace_new_col_vals_index_pos(new_entry, index, update,
|
2008-05-14 15:43:19 +00:00
|
|
|
FALSE, heap);
|
2005-10-27 07:29:40 +00:00
|
|
|
old_rec_size = rec_offs_size(offsets);
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
new_rec_size = rec_get_converted_size(index, new_entry, 0);
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2006-10-18 11:39:31 +00:00
|
|
|
page_zip = buf_block_get_page_zip(block);
|
2006-06-20 19:35:59 +00:00
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
2006-06-12 12:37:54 +00:00
|
|
|
ut_a(!page_zip || page_zip_validate(page_zip, page));
|
2006-06-20 19:35:59 +00:00
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
2006-02-10 15:06:17 +00:00
|
|
|
|
|
|
|
if (UNIV_LIKELY_NULL(page_zip)
|
2007-02-26 09:35:02 +00:00
|
|
|
&& !btr_cur_update_alloc_zip(page_zip, block, index,
|
|
|
|
new_rec_size, mtr)) {
|
branches/zip: Document and obey the rules for modifying the free bits in
the insert buffer bitmap.
ibuf_set_free_bits_func(): Never disable redo logging.
ibuf_update_free_bits_zip(): Remove.
btr_page_reorganize_low(), page_zip_reorganize(): Do not update the insert
buffer bitmap. Instead, document that callers will have to take care of it,
and adapt the callers.
btr_compress(): On error, reset the insert buffer free bits.
btr_cur_insert_if_possible(): Do not modify the insert buffer bitmap.
btr_compress(), btr_cur_optimistic_insert(): On compressed pages,
reset the insert buffer bitmap. Document why.
btr_cur_update_alloc_zip(): Document why it is necessary and sufficient
to reset the insert buffer free bits.
btr_cur_update_in_place(), btr_cur_optimistic_update(),
btr_cur_pessimistic_update(): Update the free bits in the same
mini-transaction. Document that the mini-transaction must be
committed before latching any further pages. Verify that this
is the case in all execution paths.
row_ins_sec_index_entry_by_modify(), row_ins_clust_index_entry_by_modify(),
row_undo_mod_clust_low(): Because these functions call
btr_cur_update_in_place(), btr_cur_optimistic_update(), or
btr_cur_pessimistic_update(), document that the mini-transaction must be
committed before latching any further pages. Verify that this is the case
in all execution paths.
2007-05-16 09:23:53 +00:00
|
|
|
err = DB_ZIP_OVERFLOW;
|
|
|
|
goto err_exit;
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
|
|
|
|
2006-08-29 09:30:31 +00:00
|
|
|
if (UNIV_UNLIKELY(new_rec_size
|
|
|
|
>= (page_get_free_space_of_empty(page_is_comp(page))
|
|
|
|
/ 2))) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2007-02-27 07:25:24 +00:00
|
|
|
err = DB_OVERFLOW;
|
|
|
|
goto err_exit;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (UNIV_UNLIKELY(page_get_data_size(page)
|
2006-08-29 09:30:31 +00:00
|
|
|
- old_rec_size + new_rec_size
|
|
|
|
< BTR_CUR_PAGE_COMPRESS_LIMIT)) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/* The page would become too empty */
|
|
|
|
|
2007-02-27 07:25:24 +00:00
|
|
|
err = DB_UNDERFLOW;
|
|
|
|
goto err_exit;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
max_size = old_rec_size
|
2006-08-29 09:30:31 +00:00
|
|
|
+ page_get_max_insert_size_after_reorganize(page, 1);
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
if (!(((max_size >= BTR_CUR_PAGE_REORGANIZE_LIMIT)
|
2006-08-29 09:30:31 +00:00
|
|
|
&& (max_size >= new_rec_size))
|
|
|
|
|| (page_get_n_recs(page) <= 1))) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/* There was not enough space, or it did not pay to
|
|
|
|
reorganize: for simplicity, we decide what to do assuming a
|
|
|
|
reorganization is needed, though it might not be necessary */
|
|
|
|
|
2007-02-27 07:25:24 +00:00
|
|
|
err = DB_OVERFLOW;
|
|
|
|
goto err_exit;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Do lock checking and undo logging */
|
|
|
|
err = btr_cur_upd_lock_and_undo(flags, cursor, update, cmpl_info, thr,
|
2006-08-29 09:30:31 +00:00
|
|
|
&roll_ptr);
|
2005-10-27 07:29:40 +00:00
|
|
|
if (err != DB_SUCCESS) {
|
2007-02-27 07:25:24 +00:00
|
|
|
err_exit:
|
2005-10-27 07:29:40 +00:00
|
|
|
mem_heap_free(heap);
|
|
|
|
return(err);
|
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
|
|
|
/* Ok, we may do the replacement. Store on the page infimum the
|
2005-10-27 07:29:40 +00:00
|
|
|
explicit locks on rec, before deleting rec (see the comment in
|
branches/zip: Document and obey the rules for modifying the free bits in
the insert buffer bitmap.
ibuf_set_free_bits_func(): Never disable redo logging.
ibuf_update_free_bits_zip(): Remove.
btr_page_reorganize_low(), page_zip_reorganize(): Do not update the insert
buffer bitmap. Instead, document that callers will have to take care of it,
and adapt the callers.
btr_compress(): On error, reset the insert buffer free bits.
btr_cur_insert_if_possible(): Do not modify the insert buffer bitmap.
btr_compress(), btr_cur_optimistic_insert(): On compressed pages,
reset the insert buffer bitmap. Document why.
btr_cur_update_alloc_zip(): Document why it is necessary and sufficient
to reset the insert buffer free bits.
btr_cur_update_in_place(), btr_cur_optimistic_update(),
btr_cur_pessimistic_update(): Update the free bits in the same
mini-transaction. Document that the mini-transaction must be
committed before latching any further pages. Verify that this
is the case in all execution paths.
row_ins_sec_index_entry_by_modify(), row_ins_clust_index_entry_by_modify(),
row_undo_mod_clust_low(): Because these functions call
btr_cur_update_in_place(), btr_cur_optimistic_update(), or
btr_cur_pessimistic_update(), document that the mini-transaction must be
committed before latching any further pages. Verify that this is the case
in all execution paths.
2007-05-16 09:23:53 +00:00
|
|
|
btr_cur_pessimistic_update). */
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-10-24 06:45:52 +00:00
|
|
|
lock_rec_store_on_page_infimum(block, rec);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
btr_search_update_hash_on_delete(cursor);
|
|
|
|
|
2007-10-17 12:13:29 +00:00
|
|
|
/* The call to row_rec_to_index_entry(ROW_COPY_DATA, ...) above
|
|
|
|
invokes rec_offs_make_valid() to point to the copied record that
|
|
|
|
the fields of new_entry point to. We have to undo it here. */
|
|
|
|
ut_ad(rec_offs_validate(NULL, index, offsets));
|
|
|
|
rec_offs_make_valid(page_cur_get_rec(page_cursor), index, offsets);
|
|
|
|
|
2006-10-20 12:45:53 +00:00
|
|
|
page_cur_delete_rec(page_cursor, index, offsets, mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
page_cur_move_to_prev(page_cursor);
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
trx = thr_get_trx(thr);
|
|
|
|
|
|
|
|
if (!(flags & BTR_KEEP_SYS_FLAG)) {
|
|
|
|
row_upd_index_entry_sys_field(new_entry, index, DATA_ROLL_PTR,
|
2006-08-29 09:30:31 +00:00
|
|
|
roll_ptr);
|
2005-10-27 07:29:40 +00:00
|
|
|
row_upd_index_entry_sys_field(new_entry, index, DATA_TRX_ID,
|
2006-08-29 09:30:31 +00:00
|
|
|
trx->id);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2006-02-13 14:28:00 +00:00
|
|
|
/* There are no externally stored columns in new_entry */
|
2007-10-17 12:13:29 +00:00
|
|
|
rec = btr_cur_insert_if_possible(cursor, new_entry, 0/*n_ext*/, mtr);
|
2006-02-10 15:06:17 +00:00
|
|
|
ut_a(rec); /* <- We calculated above the insert would fit */
|
2005-10-27 07:29:40 +00:00
|
|
|
|
branches/zip: Document and obey the rules for modifying the free bits in
the insert buffer bitmap.
ibuf_set_free_bits_func(): Never disable redo logging.
ibuf_update_free_bits_zip(): Remove.
btr_page_reorganize_low(), page_zip_reorganize(): Do not update the insert
buffer bitmap. Instead, document that callers will have to take care of it,
and adapt the callers.
btr_compress(): On error, reset the insert buffer free bits.
btr_cur_insert_if_possible(): Do not modify the insert buffer bitmap.
btr_compress(), btr_cur_optimistic_insert(): On compressed pages,
reset the insert buffer bitmap. Document why.
btr_cur_update_alloc_zip(): Document why it is necessary and sufficient
to reset the insert buffer free bits.
btr_cur_update_in_place(), btr_cur_optimistic_update(),
btr_cur_pessimistic_update(): Update the free bits in the same
mini-transaction. Document that the mini-transaction must be
committed before latching any further pages. Verify that this
is the case in all execution paths.
row_ins_sec_index_entry_by_modify(), row_ins_clust_index_entry_by_modify(),
row_undo_mod_clust_low(): Because these functions call
btr_cur_update_in_place(), btr_cur_optimistic_update(), or
btr_cur_pessimistic_update(), document that the mini-transaction must be
committed before latching any further pages. Verify that this is the case
in all execution paths.
2007-05-16 09:23:53 +00:00
|
|
|
if (page_zip && !dict_index_is_clust(index)
|
|
|
|
&& page_is_leaf(page)) {
|
|
|
|
/* Update the free bits in the insert buffer. */
|
2007-10-12 13:25:12 +00:00
|
|
|
ibuf_update_free_bits_zip(block, mtr);
|
branches/zip: Document and obey the rules for modifying the free bits in
the insert buffer bitmap.
ibuf_set_free_bits_func(): Never disable redo logging.
ibuf_update_free_bits_zip(): Remove.
btr_page_reorganize_low(), page_zip_reorganize(): Do not update the insert
buffer bitmap. Instead, document that callers will have to take care of it,
and adapt the callers.
btr_compress(): On error, reset the insert buffer free bits.
btr_cur_insert_if_possible(): Do not modify the insert buffer bitmap.
btr_compress(), btr_cur_optimistic_insert(): On compressed pages,
reset the insert buffer bitmap. Document why.
btr_cur_update_alloc_zip(): Document why it is necessary and sufficient
to reset the insert buffer free bits.
btr_cur_update_in_place(), btr_cur_optimistic_update(),
btr_cur_pessimistic_update(): Update the free bits in the same
mini-transaction. Document that the mini-transaction must be
committed before latching any further pages. Verify that this
is the case in all execution paths.
row_ins_sec_index_entry_by_modify(), row_ins_clust_index_entry_by_modify(),
row_undo_mod_clust_low(): Because these functions call
btr_cur_update_in_place(), btr_cur_optimistic_update(), or
btr_cur_pessimistic_update(), document that the mini-transaction must be
committed before latching any further pages. Verify that this is the case
in all execution paths.
2007-05-16 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/* Restore the old explicit lock state on the record */
|
|
|
|
|
2006-10-24 06:45:52 +00:00
|
|
|
lock_rec_restore_from_page_infimum(block, rec, block);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-02-23 19:25:29 +00:00
|
|
|
page_cur_move_to_next(page_cursor);
|
|
|
|
|
|
|
|
mem_heap_free(heap);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
return(DB_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
If, in a split, a new supremum record was created as the predecessor of the
|
|
|
|
updated record, the supremum record must inherit exactly the locks on the
|
|
|
|
updated record. In the split it may have inherited locks from the successor
|
|
|
|
of the updated record, which is not correct. This function restores the
|
|
|
|
right locks for the new supremum. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
btr_cur_pess_upd_restore_supremum(
|
|
|
|
/*==============================*/
|
2006-10-24 06:45:52 +00:00
|
|
|
buf_block_t* block, /* in: buffer block of rec */
|
|
|
|
const rec_t* rec, /* in: updated record */
|
|
|
|
mtr_t* mtr) /* in: mtr */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
2006-10-12 11:05:22 +00:00
|
|
|
page_t* page;
|
|
|
|
buf_block_t* prev_block;
|
|
|
|
ulint space;
|
2007-01-18 09:59:00 +00:00
|
|
|
ulint zip_size;
|
2006-10-12 11:05:22 +00:00
|
|
|
ulint prev_page_no;
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2006-10-24 06:45:52 +00:00
|
|
|
page = buf_block_get_frame(block);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (page_rec_get_next(page_get_infimum_rec(page)) != rec) {
|
2006-02-23 19:25:29 +00:00
|
|
|
/* Updated record is not the first user record on its page */
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-10-24 06:45:52 +00:00
|
|
|
space = buf_block_get_space(block);
|
2007-01-18 09:59:00 +00:00
|
|
|
zip_size = buf_block_get_zip_size(block);
|
2005-10-27 07:29:40 +00:00
|
|
|
prev_page_no = btr_page_get_prev(page, mtr);
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
ut_ad(prev_page_no != FIL_NULL);
|
2007-01-18 09:59:00 +00:00
|
|
|
prev_block = buf_page_get_with_no_latch(space, zip_size,
|
|
|
|
prev_page_no, mtr);
|
2006-05-11 17:00:43 +00:00
|
|
|
#ifdef UNIV_BTR_DEBUG
|
2006-10-24 06:45:52 +00:00
|
|
|
ut_a(btr_page_get_next(prev_block->frame, mtr)
|
2006-10-12 07:02:36 +00:00
|
|
|
== page_get_page_no(page));
|
2006-05-11 17:00:43 +00:00
|
|
|
#endif /* UNIV_BTR_DEBUG */
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-10-24 06:45:52 +00:00
|
|
|
/* We must already have an x-latch on prev_block! */
|
2006-10-12 11:05:22 +00:00
|
|
|
ut_ad(mtr_memo_contains(mtr, prev_block, MTR_MEMO_PAGE_X_FIX));
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-10-24 06:45:52 +00:00
|
|
|
lock_rec_reset_and_inherit_gap_locks(prev_block, block,
|
|
|
|
PAGE_HEAP_NO_SUPREMUM,
|
|
|
|
page_rec_get_heap_no(rec));
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
Performs an update of a record on a page of a tree. It is assumed
|
|
|
|
that mtr holds an x-latch on the tree and on the cursor page. If the
|
|
|
|
update is made on the leaf level, to avoid deadlocks, mtr must also
|
|
|
|
own x-latches to brothers of page, if those brothers exist. We assume
|
|
|
|
here that the ordering fields of the record do not change. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint
|
|
|
|
btr_cur_pessimistic_update(
|
|
|
|
/*=======================*/
|
|
|
|
/* out: DB_SUCCESS or error code */
|
|
|
|
ulint flags, /* in: undo logging, locking, and rollback
|
|
|
|
flags */
|
|
|
|
btr_cur_t* cursor, /* in: cursor on the record to update */
|
2007-03-28 19:35:52 +00:00
|
|
|
mem_heap_t** heap, /* in/out: pointer to memory heap, or NULL */
|
2005-10-27 07:29:40 +00:00
|
|
|
big_rec_t** big_rec,/* out: big rec vector whose fields have to
|
|
|
|
be stored externally by the caller, or NULL */
|
2007-08-20 06:59:22 +00:00
|
|
|
const upd_t* update, /* in: update vector; this is allowed also
|
2005-10-27 07:29:40 +00:00
|
|
|
contain trx id and roll ptr fields, but
|
|
|
|
the values in update vector have no effect */
|
|
|
|
ulint cmpl_info,/* in: compiler info on secondary index
|
|
|
|
updates */
|
|
|
|
que_thr_t* thr, /* in: query thread */
|
branches/zip: Document and obey the rules for modifying the free bits in
the insert buffer bitmap.
ibuf_set_free_bits_func(): Never disable redo logging.
ibuf_update_free_bits_zip(): Remove.
btr_page_reorganize_low(), page_zip_reorganize(): Do not update the insert
buffer bitmap. Instead, document that callers will have to take care of it,
and adapt the callers.
btr_compress(): On error, reset the insert buffer free bits.
btr_cur_insert_if_possible(): Do not modify the insert buffer bitmap.
btr_compress(), btr_cur_optimistic_insert(): On compressed pages,
reset the insert buffer bitmap. Document why.
btr_cur_update_alloc_zip(): Document why it is necessary and sufficient
to reset the insert buffer free bits.
btr_cur_update_in_place(), btr_cur_optimistic_update(),
btr_cur_pessimistic_update(): Update the free bits in the same
mini-transaction. Document that the mini-transaction must be
committed before latching any further pages. Verify that this
is the case in all execution paths.
row_ins_sec_index_entry_by_modify(), row_ins_clust_index_entry_by_modify(),
row_undo_mod_clust_low(): Because these functions call
btr_cur_update_in_place(), btr_cur_optimistic_update(), or
btr_cur_pessimistic_update(), document that the mini-transaction must be
committed before latching any further pages. Verify that this is the case
in all execution paths.
2007-05-16 09:23:53 +00:00
|
|
|
mtr_t* mtr) /* in: mtr; must be committed before
|
|
|
|
latching any further pages */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
|
|
|
big_rec_t* big_rec_vec = NULL;
|
|
|
|
big_rec_t* dummy_big_rec;
|
|
|
|
dict_index_t* index;
|
2006-10-18 11:39:31 +00:00
|
|
|
buf_block_t* block;
|
2005-10-27 07:29:40 +00:00
|
|
|
page_t* page;
|
2005-10-27 11:48:10 +00:00
|
|
|
page_zip_des_t* page_zip;
|
2005-10-27 07:29:40 +00:00
|
|
|
rec_t* rec;
|
|
|
|
page_cur_t* page_cursor;
|
|
|
|
dtuple_t* new_entry;
|
|
|
|
ulint err;
|
|
|
|
ulint optim_err;
|
|
|
|
dulint roll_ptr;
|
|
|
|
trx_t* trx;
|
|
|
|
ibool was_first;
|
|
|
|
ulint n_extents = 0;
|
|
|
|
ulint n_reserved;
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
ulint n_ext;
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint* offsets = NULL;
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
*big_rec = NULL;
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2006-10-18 11:39:31 +00:00
|
|
|
block = btr_cur_get_block(cursor);
|
|
|
|
page = buf_block_get_frame(block);
|
|
|
|
page_zip = buf_block_get_page_zip(block);
|
2005-10-27 07:29:40 +00:00
|
|
|
rec = btr_cur_get_rec(cursor);
|
|
|
|
index = cursor->index;
|
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
ut_ad(mtr_memo_contains(mtr, dict_index_get_lock(index),
|
2006-08-29 09:30:31 +00:00
|
|
|
MTR_MEMO_X_LOCK));
|
2006-10-18 11:39:31 +00:00
|
|
|
ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX));
|
2006-06-20 19:35:59 +00:00
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
2006-06-12 12:37:54 +00:00
|
|
|
ut_a(!page_zip || page_zip_validate(page_zip, page));
|
2006-06-20 19:35:59 +00:00
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
optim_err = btr_cur_optimistic_update(flags, cursor, update,
|
2006-08-29 09:30:31 +00:00
|
|
|
cmpl_info, thr, mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
switch (optim_err) {
|
|
|
|
case DB_UNDERFLOW:
|
|
|
|
case DB_OVERFLOW:
|
|
|
|
case DB_ZIP_OVERFLOW:
|
|
|
|
break;
|
|
|
|
default:
|
2005-10-27 07:29:40 +00:00
|
|
|
return(optim_err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do lock checking and undo logging */
|
|
|
|
err = btr_cur_upd_lock_and_undo(flags, cursor, update, cmpl_info,
|
2006-08-29 09:30:31 +00:00
|
|
|
thr, &roll_ptr);
|
2005-10-27 07:29:40 +00:00
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (optim_err == DB_OVERFLOW) {
|
2006-02-10 15:06:17 +00:00
|
|
|
ulint reserve_flag;
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/* First reserve enough free space for the file segments
|
|
|
|
of the index tree, so that the update will not fail because
|
|
|
|
of lack of space */
|
|
|
|
|
|
|
|
n_extents = cursor->tree_height / 16 + 3;
|
|
|
|
|
|
|
|
if (flags & BTR_NO_UNDO_LOG_FLAG) {
|
|
|
|
reserve_flag = FSP_CLEANING;
|
|
|
|
} else {
|
|
|
|
reserve_flag = FSP_NORMAL;
|
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
if (!fsp_reserve_free_extents(&n_reserved, index->space,
|
2006-08-29 09:30:31 +00:00
|
|
|
n_extents, reserve_flag, mtr)) {
|
2006-02-10 15:06:17 +00:00
|
|
|
return(DB_OUT_OF_FILE_SPACE);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2007-03-28 19:35:52 +00:00
|
|
|
if (!*heap) {
|
|
|
|
*heap = mem_heap_create(1024);
|
|
|
|
}
|
|
|
|
offsets = rec_get_offsets(rec, index, NULL, ULINT_UNDEFINED, heap);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
trx = thr_get_trx(thr);
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2007-10-17 12:13:29 +00:00
|
|
|
new_entry = row_rec_to_index_entry(ROW_COPY_DATA, rec, index, offsets,
|
|
|
|
&n_ext, *heap);
|
|
|
|
/* The call to row_rec_to_index_entry(ROW_COPY_DATA, ...) above
|
|
|
|
invokes rec_offs_make_valid() to point to the copied record that
|
|
|
|
the fields of new_entry point to. We have to undo it here. */
|
|
|
|
ut_ad(rec_offs_validate(NULL, index, offsets));
|
|
|
|
rec_offs_make_valid(rec, index, offsets);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-01-14 10:04:45 +00:00
|
|
|
/* The page containing the clustered index record
|
2008-02-04 12:47:00 +00:00
|
|
|
corresponding to new_entry is latched in mtr. If the
|
|
|
|
clustered index record is delete-marked, then its externally
|
|
|
|
stored fields cannot have been purged yet, because then the
|
|
|
|
purge would also have removed the clustered index record
|
|
|
|
itself. Thus the following call is safe. */
|
2005-10-27 07:29:40 +00:00
|
|
|
row_upd_index_replace_new_col_vals_index_pos(new_entry, index, update,
|
2008-05-14 15:43:19 +00:00
|
|
|
FALSE, *heap);
|
2005-10-27 07:29:40 +00:00
|
|
|
if (!(flags & BTR_KEEP_SYS_FLAG)) {
|
|
|
|
row_upd_index_entry_sys_field(new_entry, index, DATA_ROLL_PTR,
|
2006-08-29 09:30:31 +00:00
|
|
|
roll_ptr);
|
2005-10-27 07:29:40 +00:00
|
|
|
row_upd_index_entry_sys_field(new_entry, index, DATA_TRX_ID,
|
2006-08-29 09:30:31 +00:00
|
|
|
trx->id);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2007-12-05 09:49:09 +00:00
|
|
|
if ((flags & BTR_NO_UNDO_LOG_FLAG) && rec_offs_any_extern(offsets)) {
|
2005-10-27 07:29:40 +00:00
|
|
|
/* We are in a transaction rollback undoing a row
|
|
|
|
update: we must free possible externally stored fields
|
|
|
|
which got new values in the update, if they are not
|
|
|
|
inherited values. They can be inherited if we have
|
|
|
|
updated the primary key to another value, and then
|
|
|
|
update it back again. */
|
|
|
|
|
2007-03-28 19:35:52 +00:00
|
|
|
ut_ad(big_rec_vec == NULL);
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2008-08-09 00:15:46 +00:00
|
|
|
btr_rec_free_updated_extern_fields(
|
|
|
|
index, rec, page_zip, offsets, update,
|
|
|
|
trx_is_recv(trx) ? RB_RECOVERY : RB_NORMAL, mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We have to set appropriate extern storage bits in the new
|
|
|
|
record to be inserted: we have to remember which fields were such */
|
|
|
|
|
|
|
|
ut_ad(!page_is_comp(page) || !rec_get_node_ptr_flag(rec));
|
2007-03-28 19:35:52 +00:00
|
|
|
offsets = rec_get_offsets(rec, index, offsets, ULINT_UNDEFINED, heap);
|
2008-01-23 13:46:45 +00:00
|
|
|
n_ext += btr_push_update_extern_fields(new_entry, update, *heap);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-09-17 19:52:30 +00:00
|
|
|
if (UNIV_LIKELY_NULL(page_zip)) {
|
|
|
|
ut_ad(page_is_comp(page));
|
|
|
|
if (page_zip_rec_needs_ext(
|
|
|
|
rec_get_converted_size(index, new_entry, n_ext),
|
|
|
|
TRUE,
|
|
|
|
dict_index_get_n_fields(index),
|
|
|
|
page_zip_get_size(page_zip))) {
|
|
|
|
|
|
|
|
goto make_external;
|
|
|
|
}
|
|
|
|
} else if (page_zip_rec_needs_ext(
|
|
|
|
rec_get_converted_size(index, new_entry, n_ext),
|
|
|
|
page_is_comp(page), 0, 0)) {
|
|
|
|
make_external:
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
big_rec_vec = dtuple_convert_big_rec(index, new_entry, &n_ext);
|
branches/zip: dtuple_convert_big_rec(): Do not store anything locally
of externally stored columns, and fix bugs introduced in r873. (Bug #22496)
btr_page_get_sure_split_rec(), btr_page_insert_fits(),
rec_get_converted_size(), rec_convert_dtuple_to_rec(),
rec_convert_dtuple_to_rec_old(), rec_convert_dtuple_to_rec_new():
Add parameters ext and n_ext. Flag external fields during the
conversion.
rec_set_field_extern_bits(), rec_set_field_extern_bits_new(),
rec_offs_set_nth_extern(), rec_set_nth_field_extern_bit_old():
Remove. The bits are set by rec_convert_dtuple_to_rec().
page_cur_insert_rec_low(): Remove the parameters ext and n_ext.
btr_cur_add_ext(): New utility function for updating and sorting ext[].
Low-level functions now expect the array to be in ascending order
for performance reasons. Used in btr_cur_optimistic_insert(),
btr_cur_pessimistic_insert(), and btr_cur_pessimistic_update().
btr_cur_optimistic_insert(): Remove some defensive code, because we cannot
compute the added parameters of rec_get_converted_size().
btr_push_update_extern_fields(): Sort the array. Require the array to
be twice the maximum usage, so that ut_ulint_sort() can be used.
dtuple_convert_big_rec(): Allocate new space for the BLOB pointer,
to avoid overwriting prefix indexes to the same column. Adapt
dtuple_convert_back_big_rec().
row_build_index_entry(): Fetch the columns also for prefix indexes of
the clustered index.
page_zip_apply_log(), page_zip_decompress_clust(): Allow externally
stored fields to lack a locally stored part.
2006-09-29 10:40:42 +00:00
|
|
|
if (UNIV_UNLIKELY(big_rec_vec == NULL)) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
err = DB_TOO_BIG_RECORD;
|
|
|
|
goto return_after_reservations;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Store state of explicit locks on rec on the page infimum record,
|
|
|
|
before deleting rec. The page infimum acts as a dummy carrier of the
|
|
|
|
locks, taking care also of lock releases, before we can move the locks
|
|
|
|
back on the actual record. There is a special case: if we are
|
|
|
|
inserting on the root page and the insert causes a call of
|
|
|
|
btr_root_raise_and_insert. Therefore we cannot in the lock system
|
|
|
|
delete the lock structs set on the root page even if the root
|
|
|
|
page carries just node pointers. */
|
|
|
|
|
2006-10-24 06:45:52 +00:00
|
|
|
lock_rec_store_on_page_infimum(block, rec);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
btr_search_update_hash_on_delete(cursor);
|
|
|
|
|
2006-06-20 19:35:59 +00:00
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
2006-06-12 12:37:54 +00:00
|
|
|
ut_a(!page_zip || page_zip_validate(page_zip, page));
|
2006-06-20 19:35:59 +00:00
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
2006-10-24 06:45:52 +00:00
|
|
|
page_cursor = btr_cur_get_page_cur(cursor);
|
|
|
|
|
2006-10-20 12:45:53 +00:00
|
|
|
page_cur_delete_rec(page_cursor, index, offsets, mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
page_cur_move_to_prev(page_cursor);
|
|
|
|
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
rec = btr_cur_insert_if_possible(cursor, new_entry, n_ext, mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (rec) {
|
2006-10-24 06:45:52 +00:00
|
|
|
lock_rec_restore_from_page_infimum(btr_cur_get_block(cursor),
|
|
|
|
rec, block);
|
2006-04-12 09:32:17 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
offsets = rec_get_offsets(rec, index, offsets,
|
2007-03-28 19:35:52 +00:00
|
|
|
ULINT_UNDEFINED, heap);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (!rec_get_deleted_flag(rec, rec_offs_comp(offsets))) {
|
|
|
|
/* The new inserted record owns its possible externally
|
|
|
|
stored fields */
|
2006-09-19 10:14:07 +00:00
|
|
|
btr_cur_unmark_extern_fields(page_zip,
|
|
|
|
rec, index, offsets, mtr);
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
btr_cur_compress_if_useful(cursor, mtr);
|
|
|
|
|
branches/zip: Document and obey the rules for modifying the free bits in
the insert buffer bitmap.
ibuf_set_free_bits_func(): Never disable redo logging.
ibuf_update_free_bits_zip(): Remove.
btr_page_reorganize_low(), page_zip_reorganize(): Do not update the insert
buffer bitmap. Instead, document that callers will have to take care of it,
and adapt the callers.
btr_compress(): On error, reset the insert buffer free bits.
btr_cur_insert_if_possible(): Do not modify the insert buffer bitmap.
btr_compress(), btr_cur_optimistic_insert(): On compressed pages,
reset the insert buffer bitmap. Document why.
btr_cur_update_alloc_zip(): Document why it is necessary and sufficient
to reset the insert buffer free bits.
btr_cur_update_in_place(), btr_cur_optimistic_update(),
btr_cur_pessimistic_update(): Update the free bits in the same
mini-transaction. Document that the mini-transaction must be
committed before latching any further pages. Verify that this
is the case in all execution paths.
row_ins_sec_index_entry_by_modify(), row_ins_clust_index_entry_by_modify(),
row_undo_mod_clust_low(): Because these functions call
btr_cur_update_in_place(), btr_cur_optimistic_update(), or
btr_cur_pessimistic_update(), document that the mini-transaction must be
committed before latching any further pages. Verify that this is the case
in all execution paths.
2007-05-16 09:23:53 +00:00
|
|
|
if (page_zip && !dict_index_is_clust(index)
|
|
|
|
&& page_is_leaf(page)) {
|
|
|
|
/* Update the free bits in the insert buffer. */
|
2007-10-12 13:25:12 +00:00
|
|
|
ibuf_update_free_bits_zip(block, mtr);
|
branches/zip: Document and obey the rules for modifying the free bits in
the insert buffer bitmap.
ibuf_set_free_bits_func(): Never disable redo logging.
ibuf_update_free_bits_zip(): Remove.
btr_page_reorganize_low(), page_zip_reorganize(): Do not update the insert
buffer bitmap. Instead, document that callers will have to take care of it,
and adapt the callers.
btr_compress(): On error, reset the insert buffer free bits.
btr_cur_insert_if_possible(): Do not modify the insert buffer bitmap.
btr_compress(), btr_cur_optimistic_insert(): On compressed pages,
reset the insert buffer bitmap. Document why.
btr_cur_update_alloc_zip(): Document why it is necessary and sufficient
to reset the insert buffer free bits.
btr_cur_update_in_place(), btr_cur_optimistic_update(),
btr_cur_pessimistic_update(): Update the free bits in the same
mini-transaction. Document that the mini-transaction must be
committed before latching any further pages. Verify that this
is the case in all execution paths.
row_ins_sec_index_entry_by_modify(), row_ins_clust_index_entry_by_modify(),
row_undo_mod_clust_low(): Because these functions call
btr_cur_update_in_place(), btr_cur_optimistic_update(), or
btr_cur_pessimistic_update(), document that the mini-transaction must be
committed before latching any further pages. Verify that this is the case
in all execution paths.
2007-05-16 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
err = DB_SUCCESS;
|
|
|
|
goto return_after_reservations;
|
branches/zip: Document and obey the rules for modifying the free bits in
the insert buffer bitmap.
ibuf_set_free_bits_func(): Never disable redo logging.
ibuf_update_free_bits_zip(): Remove.
btr_page_reorganize_low(), page_zip_reorganize(): Do not update the insert
buffer bitmap. Instead, document that callers will have to take care of it,
and adapt the callers.
btr_compress(): On error, reset the insert buffer free bits.
btr_cur_insert_if_possible(): Do not modify the insert buffer bitmap.
btr_compress(), btr_cur_optimistic_insert(): On compressed pages,
reset the insert buffer bitmap. Document why.
btr_cur_update_alloc_zip(): Document why it is necessary and sufficient
to reset the insert buffer free bits.
btr_cur_update_in_place(), btr_cur_optimistic_update(),
btr_cur_pessimistic_update(): Update the free bits in the same
mini-transaction. Document that the mini-transaction must be
committed before latching any further pages. Verify that this
is the case in all execution paths.
row_ins_sec_index_entry_by_modify(), row_ins_clust_index_entry_by_modify(),
row_undo_mod_clust_low(): Because these functions call
btr_cur_update_in_place(), btr_cur_optimistic_update(), or
btr_cur_pessimistic_update(), document that the mini-transaction must be
committed before latching any further pages. Verify that this is the case
in all execution paths.
2007-05-16 09:23:53 +00:00
|
|
|
} else {
|
|
|
|
ut_a(optim_err != DB_UNDERFLOW);
|
|
|
|
|
|
|
|
/* Out of space: reset the free bits. */
|
|
|
|
if (!dict_index_is_clust(index)
|
|
|
|
&& page_is_leaf(page)) {
|
|
|
|
ibuf_reset_free_bits(block);
|
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
/* Was the record to be updated positioned as the first user
|
|
|
|
record on its page? */
|
|
|
|
was_first = page_cur_is_before_first(page_cursor);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/* The first parameter means that no lock checking and undo logging
|
|
|
|
is made in the insert */
|
|
|
|
|
|
|
|
err = btr_cur_pessimistic_insert(BTR_NO_UNDO_LOG_FLAG
|
2006-08-29 09:30:31 +00:00
|
|
|
| BTR_NO_LOCKING_FLAG
|
|
|
|
| BTR_KEEP_SYS_FLAG,
|
|
|
|
cursor, new_entry, &rec,
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
&dummy_big_rec, n_ext, NULL, mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
ut_a(rec);
|
|
|
|
ut_a(err == DB_SUCCESS);
|
|
|
|
ut_a(dummy_big_rec == NULL);
|
|
|
|
|
|
|
|
if (!rec_get_deleted_flag(rec, rec_offs_comp(offsets))) {
|
|
|
|
/* The new inserted record owns its possible externally
|
|
|
|
stored fields */
|
2007-11-05 14:08:18 +00:00
|
|
|
buf_block_t* rec_block = btr_cur_get_block(cursor);
|
|
|
|
|
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
|
|
|
ut_a(!page_zip || page_zip_validate(page_zip, page));
|
|
|
|
page = buf_block_get_frame(rec_block);
|
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
|
|
|
page_zip = buf_block_get_page_zip(rec_block);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-02-13 14:28:00 +00:00
|
|
|
offsets = rec_get_offsets(rec, index, offsets,
|
2007-03-28 19:35:52 +00:00
|
|
|
ULINT_UNDEFINED, heap);
|
2006-09-19 10:14:07 +00:00
|
|
|
btr_cur_unmark_extern_fields(page_zip,
|
|
|
|
rec, index, offsets, mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2006-10-24 06:45:52 +00:00
|
|
|
lock_rec_restore_from_page_infimum(btr_cur_get_block(cursor),
|
|
|
|
rec, block);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/* If necessary, restore also the correct lock state for a new,
|
|
|
|
preceding supremum record created in a page split. While the old
|
|
|
|
record was nonexistent, the supremum might have inherited its locks
|
|
|
|
from a wrong record. */
|
|
|
|
|
|
|
|
if (!was_first) {
|
2006-10-24 06:45:52 +00:00
|
|
|
btr_cur_pess_upd_restore_supremum(btr_cur_get_block(cursor),
|
|
|
|
rec, mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return_after_reservations:
|
2006-08-03 08:06:45 +00:00
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
|
|
|
ut_a(!page_zip || page_zip_validate(page_zip, page));
|
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (n_extents > 0) {
|
|
|
|
fil_space_release_free_extents(index->space, n_reserved);
|
|
|
|
}
|
|
|
|
|
|
|
|
*big_rec = big_rec_vec;
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*==================== B-TREE DELETE MARK AND UNMARK ===============*/
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
Writes the redo log record for delete marking or unmarking of an index
|
|
|
|
record. */
|
|
|
|
UNIV_INLINE
|
|
|
|
void
|
|
|
|
btr_cur_del_mark_set_clust_rec_log(
|
|
|
|
/*===============================*/
|
|
|
|
ulint flags, /* in: flags */
|
|
|
|
rec_t* rec, /* in: record */
|
|
|
|
dict_index_t* index, /* in: index of the record */
|
|
|
|
ibool val, /* in: value to set */
|
|
|
|
trx_t* trx, /* in: deleting transaction */
|
|
|
|
dulint roll_ptr,/* in: roll ptr to the undo log record */
|
|
|
|
mtr_t* mtr) /* in: mtr */
|
|
|
|
{
|
|
|
|
byte* log_ptr;
|
|
|
|
ut_ad(flags < 256);
|
|
|
|
ut_ad(val <= 1);
|
|
|
|
|
2006-02-27 09:33:26 +00:00
|
|
|
ut_ad(!!page_rec_is_comp(rec) == dict_table_is_comp(index->table));
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
log_ptr = mlog_open_and_write_index(mtr, rec, index,
|
2006-08-29 09:30:31 +00:00
|
|
|
page_rec_is_comp(rec)
|
|
|
|
? MLOG_COMP_REC_CLUST_DELETE_MARK
|
|
|
|
: MLOG_REC_CLUST_DELETE_MARK,
|
|
|
|
1 + 1 + DATA_ROLL_PTR_LEN
|
|
|
|
+ 14 + 2);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (!log_ptr) {
|
|
|
|
/* Logging in mtr is switched off during crash recovery */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mach_write_to_1(log_ptr, flags);
|
|
|
|
log_ptr++;
|
|
|
|
mach_write_to_1(log_ptr, val);
|
|
|
|
log_ptr++;
|
|
|
|
|
|
|
|
log_ptr = row_upd_write_sys_vals_to_log(index, trx, roll_ptr, log_ptr,
|
2006-08-29 09:30:31 +00:00
|
|
|
mtr);
|
2006-09-19 10:14:07 +00:00
|
|
|
mach_write_to_2(log_ptr, page_offset(rec));
|
2005-10-27 07:29:40 +00:00
|
|
|
log_ptr += 2;
|
|
|
|
|
|
|
|
mlog_close(mtr, log_ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
Parses the redo log record for delete marking or unmarking of a clustered
|
|
|
|
index record. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
byte*
|
|
|
|
btr_cur_parse_del_mark_set_clust_rec(
|
|
|
|
/*=================================*/
|
|
|
|
/* out: end of log record or NULL */
|
|
|
|
byte* ptr, /* in: buffer */
|
|
|
|
byte* end_ptr,/* in: buffer end */
|
2005-10-27 11:48:10 +00:00
|
|
|
page_t* page, /* in/out: page or NULL */
|
|
|
|
page_zip_des_t* page_zip,/* in/out: compressed page, or NULL */
|
|
|
|
dict_index_t* index) /* in: index corresponding to page */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
|
|
|
ulint flags;
|
|
|
|
ulint val;
|
|
|
|
ulint pos;
|
|
|
|
dulint trx_id;
|
|
|
|
dulint roll_ptr;
|
|
|
|
ulint offset;
|
|
|
|
rec_t* rec;
|
|
|
|
|
2006-02-27 09:33:26 +00:00
|
|
|
ut_ad(!page
|
2006-08-29 09:30:31 +00:00
|
|
|
|| !!page_is_comp(page) == dict_table_is_comp(index->table));
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (end_ptr < ptr + 2) {
|
|
|
|
|
|
|
|
return(NULL);
|
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
flags = mach_read_from_1(ptr);
|
|
|
|
ptr++;
|
|
|
|
val = mach_read_from_1(ptr);
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
ptr = row_upd_parse_sys_vals(ptr, end_ptr, &pos, &trx_id, &roll_ptr);
|
|
|
|
|
|
|
|
if (ptr == NULL) {
|
|
|
|
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (end_ptr < ptr + 2) {
|
|
|
|
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
offset = mach_read_from_2(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
|
|
|
|
ut_a(offset <= UNIV_PAGE_SIZE);
|
|
|
|
|
|
|
|
if (page) {
|
|
|
|
rec = page + offset;
|
2005-10-27 11:48:10 +00:00
|
|
|
|
|
|
|
/* We do not need to reserve btr_search_latch, as the page
|
|
|
|
is only being recovered, and there cannot be a hash index to
|
|
|
|
it. */
|
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
btr_rec_set_deleted_flag(rec, page_zip, val);
|
2005-10-27 11:48:10 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
if (!(flags & BTR_KEEP_SYS_FLAG)) {
|
|
|
|
mem_heap_t* heap = NULL;
|
|
|
|
ulint offsets_[REC_OFFS_NORMAL_SIZE];
|
2007-09-28 07:05:57 +00:00
|
|
|
rec_offs_init(offsets_);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
row_upd_rec_sys_fields_in_recovery(
|
|
|
|
rec, page_zip,
|
|
|
|
rec_get_offsets(rec, index, offsets_,
|
|
|
|
ULINT_UNDEFINED, &heap),
|
|
|
|
pos, trx_id, roll_ptr);
|
2005-10-27 07:29:40 +00:00
|
|
|
if (UNIV_LIKELY_NULL(heap)) {
|
|
|
|
mem_heap_free(heap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
return(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************
|
|
|
|
Marks a clustered index record deleted. Writes an undo log record to
|
|
|
|
undo log on this delete marking. Writes in the trx id field the id
|
|
|
|
of the deleting transaction, and in the roll ptr field pointer to the
|
|
|
|
undo log record created. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint
|
|
|
|
btr_cur_del_mark_set_clust_rec(
|
|
|
|
/*===========================*/
|
|
|
|
/* out: DB_SUCCESS, DB_LOCK_WAIT, or error
|
|
|
|
number */
|
|
|
|
ulint flags, /* in: undo logging and locking flags */
|
|
|
|
btr_cur_t* cursor, /* in: cursor */
|
|
|
|
ibool val, /* in: value to set */
|
|
|
|
que_thr_t* thr, /* in: query thread */
|
|
|
|
mtr_t* mtr) /* in: mtr */
|
|
|
|
{
|
|
|
|
dict_index_t* index;
|
|
|
|
buf_block_t* block;
|
|
|
|
dulint roll_ptr;
|
|
|
|
ulint err;
|
|
|
|
rec_t* rec;
|
2005-10-27 11:48:10 +00:00
|
|
|
page_zip_des_t* page_zip;
|
2005-10-27 07:29:40 +00:00
|
|
|
trx_t* trx;
|
|
|
|
mem_heap_t* heap = NULL;
|
|
|
|
ulint offsets_[REC_OFFS_NORMAL_SIZE];
|
|
|
|
ulint* offsets = offsets_;
|
2007-09-28 07:05:57 +00:00
|
|
|
rec_offs_init(offsets_);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
rec = btr_cur_get_rec(cursor);
|
|
|
|
index = cursor->index;
|
2006-02-27 09:33:26 +00:00
|
|
|
ut_ad(!!page_rec_is_comp(rec) == dict_table_is_comp(index->table));
|
2005-10-27 07:29:40 +00:00
|
|
|
offsets = rec_get_offsets(rec, index, offsets, ULINT_UNDEFINED, &heap);
|
|
|
|
|
|
|
|
#ifdef UNIV_DEBUG
|
|
|
|
if (btr_cur_print_record_ops && thr) {
|
|
|
|
btr_cur_trx_report(thr_get_trx(thr), index, "del mark ");
|
|
|
|
rec_print_new(stderr, rec, offsets);
|
|
|
|
}
|
|
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
|
2006-03-09 17:26:02 +00:00
|
|
|
ut_ad(dict_index_is_clust(index));
|
2005-10-27 07:29:40 +00:00
|
|
|
ut_ad(!rec_get_deleted_flag(rec, rec_offs_comp(offsets)));
|
|
|
|
|
|
|
|
err = lock_clust_rec_modify_check_and_lock(flags,
|
2006-10-24 06:45:52 +00:00
|
|
|
btr_cur_get_block(cursor),
|
2006-08-29 09:30:31 +00:00
|
|
|
rec, index, offsets, thr);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
|
2005-10-27 11:48:10 +00:00
|
|
|
goto func_exit;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = trx_undo_report_row_operation(flags, TRX_UNDO_MODIFY_OP, thr,
|
2006-08-29 09:30:31 +00:00
|
|
|
index, NULL, NULL, 0, rec,
|
|
|
|
&roll_ptr);
|
2005-10-27 07:29:40 +00:00
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
|
2005-10-27 11:48:10 +00:00
|
|
|
goto func_exit;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2006-10-18 11:39:31 +00:00
|
|
|
block = btr_cur_get_block(cursor);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (block->is_hashed) {
|
|
|
|
rw_lock_x_lock(&btr_search_latch);
|
|
|
|
}
|
|
|
|
|
2006-10-18 11:39:31 +00:00
|
|
|
page_zip = buf_block_get_page_zip(block);
|
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
btr_rec_set_deleted_flag(rec, page_zip, val);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
trx = thr_get_trx(thr);
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
if (!(flags & BTR_KEEP_SYS_FLAG)) {
|
2006-02-10 15:06:17 +00:00
|
|
|
row_upd_rec_sys_fields(rec, page_zip,
|
2006-08-29 09:30:31 +00:00
|
|
|
index, offsets, trx, roll_ptr);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
if (block->is_hashed) {
|
|
|
|
rw_lock_x_unlock(&btr_search_latch);
|
|
|
|
}
|
|
|
|
|
|
|
|
btr_cur_del_mark_set_clust_rec_log(flags, rec, index, val, trx,
|
2006-08-29 09:30:31 +00:00
|
|
|
roll_ptr, mtr);
|
2005-10-27 11:48:10 +00:00
|
|
|
|
|
|
|
func_exit:
|
2005-10-27 07:29:40 +00:00
|
|
|
if (UNIV_LIKELY_NULL(heap)) {
|
|
|
|
mem_heap_free(heap);
|
|
|
|
}
|
2005-10-27 11:48:10 +00:00
|
|
|
return(err);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
Writes the redo log record for a delete mark setting of a secondary
|
|
|
|
index record. */
|
|
|
|
UNIV_INLINE
|
|
|
|
void
|
|
|
|
btr_cur_del_mark_set_sec_rec_log(
|
|
|
|
/*=============================*/
|
|
|
|
rec_t* rec, /* in: record */
|
|
|
|
ibool val, /* in: value to set */
|
|
|
|
mtr_t* mtr) /* in: mtr */
|
|
|
|
{
|
|
|
|
byte* log_ptr;
|
|
|
|
ut_ad(val <= 1);
|
|
|
|
|
|
|
|
log_ptr = mlog_open(mtr, 11 + 1 + 2);
|
|
|
|
|
|
|
|
if (!log_ptr) {
|
|
|
|
/* Logging in mtr is switched off during crash recovery:
|
|
|
|
in that case mlog_open returns NULL */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
log_ptr = mlog_write_initial_log_record_fast(
|
|
|
|
rec, MLOG_REC_SEC_DELETE_MARK, log_ptr, mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
mach_write_to_1(log_ptr, val);
|
|
|
|
log_ptr++;
|
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
mach_write_to_2(log_ptr, page_offset(rec));
|
2005-10-27 07:29:40 +00:00
|
|
|
log_ptr += 2;
|
|
|
|
|
|
|
|
mlog_close(mtr, log_ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
Parses the redo log record for delete marking or unmarking of a secondary
|
|
|
|
index record. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
byte*
|
|
|
|
btr_cur_parse_del_mark_set_sec_rec(
|
|
|
|
/*===============================*/
|
|
|
|
/* out: end of log record or NULL */
|
|
|
|
byte* ptr, /* in: buffer */
|
|
|
|
byte* end_ptr,/* in: buffer end */
|
2005-10-27 11:48:10 +00:00
|
|
|
page_t* page, /* in/out: page or NULL */
|
|
|
|
page_zip_des_t* page_zip)/* in/out: compressed page, or NULL */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
|
|
|
ulint val;
|
|
|
|
ulint offset;
|
|
|
|
rec_t* rec;
|
|
|
|
|
|
|
|
if (end_ptr < ptr + 3) {
|
|
|
|
|
|
|
|
return(NULL);
|
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
val = mach_read_from_1(ptr);
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
offset = mach_read_from_2(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
|
|
|
|
ut_a(offset <= UNIV_PAGE_SIZE);
|
|
|
|
|
|
|
|
if (page) {
|
|
|
|
rec = page + offset;
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/* We do not need to reserve btr_search_latch, as the page
|
|
|
|
is only being recovered, and there cannot be a hash index to
|
|
|
|
it. */
|
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
btr_rec_set_deleted_flag(rec, page_zip, val);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
return(ptr);
|
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/***************************************************************
|
|
|
|
Sets a secondary index record delete mark to TRUE or FALSE. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint
|
|
|
|
btr_cur_del_mark_set_sec_rec(
|
|
|
|
/*=========================*/
|
|
|
|
/* out: DB_SUCCESS, DB_LOCK_WAIT, or error
|
|
|
|
number */
|
|
|
|
ulint flags, /* in: locking flag */
|
|
|
|
btr_cur_t* cursor, /* in: cursor */
|
|
|
|
ibool val, /* in: value to set */
|
|
|
|
que_thr_t* thr, /* in: query thread */
|
|
|
|
mtr_t* mtr) /* in: mtr */
|
|
|
|
{
|
|
|
|
buf_block_t* block;
|
|
|
|
rec_t* rec;
|
|
|
|
ulint err;
|
|
|
|
|
2006-10-18 11:39:31 +00:00
|
|
|
block = btr_cur_get_block(cursor);
|
2005-10-27 07:29:40 +00:00
|
|
|
rec = btr_cur_get_rec(cursor);
|
|
|
|
|
|
|
|
#ifdef UNIV_DEBUG
|
|
|
|
if (btr_cur_print_record_ops && thr) {
|
|
|
|
btr_cur_trx_report(thr_get_trx(thr), cursor->index,
|
2006-08-29 09:30:31 +00:00
|
|
|
"del mark ");
|
2005-10-27 07:29:40 +00:00
|
|
|
rec_print(stderr, rec, cursor->index);
|
|
|
|
}
|
|
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
|
2006-10-24 06:45:52 +00:00
|
|
|
err = lock_sec_rec_modify_check_and_lock(flags,
|
2006-10-18 11:39:31 +00:00
|
|
|
btr_cur_get_block(cursor),
|
2006-10-24 06:45:52 +00:00
|
|
|
rec, cursor->index, thr);
|
2005-10-27 07:29:40 +00:00
|
|
|
if (err != DB_SUCCESS) {
|
|
|
|
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
|
2006-10-18 11:39:31 +00:00
|
|
|
ut_ad(!!page_rec_is_comp(rec)
|
2006-08-29 09:30:31 +00:00
|
|
|
== dict_table_is_comp(cursor->index->table));
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
if (block->is_hashed) {
|
|
|
|
rw_lock_x_lock(&btr_search_latch);
|
|
|
|
}
|
|
|
|
|
2006-10-18 11:39:31 +00:00
|
|
|
btr_rec_set_deleted_flag(rec, buf_block_get_page_zip(block), val);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (block->is_hashed) {
|
|
|
|
rw_lock_x_unlock(&btr_search_latch);
|
|
|
|
}
|
|
|
|
|
|
|
|
btr_cur_del_mark_set_sec_rec_log(rec, val, mtr);
|
|
|
|
|
|
|
|
return(DB_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2008-02-27 07:03:34 +00:00
|
|
|
/***************************************************************
|
|
|
|
Sets a secondary index record's delete mark to the given value. This
|
|
|
|
function is only used by the insert buffer merge mechanism. */
|
2008-09-17 19:31:42 +00:00
|
|
|
UNIV_INTERN
|
2008-02-27 07:03:34 +00:00
|
|
|
void
|
|
|
|
btr_cur_set_deleted_flag_for_ibuf(
|
|
|
|
/*==============================*/
|
2008-09-17 19:31:42 +00:00
|
|
|
rec_t* rec, /* in/out: record */
|
2008-02-27 07:03:34 +00:00
|
|
|
page_zip_des_t* page_zip, /* in/out: compressed page
|
|
|
|
corresponding to rec, or NULL
|
|
|
|
when the tablespace is
|
|
|
|
uncompressed */
|
|
|
|
ibool val, /* in: value to set */
|
2007-11-29 12:23:48 +00:00
|
|
|
mtr_t* mtr) /* in: mtr */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
|
|
|
/* 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. */
|
|
|
|
|
2008-09-17 19:31:42 +00:00
|
|
|
btr_rec_set_deleted_flag(rec, page_zip, val);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-02-27 07:03:34 +00:00
|
|
|
btr_cur_del_mark_set_sec_rec_log(rec, val, mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*==================== B-TREE RECORD REMOVE =========================*/
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
Tries to compress a page of the tree if it seems useful. It is assumed
|
|
|
|
that mtr holds an x-latch on the tree and on the cursor page. To avoid
|
|
|
|
deadlocks, mtr must also own x-latches to brothers of page, if those
|
|
|
|
brothers exist. NOTE: it is assumed that the caller has reserved enough
|
|
|
|
free extents so that the compression will always succeed if done! */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
ibool
|
|
|
|
btr_cur_compress_if_useful(
|
|
|
|
/*=======================*/
|
|
|
|
/* out: TRUE if compression occurred */
|
|
|
|
btr_cur_t* cursor, /* in: cursor on the page to compress;
|
|
|
|
cursor does not stay valid if compression
|
|
|
|
occurs */
|
|
|
|
mtr_t* mtr) /* in: mtr */
|
|
|
|
{
|
|
|
|
ut_ad(mtr_memo_contains(mtr,
|
2006-09-19 10:14:07 +00:00
|
|
|
dict_index_get_lock(btr_cur_get_index(cursor)),
|
2006-08-29 09:30:31 +00:00
|
|
|
MTR_MEMO_X_LOCK));
|
2006-10-18 11:39:31 +00:00
|
|
|
ut_ad(mtr_memo_contains(mtr, btr_cur_get_block(cursor),
|
|
|
|
MTR_MEMO_PAGE_X_FIX));
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-05-11 12:31:22 +00:00
|
|
|
return(btr_cur_compress_recommendation(cursor, mtr)
|
2006-08-29 09:30:31 +00:00
|
|
|
&& btr_compress(cursor, mtr));
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************
|
|
|
|
Removes the record on which the tree cursor is positioned on a leaf page.
|
|
|
|
It is assumed that the mtr has an x-latch on the page where the cursor is
|
|
|
|
positioned, but no latch on the whole tree. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
ibool
|
|
|
|
btr_cur_optimistic_delete(
|
|
|
|
/*======================*/
|
|
|
|
/* out: TRUE if success, i.e., the page
|
|
|
|
did not become too empty */
|
|
|
|
btr_cur_t* cursor, /* in: cursor on leaf page, on the record to
|
|
|
|
delete; cursor stays valid: if deletion
|
|
|
|
succeeds, on function exit it points to the
|
|
|
|
successor of the deleted record */
|
|
|
|
mtr_t* mtr) /* in: mtr */
|
|
|
|
{
|
2006-10-13 09:15:17 +00:00
|
|
|
buf_block_t* block;
|
2005-10-27 07:29:40 +00:00
|
|
|
rec_t* rec;
|
|
|
|
mem_heap_t* heap = NULL;
|
|
|
|
ulint offsets_[REC_OFFS_NORMAL_SIZE];
|
|
|
|
ulint* offsets = offsets_;
|
|
|
|
ibool no_compress_needed;
|
2007-09-28 07:05:57 +00:00
|
|
|
rec_offs_init(offsets_);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-10-18 11:39:31 +00:00
|
|
|
ut_ad(mtr_memo_contains(mtr, btr_cur_get_block(cursor),
|
|
|
|
MTR_MEMO_PAGE_X_FIX));
|
2005-10-27 07:29:40 +00:00
|
|
|
/* This is intended only for leaf page deletions */
|
|
|
|
|
2006-10-18 11:39:31 +00:00
|
|
|
block = btr_cur_get_block(cursor);
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2006-10-13 09:15:17 +00:00
|
|
|
ut_ad(page_is_leaf(buf_block_get_frame(block)));
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
rec = btr_cur_get_rec(cursor);
|
|
|
|
offsets = rec_get_offsets(rec, cursor->index, offsets,
|
2006-08-29 09:30:31 +00:00
|
|
|
ULINT_UNDEFINED, &heap);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
no_compress_needed = !rec_offs_any_extern(offsets)
|
2006-09-19 10:14:07 +00:00
|
|
|
&& btr_cur_can_delete_without_compress(
|
|
|
|
cursor, rec_offs_size(offsets), mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (no_compress_needed) {
|
|
|
|
|
2006-10-13 09:15:17 +00:00
|
|
|
page_t* page = buf_block_get_frame(block);
|
|
|
|
page_zip_des_t* page_zip= buf_block_get_page_zip(block);
|
2007-10-12 13:25:12 +00:00
|
|
|
ulint max_ins = 0;
|
2006-06-12 12:37:54 +00:00
|
|
|
|
2006-10-24 06:45:52 +00:00
|
|
|
lock_update_delete(block, rec);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
btr_search_update_hash_on_delete(cursor);
|
|
|
|
|
2007-10-12 13:25:12 +00:00
|
|
|
if (!page_zip) {
|
|
|
|
max_ins = page_get_max_insert_size_after_reorganize(
|
|
|
|
page, 1);
|
branches/zip: Enable the insert buffer on compressed tablespaces.
page_zip_max_ins_size(): New function.
btr_cur_optimistic_insert(), btr_cur_optimistic_delete(),
btr_page_split_and_insert(), btr_compress(): Do not update the
ibuf free bits for non-leaf pages or pages belonging to a clustered index.
The insert buffer only covers operations on leaf pages of secondary indexes.
For pages covered by the insert buffer, limit the max_ins_size to
page_zip_max_ins_size().
buf_page_get_gen(): Merge the insert buffer after decompressing the page.
buf_page_io_complete(): Relax the assertion about ibuf_count. For
compressed-only pages, the insert buffer merge takes place
in buf_page_get_gen().
ibuf_index_page_calc_free_bits(), ibuf_index_page_calc_free_from_bits(),
ibuf_index_page_calc_free(), ibuf_update_free_bits_if_full(),
ibuf_update_free_bits_low(), ibuf_update_free_bits_for_two_pages_low(),
ibuf_set_free_bits_low(): Add the parameter zip_size. Limit the maximum
insert size to page_zip_max_ins_size().
2007-02-19 20:32:06 +00:00
|
|
|
}
|
2006-06-20 19:35:59 +00:00
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
2006-06-12 12:37:54 +00:00
|
|
|
ut_a(!page_zip || page_zip_validate(page_zip, page));
|
2006-06-20 19:35:59 +00:00
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
2005-10-27 07:29:40 +00:00
|
|
|
page_cur_delete_rec(btr_cur_get_page_cur(cursor),
|
2006-10-20 12:45:53 +00:00
|
|
|
cursor->index, offsets, mtr);
|
2006-06-20 19:35:59 +00:00
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
2006-06-12 12:37:54 +00:00
|
|
|
ut_a(!page_zip || page_zip_validate(page_zip, page));
|
2006-06-20 19:35:59 +00:00
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-09-18 07:01:13 +00:00
|
|
|
if (dict_index_is_clust(cursor->index)
|
|
|
|
|| !page_is_leaf(page)) {
|
2007-10-12 13:25:12 +00:00
|
|
|
/* The insert buffer does not handle
|
|
|
|
inserts to clustered indexes or to non-leaf
|
|
|
|
pages of secondary index B-trees. */
|
|
|
|
} else if (page_zip) {
|
|
|
|
ibuf_update_free_bits_zip(block, mtr);
|
|
|
|
} else {
|
|
|
|
ibuf_update_free_bits_low(block, max_ins, mtr);
|
2007-05-06 12:39:46 +00:00
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (UNIV_LIKELY_NULL(heap)) {
|
|
|
|
mem_heap_free(heap);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(no_compress_needed);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
Removes the record on which the tree cursor is positioned. Tries
|
|
|
|
to compress the page if its fillfactor drops below a threshold
|
|
|
|
or if it is the only page on the level. It is assumed that mtr holds
|
|
|
|
an x-latch on the tree and on the cursor page. To avoid deadlocks,
|
|
|
|
mtr must also own x-latches to brothers of page, if those brothers
|
|
|
|
exist. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
ibool
|
|
|
|
btr_cur_pessimistic_delete(
|
|
|
|
/*=======================*/
|
|
|
|
/* out: TRUE if compression occurred */
|
|
|
|
ulint* err, /* out: DB_SUCCESS or DB_OUT_OF_FILE_SPACE;
|
|
|
|
the latter may occur because we may have
|
|
|
|
to update node pointers on upper levels,
|
|
|
|
and in the case of variable length keys
|
|
|
|
these may actually grow in size */
|
|
|
|
ibool has_reserved_extents, /* in: TRUE if the
|
|
|
|
caller has already reserved enough free
|
|
|
|
extents so that he knows that the operation
|
|
|
|
will succeed */
|
|
|
|
btr_cur_t* cursor, /* in: cursor on the record to delete;
|
|
|
|
if compression does not occur, the cursor
|
|
|
|
stays valid: it points to successor of
|
|
|
|
deleted record on function exit */
|
2008-08-09 00:15:46 +00:00
|
|
|
enum trx_rb_ctx rb_ctx, /* in: rollback context */
|
2005-10-27 07:29:40 +00:00
|
|
|
mtr_t* mtr) /* in: mtr */
|
|
|
|
{
|
2006-10-18 11:39:31 +00:00
|
|
|
buf_block_t* block;
|
2005-10-27 07:29:40 +00:00
|
|
|
page_t* page;
|
2005-10-27 11:48:10 +00:00
|
|
|
page_zip_des_t* page_zip;
|
2006-09-19 10:14:07 +00:00
|
|
|
dict_index_t* index;
|
2005-10-27 07:29:40 +00:00
|
|
|
rec_t* rec;
|
|
|
|
dtuple_t* node_ptr;
|
|
|
|
ulint n_extents = 0;
|
|
|
|
ulint n_reserved;
|
|
|
|
ibool success;
|
|
|
|
ibool ret = FALSE;
|
|
|
|
ulint level;
|
|
|
|
mem_heap_t* heap;
|
|
|
|
ulint* offsets;
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2006-10-18 11:39:31 +00:00
|
|
|
block = btr_cur_get_block(cursor);
|
|
|
|
page = buf_block_get_frame(block);
|
2006-09-19 10:14:07 +00:00
|
|
|
index = btr_cur_get_index(cursor);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
ut_ad(mtr_memo_contains(mtr, dict_index_get_lock(index),
|
2006-08-29 09:30:31 +00:00
|
|
|
MTR_MEMO_X_LOCK));
|
2006-10-18 11:39:31 +00:00
|
|
|
ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX));
|
2005-10-27 07:29:40 +00:00
|
|
|
if (!has_reserved_extents) {
|
|
|
|
/* First reserve enough free space for the file segments
|
|
|
|
of the index tree, so that the node pointer updates will
|
|
|
|
not fail because of lack of space */
|
|
|
|
|
|
|
|
n_extents = cursor->tree_height / 32 + 1;
|
|
|
|
|
|
|
|
success = fsp_reserve_free_extents(&n_reserved,
|
2006-09-19 10:14:07 +00:00
|
|
|
index->space,
|
2006-08-29 09:30:31 +00:00
|
|
|
n_extents,
|
|
|
|
FSP_CLEANING, mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
if (!success) {
|
|
|
|
*err = DB_OUT_OF_FILE_SPACE;
|
|
|
|
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
heap = mem_heap_create(1024);
|
|
|
|
rec = btr_cur_get_rec(cursor);
|
2006-10-18 11:39:31 +00:00
|
|
|
page_zip = buf_block_get_page_zip(block);
|
2006-06-20 19:35:59 +00:00
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
2006-06-12 12:37:54 +00:00
|
|
|
ut_a(!page_zip || page_zip_validate(page_zip, page));
|
2006-06-20 19:35:59 +00:00
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
offsets = rec_get_offsets(rec, index, NULL, ULINT_UNDEFINED, &heap);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2007-12-05 09:49:09 +00:00
|
|
|
if (rec_offs_any_extern(offsets)) {
|
2006-09-19 10:14:07 +00:00
|
|
|
btr_rec_free_externally_stored_fields(index,
|
2006-08-29 09:30:31 +00:00
|
|
|
rec, offsets, page_zip,
|
2008-08-09 00:15:46 +00:00
|
|
|
rb_ctx, mtr);
|
2006-06-20 19:35:59 +00:00
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
2006-06-12 12:37:54 +00:00
|
|
|
ut_a(!page_zip || page_zip_validate(page_zip, page));
|
2006-06-20 19:35:59 +00:00
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (UNIV_UNLIKELY(page_get_n_recs(page) < 2)
|
branches/innodb+: Merge revisions 2835:2862 from branches/zip:
------------------------------------------------------------------------
r2838 | vasil | 2008-10-21 12:49:27 +0300 (Tue, 21 Oct 2008) | 61 lines
branches/zip:
Merge 2744:2837 from branches/5.1 (skipping r2782 and r2826):
------------------------------------------------------------------------
r2832 | vasil | 2008-10-21 10:08:30 +0300 (Tue, 21 Oct 2008) | 10 lines
Changed paths:
M /branches/5.1/handler/ha_innodb.cc
branches/5.1:
In ha_innobase::info():
Replace sql_print_warning() which prints to mysqld error log with
push_warning_printf() which sends the error message to the client.
Suggested by: Marko, Sunny, Michael
Objected by: Inaam
------------------------------------------------------------------------
r2837 | vasil | 2008-10-21 12:07:44 +0300 (Tue, 21 Oct 2008) | 32 lines
Changed paths:
M /branches/5.1/mysql-test/innodb-semi-consistent.result
M /branches/5.1/mysql-test/innodb-semi-consistent.test
M /branches/5.1/mysql-test/innodb.result
M /branches/5.1/mysql-test/innodb.test
branches/5.1:
Merge a change from MySQL (this fixes the failing innodb and
innodb-semi-consistent tests):
revno: 2757
committer: Georgi Kodinov <kgeorge@mysql.com>
branch nick: B39812-5.1-5.1.29-rc
timestamp: Fri 2008-10-03 15:24:19 +0300
message:
Bug #39812: Make statement replication default for 5.1 (to match 5.0)
Make STMT replication default for 5.1.
Add a default of MIXED into the config files
Fix the tests that needed MIXED replication mode.
modified:
mysql-test/include/mix1.inc
mysql-test/r/innodb-semi-consistent.result
mysql-test/r/innodb.result
mysql-test/r/innodb_mysql.result
mysql-test/r/tx_isolation_func.result
mysql-test/t/innodb-semi-consistent.test
mysql-test/t/innodb.test
mysql-test/t/tx_isolation_func.test
sql/mysqld.cc
support-files/my-huge.cnf.sh
support-files/my-innodb-heavy-4G.cnf.sh
support-files/my-large.cnf.sh
support-files/my-medium.cnf.sh
support-files/my-small.cnf.sh
------------------------------------------------------------------------
------------------------------------------------------------------------
r2847 | marko | 2008-10-22 10:07:37 +0300 (Wed, 22 Oct 2008) | 6 lines
branches/zip: page_zip_rec_needs_ext(): Fix a bug that was introduced
in the fix of Mantis issue #73. With key_block_size=16, we will also
have to check the available space on the uncompressed page.
Otherwise, the clustered index record can be almost 16 kilobytes in
size, and the undo log record will not fit.
------------------------------------------------------------------------
r2850 | marko | 2008-10-22 13:52:12 +0300 (Wed, 22 Oct 2008) | 2 lines
branches/zip: ibuf_insert_to_index_page(): Discard the local variable block.
page_cur is always positioned on block, the function parameter.
------------------------------------------------------------------------
r2853 | sunny | 2008-10-23 01:52:09 +0300 (Thu, 23 Oct 2008) | 2 lines
branches/zip: Add missing UNIV_INTERN.
------------------------------------------------------------------------
r2855 | sunny | 2008-10-23 09:29:46 +0300 (Thu, 23 Oct 2008) | 36 lines
branches/zip:
Merge revisions 2837:2852 from branches/5.1:
------------------------------------------------------------------------
r2849 | sunny | 2008-10-22 12:01:18 +0300 (Wed, 22 Oct 2008) | 8 lines
Changed paths:
M /branches/5.1/handler/ha_innodb.cc
M /branches/5.1/include/row0mysql.h
M /branches/5.1/row/row0mysql.c
branches/5.1: Return the actual error code encountered when allocating
a new autoinc value. The change in behavior (bug) was introduced in 5.1.22
when we introduced the new AUTOINC locking model.
rb://31
Bug#40224 New AUTOINC changes mask reporting of deadlock/timeout errors
------------------------------------------------------------------------
r2852 | sunny | 2008-10-23 01:42:24 +0300 (Thu, 23 Oct 2008) | 9 lines
Changed paths:
M /branches/5.1/handler/ha_innodb.cc
M /branches/5.1/handler/ha_innodb.h
branches/5.1: Backport r2724 from branches/zip
Check column value against the col max value before updating the table's
global autoinc counter value. This is part of simplifying the AUTOINC
sub-system. We extract the type info from MySQL data structures at runtime.
This fixes Bug#37788 InnoDB Plugin: AUTO_INCREMENT wrong for compressed tables
------------------------------------------------------------------------
------------------------------------------------------------------------
r2856 | sunny | 2008-10-23 10:07:05 +0300 (Thu, 23 Oct 2008) | 1 line
Reverting test file changes from r2855
------------------------------------------------------------------------
r2857 | sunny | 2008-10-23 10:24:33 +0300 (Thu, 23 Oct 2008) | 30 lines
branches/zip:
Merge revisions 2852:2854 from branches/5.1:
------------------------------------------------------------------------
r2854 | sunny | 2008-10-23 08:30:32 +0300 (Thu, 23 Oct 2008) | 13 lines
Changed paths:
M /branches/5.1/dict/dict0dict.c
M /branches/5.1/dict/dict0mem.c
M /branches/5.1/handler/ha_innodb.cc
M /branches/5.1/handler/ha_innodb.h
M /branches/5.1/include/dict0dict.h
M /branches/5.1/include/dict0mem.h
M /branches/5.1/row/row0mysql.c
branches/5.1: Backport changes from branches/zip r2725
Simplify the autoinc initialization code. This removes the
non-determinism related to reading the table's autoinc value for the first
time. This change has also reduced the sizeof dict_table_t by sizeof(ibool)
bytes because we don't need the dict_table_t::autoinc_inited field anymore.
Bug#39830 Table autoinc value not updated on first insert.
Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info
Bug#36411 Failed to read auto-increment value from storage engine" in 5.1.24 auto-inc
rb://16
------------------------------------------------------------------------
------------------------------------------------------------------------
r2858 | vasil | 2008-10-23 11:33:43 +0300 (Thu, 23 Oct 2008) | 4 lines
branches/zip:
Update the ChangeLog
------------------------------------------------------------------------
r2861 | marko | 2008-10-23 12:27:15 +0300 (Thu, 23 Oct 2008) | 24 lines
branches/zip: Clean up the file format stamping.
trx_sys_file_format_max_upgrade(): Rename from
trx_sys_file_format_max_update(). Improve the documentation. Add a
const qualifier to the parameter "name". Replace the parameter
"flags" with "format_id", because this function should deal with file
format identifiers, not with table flags.
trx_sys_file_format_max_write(), trx_sys_file_format_max_set(): Add a
const qualifier to the parameter "name".
ha_innodb.cc: Correct the spelling in some comments: "side effect".
Remove redundant prototypes for some static callback functions.
innodb_file_format_name_update(), innodb_file_format_check_update():
Correct the function signature. Use appropriate pointer type conversions.
MYSQL_SYSVAR_STR(file_format), MYSQL_SYSVAR_STR(file_format_check):
Remove the type conversions from the callback function pointers. When
the function signatures match, no type conversion is needed. The type
conversions would only prevent compilation warnings for any mismatch.
Approved by Sunny in rb://25.
------------------------------------------------------------------------
r2862 | marko | 2008-10-23 12:37:42 +0300 (Thu, 23 Oct 2008) | 8 lines
branches/zip: Non-functional changes:
ibuf_get_volume_buffered(): Declare with static linkage.
This function is private to ibuf0ibuf.c.
btr_cur_pessimistic_delete(): Use the cached result of
btr_cur_get_index(cursor).
------------------------------------------------------------------------
2008-10-23 10:03:20 +00:00
|
|
|
&& UNIV_UNLIKELY(dict_index_get_page(index)
|
2006-10-18 11:39:31 +00:00
|
|
|
!= buf_block_get_page_no(block))) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/* If there is only one record, drop the whole page in
|
|
|
|
btr_discard_page, if this is not the root page */
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
btr_discard_page(cursor, mtr);
|
|
|
|
|
|
|
|
*err = DB_SUCCESS;
|
|
|
|
ret = TRUE;
|
|
|
|
|
2006-02-23 19:25:29 +00:00
|
|
|
goto return_after_reservations;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2006-10-24 06:45:52 +00:00
|
|
|
lock_update_delete(block, rec);
|
2005-10-27 07:29:40 +00:00
|
|
|
level = btr_page_get_level(page, mtr);
|
|
|
|
|
|
|
|
if (level > 0
|
2006-09-19 10:14:07 +00:00
|
|
|
&& UNIV_UNLIKELY(rec == page_rec_get_next(
|
|
|
|
page_get_infimum_rec(page)))) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
rec_t* next_rec = page_rec_get_next(rec);
|
|
|
|
|
|
|
|
if (btr_page_get_prev(page, mtr) == FIL_NULL) {
|
|
|
|
|
|
|
|
/* If we delete the leftmost node pointer on a
|
|
|
|
non-leaf level, we must mark the new leftmost node
|
|
|
|
pointer as the predefined minimum record */
|
|
|
|
|
2006-06-12 12:37:54 +00:00
|
|
|
/* This will make page_zip_validate() fail until
|
|
|
|
page_cur_delete_rec() completes. This is harmless,
|
|
|
|
because everything will take place within a single
|
|
|
|
mini-transaction and because writing to the redo log
|
|
|
|
is an atomic operation (performed by mtr_commit()). */
|
2006-02-10 15:06:17 +00:00
|
|
|
btr_set_min_rec_mark(next_rec, mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
} else {
|
|
|
|
/* Otherwise, if we delete the leftmost node pointer
|
|
|
|
on a page, we have to change the father node pointer
|
|
|
|
so that it is equal to the new leftmost node pointer
|
|
|
|
on the page */
|
|
|
|
|
2006-10-18 11:39:31 +00:00
|
|
|
btr_node_ptr_delete(index, block, mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
node_ptr = dict_index_build_node_ptr(
|
2006-10-23 18:26:10 +00:00
|
|
|
index, next_rec, buf_block_get_page_no(block),
|
2006-09-19 10:14:07 +00:00
|
|
|
heap, level);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
btr_insert_on_non_leaf_level(index,
|
2006-08-29 09:30:31 +00:00
|
|
|
level + 1, node_ptr, mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
btr_search_update_hash_on_delete(cursor);
|
|
|
|
|
2006-10-20 12:45:53 +00:00
|
|
|
page_cur_delete_rec(btr_cur_get_page_cur(cursor), index, offsets, mtr);
|
2006-06-20 19:35:59 +00:00
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
2006-06-12 12:37:54 +00:00
|
|
|
ut_a(!page_zip || page_zip_validate(page_zip, page));
|
2006-06-20 19:35:59 +00:00
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-10-25 08:52:43 +00:00
|
|
|
ut_ad(btr_check_node_ptr(index, block, mtr));
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
*err = DB_SUCCESS;
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
return_after_reservations:
|
|
|
|
mem_heap_free(heap);
|
|
|
|
|
|
|
|
if (ret == FALSE) {
|
|
|
|
ret = btr_cur_compress_if_useful(cursor, mtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n_extents > 0) {
|
2006-09-19 10:14:07 +00:00
|
|
|
fil_space_release_free_extents(index->space, n_reserved);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Adds path information to the cursor for the current page, for which
|
|
|
|
the binary search has been performed. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
btr_cur_add_path_info(
|
|
|
|
/*==================*/
|
|
|
|
btr_cur_t* cursor, /* in: cursor positioned on a page */
|
|
|
|
ulint height, /* in: height of the page in tree;
|
|
|
|
0 means leaf node */
|
|
|
|
ulint root_height) /* in: root node height in tree */
|
|
|
|
{
|
|
|
|
btr_path_t* slot;
|
|
|
|
rec_t* rec;
|
|
|
|
|
|
|
|
ut_a(cursor->path_arr);
|
|
|
|
|
|
|
|
if (root_height >= BTR_PATH_ARRAY_N_SLOTS - 1) {
|
|
|
|
/* Do nothing; return empty path */
|
|
|
|
|
|
|
|
slot = cursor->path_arr;
|
|
|
|
slot->nth_rec = ULINT_UNDEFINED;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (height == 0) {
|
|
|
|
/* Mark end of slots for path */
|
|
|
|
slot = cursor->path_arr + root_height + 1;
|
|
|
|
slot->nth_rec = ULINT_UNDEFINED;
|
|
|
|
}
|
|
|
|
|
|
|
|
rec = btr_cur_get_rec(cursor);
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
slot = cursor->path_arr + (root_height - height);
|
|
|
|
|
|
|
|
slot->nth_rec = page_rec_get_n_recs_before(rec);
|
2006-10-09 16:22:47 +00:00
|
|
|
slot->n_recs = page_get_n_recs(page_align(rec));
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Estimates the number of rows in a given index range. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2008-05-14 15:43:19 +00:00
|
|
|
ib_int64_t
|
2005-10-27 07:29:40 +00:00
|
|
|
btr_estimate_n_rows_in_range(
|
|
|
|
/*=========================*/
|
|
|
|
/* out: estimated number of rows */
|
|
|
|
dict_index_t* index, /* in: index */
|
2006-10-20 08:30:07 +00:00
|
|
|
const dtuple_t* tuple1, /* in: range start, may also be empty tuple */
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint mode1, /* in: search mode for range start */
|
2006-10-20 08:30:07 +00:00
|
|
|
const dtuple_t* tuple2, /* in: range end, may also be empty tuple */
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint mode2) /* in: search mode for range end */
|
|
|
|
{
|
|
|
|
btr_path_t path1[BTR_PATH_ARRAY_N_SLOTS];
|
|
|
|
btr_path_t path2[BTR_PATH_ARRAY_N_SLOTS];
|
|
|
|
btr_cur_t cursor;
|
|
|
|
btr_path_t* slot1;
|
|
|
|
btr_path_t* slot2;
|
|
|
|
ibool diverged;
|
2006-02-23 19:25:29 +00:00
|
|
|
ibool diverged_lot;
|
|
|
|
ulint divergence_level;
|
2008-05-14 15:43:19 +00:00
|
|
|
ib_int64_t n_rows;
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint i;
|
|
|
|
mtr_t mtr;
|
|
|
|
|
|
|
|
mtr_start(&mtr);
|
|
|
|
|
|
|
|
cursor.path_arr = path1;
|
|
|
|
|
|
|
|
if (dtuple_get_n_fields(tuple1) > 0) {
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
btr_cur_search_to_nth_level(index, 0, tuple1, mode1,
|
2006-08-29 09:30:31 +00:00
|
|
|
BTR_SEARCH_LEAF | BTR_ESTIMATE,
|
|
|
|
&cursor, 0, &mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
} else {
|
|
|
|
btr_cur_open_at_index_side(TRUE, index,
|
2006-08-29 09:30:31 +00:00
|
|
|
BTR_SEARCH_LEAF | BTR_ESTIMATE,
|
|
|
|
&cursor, &mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
mtr_commit(&mtr);
|
|
|
|
|
|
|
|
mtr_start(&mtr);
|
|
|
|
|
|
|
|
cursor.path_arr = path2;
|
|
|
|
|
|
|
|
if (dtuple_get_n_fields(tuple2) > 0) {
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
btr_cur_search_to_nth_level(index, 0, tuple2, mode2,
|
2006-08-29 09:30:31 +00:00
|
|
|
BTR_SEARCH_LEAF | BTR_ESTIMATE,
|
|
|
|
&cursor, 0, &mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
} else {
|
|
|
|
btr_cur_open_at_index_side(FALSE, index,
|
2006-08-29 09:30:31 +00:00
|
|
|
BTR_SEARCH_LEAF | BTR_ESTIMATE,
|
|
|
|
&cursor, &mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
mtr_commit(&mtr);
|
|
|
|
|
|
|
|
/* We have the path information for the range in path1 and path2 */
|
|
|
|
|
|
|
|
n_rows = 1;
|
2006-08-29 09:30:31 +00:00
|
|
|
diverged = FALSE; /* This becomes true when the path is not
|
|
|
|
the same any more */
|
|
|
|
diverged_lot = FALSE; /* This becomes true when the paths are
|
|
|
|
not the same or adjacent any more */
|
|
|
|
divergence_level = 1000000; /* This is the level where paths diverged
|
|
|
|
a lot */
|
2006-02-23 19:25:29 +00:00
|
|
|
for (i = 0; ; i++) {
|
2005-10-27 07:29:40 +00:00
|
|
|
ut_ad(i < BTR_PATH_ARRAY_N_SLOTS);
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
slot1 = path1 + i;
|
|
|
|
slot2 = path2 + i;
|
|
|
|
|
|
|
|
if (slot1->nth_rec == ULINT_UNDEFINED
|
2006-08-29 09:30:31 +00:00
|
|
|
|| slot2->nth_rec == ULINT_UNDEFINED) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-02-23 19:25:29 +00:00
|
|
|
if (i > divergence_level + 1) {
|
|
|
|
/* In trees whose height is > 1 our algorithm
|
|
|
|
tends to underestimate: multiply the estimate
|
|
|
|
by 2: */
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-02-23 19:25:29 +00:00
|
|
|
n_rows = n_rows * 2;
|
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/* Do not estimate the number of rows in the range
|
2006-02-23 19:25:29 +00:00
|
|
|
to over 1 / 2 of the estimated rows in the whole
|
2005-10-27 07:29:40 +00:00
|
|
|
table */
|
|
|
|
|
|
|
|
if (n_rows > index->table->stat_n_rows / 2) {
|
2006-02-23 19:25:29 +00:00
|
|
|
n_rows = index->table->stat_n_rows / 2;
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/* If there are just 0 or 1 rows in the table,
|
|
|
|
then we estimate all rows are in the range */
|
2006-02-23 19:25:29 +00:00
|
|
|
|
|
|
|
if (n_rows == 0) {
|
|
|
|
n_rows = index->table->stat_n_rows;
|
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return(n_rows);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!diverged && slot1->nth_rec != slot2->nth_rec) {
|
|
|
|
|
|
|
|
diverged = TRUE;
|
|
|
|
|
|
|
|
if (slot1->nth_rec < slot2->nth_rec) {
|
|
|
|
n_rows = slot2->nth_rec - slot1->nth_rec;
|
|
|
|
|
|
|
|
if (n_rows > 1) {
|
2006-02-23 19:25:29 +00:00
|
|
|
diverged_lot = TRUE;
|
|
|
|
divergence_level = i;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Maybe the tree has changed between
|
|
|
|
searches */
|
|
|
|
|
|
|
|
return(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (diverged && !diverged_lot) {
|
|
|
|
|
2006-02-23 19:25:29 +00:00
|
|
|
if (slot1->nth_rec < slot1->n_recs
|
2006-08-29 09:30:31 +00:00
|
|
|
|| slot2->nth_rec > 1) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-02-23 19:25:29 +00:00
|
|
|
diverged_lot = TRUE;
|
2005-10-27 07:29:40 +00:00
|
|
|
divergence_level = i;
|
|
|
|
|
|
|
|
n_rows = 0;
|
|
|
|
|
2006-02-23 19:25:29 +00:00
|
|
|
if (slot1->nth_rec < slot1->n_recs) {
|
|
|
|
n_rows += slot1->n_recs
|
|
|
|
- slot1->nth_rec;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (slot2->nth_rec > 1) {
|
2006-02-23 19:25:29 +00:00
|
|
|
n_rows += slot2->nth_rec - 1;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
} else if (diverged_lot) {
|
|
|
|
|
|
|
|
n_rows = (n_rows * (slot1->n_recs + slot2->n_recs))
|
2006-08-29 09:30:31 +00:00
|
|
|
/ 2;
|
2006-02-23 19:25:29 +00:00
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Estimates the number of different key values in a given index, for
|
|
|
|
each n-column prefix of the index where n <= dict_index_get_n_unique(index).
|
|
|
|
The estimates are stored in the array index->stat_n_diff_key_vals. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
void
|
|
|
|
btr_estimate_number_of_different_key_vals(
|
|
|
|
/*======================================*/
|
|
|
|
dict_index_t* index) /* in: index */
|
|
|
|
{
|
|
|
|
btr_cur_t cursor;
|
|
|
|
page_t* page;
|
|
|
|
rec_t* rec;
|
|
|
|
ulint n_cols;
|
|
|
|
ulint matched_fields;
|
|
|
|
ulint matched_bytes;
|
2008-05-14 15:43:19 +00:00
|
|
|
ib_int64_t* n_diff;
|
2008-09-17 19:52:30 +00:00
|
|
|
ullint n_sample_pages; /* number of pages to sample */
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint not_empty_flag = 0;
|
|
|
|
ulint total_external_size = 0;
|
|
|
|
ulint i;
|
|
|
|
ulint j;
|
branches/innodb+: Merge revisions 2774:2799 from branches/zip:
------------------------------------------------------------------------
r2781 | marko | 2008-10-13 13:40:57 +0300 (Mon, 13 Oct 2008) | 1 line
branches/zip: page_cur_delete_rec(): Call page_zip_validate_low().
------------------------------------------------------------------------
r2783 | vasil | 2008-10-13 18:34:34 +0300 (Mon, 13 Oct 2008) | 9 lines
branches/zip:
Remove mysql-test/patches/bug37312.diff because MySQL "fixed"
Bug#37312 by removing the test.
http://bugs.mysql.com/37312
http://lists.mysql.com/commits/54462
------------------------------------------------------------------------
r2784 | marko | 2008-10-13 21:35:30 +0300 (Mon, 13 Oct 2008) | 1 line
branches/zip: Add missing NULL check to the assertion added in r2781.
------------------------------------------------------------------------
r2785 | marko | 2008-10-13 22:29:12 +0300 (Mon, 13 Oct 2008) | 2 lines
branches/zip: page_cur_delete_rec(): Remove the bogus page_zip_validate_low()
assertion that was added in r2781 and explain why it was bogus.
------------------------------------------------------------------------
r2786 | calvin | 2008-10-14 19:14:47 +0300 (Tue, 14 Oct 2008) | 7 lines
branches/zip: fix Mantis issue #96 Problem compiling ha_innodb.cc
on 64-bit Windows
Change the definition of srv_replication_delay from ulint to ulong.
ulint is 64-bit on Win64.
Approved by: Heikki (on IM)
------------------------------------------------------------------------
r2787 | calvin | 2008-10-14 19:19:41 +0300 (Tue, 14 Oct 2008) | 7 lines
branches/zip: fix compiler warning
Change the definition of add_on from ulint to ullint, to eliminate
the warning in .\btr\btr0cur.c:
conversion from 'ullint' to 'ulint', possible loss of data
Approved by: Heikki (on IM)
------------------------------------------------------------------------
r2793 | marko | 2008-10-15 10:00:06 +0300 (Wed, 15 Oct 2008) | 2 lines
branches/zip: row_create_table_for_mysql(), row_create_index_for_mysql():
Note that the dictionary object will be freed.
------------------------------------------------------------------------
r2794 | marko | 2008-10-15 10:32:40 +0300 (Wed, 15 Oct 2008) | 9 lines
branches/zip: When invoking page_zip_copy_recs(), update the lock table
and the adaptive hash index. This should fix Issue #95 and Issue #87.
page_zip_copy_recs(): Copy PAGE_MAX_TRX_ID as well, to have similar behavior
to page_copy_rec_list_start() and page_copy_rec_list_end().
btr_root_raise_and_insert(), btr_page_split_and_insert(), btr_lift_page_up():
Update the lock table and the adaptive hash index.
------------------------------------------------------------------------
r2797 | marko | 2008-10-15 13:21:54 +0300 (Wed, 15 Oct 2008) | 3 lines
branches/zip: Introduce UNIV_ZIP_COPY for invoking page_zip_copy_recs()
more often in B-tree operations.
------------------------------------------------------------------------
r2799 | marko | 2008-10-15 14:27:42 +0300 (Wed, 15 Oct 2008) | 25 lines
branches/zip: When the server crashes while freeing an externally stored
column of a compressed table, the BTR_EXTERN_LEN field in the BLOB pointer
will be written as 0. Tolerate this in the functions that deal with
externally stored columns. This fixes Issue #80 and was posted at rb://26.
Note that the clustered index record is always deleted or purged last,
after any secondary index records referring to it have been deleted.
btr_free_externally_stored_field(): On an uncompressed table, zero out
the BTR_EXTERN_LEN, so that half-deleted BLOBs can be detected after
crash recovery.
btr_copy_externally_stored_field_prefix(): Return 0 if the BLOB has been
half-deleted.
row_upd_ext_fetch(): Assert that the externally stored column exists.
row_ext_cache_fill(): Allow btr_copy_externally_stored_field_prefix()
to return 0.
row_sel_sec_rec_is_for_blob(): Return FALSE if the BLOB has been half-deleted.
This is correct, because the clustered index record would have been deleted
or purged last, after any secondary index records referring to it had been
deleted.
------------------------------------------------------------------------
2008-10-15 12:09:17 +00:00
|
|
|
ullint add_on;
|
2005-10-27 07:29:40 +00:00
|
|
|
mtr_t mtr;
|
|
|
|
mem_heap_t* heap = NULL;
|
|
|
|
ulint offsets_rec_[REC_OFFS_NORMAL_SIZE];
|
|
|
|
ulint offsets_next_rec_[REC_OFFS_NORMAL_SIZE];
|
|
|
|
ulint* offsets_rec = offsets_rec_;
|
|
|
|
ulint* offsets_next_rec= offsets_next_rec_;
|
2007-09-28 07:05:57 +00:00
|
|
|
rec_offs_init(offsets_rec_);
|
|
|
|
rec_offs_init(offsets_next_rec_);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
n_cols = dict_index_get_n_unique(index);
|
|
|
|
|
2008-05-14 15:43:19 +00:00
|
|
|
n_diff = mem_zalloc((n_cols + 1) * sizeof(ib_int64_t));
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-09-17 19:52:30 +00:00
|
|
|
/* It makes no sense to test more pages than are contained
|
|
|
|
in the index, thus we lower the number if it is too high */
|
|
|
|
if (srv_stats_sample_pages > index->stat_index_size) {
|
|
|
|
if (index->stat_index_size > 0) {
|
|
|
|
n_sample_pages = index->stat_index_size;
|
|
|
|
} else {
|
|
|
|
n_sample_pages = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
n_sample_pages = srv_stats_sample_pages;
|
|
|
|
}
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/* We sample some pages in the index to get an estimate */
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2008-09-17 19:52:30 +00:00
|
|
|
for (i = 0; i < n_sample_pages; i++) {
|
2005-10-27 07:29:40 +00:00
|
|
|
rec_t* supremum;
|
|
|
|
mtr_start(&mtr);
|
|
|
|
|
|
|
|
btr_cur_open_at_rnd_pos(index, BTR_SEARCH_LEAF, &cursor, &mtr);
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/* Count the number of different key values for each prefix of
|
|
|
|
the key on this index page. If the prefix does not determine
|
2008-08-09 00:15:46 +00:00
|
|
|
the index record uniquely in the B-tree, then we subtract one
|
2005-10-27 07:29:40 +00:00
|
|
|
because otherwise our algorithm would give a wrong estimate
|
|
|
|
for an index where there is just one key value. */
|
|
|
|
|
|
|
|
page = btr_cur_get_page(&cursor);
|
|
|
|
|
|
|
|
supremum = page_get_supremum_rec(page);
|
|
|
|
rec = page_rec_get_next(page_get_infimum_rec(page));
|
|
|
|
|
|
|
|
if (rec != supremum) {
|
|
|
|
not_empty_flag = 1;
|
|
|
|
offsets_rec = rec_get_offsets(rec, index, offsets_rec,
|
2006-08-29 09:30:31 +00:00
|
|
|
ULINT_UNDEFINED, &heap);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (rec != supremum) {
|
|
|
|
rec_t* next_rec = page_rec_get_next(rec);
|
|
|
|
if (next_rec == supremum) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
matched_fields = 0;
|
|
|
|
matched_bytes = 0;
|
|
|
|
offsets_next_rec = rec_get_offsets(next_rec, index,
|
2006-08-29 09:30:31 +00:00
|
|
|
offsets_next_rec,
|
|
|
|
n_cols, &heap);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
cmp_rec_rec_with_match(rec, next_rec,
|
2006-08-29 09:30:31 +00:00
|
|
|
offsets_rec, offsets_next_rec,
|
|
|
|
index, &matched_fields,
|
|
|
|
&matched_bytes);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
for (j = matched_fields + 1; j <= n_cols; j++) {
|
|
|
|
/* We add one if this index record has
|
|
|
|
a different prefix from the previous */
|
|
|
|
|
|
|
|
n_diff[j]++;
|
|
|
|
}
|
|
|
|
|
2006-08-29 09:30:31 +00:00
|
|
|
total_external_size
|
2006-09-19 10:14:07 +00:00
|
|
|
+= btr_rec_get_externally_stored_len(
|
|
|
|
rec, offsets_rec);
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
rec = next_rec;
|
|
|
|
/* Initialize offsets_rec for the next round
|
|
|
|
and assign the old offsets_rec buffer to
|
|
|
|
offsets_next_rec. */
|
|
|
|
{
|
|
|
|
ulint* offsets_tmp = offsets_rec;
|
|
|
|
offsets_rec = offsets_next_rec;
|
|
|
|
offsets_next_rec = offsets_tmp;
|
|
|
|
}
|
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (n_cols == dict_index_get_n_unique_in_tree(index)) {
|
|
|
|
|
|
|
|
/* If there is more than one leaf page in the tree,
|
|
|
|
we add one because we know that the first record
|
|
|
|
on the page certainly had a different prefix than the
|
|
|
|
last record on the previous index page in the
|
|
|
|
alphabetical order. Before this fix, if there was
|
|
|
|
just one big record on each clustered index page, the
|
|
|
|
algorithm grossly underestimated the number of rows
|
|
|
|
in the table. */
|
|
|
|
|
|
|
|
if (btr_page_get_prev(page, &mtr) != FIL_NULL
|
2006-08-29 09:30:31 +00:00
|
|
|
|| btr_page_get_next(page, &mtr) != FIL_NULL) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
n_diff[n_cols]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
offsets_rec = rec_get_offsets(rec, index, offsets_rec,
|
2006-08-29 09:30:31 +00:00
|
|
|
ULINT_UNDEFINED, &heap);
|
2006-09-19 10:14:07 +00:00
|
|
|
total_external_size += btr_rec_get_externally_stored_len(
|
|
|
|
rec, offsets_rec);
|
2005-10-27 07:29:40 +00:00
|
|
|
mtr_commit(&mtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we saw k borders between different key values on
|
2008-09-17 19:52:30 +00:00
|
|
|
n_sample_pages leaf pages, we can estimate how many
|
2005-10-27 07:29:40 +00:00
|
|
|
there will be in index->stat_n_leaf_pages */
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/* We must take into account that our sample actually represents
|
|
|
|
also the pages used for external storage of fields (those pages are
|
2006-02-23 19:25:29 +00:00
|
|
|
included in index->stat_n_leaf_pages) */
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
for (j = 0; j <= n_cols; j++) {
|
2006-08-29 09:30:31 +00:00
|
|
|
index->stat_n_diff_key_vals[j]
|
|
|
|
= ((n_diff[j]
|
2008-05-14 15:43:19 +00:00
|
|
|
* (ib_int64_t)index->stat_n_leaf_pages
|
2008-09-17 19:52:30 +00:00
|
|
|
+ n_sample_pages - 1
|
2006-08-29 09:30:31 +00:00
|
|
|
+ total_external_size
|
|
|
|
+ not_empty_flag)
|
2008-09-17 19:52:30 +00:00
|
|
|
/ (n_sample_pages
|
2006-08-29 09:30:31 +00:00
|
|
|
+ total_external_size));
|
|
|
|
|
|
|
|
/* If the tree is small, smaller than
|
2008-09-17 19:52:30 +00:00
|
|
|
10 * n_sample_pages + total_external_size, then
|
2005-10-27 07:29:40 +00:00
|
|
|
the above estimate is ok. For bigger trees it is common that we
|
|
|
|
do not see any borders between key values in the few pages
|
2008-09-17 19:52:30 +00:00
|
|
|
we pick. But still there may be n_sample_pages
|
2005-10-27 07:29:40 +00:00
|
|
|
different key values, or even more. Let us try to approximate
|
|
|
|
that: */
|
|
|
|
|
2006-02-23 19:25:29 +00:00
|
|
|
add_on = index->stat_n_leaf_pages
|
2008-09-17 19:52:30 +00:00
|
|
|
/ (10 * (n_sample_pages
|
2006-08-29 09:30:31 +00:00
|
|
|
+ total_external_size));
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-09-17 19:52:30 +00:00
|
|
|
if (add_on > n_sample_pages) {
|
|
|
|
add_on = n_sample_pages;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
index->stat_n_diff_key_vals[j] += add_on;
|
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
mem_free(n_diff);
|
|
|
|
if (UNIV_LIKELY_NULL(heap)) {
|
|
|
|
mem_heap_free(heap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*================== EXTERNAL STORAGE OF BIG FIELDS ===================*/
|
|
|
|
|
|
|
|
/***************************************************************
|
|
|
|
Gets the externally stored size of a record, in units of a database page. */
|
|
|
|
static
|
|
|
|
ulint
|
|
|
|
btr_rec_get_externally_stored_len(
|
|
|
|
/*==============================*/
|
|
|
|
/* out: externally stored part,
|
|
|
|
in units of a database page */
|
|
|
|
rec_t* rec, /* in: record */
|
|
|
|
const ulint* offsets)/* in: array returned by rec_get_offsets() */
|
|
|
|
{
|
|
|
|
ulint n_fields;
|
|
|
|
byte* data;
|
|
|
|
ulint local_len;
|
|
|
|
ulint extern_len;
|
|
|
|
ulint total_extern_len = 0;
|
|
|
|
ulint i;
|
|
|
|
|
|
|
|
ut_ad(!rec_offs_comp(offsets) || !rec_get_node_ptr_flag(rec));
|
|
|
|
n_fields = rec_offs_n_fields(offsets);
|
|
|
|
|
|
|
|
for (i = 0; i < n_fields; i++) {
|
|
|
|
if (rec_offs_nth_extern(offsets, i)) {
|
|
|
|
|
|
|
|
data = rec_get_nth_field(rec, offsets, i, &local_len);
|
|
|
|
|
|
|
|
local_len -= BTR_EXTERN_FIELD_REF_SIZE;
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
extern_len = mach_read_from_4(data + local_len
|
2006-08-29 09:30:31 +00:00
|
|
|
+ BTR_EXTERN_LEN + 4);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
total_extern_len += ut_calc_align(extern_len,
|
2006-08-29 09:30:31 +00:00
|
|
|
UNIV_PAGE_SIZE);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(total_extern_len / UNIV_PAGE_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Sets the ownership bit of an externally stored field in a record. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
btr_cur_set_ownership_of_extern_field(
|
|
|
|
/*==================================*/
|
2006-02-10 15:06:17 +00:00
|
|
|
page_zip_des_t* page_zip,/* in/out: compressed page whose uncompressed
|
|
|
|
part will be updated, or NULL */
|
2005-11-18 07:40:34 +00:00
|
|
|
rec_t* rec, /* in/out: clustered index record */
|
2006-02-10 15:06:17 +00:00
|
|
|
dict_index_t* index, /* in: index of the page */
|
2005-10-27 07:29:40 +00:00
|
|
|
const ulint* offsets,/* in: array returned by rec_get_offsets() */
|
|
|
|
ulint i, /* in: field number */
|
|
|
|
ibool val, /* in: value to set */
|
2005-10-27 11:48:10 +00:00
|
|
|
mtr_t* mtr) /* in: mtr, or NULL if not logged */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
|
|
|
byte* data;
|
|
|
|
ulint local_len;
|
|
|
|
ulint byte_val;
|
|
|
|
|
|
|
|
data = rec_get_nth_field(rec, offsets, i, &local_len);
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
ut_a(local_len >= BTR_EXTERN_FIELD_REF_SIZE);
|
|
|
|
|
|
|
|
local_len -= BTR_EXTERN_FIELD_REF_SIZE;
|
|
|
|
|
|
|
|
byte_val = mach_read_from_1(data + local_len + BTR_EXTERN_LEN);
|
|
|
|
|
|
|
|
if (val) {
|
|
|
|
byte_val = byte_val & (~BTR_EXTERN_OWNER_FLAG);
|
|
|
|
} else {
|
|
|
|
byte_val = byte_val | BTR_EXTERN_OWNER_FLAG;
|
|
|
|
}
|
2005-10-27 11:48:10 +00:00
|
|
|
|
2006-03-13 07:42:31 +00:00
|
|
|
if (UNIV_LIKELY_NULL(page_zip)) {
|
|
|
|
mach_write_to_1(data + local_len + BTR_EXTERN_LEN, byte_val);
|
2006-08-29 09:30:31 +00:00
|
|
|
page_zip_write_blob_ptr(page_zip, rec, index, offsets, i, mtr);
|
2006-03-13 07:42:31 +00:00
|
|
|
} else if (UNIV_LIKELY(mtr != NULL)) {
|
2006-02-22 13:02:40 +00:00
|
|
|
|
2005-10-27 11:48:10 +00:00
|
|
|
mlog_write_ulint(data + local_len + BTR_EXTERN_LEN, byte_val,
|
2006-08-29 09:30:31 +00:00
|
|
|
MLOG_1BYTE, mtr);
|
2005-10-27 11:48:10 +00:00
|
|
|
} else {
|
|
|
|
mach_write_to_1(data + local_len + BTR_EXTERN_LEN, byte_val);
|
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Marks not updated extern fields as not-owned by this record. The ownership
|
|
|
|
is transferred to the updated record which is inserted elsewhere in the
|
|
|
|
index tree. In purge only the owner of externally stored field is allowed
|
|
|
|
to free the field. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
void
|
|
|
|
btr_cur_mark_extern_inherited_fields(
|
|
|
|
/*=================================*/
|
2006-02-10 15:06:17 +00:00
|
|
|
page_zip_des_t* page_zip,/* in/out: compressed page whose uncompressed
|
|
|
|
part will be updated, or NULL */
|
2005-11-18 07:40:34 +00:00
|
|
|
rec_t* rec, /* in/out: record in a clustered index */
|
2006-02-10 15:06:17 +00:00
|
|
|
dict_index_t* index, /* in: index of the page */
|
2005-10-27 07:29:40 +00:00
|
|
|
const ulint* offsets,/* in: array returned by rec_get_offsets() */
|
2007-08-20 06:59:22 +00:00
|
|
|
const upd_t* update, /* in: update vector */
|
2005-10-27 11:48:10 +00:00
|
|
|
mtr_t* mtr) /* in: mtr, or NULL if not logged */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
|
|
|
ulint n;
|
|
|
|
ulint j;
|
|
|
|
ulint i;
|
|
|
|
|
|
|
|
ut_ad(rec_offs_validate(rec, NULL, offsets));
|
|
|
|
ut_ad(!rec_offs_comp(offsets) || !rec_get_node_ptr_flag(rec));
|
2008-01-04 14:01:45 +00:00
|
|
|
|
|
|
|
if (!rec_offs_any_extern(offsets)) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
n = rec_offs_n_fields(offsets);
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
if (rec_offs_nth_extern(offsets, i)) {
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/* Check it is not in updated fields */
|
|
|
|
|
|
|
|
if (update) {
|
|
|
|
for (j = 0; j < upd_get_n_fields(update);
|
2006-08-29 09:30:31 +00:00
|
|
|
j++) {
|
2005-10-27 07:29:40 +00:00
|
|
|
if (upd_get_nth_field(update, j)
|
2006-08-29 09:30:31 +00:00
|
|
|
->field_no == i) {
|
2005-10-27 11:48:10 +00:00
|
|
|
|
|
|
|
goto updated;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
btr_cur_set_ownership_of_extern_field(
|
|
|
|
page_zip, rec, index, offsets, i, FALSE, mtr);
|
2005-10-27 11:48:10 +00:00
|
|
|
updated:
|
|
|
|
;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
The complement of the previous function: in an update entry may inherit
|
|
|
|
some externally stored fields from a record. We must mark them as inherited
|
|
|
|
in entry, so that they are not freed in a rollback. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
void
|
|
|
|
btr_cur_mark_dtuple_inherited_extern(
|
|
|
|
/*=================================*/
|
2006-10-20 08:30:07 +00:00
|
|
|
dtuple_t* entry, /* in/out: updated entry to be
|
|
|
|
inserted to clustered index */
|
2007-06-19 12:44:45 +00:00
|
|
|
const upd_t* update) /* in: update vector */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
2006-10-20 08:30:07 +00:00
|
|
|
ulint i;
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2007-10-16 06:05:09 +00:00
|
|
|
for (i = 0; i < dtuple_get_n_fields(entry); i++) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
dfield_t* dfield = dtuple_get_nth_field(entry, i);
|
|
|
|
byte* data;
|
|
|
|
ulint len;
|
|
|
|
ulint j;
|
2006-02-23 19:25:29 +00:00
|
|
|
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
if (!dfield_is_ext(dfield)) {
|
|
|
|
continue;
|
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
/* Check if it is in updated fields */
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
for (j = 0; j < upd_get_n_fields(update); j++) {
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
if (upd_get_nth_field(update, j)->field_no == i) {
|
|
|
|
|
|
|
|
goto is_updated;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
data = dfield_get_data(dfield);
|
2007-08-01 07:53:27 +00:00
|
|
|
len = dfield_get_len(dfield);
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
data[len - BTR_EXTERN_FIELD_REF_SIZE + BTR_EXTERN_LEN]
|
|
|
|
|= BTR_EXTERN_INHERITED_FLAG;
|
2005-10-27 07:29:40 +00:00
|
|
|
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
is_updated:
|
|
|
|
;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Marks all extern fields in a record as owned by the record. This function
|
|
|
|
should be called if the delete mark of a record is removed: a not delete
|
|
|
|
marked record always owns all its extern fields. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
btr_cur_unmark_extern_fields(
|
|
|
|
/*=========================*/
|
2006-02-10 15:06:17 +00:00
|
|
|
page_zip_des_t* page_zip,/* in/out: compressed page whose uncompressed
|
|
|
|
part will be updated, or NULL */
|
|
|
|
rec_t* rec, /* in/out: record in a clustered index */
|
|
|
|
dict_index_t* index, /* in: index of the page */
|
|
|
|
const ulint* offsets,/* in: array returned by rec_get_offsets() */
|
|
|
|
mtr_t* mtr) /* in: mtr, or NULL if not logged */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
|
|
|
ulint n;
|
|
|
|
ulint i;
|
|
|
|
|
|
|
|
ut_ad(!rec_offs_comp(offsets) || !rec_get_node_ptr_flag(rec));
|
|
|
|
n = rec_offs_n_fields(offsets);
|
|
|
|
|
2007-03-14 12:34:55 +00:00
|
|
|
if (!rec_offs_any_extern(offsets)) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
if (rec_offs_nth_extern(offsets, i)) {
|
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
btr_cur_set_ownership_of_extern_field(
|
|
|
|
page_zip, rec, index, offsets, i, TRUE, mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Marks all extern fields in a dtuple as owned by the record. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
void
|
|
|
|
btr_cur_unmark_dtuple_extern_fields(
|
|
|
|
/*================================*/
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
dtuple_t* entry) /* in/out: clustered index entry */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
|
|
|
ulint i;
|
|
|
|
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
for (i = 0; i < dtuple_get_n_fields(entry); i++) {
|
|
|
|
dfield_t* dfield = dtuple_get_nth_field(entry, i);
|
2006-02-23 19:25:29 +00:00
|
|
|
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
if (dfield_is_ext(dfield)) {
|
|
|
|
byte* data = dfield_get_data(dfield);
|
|
|
|
ulint len = dfield_get_len(dfield);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
data[len - BTR_EXTERN_FIELD_REF_SIZE + BTR_EXTERN_LEN]
|
|
|
|
&= ~BTR_EXTERN_OWNER_FLAG;
|
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2007-10-17 12:13:29 +00:00
|
|
|
Flags the data tuple fields that are marked as extern storage in the
|
|
|
|
update vector. We use this function to remember which fields we must
|
|
|
|
mark as extern storage in a record inserted for an update. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint
|
|
|
|
btr_push_update_extern_fields(
|
|
|
|
/*==========================*/
|
2007-10-17 12:13:29 +00:00
|
|
|
/* out: number of flagged external columns */
|
|
|
|
dtuple_t* tuple, /* in/out: data tuple */
|
2008-01-23 13:46:45 +00:00
|
|
|
const upd_t* update, /* in: update vector */
|
|
|
|
mem_heap_t* heap) /* in: memory heap */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
2007-10-17 12:13:29 +00:00
|
|
|
ulint n_pushed = 0;
|
|
|
|
ulint n;
|
|
|
|
const upd_field_t* uf;
|
2005-10-27 07:29:40 +00:00
|
|
|
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
ut_ad(tuple);
|
2007-10-17 12:13:29 +00:00
|
|
|
ut_ad(update);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2007-10-17 12:13:29 +00:00
|
|
|
uf = update->fields;
|
|
|
|
n = upd_get_n_fields(update);
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
|
2007-10-17 12:13:29 +00:00
|
|
|
for (; n--; uf++) {
|
|
|
|
if (dfield_is_ext(&uf->new_val)) {
|
|
|
|
dfield_t* field
|
|
|
|
= dtuple_get_nth_field(tuple, uf->field_no);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2007-10-17 12:13:29 +00:00
|
|
|
if (!dfield_is_ext(field)) {
|
|
|
|
dfield_set_ext(field);
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
n_pushed++;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
2008-01-23 13:46:45 +00:00
|
|
|
|
|
|
|
switch (uf->orig_len) {
|
|
|
|
byte* data;
|
|
|
|
ulint len;
|
|
|
|
byte* buf;
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case BTR_EXTERN_FIELD_REF_SIZE:
|
|
|
|
/* Restore the original locally stored
|
|
|
|
part of the column. In the undo log,
|
|
|
|
InnoDB writes a longer prefix of externally
|
|
|
|
stored columns, so that column prefixes
|
|
|
|
in secondary indexes can be reconstructed. */
|
2008-03-03 10:25:27 +00:00
|
|
|
dfield_set_data(field, (byte*) dfield_get_data(field)
|
2008-01-23 13:46:45 +00:00
|
|
|
+ dfield_get_len(field)
|
|
|
|
- BTR_EXTERN_FIELD_REF_SIZE,
|
|
|
|
BTR_EXTERN_FIELD_REF_SIZE);
|
|
|
|
dfield_set_ext(field);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Reconstruct the original locally
|
|
|
|
stored part of the column. The data
|
|
|
|
will have to be copied. */
|
|
|
|
ut_a(uf->orig_len > BTR_EXTERN_FIELD_REF_SIZE);
|
|
|
|
|
|
|
|
data = dfield_get_data(field);
|
|
|
|
len = dfield_get_len(field);
|
|
|
|
|
|
|
|
buf = mem_heap_alloc(heap, uf->orig_len);
|
|
|
|
/* Copy the locally stored prefix. */
|
|
|
|
memcpy(buf, data,
|
|
|
|
uf->orig_len
|
|
|
|
- BTR_EXTERN_FIELD_REF_SIZE);
|
|
|
|
/* Copy the BLOB pointer. */
|
|
|
|
memcpy(buf + uf->orig_len
|
|
|
|
- BTR_EXTERN_FIELD_REF_SIZE,
|
|
|
|
data + len - BTR_EXTERN_FIELD_REF_SIZE,
|
|
|
|
BTR_EXTERN_FIELD_REF_SIZE);
|
|
|
|
|
|
|
|
dfield_set_data(field, buf, uf->orig_len);
|
|
|
|
dfield_set_ext(field);
|
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
return(n_pushed);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Returns the length of a BLOB part stored on the header page. */
|
|
|
|
static
|
|
|
|
ulint
|
|
|
|
btr_blob_get_part_len(
|
|
|
|
/*==================*/
|
2007-01-17 09:07:20 +00:00
|
|
|
/* out: part length */
|
|
|
|
const byte* blob_header) /* in: blob header */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
|
|
|
return(mach_read_from_4(blob_header + BTR_BLOB_HDR_PART_LEN));
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Returns the page number where the next BLOB part is stored. */
|
|
|
|
static
|
|
|
|
ulint
|
|
|
|
btr_blob_get_next_page_no(
|
|
|
|
/*======================*/
|
2007-01-17 09:07:20 +00:00
|
|
|
/* out: page number or FIL_NULL if
|
|
|
|
no more pages */
|
|
|
|
const byte* blob_header) /* in: blob header */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
|
|
|
return(mach_read_from_4(blob_header + BTR_BLOB_HDR_NEXT_PAGE_NO));
|
|
|
|
}
|
|
|
|
|
2007-01-18 14:02:56 +00:00
|
|
|
/***********************************************************************
|
|
|
|
Deallocate a buffer block that was reserved for a BLOB part. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
btr_blob_free(
|
|
|
|
/*==========*/
|
|
|
|
buf_block_t* block, /* in: buffer block */
|
|
|
|
ibool all, /* in: TRUE=remove also the compressed page
|
|
|
|
if there is one */
|
|
|
|
mtr_t* mtr) /* in: mini-transaction to commit */
|
|
|
|
{
|
|
|
|
ulint space = buf_block_get_space(block);
|
|
|
|
ulint page_no = buf_block_get_page_no(block);
|
|
|
|
|
|
|
|
ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX));
|
|
|
|
|
|
|
|
mtr_commit(mtr);
|
|
|
|
|
2008-01-10 09:37:13 +00:00
|
|
|
buf_pool_mutex_enter();
|
2007-01-18 14:02:56 +00:00
|
|
|
mutex_enter(&block->mutex);
|
|
|
|
|
|
|
|
/* Only free the block if it is still allocated to
|
|
|
|
the same file page. */
|
|
|
|
|
|
|
|
if (buf_block_get_state(block)
|
|
|
|
== BUF_BLOCK_FILE_PAGE
|
|
|
|
&& buf_block_get_space(block) == space
|
|
|
|
&& buf_block_get_page_no(block) == page_no) {
|
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
if (buf_LRU_free_block(&block->page, all, NULL)
|
|
|
|
!= BUF_LRU_FREED
|
2007-01-18 14:02:56 +00:00
|
|
|
&& all && block->page.zip.data) {
|
|
|
|
/* Attempt to deallocate the uncompressed page
|
|
|
|
if the whole block cannot be deallocted. */
|
|
|
|
|
2007-12-10 09:48:28 +00:00
|
|
|
buf_LRU_free_block(&block->page, FALSE, NULL);
|
2007-01-18 14:02:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-10 09:37:13 +00:00
|
|
|
buf_pool_mutex_exit();
|
2007-01-18 14:02:56 +00:00
|
|
|
mutex_exit(&block->mutex);
|
|
|
|
}
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/***********************************************************************
|
|
|
|
Stores the fields in big_rec_vec to the tablespace and puts pointers to
|
2006-02-10 15:06:17 +00:00
|
|
|
them in rec. The extern flags in rec will have to be set beforehand.
|
|
|
|
The fields are stored on pages allocated from leaf node
|
2005-10-27 07:29:40 +00:00
|
|
|
file segment of the index tree. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint
|
|
|
|
btr_store_big_rec_extern_fields(
|
|
|
|
/*============================*/
|
|
|
|
/* out: DB_SUCCESS or error */
|
|
|
|
dict_index_t* index, /* in: index of rec; the index tree
|
|
|
|
MUST be X-latched */
|
2006-10-24 14:06:31 +00:00
|
|
|
buf_block_t* rec_block, /* in/out: block containing rec */
|
2005-11-18 07:40:34 +00:00
|
|
|
rec_t* rec, /* in/out: record */
|
2006-04-12 09:32:17 +00:00
|
|
|
const ulint* offsets, /* in: rec_get_offsets(rec, index);
|
|
|
|
the "external storage" flags in offsets
|
|
|
|
will not correspond to rec when
|
|
|
|
this function returns */
|
2005-10-27 07:29:40 +00:00
|
|
|
big_rec_t* big_rec_vec, /* in: vector containing fields
|
|
|
|
to be stored externally */
|
|
|
|
mtr_t* local_mtr __attribute__((unused))) /* in: mtr
|
2006-02-23 19:25:29 +00:00
|
|
|
containing the latch to rec and to the
|
|
|
|
tree */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
2006-10-26 08:47:00 +00:00
|
|
|
ulint rec_page_no;
|
2006-02-10 15:06:17 +00:00
|
|
|
byte* field_ref;
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint extern_len;
|
|
|
|
ulint store_len;
|
|
|
|
ulint page_no;
|
|
|
|
ulint space_id;
|
2007-01-18 09:59:00 +00:00
|
|
|
ulint zip_size;
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint prev_page_no;
|
|
|
|
ulint hint_page_no;
|
|
|
|
ulint i;
|
|
|
|
mtr_t mtr;
|
2007-01-29 08:51:20 +00:00
|
|
|
mem_heap_t* heap = NULL;
|
2006-02-16 12:58:18 +00:00
|
|
|
page_zip_des_t* page_zip;
|
|
|
|
z_stream c_stream;
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
ut_ad(rec_offs_validate(rec, index, offsets));
|
2006-09-19 10:14:07 +00:00
|
|
|
ut_ad(mtr_memo_contains(local_mtr, dict_index_get_lock(index),
|
2006-08-29 09:30:31 +00:00
|
|
|
MTR_MEMO_X_LOCK));
|
2006-10-24 14:06:31 +00:00
|
|
|
ut_ad(mtr_memo_contains(local_mtr, rec_block, MTR_MEMO_PAGE_X_FIX));
|
|
|
|
ut_ad(buf_block_get_frame(rec_block) == page_align(rec));
|
2006-03-09 17:26:02 +00:00
|
|
|
ut_a(dict_index_is_clust(index));
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2006-10-18 11:39:31 +00:00
|
|
|
page_zip = buf_block_get_page_zip(rec_block);
|
2006-05-04 11:44:49 +00:00
|
|
|
ut_a(dict_table_zip_size(index->table)
|
2006-10-18 11:39:31 +00:00
|
|
|
== buf_block_get_zip_size(rec_block));
|
|
|
|
|
|
|
|
space_id = buf_block_get_space(rec_block);
|
2007-01-18 09:59:00 +00:00
|
|
|
zip_size = buf_block_get_zip_size(rec_block);
|
2006-10-26 08:47:00 +00:00
|
|
|
rec_page_no = buf_block_get_page_no(rec_block);
|
2007-11-22 10:02:50 +00:00
|
|
|
ut_a(fil_page_get_type(page_align(rec)) == FIL_PAGE_INDEX);
|
2006-02-16 12:58:18 +00:00
|
|
|
|
2006-02-21 14:43:23 +00:00
|
|
|
if (UNIV_LIKELY_NULL(page_zip)) {
|
2006-02-16 12:58:18 +00:00
|
|
|
int err;
|
|
|
|
|
2007-01-29 08:51:20 +00:00
|
|
|
/* Zlib deflate needs 128 kilobytes for the default
|
|
|
|
window size, plus 512 << memLevel, plus a few
|
|
|
|
kilobytes for small objects. We use reduced memLevel
|
|
|
|
to limit the memory consumption, and preallocate the
|
|
|
|
heap, hoping to avoid memory fragmentation. */
|
|
|
|
heap = mem_heap_create(250000);
|
|
|
|
page_zip_set_alloc(&c_stream, heap);
|
2006-02-16 12:58:18 +00:00
|
|
|
|
2007-01-29 08:51:20 +00:00
|
|
|
err = deflateInit2(&c_stream, Z_DEFAULT_COMPRESSION,
|
|
|
|
Z_DEFLATED, 15, 7, Z_DEFAULT_STRATEGY);
|
2006-02-16 12:58:18 +00:00
|
|
|
ut_a(err == Z_OK);
|
|
|
|
}
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/* We have to create a file segment to the tablespace
|
|
|
|
for each field and put the pointer to the field in rec */
|
|
|
|
|
|
|
|
for (i = 0; i < big_rec_vec->n_fields; i++) {
|
2006-02-16 12:58:18 +00:00
|
|
|
ut_ad(rec_offs_nth_extern(offsets,
|
2006-08-29 09:30:31 +00:00
|
|
|
big_rec_vec->fields[i].field_no));
|
2006-02-10 15:06:17 +00:00
|
|
|
{
|
2006-02-23 19:25:29 +00:00
|
|
|
ulint local_len;
|
2006-09-19 10:14:07 +00:00
|
|
|
field_ref = rec_get_nth_field(
|
|
|
|
rec, offsets, big_rec_vec->fields[i].field_no,
|
|
|
|
&local_len);
|
2006-02-10 15:06:17 +00:00
|
|
|
ut_a(local_len >= BTR_EXTERN_FIELD_REF_SIZE);
|
|
|
|
local_len -= BTR_EXTERN_FIELD_REF_SIZE;
|
|
|
|
field_ref += local_len;
|
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
extern_len = big_rec_vec->fields[i].len;
|
|
|
|
|
|
|
|
ut_a(extern_len > 0);
|
|
|
|
|
|
|
|
prev_page_no = FIL_NULL;
|
|
|
|
|
2006-02-21 14:43:23 +00:00
|
|
|
if (UNIV_LIKELY_NULL(page_zip)) {
|
2006-02-16 12:58:18 +00:00
|
|
|
int err = deflateReset(&c_stream);
|
|
|
|
ut_a(err == Z_OK);
|
|
|
|
|
branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.
dfield_t: Add an "external storage" flag, dfield->ext.
dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.
dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.
data_write_sql_null(): Use memset().
big_rec_field_t: Replace byte* data with const void* data.
ut_ulint_sort(): Remove.
upd_field_t: Remove extern_storage.
upd_node_t: Replace ext_vec, n_ext_vec with n_ext.
row_merge_copy_blobs(): New function.
row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.
btr_page_insert_fits(): Add const qualifiers.
btr_cur_add_ext(), upd_ext_vec_contains(): Remove.
dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
|
|
|
c_stream.next_in = (void*) big_rec_vec->fields[i].data;
|
2006-02-16 12:58:18 +00:00
|
|
|
c_stream.avail_in = extern_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
2006-10-12 11:05:22 +00:00
|
|
|
buf_block_t* block;
|
|
|
|
page_t* page;
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
mtr_start(&mtr);
|
|
|
|
|
|
|
|
if (prev_page_no == FIL_NULL) {
|
2006-10-26 08:47:00 +00:00
|
|
|
hint_page_no = 1 + rec_page_no;
|
2005-10-27 07:29:40 +00:00
|
|
|
} else {
|
|
|
|
hint_page_no = prev_page_no + 1;
|
|
|
|
}
|
2005-11-18 07:40:34 +00:00
|
|
|
|
2006-10-12 11:05:22 +00:00
|
|
|
block = btr_page_alloc(index, hint_page_no,
|
|
|
|
FSP_NO_DIR, 0, &mtr);
|
|
|
|
if (UNIV_UNLIKELY(block == NULL)) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
|
2006-02-21 14:43:23 +00:00
|
|
|
if (UNIV_LIKELY_NULL(page_zip)) {
|
2006-02-16 12:58:18 +00:00
|
|
|
deflateEnd(&c_stream);
|
2007-01-29 08:51:20 +00:00
|
|
|
mem_heap_free(heap);
|
2006-02-16 12:58:18 +00:00
|
|
|
}
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
return(DB_OUT_OF_FILE_SPACE);
|
|
|
|
}
|
|
|
|
|
2006-10-12 11:05:22 +00:00
|
|
|
page_no = buf_block_get_page_no(block);
|
|
|
|
page = buf_block_get_frame(block);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (prev_page_no != FIL_NULL) {
|
2006-10-12 11:05:22 +00:00
|
|
|
buf_block_t* prev_block;
|
|
|
|
page_t* prev_page;
|
2006-09-06 14:17:20 +00:00
|
|
|
|
2007-01-18 09:59:00 +00:00
|
|
|
prev_block = buf_page_get(space_id, zip_size,
|
2006-10-12 11:05:22 +00:00
|
|
|
prev_page_no,
|
|
|
|
RW_X_LATCH, &mtr);
|
|
|
|
buf_block_dbg_add_level(prev_block,
|
|
|
|
SYNC_EXTERN_STORAGE);
|
|
|
|
prev_page = buf_block_get_frame(prev_block);
|
2006-02-16 12:58:18 +00:00
|
|
|
|
2006-02-21 14:43:23 +00:00
|
|
|
if (UNIV_LIKELY_NULL(page_zip)) {
|
2006-09-19 10:14:07 +00:00
|
|
|
mlog_write_ulint(
|
|
|
|
prev_page + FIL_PAGE_NEXT,
|
|
|
|
page_no, MLOG_4BYTES, &mtr);
|
2006-10-18 11:39:31 +00:00
|
|
|
memcpy(buf_block_get_page_zip(
|
|
|
|
prev_block)
|
2006-09-06 14:17:20 +00:00
|
|
|
->data + FIL_PAGE_NEXT,
|
|
|
|
prev_page + FIL_PAGE_NEXT, 4);
|
2006-02-16 12:58:18 +00:00
|
|
|
} else {
|
2006-09-19 10:14:07 +00:00
|
|
|
mlog_write_ulint(
|
|
|
|
prev_page + FIL_PAGE_DATA
|
|
|
|
+ BTR_BLOB_HDR_NEXT_PAGE_NO,
|
|
|
|
page_no, MLOG_4BYTES, &mtr);
|
2006-02-16 12:58:18 +00:00
|
|
|
}
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2006-02-21 14:43:23 +00:00
|
|
|
if (UNIV_LIKELY_NULL(page_zip)) {
|
2006-05-30 09:04:57 +00:00
|
|
|
int err;
|
|
|
|
page_zip_des_t* blob_page_zip;
|
2006-02-16 12:58:18 +00:00
|
|
|
|
2006-04-26 09:35:18 +00:00
|
|
|
mach_write_to_2(page + FIL_PAGE_TYPE,
|
2008-01-24 08:12:02 +00:00
|
|
|
prev_page_no == FIL_NULL
|
|
|
|
? FIL_PAGE_TYPE_ZBLOB
|
|
|
|
: FIL_PAGE_TYPE_ZBLOB2);
|
2006-04-05 13:41:12 +00:00
|
|
|
|
|
|
|
c_stream.next_out = page
|
2006-09-27 10:51:05 +00:00
|
|
|
+ FIL_PAGE_DATA;
|
2006-11-27 13:44:32 +00:00
|
|
|
c_stream.avail_out
|
|
|
|
= page_zip_get_size(page_zip)
|
2006-09-27 10:51:05 +00:00
|
|
|
- FIL_PAGE_DATA;
|
2006-02-16 12:58:18 +00:00
|
|
|
|
|
|
|
err = deflate(&c_stream, Z_FINISH);
|
|
|
|
ut_a(err == Z_OK || err == Z_STREAM_END);
|
|
|
|
ut_a(err == Z_STREAM_END
|
2006-08-29 09:30:31 +00:00
|
|
|
|| c_stream.avail_out == 0);
|
2006-02-16 12:58:18 +00:00
|
|
|
|
|
|
|
/* Write the "next BLOB page" pointer */
|
2006-04-05 13:41:12 +00:00
|
|
|
mlog_write_ulint(page + FIL_PAGE_NEXT,
|
2006-08-29 09:30:31 +00:00
|
|
|
FIL_NULL, MLOG_4BYTES, &mtr);
|
2006-09-27 10:51:05 +00:00
|
|
|
/* Initialize the unused "prev page" pointer */
|
|
|
|
mlog_write_ulint(page + FIL_PAGE_PREV,
|
|
|
|
FIL_NULL, MLOG_4BYTES, &mtr);
|
2006-11-15 21:58:01 +00:00
|
|
|
/* Write a back pointer to the record
|
|
|
|
into the otherwise unused area. This
|
|
|
|
information could be useful in
|
|
|
|
debugging. Later, we might want to
|
|
|
|
implement the possibility to relocate
|
|
|
|
BLOB pages. Then, we would need to be
|
|
|
|
able to adjust the BLOB pointer in the
|
|
|
|
record. We do not store the heap
|
|
|
|
number of the record, because it can
|
|
|
|
change in page_zip_reorganize() or
|
2007-12-03 10:25:20 +00:00
|
|
|
btr_page_reorganize(). However, also
|
|
|
|
the page number of the record may
|
|
|
|
change when B-tree nodes are split or
|
|
|
|
merged. */
|
2006-11-15 21:58:01 +00:00
|
|
|
mlog_write_ulint(page
|
|
|
|
+ FIL_PAGE_FILE_FLUSH_LSN,
|
|
|
|
space_id,
|
|
|
|
MLOG_4BYTES, &mtr);
|
|
|
|
mlog_write_ulint(page
|
|
|
|
+ FIL_PAGE_FILE_FLUSH_LSN + 4,
|
|
|
|
rec_page_no,
|
|
|
|
MLOG_4BYTES, &mtr);
|
|
|
|
|
2006-02-16 12:58:18 +00:00
|
|
|
/* Zero out the unused part of the page. */
|
2006-11-27 13:44:32 +00:00
|
|
|
memset(page + page_zip_get_size(page_zip)
|
2006-08-29 09:30:31 +00:00
|
|
|
- c_stream.avail_out,
|
|
|
|
0, c_stream.avail_out);
|
2006-04-05 13:41:12 +00:00
|
|
|
mlog_log_string(page + FIL_PAGE_TYPE,
|
2006-11-27 13:44:32 +00:00
|
|
|
page_zip_get_size(page_zip)
|
|
|
|
- FIL_PAGE_TYPE,
|
2006-08-29 09:30:31 +00:00
|
|
|
&mtr);
|
2006-05-30 09:04:57 +00:00
|
|
|
/* Copy the page to compressed storage,
|
|
|
|
because it will be flushed to disk
|
|
|
|
from there. */
|
2006-10-12 11:05:22 +00:00
|
|
|
blob_page_zip = buf_block_get_page_zip(block);
|
2006-05-30 09:04:57 +00:00
|
|
|
ut_ad(blob_page_zip);
|
2006-11-27 13:44:32 +00:00
|
|
|
ut_ad(page_zip_get_size(blob_page_zip)
|
|
|
|
== page_zip_get_size(page_zip));
|
2006-05-30 09:04:57 +00:00
|
|
|
memcpy(blob_page_zip->data, page,
|
2006-11-27 13:44:32 +00:00
|
|
|
page_zip_get_size(page_zip));
|
2006-02-16 12:58:18 +00:00
|
|
|
|
|
|
|
if (err == Z_OK && prev_page_no != FIL_NULL) {
|
|
|
|
|
|
|
|
goto next_zip_page;
|
|
|
|
}
|
|
|
|
|
2007-01-18 09:59:00 +00:00
|
|
|
rec_block = buf_page_get(space_id, zip_size,
|
|
|
|
rec_page_no,
|
2006-10-26 08:47:00 +00:00
|
|
|
RW_X_LATCH, &mtr);
|
2006-10-12 11:05:22 +00:00
|
|
|
buf_block_dbg_add_level(rec_block,
|
|
|
|
SYNC_NO_ORDER_CHECK);
|
2008-09-22 07:57:34 +00:00
|
|
|
|
2006-02-16 12:58:18 +00:00
|
|
|
if (err == Z_STREAM_END) {
|
2006-07-27 12:32:12 +00:00
|
|
|
mach_write_to_4(field_ref
|
|
|
|
+ BTR_EXTERN_LEN, 0);
|
|
|
|
mach_write_to_4(field_ref
|
2006-02-16 12:58:18 +00:00
|
|
|
+ BTR_EXTERN_LEN + 4,
|
2006-07-27 12:32:12 +00:00
|
|
|
c_stream.total_in);
|
2006-02-16 12:58:18 +00:00
|
|
|
} else {
|
2006-07-27 12:32:12 +00:00
|
|
|
memset(field_ref + BTR_EXTERN_LEN,
|
2006-08-29 09:30:31 +00:00
|
|
|
0, 8);
|
2006-02-16 12:58:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (prev_page_no == FIL_NULL) {
|
2006-07-27 12:32:12 +00:00
|
|
|
mach_write_to_4(field_ref
|
2006-02-16 12:58:18 +00:00
|
|
|
+ BTR_EXTERN_SPACE_ID,
|
2006-07-27 12:32:12 +00:00
|
|
|
space_id);
|
2006-02-16 12:58:18 +00:00
|
|
|
|
2006-07-27 12:32:12 +00:00
|
|
|
mach_write_to_4(field_ref
|
2006-02-16 12:58:18 +00:00
|
|
|
+ BTR_EXTERN_PAGE_NO,
|
2006-07-27 12:32:12 +00:00
|
|
|
page_no);
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2006-07-27 12:32:12 +00:00
|
|
|
mach_write_to_4(field_ref
|
2006-02-16 12:58:18 +00:00
|
|
|
+ BTR_EXTERN_OFFSET,
|
2006-07-27 12:32:12 +00:00
|
|
|
FIL_PAGE_NEXT);
|
2006-02-16 12:58:18 +00:00
|
|
|
}
|
2006-02-21 14:43:23 +00:00
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
page_zip_write_blob_ptr(
|
|
|
|
page_zip, rec, index, offsets,
|
|
|
|
big_rec_vec->fields[i].field_no, &mtr);
|
2006-02-16 12:58:18 +00:00
|
|
|
|
|
|
|
next_zip_page:
|
|
|
|
prev_page_no = page_no;
|
|
|
|
|
2007-01-18 14:02:56 +00:00
|
|
|
/* Commit mtr and release the
|
|
|
|
uncompressed page frame to save memory. */
|
|
|
|
btr_blob_free(block, FALSE, &mtr);
|
2007-01-16 11:56:33 +00:00
|
|
|
|
2006-02-16 12:58:18 +00:00
|
|
|
if (err == Z_STREAM_END) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2006-04-05 13:41:12 +00:00
|
|
|
mlog_write_ulint(page + FIL_PAGE_TYPE,
|
2006-08-29 09:30:31 +00:00
|
|
|
FIL_PAGE_TYPE_BLOB,
|
|
|
|
MLOG_2BYTES, &mtr);
|
2006-04-05 13:41:12 +00:00
|
|
|
|
2006-02-16 12:58:18 +00:00
|
|
|
if (extern_len > (UNIV_PAGE_SIZE
|
2006-08-29 09:30:31 +00:00
|
|
|
- FIL_PAGE_DATA
|
|
|
|
- BTR_BLOB_HDR_SIZE
|
|
|
|
- FIL_PAGE_DATA_END)) {
|
2006-02-16 12:58:18 +00:00
|
|
|
store_len = UNIV_PAGE_SIZE
|
|
|
|
- FIL_PAGE_DATA
|
2005-10-27 07:29:40 +00:00
|
|
|
- BTR_BLOB_HDR_SIZE
|
|
|
|
- FIL_PAGE_DATA_END;
|
2006-02-16 12:58:18 +00:00
|
|
|
} else {
|
|
|
|
store_len = extern_len;
|
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-02-16 12:58:18 +00:00
|
|
|
mlog_write_string(page + FIL_PAGE_DATA
|
2006-08-29 09:30:31 +00:00
|
|
|
+ BTR_BLOB_HDR_SIZE,
|
2007-10-25 07:03:02 +00:00
|
|
|
(const byte*)
|
2006-08-29 09:30:31 +00:00
|
|
|
big_rec_vec->fields[i].data
|
|
|
|
+ big_rec_vec->fields[i].len
|
|
|
|
- extern_len,
|
|
|
|
store_len, &mtr);
|
2006-02-16 12:58:18 +00:00
|
|
|
mlog_write_ulint(page + FIL_PAGE_DATA
|
2006-08-29 09:30:31 +00:00
|
|
|
+ BTR_BLOB_HDR_PART_LEN,
|
|
|
|
store_len, MLOG_4BYTES, &mtr);
|
2006-02-16 12:58:18 +00:00
|
|
|
mlog_write_ulint(page + FIL_PAGE_DATA
|
2006-08-29 09:30:31 +00:00
|
|
|
+ BTR_BLOB_HDR_NEXT_PAGE_NO,
|
|
|
|
FIL_NULL, MLOG_4BYTES, &mtr);
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2006-02-16 12:58:18 +00:00
|
|
|
extern_len -= store_len;
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2007-01-18 09:59:00 +00:00
|
|
|
rec_block = buf_page_get(space_id, zip_size,
|
|
|
|
rec_page_no,
|
2006-10-26 08:47:00 +00:00
|
|
|
RW_X_LATCH, &mtr);
|
2006-10-12 11:05:22 +00:00
|
|
|
buf_block_dbg_add_level(rec_block,
|
|
|
|
SYNC_NO_ORDER_CHECK);
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2006-02-16 12:58:18 +00:00
|
|
|
mlog_write_ulint(field_ref + BTR_EXTERN_LEN, 0,
|
2006-08-29 09:30:31 +00:00
|
|
|
MLOG_4BYTES, &mtr);
|
2006-02-10 15:06:17 +00:00
|
|
|
mlog_write_ulint(field_ref
|
2006-08-29 09:30:31 +00:00
|
|
|
+ BTR_EXTERN_LEN + 4,
|
|
|
|
big_rec_vec->fields[i].len
|
|
|
|
- extern_len,
|
|
|
|
MLOG_4BYTES, &mtr);
|
2006-02-16 12:58:18 +00:00
|
|
|
|
|
|
|
if (prev_page_no == FIL_NULL) {
|
|
|
|
mlog_write_ulint(field_ref
|
2006-08-29 09:30:31 +00:00
|
|
|
+ BTR_EXTERN_SPACE_ID,
|
|
|
|
space_id,
|
|
|
|
MLOG_4BYTES, &mtr);
|
2006-02-16 12:58:18 +00:00
|
|
|
|
|
|
|
mlog_write_ulint(field_ref
|
2006-08-29 09:30:31 +00:00
|
|
|
+ BTR_EXTERN_PAGE_NO,
|
|
|
|
page_no,
|
|
|
|
MLOG_4BYTES, &mtr);
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2006-02-16 12:58:18 +00:00
|
|
|
mlog_write_ulint(field_ref
|
2006-08-29 09:30:31 +00:00
|
|
|
+ BTR_EXTERN_OFFSET,
|
|
|
|
FIL_PAGE_DATA,
|
|
|
|
MLOG_4BYTES, &mtr);
|
2006-02-16 12:58:18 +00:00
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-02-16 12:58:18 +00:00
|
|
|
prev_page_no = page_no;
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-02-16 12:58:18 +00:00
|
|
|
mtr_commit(&mtr);
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2006-02-16 12:58:18 +00:00
|
|
|
if (extern_len == 0) {
|
|
|
|
break;
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-21 14:43:23 +00:00
|
|
|
if (UNIV_LIKELY_NULL(page_zip)) {
|
2006-02-16 12:58:18 +00:00
|
|
|
deflateEnd(&c_stream);
|
2007-01-29 08:51:20 +00:00
|
|
|
mem_heap_free(heap);
|
2006-02-16 12:58:18 +00:00
|
|
|
}
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
return(DB_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Frees the space in an externally stored field to the file space
|
2006-02-10 15:06:17 +00:00
|
|
|
management if the field in data is owned by the externally stored field,
|
2005-10-27 07:29:40 +00:00
|
|
|
in a rollback we may have the additional condition that the field must
|
|
|
|
not be inherited. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
void
|
|
|
|
btr_free_externally_stored_field(
|
|
|
|
/*=============================*/
|
|
|
|
dict_index_t* index, /* in: index of the data, the index
|
|
|
|
tree MUST be X-latched; if the tree
|
|
|
|
height is 1, then also the root page
|
|
|
|
must be X-latched! (this is relevant
|
|
|
|
in the case this function is called
|
|
|
|
from purge where 'data' is located on
|
|
|
|
an undo log page, not an index
|
|
|
|
page) */
|
2006-02-21 14:15:11 +00:00
|
|
|
byte* field_ref, /* in/out: field reference */
|
2006-10-25 08:52:43 +00:00
|
|
|
const rec_t* rec, /* in: record containing field_ref, for
|
2006-02-21 14:15:11 +00:00
|
|
|
page_zip_write_blob_ptr(), or NULL */
|
|
|
|
const ulint* offsets, /* in: rec_get_offsets(rec, index),
|
2006-02-10 15:06:17 +00:00
|
|
|
or NULL */
|
2006-02-21 14:15:11 +00:00
|
|
|
page_zip_des_t* page_zip, /* in: compressed page corresponding
|
|
|
|
to rec, or NULL if rec == NULL */
|
|
|
|
ulint i, /* in: field number of field_ref;
|
|
|
|
ignored if rec == NULL */
|
2008-08-09 00:15:46 +00:00
|
|
|
enum trx_rb_ctx rb_ctx, /* in: rollback context */
|
2006-02-23 19:25:29 +00:00
|
|
|
mtr_t* local_mtr __attribute__((unused))) /* in: mtr
|
|
|
|
containing the latch to data an an
|
|
|
|
X-latch to the index tree */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
2006-10-12 11:05:22 +00:00
|
|
|
page_t* page;
|
|
|
|
ulint space_id;
|
2007-01-18 09:59:00 +00:00
|
|
|
ulint rec_zip_size = dict_table_zip_size(index->table);
|
|
|
|
ulint ext_zip_size;
|
2006-10-12 11:05:22 +00:00
|
|
|
ulint page_no;
|
|
|
|
ulint next_page_no;
|
|
|
|
mtr_t mtr;
|
|
|
|
#ifdef UNIV_DEBUG
|
2006-09-19 10:14:07 +00:00
|
|
|
ut_ad(mtr_memo_contains(local_mtr, dict_index_get_lock(index),
|
2006-08-29 09:30:31 +00:00
|
|
|
MTR_MEMO_X_LOCK));
|
2006-10-25 08:52:43 +00:00
|
|
|
ut_ad(mtr_memo_contains_page(local_mtr, field_ref,
|
|
|
|
MTR_MEMO_PAGE_X_FIX));
|
2006-02-21 14:15:11 +00:00
|
|
|
ut_ad(!rec || rec_offs_validate(rec, index, offsets));
|
2006-02-10 15:06:17 +00:00
|
|
|
|
2006-02-21 14:15:11 +00:00
|
|
|
if (rec) {
|
2006-02-16 12:58:18 +00:00
|
|
|
ulint local_len;
|
2006-10-25 08:52:43 +00:00
|
|
|
const byte* f = rec_get_nth_field(rec, offsets,
|
|
|
|
i, &local_len);
|
2006-02-16 12:58:18 +00:00
|
|
|
ut_a(local_len >= BTR_EXTERN_FIELD_REF_SIZE);
|
|
|
|
local_len -= BTR_EXTERN_FIELD_REF_SIZE;
|
2006-02-21 14:15:11 +00:00
|
|
|
f += local_len;
|
|
|
|
ut_ad(f == field_ref);
|
2006-02-16 12:58:18 +00:00
|
|
|
}
|
2006-02-21 14:15:11 +00:00
|
|
|
#endif /* UNIV_DEBUG */
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2008-08-09 00:15:46 +00:00
|
|
|
if (UNIV_UNLIKELY(!memcmp(field_ref, field_ref_zero,
|
|
|
|
BTR_EXTERN_FIELD_REF_SIZE))) {
|
|
|
|
/* In the rollback of uncommitted transactions, we may
|
|
|
|
encounter a clustered index record whose BLOBs have
|
|
|
|
not been written. There is nothing to free then. */
|
|
|
|
ut_a(rb_ctx == RB_RECOVERY);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-01-18 09:59:00 +00:00
|
|
|
space_id = mach_read_from_4(field_ref + BTR_EXTERN_SPACE_ID);
|
|
|
|
|
|
|
|
if (UNIV_UNLIKELY(space_id != dict_index_get_space(index))) {
|
|
|
|
ext_zip_size = fil_space_get_zip_size(space_id);
|
2007-11-05 13:14:11 +00:00
|
|
|
/* This must be an undo log record in the system tablespace,
|
|
|
|
that is, in row_purge_upd_exist_or_extern().
|
|
|
|
Currently, externally stored records are stored in the
|
|
|
|
same tablespace as the referring records. */
|
|
|
|
ut_ad(!page_get_space_id(page_align(field_ref)));
|
|
|
|
ut_ad(!rec);
|
|
|
|
ut_ad(!page_zip);
|
2007-01-18 09:59:00 +00:00
|
|
|
} else {
|
|
|
|
ext_zip_size = rec_zip_size;
|
|
|
|
}
|
|
|
|
|
2007-11-05 13:14:11 +00:00
|
|
|
if (!rec) {
|
|
|
|
/* This is a call from row_purge_upd_exist_or_extern(). */
|
|
|
|
ut_ad(!page_zip);
|
|
|
|
rec_zip_size = 0;
|
|
|
|
}
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
for (;;) {
|
2006-10-12 11:05:22 +00:00
|
|
|
buf_block_t* rec_block;
|
|
|
|
buf_block_t* ext_block;
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
mtr_start(&mtr);
|
|
|
|
|
2006-10-12 11:05:22 +00:00
|
|
|
rec_block = buf_page_get(page_get_space_id(
|
|
|
|
page_align(field_ref)),
|
2007-01-18 09:59:00 +00:00
|
|
|
rec_zip_size,
|
2006-10-12 11:05:22 +00:00
|
|
|
page_get_page_no(
|
|
|
|
page_align(field_ref)),
|
|
|
|
RW_X_LATCH, &mtr);
|
|
|
|
buf_block_dbg_add_level(rec_block, SYNC_NO_ORDER_CHECK);
|
2006-02-10 15:06:17 +00:00
|
|
|
page_no = mach_read_from_4(field_ref + BTR_EXTERN_PAGE_NO);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-02-16 12:58:18 +00:00
|
|
|
if (/* There is no external storage data */
|
|
|
|
page_no == FIL_NULL
|
|
|
|
/* This field does not own the externally stored field */
|
|
|
|
|| (mach_read_from_1(field_ref + BTR_EXTERN_LEN)
|
2006-08-29 09:30:31 +00:00
|
|
|
& BTR_EXTERN_OWNER_FLAG)
|
2006-02-16 12:58:18 +00:00
|
|
|
/* Rollback and inherited field */
|
2008-08-09 00:15:46 +00:00
|
|
|
|| (rb_ctx != RB_NONE
|
2006-08-29 09:30:31 +00:00
|
|
|
&& (mach_read_from_1(field_ref + BTR_EXTERN_LEN)
|
|
|
|
& BTR_EXTERN_INHERITED_FLAG))) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-02-16 12:58:18 +00:00
|
|
|
/* Do not free */
|
2005-10-27 07:29:40 +00:00
|
|
|
mtr_commit(&mtr);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2006-02-16 12:58:18 +00:00
|
|
|
|
2007-01-18 09:59:00 +00:00
|
|
|
ext_block = buf_page_get(space_id, ext_zip_size, page_no,
|
|
|
|
RW_X_LATCH, &mtr);
|
2006-10-12 11:05:22 +00:00
|
|
|
buf_block_dbg_add_level(ext_block, SYNC_EXTERN_STORAGE);
|
|
|
|
page = buf_block_get_frame(ext_block);
|
|
|
|
|
2007-01-18 09:59:00 +00:00
|
|
|
if (ext_zip_size) {
|
2006-04-03 20:33:31 +00:00
|
|
|
/* Note that page_zip will be NULL
|
|
|
|
in row_purge_upd_exist_or_extern(). */
|
2008-01-24 08:12:02 +00:00
|
|
|
switch (fil_page_get_type(page)) {
|
|
|
|
case FIL_PAGE_TYPE_ZBLOB:
|
|
|
|
case FIL_PAGE_TYPE_ZBLOB2:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ut_error;
|
|
|
|
}
|
2006-04-05 13:41:12 +00:00
|
|
|
next_page_no = mach_read_from_4(page + FIL_PAGE_NEXT);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-10-13 11:55:27 +00:00
|
|
|
btr_page_free_low(index, ext_block, 0, &mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-07-27 12:32:12 +00:00
|
|
|
if (UNIV_LIKELY(page_zip != NULL)) {
|
|
|
|
mach_write_to_4(field_ref + BTR_EXTERN_PAGE_NO,
|
|
|
|
next_page_no);
|
|
|
|
mach_write_to_4(field_ref + BTR_EXTERN_LEN + 4,
|
|
|
|
0);
|
|
|
|
page_zip_write_blob_ptr(page_zip, rec, index,
|
2006-08-29 09:30:31 +00:00
|
|
|
offsets, i, &mtr);
|
2006-07-27 12:32:12 +00:00
|
|
|
} else {
|
|
|
|
mlog_write_ulint(field_ref
|
2006-08-29 09:30:31 +00:00
|
|
|
+ BTR_EXTERN_PAGE_NO,
|
|
|
|
next_page_no,
|
|
|
|
MLOG_4BYTES, &mtr);
|
2006-07-27 12:32:12 +00:00
|
|
|
mlog_write_ulint(field_ref
|
2006-08-29 09:30:31 +00:00
|
|
|
+ BTR_EXTERN_LEN + 4, 0,
|
|
|
|
MLOG_4BYTES, &mtr);
|
2006-04-03 20:33:31 +00:00
|
|
|
}
|
2006-02-16 12:58:18 +00:00
|
|
|
} else {
|
2007-11-22 10:02:50 +00:00
|
|
|
ut_a(fil_page_get_type(page) == FIL_PAGE_TYPE_BLOB);
|
2006-07-27 12:32:12 +00:00
|
|
|
ut_a(!page_zip);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
next_page_no = mach_read_from_4(
|
|
|
|
page + FIL_PAGE_DATA
|
|
|
|
+ BTR_BLOB_HDR_NEXT_PAGE_NO);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-02-16 12:58:18 +00:00
|
|
|
/* We must supply the page level (= 0) as an argument
|
|
|
|
because we did not store it on the page (we save the
|
|
|
|
space overhead from an index page header. */
|
|
|
|
|
2006-10-12 07:02:36 +00:00
|
|
|
ut_a(space_id == page_get_space_id(page));
|
|
|
|
ut_a(page_no == page_get_page_no(page));
|
2006-02-16 12:58:18 +00:00
|
|
|
|
2006-10-13 11:55:27 +00:00
|
|
|
btr_page_free_low(index, ext_block, 0, &mtr);
|
2006-02-16 12:58:18 +00:00
|
|
|
|
|
|
|
mlog_write_ulint(field_ref + BTR_EXTERN_PAGE_NO,
|
2006-08-29 09:30:31 +00:00
|
|
|
next_page_no,
|
|
|
|
MLOG_4BYTES, &mtr);
|
branches/innodb+: Merge revisions 2774:2799 from branches/zip:
------------------------------------------------------------------------
r2781 | marko | 2008-10-13 13:40:57 +0300 (Mon, 13 Oct 2008) | 1 line
branches/zip: page_cur_delete_rec(): Call page_zip_validate_low().
------------------------------------------------------------------------
r2783 | vasil | 2008-10-13 18:34:34 +0300 (Mon, 13 Oct 2008) | 9 lines
branches/zip:
Remove mysql-test/patches/bug37312.diff because MySQL "fixed"
Bug#37312 by removing the test.
http://bugs.mysql.com/37312
http://lists.mysql.com/commits/54462
------------------------------------------------------------------------
r2784 | marko | 2008-10-13 21:35:30 +0300 (Mon, 13 Oct 2008) | 1 line
branches/zip: Add missing NULL check to the assertion added in r2781.
------------------------------------------------------------------------
r2785 | marko | 2008-10-13 22:29:12 +0300 (Mon, 13 Oct 2008) | 2 lines
branches/zip: page_cur_delete_rec(): Remove the bogus page_zip_validate_low()
assertion that was added in r2781 and explain why it was bogus.
------------------------------------------------------------------------
r2786 | calvin | 2008-10-14 19:14:47 +0300 (Tue, 14 Oct 2008) | 7 lines
branches/zip: fix Mantis issue #96 Problem compiling ha_innodb.cc
on 64-bit Windows
Change the definition of srv_replication_delay from ulint to ulong.
ulint is 64-bit on Win64.
Approved by: Heikki (on IM)
------------------------------------------------------------------------
r2787 | calvin | 2008-10-14 19:19:41 +0300 (Tue, 14 Oct 2008) | 7 lines
branches/zip: fix compiler warning
Change the definition of add_on from ulint to ullint, to eliminate
the warning in .\btr\btr0cur.c:
conversion from 'ullint' to 'ulint', possible loss of data
Approved by: Heikki (on IM)
------------------------------------------------------------------------
r2793 | marko | 2008-10-15 10:00:06 +0300 (Wed, 15 Oct 2008) | 2 lines
branches/zip: row_create_table_for_mysql(), row_create_index_for_mysql():
Note that the dictionary object will be freed.
------------------------------------------------------------------------
r2794 | marko | 2008-10-15 10:32:40 +0300 (Wed, 15 Oct 2008) | 9 lines
branches/zip: When invoking page_zip_copy_recs(), update the lock table
and the adaptive hash index. This should fix Issue #95 and Issue #87.
page_zip_copy_recs(): Copy PAGE_MAX_TRX_ID as well, to have similar behavior
to page_copy_rec_list_start() and page_copy_rec_list_end().
btr_root_raise_and_insert(), btr_page_split_and_insert(), btr_lift_page_up():
Update the lock table and the adaptive hash index.
------------------------------------------------------------------------
r2797 | marko | 2008-10-15 13:21:54 +0300 (Wed, 15 Oct 2008) | 3 lines
branches/zip: Introduce UNIV_ZIP_COPY for invoking page_zip_copy_recs()
more often in B-tree operations.
------------------------------------------------------------------------
r2799 | marko | 2008-10-15 14:27:42 +0300 (Wed, 15 Oct 2008) | 25 lines
branches/zip: When the server crashes while freeing an externally stored
column of a compressed table, the BTR_EXTERN_LEN field in the BLOB pointer
will be written as 0. Tolerate this in the functions that deal with
externally stored columns. This fixes Issue #80 and was posted at rb://26.
Note that the clustered index record is always deleted or purged last,
after any secondary index records referring to it have been deleted.
btr_free_externally_stored_field(): On an uncompressed table, zero out
the BTR_EXTERN_LEN, so that half-deleted BLOBs can be detected after
crash recovery.
btr_copy_externally_stored_field_prefix(): Return 0 if the BLOB has been
half-deleted.
row_upd_ext_fetch(): Assert that the externally stored column exists.
row_ext_cache_fill(): Allow btr_copy_externally_stored_field_prefix()
to return 0.
row_sel_sec_rec_is_for_blob(): Return FALSE if the BLOB has been half-deleted.
This is correct, because the clustered index record would have been deleted
or purged last, after any secondary index records referring to it had been
deleted.
------------------------------------------------------------------------
2008-10-15 12:09:17 +00:00
|
|
|
/* Zero out the BLOB length. If the server
|
|
|
|
crashes during the execution of this function,
|
|
|
|
trx_rollback_or_clean_all_recovered() could
|
|
|
|
dereference the half-deleted BLOB, fetching a
|
|
|
|
wrong prefix for the BLOB. */
|
2006-02-16 12:58:18 +00:00
|
|
|
mlog_write_ulint(field_ref + BTR_EXTERN_LEN + 4,
|
branches/innodb+: Merge revisions 2774:2799 from branches/zip:
------------------------------------------------------------------------
r2781 | marko | 2008-10-13 13:40:57 +0300 (Mon, 13 Oct 2008) | 1 line
branches/zip: page_cur_delete_rec(): Call page_zip_validate_low().
------------------------------------------------------------------------
r2783 | vasil | 2008-10-13 18:34:34 +0300 (Mon, 13 Oct 2008) | 9 lines
branches/zip:
Remove mysql-test/patches/bug37312.diff because MySQL "fixed"
Bug#37312 by removing the test.
http://bugs.mysql.com/37312
http://lists.mysql.com/commits/54462
------------------------------------------------------------------------
r2784 | marko | 2008-10-13 21:35:30 +0300 (Mon, 13 Oct 2008) | 1 line
branches/zip: Add missing NULL check to the assertion added in r2781.
------------------------------------------------------------------------
r2785 | marko | 2008-10-13 22:29:12 +0300 (Mon, 13 Oct 2008) | 2 lines
branches/zip: page_cur_delete_rec(): Remove the bogus page_zip_validate_low()
assertion that was added in r2781 and explain why it was bogus.
------------------------------------------------------------------------
r2786 | calvin | 2008-10-14 19:14:47 +0300 (Tue, 14 Oct 2008) | 7 lines
branches/zip: fix Mantis issue #96 Problem compiling ha_innodb.cc
on 64-bit Windows
Change the definition of srv_replication_delay from ulint to ulong.
ulint is 64-bit on Win64.
Approved by: Heikki (on IM)
------------------------------------------------------------------------
r2787 | calvin | 2008-10-14 19:19:41 +0300 (Tue, 14 Oct 2008) | 7 lines
branches/zip: fix compiler warning
Change the definition of add_on from ulint to ullint, to eliminate
the warning in .\btr\btr0cur.c:
conversion from 'ullint' to 'ulint', possible loss of data
Approved by: Heikki (on IM)
------------------------------------------------------------------------
r2793 | marko | 2008-10-15 10:00:06 +0300 (Wed, 15 Oct 2008) | 2 lines
branches/zip: row_create_table_for_mysql(), row_create_index_for_mysql():
Note that the dictionary object will be freed.
------------------------------------------------------------------------
r2794 | marko | 2008-10-15 10:32:40 +0300 (Wed, 15 Oct 2008) | 9 lines
branches/zip: When invoking page_zip_copy_recs(), update the lock table
and the adaptive hash index. This should fix Issue #95 and Issue #87.
page_zip_copy_recs(): Copy PAGE_MAX_TRX_ID as well, to have similar behavior
to page_copy_rec_list_start() and page_copy_rec_list_end().
btr_root_raise_and_insert(), btr_page_split_and_insert(), btr_lift_page_up():
Update the lock table and the adaptive hash index.
------------------------------------------------------------------------
r2797 | marko | 2008-10-15 13:21:54 +0300 (Wed, 15 Oct 2008) | 3 lines
branches/zip: Introduce UNIV_ZIP_COPY for invoking page_zip_copy_recs()
more often in B-tree operations.
------------------------------------------------------------------------
r2799 | marko | 2008-10-15 14:27:42 +0300 (Wed, 15 Oct 2008) | 25 lines
branches/zip: When the server crashes while freeing an externally stored
column of a compressed table, the BTR_EXTERN_LEN field in the BLOB pointer
will be written as 0. Tolerate this in the functions that deal with
externally stored columns. This fixes Issue #80 and was posted at rb://26.
Note that the clustered index record is always deleted or purged last,
after any secondary index records referring to it have been deleted.
btr_free_externally_stored_field(): On an uncompressed table, zero out
the BTR_EXTERN_LEN, so that half-deleted BLOBs can be detected after
crash recovery.
btr_copy_externally_stored_field_prefix(): Return 0 if the BLOB has been
half-deleted.
row_upd_ext_fetch(): Assert that the externally stored column exists.
row_ext_cache_fill(): Allow btr_copy_externally_stored_field_prefix()
to return 0.
row_sel_sec_rec_is_for_blob(): Return FALSE if the BLOB has been half-deleted.
This is correct, because the clustered index record would have been deleted
or purged last, after any secondary index records referring to it had been
deleted.
------------------------------------------------------------------------
2008-10-15 12:09:17 +00:00
|
|
|
0,
|
2006-08-29 09:30:31 +00:00
|
|
|
MLOG_4BYTES, &mtr);
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
|
|
|
|
2007-01-18 14:02:56 +00:00
|
|
|
/* Commit mtr and release the BLOB block to save memory. */
|
|
|
|
btr_blob_free(ext_block, TRUE, &mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************
|
|
|
|
Frees the externally stored fields for a record. */
|
2006-02-16 12:58:18 +00:00
|
|
|
static
|
2005-10-27 07:29:40 +00:00
|
|
|
void
|
|
|
|
btr_rec_free_externally_stored_fields(
|
|
|
|
/*==================================*/
|
|
|
|
dict_index_t* index, /* in: index of the data, the index
|
|
|
|
tree MUST be X-latched */
|
2005-11-18 07:40:34 +00:00
|
|
|
rec_t* rec, /* in/out: record */
|
2005-10-27 07:29:40 +00:00
|
|
|
const ulint* offsets,/* in: rec_get_offsets(rec, index) */
|
2006-02-10 15:06:17 +00:00
|
|
|
page_zip_des_t* page_zip,/* in: compressed page whose uncompressed
|
|
|
|
part will be updated, or NULL */
|
2008-08-09 00:15:46 +00:00
|
|
|
enum trx_rb_ctx rb_ctx, /* in: rollback context */
|
2005-10-27 07:29:40 +00:00
|
|
|
mtr_t* mtr) /* in: mini-transaction handle which contains
|
|
|
|
an X-latch to record page and to the index
|
|
|
|
tree */
|
|
|
|
{
|
|
|
|
ulint n_fields;
|
|
|
|
ulint i;
|
|
|
|
|
|
|
|
ut_ad(rec_offs_validate(rec, index, offsets));
|
2006-10-09 19:36:58 +00:00
|
|
|
ut_ad(mtr_memo_contains_page(mtr, rec, MTR_MEMO_PAGE_X_FIX));
|
2005-10-27 07:29:40 +00:00
|
|
|
/* Free possible externally stored fields in the record */
|
|
|
|
|
2006-02-27 09:33:26 +00:00
|
|
|
ut_ad(dict_table_is_comp(index->table) == !!rec_offs_comp(offsets));
|
2005-10-27 07:29:40 +00:00
|
|
|
n_fields = rec_offs_n_fields(offsets);
|
|
|
|
|
|
|
|
for (i = 0; i < n_fields; i++) {
|
|
|
|
if (rec_offs_nth_extern(offsets, i)) {
|
2006-02-21 14:15:11 +00:00
|
|
|
ulint len;
|
2006-08-29 09:30:31 +00:00
|
|
|
byte* data
|
|
|
|
= rec_get_nth_field(rec, offsets, i, &len);
|
2006-02-21 14:15:11 +00:00
|
|
|
ut_a(len >= BTR_EXTERN_FIELD_REF_SIZE);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
btr_free_externally_stored_field(
|
|
|
|
index, data + len - BTR_EXTERN_FIELD_REF_SIZE,
|
2008-08-09 00:15:46 +00:00
|
|
|
rec, offsets, page_zip, i, rb_ctx, mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************
|
|
|
|
Frees the externally stored fields for a record, if the field is mentioned
|
|
|
|
in the update vector. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
btr_rec_free_updated_extern_fields(
|
|
|
|
/*===============================*/
|
|
|
|
dict_index_t* index, /* in: index of rec; the index tree MUST be
|
|
|
|
X-latched */
|
2005-11-18 07:40:34 +00:00
|
|
|
rec_t* rec, /* in/out: record */
|
2006-02-10 15:06:17 +00:00
|
|
|
page_zip_des_t* page_zip,/* in: compressed page whose uncompressed
|
|
|
|
part will be updated, or NULL */
|
2005-10-27 07:29:40 +00:00
|
|
|
const ulint* offsets,/* in: rec_get_offsets(rec, index) */
|
2007-06-19 12:44:45 +00:00
|
|
|
const upd_t* update, /* in: update vector */
|
2008-08-09 00:15:46 +00:00
|
|
|
enum trx_rb_ctx rb_ctx, /* in: rollback context */
|
2005-10-27 07:29:40 +00:00
|
|
|
mtr_t* mtr) /* in: mini-transaction handle which contains
|
|
|
|
an X-latch to record page and to the tree */
|
|
|
|
{
|
2007-06-19 12:44:45 +00:00
|
|
|
ulint n_fields;
|
|
|
|
ulint i;
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
ut_ad(rec_offs_validate(rec, index, offsets));
|
2006-10-09 19:36:58 +00:00
|
|
|
ut_ad(mtr_memo_contains_page(mtr, rec, MTR_MEMO_PAGE_X_FIX));
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/* Free possible externally stored fields in the record */
|
|
|
|
|
|
|
|
n_fields = upd_get_n_fields(update);
|
|
|
|
|
|
|
|
for (i = 0; i < n_fields; i++) {
|
2007-06-19 12:44:45 +00:00
|
|
|
const upd_field_t* ufield = upd_get_nth_field(update, i);
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
if (rec_offs_nth_extern(offsets, ufield->field_no)) {
|
2006-02-21 14:15:11 +00:00
|
|
|
ulint len;
|
2006-09-19 10:14:07 +00:00
|
|
|
byte* data = rec_get_nth_field(
|
|
|
|
rec, offsets, ufield->field_no, &len);
|
2006-02-21 14:15:11 +00:00
|
|
|
ut_a(len >= BTR_EXTERN_FIELD_REF_SIZE);
|
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
btr_free_externally_stored_field(
|
|
|
|
index, data + len - BTR_EXTERN_FIELD_REF_SIZE,
|
|
|
|
rec, offsets, page_zip,
|
2008-08-09 00:15:46 +00:00
|
|
|
ufield->field_no, rb_ctx, mtr);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2008-01-16 10:45:14 +00:00
|
|
|
Copies the prefix of an uncompressed BLOB. The clustered index record
|
|
|
|
that points to this BLOB must be protected by a lock or a page latch. */
|
2006-02-16 12:58:18 +00:00
|
|
|
static
|
2006-09-26 06:22:16 +00:00
|
|
|
ulint
|
2007-01-17 09:07:20 +00:00
|
|
|
btr_copy_blob_prefix(
|
|
|
|
/*=================*/
|
2007-12-20 09:10:42 +00:00
|
|
|
/* out: number of bytes written to buf */
|
2006-09-26 06:22:16 +00:00
|
|
|
byte* buf, /* out: the externally stored part of
|
|
|
|
the field, or a prefix of it */
|
|
|
|
ulint len, /* in: length of buf, in bytes */
|
2007-01-18 09:59:00 +00:00
|
|
|
ulint space_id,/* in: space id of the BLOB pages */
|
2006-09-26 06:22:16 +00:00
|
|
|
ulint page_no,/* in: page number of the first BLOB page */
|
|
|
|
ulint offset) /* in: offset on the first BLOB page */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
2006-09-26 06:22:16 +00:00
|
|
|
ulint copied_len = 0;
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2007-01-17 09:07:20 +00:00
|
|
|
for (;;) {
|
|
|
|
mtr_t mtr;
|
|
|
|
buf_block_t* block;
|
|
|
|
const page_t* page;
|
|
|
|
const byte* blob_header;
|
|
|
|
ulint part_len;
|
|
|
|
ulint copy_len;
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2007-01-17 09:07:20 +00:00
|
|
|
mtr_start(&mtr);
|
2006-02-16 12:58:18 +00:00
|
|
|
|
2007-01-18 09:59:00 +00:00
|
|
|
block = buf_page_get(space_id, 0, page_no, RW_S_LATCH, &mtr);
|
2007-01-17 09:07:20 +00:00
|
|
|
buf_block_dbg_add_level(block, SYNC_EXTERN_STORAGE);
|
|
|
|
page = buf_block_get_frame(block);
|
2006-02-16 12:58:18 +00:00
|
|
|
|
2007-01-17 09:07:20 +00:00
|
|
|
/* Unfortunately, FIL_PAGE_TYPE was uninitialized for
|
|
|
|
many pages until MySQL/InnoDB 5.1.7. */
|
|
|
|
/* ut_ad(fil_page_get_type(page) == FIL_PAGE_TYPE_BLOB); */
|
|
|
|
blob_header = page + offset;
|
|
|
|
part_len = btr_blob_get_part_len(blob_header);
|
|
|
|
copy_len = ut_min(part_len, len - copied_len);
|
|
|
|
|
|
|
|
memcpy(buf + copied_len,
|
|
|
|
blob_header + BTR_BLOB_HDR_SIZE, copy_len);
|
|
|
|
copied_len += copy_len;
|
|
|
|
|
|
|
|
page_no = btr_blob_get_next_page_no(blob_header);
|
|
|
|
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
|
|
|
|
if (page_no == FIL_NULL || copy_len != part_len) {
|
|
|
|
return(copied_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* On other BLOB pages except the first the BLOB header
|
|
|
|
always is at the page data start: */
|
|
|
|
|
|
|
|
offset = FIL_PAGE_DATA;
|
|
|
|
|
|
|
|
ut_ad(copied_len <= len);
|
2006-02-16 12:58:18 +00:00
|
|
|
}
|
2007-01-17 09:07:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2008-01-16 10:45:14 +00:00
|
|
|
Copies the prefix of a compressed BLOB. The clustered index record
|
|
|
|
that points to this BLOB must be protected by a lock or a page latch. */
|
2007-01-17 09:07:20 +00:00
|
|
|
static
|
|
|
|
void
|
|
|
|
btr_copy_zblob_prefix(
|
|
|
|
/*==================*/
|
|
|
|
z_stream* d_stream,/* in/out: the decompressing stream */
|
|
|
|
ulint zip_size,/* in: compressed BLOB page size */
|
2007-01-18 09:59:00 +00:00
|
|
|
ulint space_id,/* in: space id of the BLOB pages */
|
2007-01-17 09:07:20 +00:00
|
|
|
ulint page_no,/* in: page number of the first BLOB page */
|
|
|
|
ulint offset) /* in: offset on the first BLOB page */
|
|
|
|
{
|
2008-03-03 10:25:27 +00:00
|
|
|
ulint page_type = FIL_PAGE_TYPE_ZBLOB;
|
|
|
|
|
2007-01-17 09:07:20 +00:00
|
|
|
ut_ad(ut_is_2pow(zip_size));
|
|
|
|
ut_ad(zip_size >= PAGE_ZIP_MIN_SIZE);
|
|
|
|
ut_ad(zip_size <= UNIV_PAGE_SIZE);
|
|
|
|
ut_ad(space_id);
|
2006-02-16 12:58:18 +00:00
|
|
|
|
2006-02-23 19:25:29 +00:00
|
|
|
for (;;) {
|
2007-01-18 23:10:49 +00:00
|
|
|
buf_page_t* bpage;
|
2007-01-17 09:07:20 +00:00
|
|
|
int err;
|
|
|
|
ulint next_page_no;
|
2006-10-12 11:05:22 +00:00
|
|
|
|
2008-01-16 10:45:14 +00:00
|
|
|
/* There is no latch on bpage directly. Instead,
|
|
|
|
bpage is protected by the B-tree page latch that
|
|
|
|
is being held on the clustered index record, or,
|
|
|
|
in row_merge_copy_blobs(), by an exclusive table lock. */
|
2007-01-18 23:10:49 +00:00
|
|
|
bpage = buf_page_get_zip(space_id, zip_size, page_no);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2007-01-18 23:10:49 +00:00
|
|
|
if (UNIV_UNLIKELY(!bpage)) {
|
|
|
|
ut_print_timestamp(stderr);
|
|
|
|
fprintf(stderr,
|
|
|
|
" InnoDB: Cannot load"
|
|
|
|
" compressed BLOB"
|
|
|
|
" page %lu space %lu\n",
|
|
|
|
(ulong) page_no, (ulong) space_id);
|
|
|
|
return;
|
|
|
|
}
|
2006-10-12 11:05:22 +00:00
|
|
|
|
2008-01-24 08:12:02 +00:00
|
|
|
if (UNIV_UNLIKELY
|
|
|
|
(fil_page_get_type(bpage->zip.data) != page_type)) {
|
2007-01-17 09:07:20 +00:00
|
|
|
ut_print_timestamp(stderr);
|
|
|
|
fprintf(stderr,
|
2008-01-24 08:12:02 +00:00
|
|
|
" InnoDB: Unexpected type %lu of"
|
2007-01-17 09:07:20 +00:00
|
|
|
" compressed BLOB"
|
|
|
|
" page %lu space %lu\n",
|
2007-01-18 23:10:49 +00:00
|
|
|
(ulong) fil_page_get_type(bpage->zip.data),
|
2007-01-17 09:07:20 +00:00
|
|
|
(ulong) page_no, (ulong) space_id);
|
2007-01-18 23:10:49 +00:00
|
|
|
goto end_of_blob;
|
2007-01-17 09:07:20 +00:00
|
|
|
}
|
2006-04-05 13:41:12 +00:00
|
|
|
|
2007-01-18 23:10:49 +00:00
|
|
|
next_page_no = mach_read_from_4(bpage->zip.data + offset);
|
2006-04-05 13:41:12 +00:00
|
|
|
|
2007-01-17 09:07:20 +00:00
|
|
|
if (UNIV_LIKELY(offset == FIL_PAGE_NEXT)) {
|
|
|
|
/* When the BLOB begins at page header,
|
|
|
|
the compressed data payload does not
|
|
|
|
immediately follow the next page pointer. */
|
|
|
|
offset = FIL_PAGE_DATA;
|
|
|
|
} else {
|
|
|
|
offset += 4;
|
|
|
|
}
|
2006-04-05 13:41:12 +00:00
|
|
|
|
2007-01-18 23:10:49 +00:00
|
|
|
d_stream->next_in = bpage->zip.data + offset;
|
2007-01-17 09:07:20 +00:00
|
|
|
d_stream->avail_in = zip_size - offset;
|
2006-04-05 13:41:12 +00:00
|
|
|
|
2007-01-17 09:07:20 +00:00
|
|
|
err = inflate(d_stream, Z_NO_FLUSH);
|
|
|
|
switch (err) {
|
|
|
|
case Z_OK:
|
|
|
|
if (!d_stream->avail_out) {
|
|
|
|
goto end_of_blob;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Z_STREAM_END:
|
|
|
|
if (next_page_no == FIL_NULL) {
|
|
|
|
goto end_of_blob;
|
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
default:
|
2006-09-05 19:41:05 +00:00
|
|
|
inflate_error:
|
2007-01-17 09:07:20 +00:00
|
|
|
ut_print_timestamp(stderr);
|
|
|
|
fprintf(stderr,
|
|
|
|
" InnoDB: inflate() of"
|
|
|
|
" compressed BLOB"
|
2008-01-10 11:06:01 +00:00
|
|
|
" page %lu space %lu returned %d (%s)\n",
|
2007-01-17 09:07:20 +00:00
|
|
|
(ulong) page_no, (ulong) space_id,
|
2008-01-10 11:06:01 +00:00
|
|
|
err, d_stream->msg);
|
2007-01-17 09:07:20 +00:00
|
|
|
case Z_BUF_ERROR:
|
|
|
|
goto end_of_blob;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (next_page_no == FIL_NULL) {
|
|
|
|
if (!d_stream->avail_in) {
|
2006-04-05 13:41:12 +00:00
|
|
|
ut_print_timestamp(stderr);
|
|
|
|
fprintf(stderr,
|
2007-01-17 09:07:20 +00:00
|
|
|
" InnoDB: unexpected end of"
|
2006-08-29 09:30:31 +00:00
|
|
|
" compressed BLOB"
|
2007-01-17 09:07:20 +00:00
|
|
|
" page %lu space %lu\n",
|
|
|
|
(ulong) page_no,
|
|
|
|
(ulong) space_id);
|
|
|
|
} else {
|
|
|
|
err = inflate(d_stream, Z_FINISH);
|
2007-01-18 23:10:49 +00:00
|
|
|
switch (err) {
|
|
|
|
case Z_STREAM_END:
|
|
|
|
case Z_BUF_ERROR:
|
|
|
|
break;
|
|
|
|
default:
|
2007-01-17 09:07:20 +00:00
|
|
|
goto inflate_error;
|
2006-09-06 09:51:00 +00:00
|
|
|
}
|
2006-02-16 12:58:18 +00:00
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2007-01-17 09:07:20 +00:00
|
|
|
end_of_blob:
|
2007-01-18 23:10:49 +00:00
|
|
|
buf_page_release_zip(bpage);
|
2007-01-17 09:07:20 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-05-22 09:30:34 +00:00
|
|
|
|
2007-01-18 23:10:49 +00:00
|
|
|
buf_page_release_zip(bpage);
|
2006-05-22 09:30:34 +00:00
|
|
|
|
2007-01-17 09:07:20 +00:00
|
|
|
/* On other BLOB pages except the first
|
|
|
|
the BLOB header always is at the page header: */
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2007-01-17 09:07:20 +00:00
|
|
|
page_no = next_page_no;
|
|
|
|
offset = FIL_PAGE_NEXT;
|
2008-01-24 08:12:02 +00:00
|
|
|
page_type = FIL_PAGE_TYPE_ZBLOB2;
|
2007-01-17 09:07:20 +00:00
|
|
|
}
|
|
|
|
}
|
2006-02-16 12:58:18 +00:00
|
|
|
|
2007-01-17 09:07:20 +00:00
|
|
|
/***********************************************************************
|
2008-01-16 10:45:14 +00:00
|
|
|
Copies the prefix of an externally stored field of a record. The
|
|
|
|
clustered index record that points to this BLOB must be protected by a
|
|
|
|
lock or a page latch. */
|
2007-01-17 09:07:20 +00:00
|
|
|
static
|
|
|
|
ulint
|
|
|
|
btr_copy_externally_stored_field_prefix_low(
|
|
|
|
/*========================================*/
|
2007-12-20 09:10:42 +00:00
|
|
|
/* out: number of bytes written to buf */
|
2007-01-17 09:07:20 +00:00
|
|
|
byte* buf, /* out: the externally stored part of
|
|
|
|
the field, or a prefix of it */
|
|
|
|
ulint len, /* in: length of buf, in bytes */
|
|
|
|
ulint zip_size,/* in: nonzero=compressed BLOB page size,
|
|
|
|
zero for uncompressed BLOBs */
|
|
|
|
ulint space_id,/* in: space id of the first BLOB page */
|
|
|
|
ulint page_no,/* in: page number of the first BLOB page */
|
|
|
|
ulint offset) /* in: offset on the first BLOB page */
|
|
|
|
{
|
|
|
|
if (UNIV_UNLIKELY(len == 0)) {
|
|
|
|
return(0);
|
|
|
|
}
|
2006-02-16 12:58:18 +00:00
|
|
|
|
2007-01-17 09:07:20 +00:00
|
|
|
if (UNIV_UNLIKELY(zip_size)) {
|
|
|
|
int err;
|
|
|
|
z_stream d_stream;
|
2007-01-29 08:51:20 +00:00
|
|
|
mem_heap_t* heap;
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2007-01-29 08:51:20 +00:00
|
|
|
/* Zlib inflate needs 32 kilobytes for the default
|
|
|
|
window size, plus a few kilobytes for small objects. */
|
|
|
|
heap = mem_heap_create(40000);
|
|
|
|
page_zip_set_alloc(&d_stream, heap);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2007-01-17 09:07:20 +00:00
|
|
|
err = inflateInit(&d_stream);
|
|
|
|
ut_a(err == Z_OK);
|
2006-05-22 09:30:34 +00:00
|
|
|
|
2007-01-17 09:07:20 +00:00
|
|
|
d_stream.next_out = buf;
|
|
|
|
d_stream.avail_out = len;
|
|
|
|
d_stream.avail_in = 0;
|
2006-05-22 09:30:34 +00:00
|
|
|
|
2007-01-17 09:07:20 +00:00
|
|
|
btr_copy_zblob_prefix(&d_stream, zip_size,
|
|
|
|
space_id, page_no, offset);
|
2007-01-18 23:10:49 +00:00
|
|
|
inflateEnd(&d_stream);
|
2007-01-29 08:51:20 +00:00
|
|
|
mem_heap_free(heap);
|
2007-01-17 09:07:20 +00:00
|
|
|
return(d_stream.total_out);
|
|
|
|
} else {
|
|
|
|
return(btr_copy_blob_prefix(buf, len, space_id,
|
|
|
|
page_no, offset));
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-26 06:22:16 +00:00
|
|
|
/***********************************************************************
|
2008-01-16 10:45:14 +00:00
|
|
|
Copies the prefix of an externally stored field of a record. The
|
|
|
|
clustered index record must be protected by a lock or a page latch. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2006-09-26 06:22:16 +00:00
|
|
|
ulint
|
|
|
|
btr_copy_externally_stored_field_prefix(
|
|
|
|
/*====================================*/
|
branches/innodb+: Merge revisions 2774:2799 from branches/zip:
------------------------------------------------------------------------
r2781 | marko | 2008-10-13 13:40:57 +0300 (Mon, 13 Oct 2008) | 1 line
branches/zip: page_cur_delete_rec(): Call page_zip_validate_low().
------------------------------------------------------------------------
r2783 | vasil | 2008-10-13 18:34:34 +0300 (Mon, 13 Oct 2008) | 9 lines
branches/zip:
Remove mysql-test/patches/bug37312.diff because MySQL "fixed"
Bug#37312 by removing the test.
http://bugs.mysql.com/37312
http://lists.mysql.com/commits/54462
------------------------------------------------------------------------
r2784 | marko | 2008-10-13 21:35:30 +0300 (Mon, 13 Oct 2008) | 1 line
branches/zip: Add missing NULL check to the assertion added in r2781.
------------------------------------------------------------------------
r2785 | marko | 2008-10-13 22:29:12 +0300 (Mon, 13 Oct 2008) | 2 lines
branches/zip: page_cur_delete_rec(): Remove the bogus page_zip_validate_low()
assertion that was added in r2781 and explain why it was bogus.
------------------------------------------------------------------------
r2786 | calvin | 2008-10-14 19:14:47 +0300 (Tue, 14 Oct 2008) | 7 lines
branches/zip: fix Mantis issue #96 Problem compiling ha_innodb.cc
on 64-bit Windows
Change the definition of srv_replication_delay from ulint to ulong.
ulint is 64-bit on Win64.
Approved by: Heikki (on IM)
------------------------------------------------------------------------
r2787 | calvin | 2008-10-14 19:19:41 +0300 (Tue, 14 Oct 2008) | 7 lines
branches/zip: fix compiler warning
Change the definition of add_on from ulint to ullint, to eliminate
the warning in .\btr\btr0cur.c:
conversion from 'ullint' to 'ulint', possible loss of data
Approved by: Heikki (on IM)
------------------------------------------------------------------------
r2793 | marko | 2008-10-15 10:00:06 +0300 (Wed, 15 Oct 2008) | 2 lines
branches/zip: row_create_table_for_mysql(), row_create_index_for_mysql():
Note that the dictionary object will be freed.
------------------------------------------------------------------------
r2794 | marko | 2008-10-15 10:32:40 +0300 (Wed, 15 Oct 2008) | 9 lines
branches/zip: When invoking page_zip_copy_recs(), update the lock table
and the adaptive hash index. This should fix Issue #95 and Issue #87.
page_zip_copy_recs(): Copy PAGE_MAX_TRX_ID as well, to have similar behavior
to page_copy_rec_list_start() and page_copy_rec_list_end().
btr_root_raise_and_insert(), btr_page_split_and_insert(), btr_lift_page_up():
Update the lock table and the adaptive hash index.
------------------------------------------------------------------------
r2797 | marko | 2008-10-15 13:21:54 +0300 (Wed, 15 Oct 2008) | 3 lines
branches/zip: Introduce UNIV_ZIP_COPY for invoking page_zip_copy_recs()
more often in B-tree operations.
------------------------------------------------------------------------
r2799 | marko | 2008-10-15 14:27:42 +0300 (Wed, 15 Oct 2008) | 25 lines
branches/zip: When the server crashes while freeing an externally stored
column of a compressed table, the BTR_EXTERN_LEN field in the BLOB pointer
will be written as 0. Tolerate this in the functions that deal with
externally stored columns. This fixes Issue #80 and was posted at rb://26.
Note that the clustered index record is always deleted or purged last,
after any secondary index records referring to it have been deleted.
btr_free_externally_stored_field(): On an uncompressed table, zero out
the BTR_EXTERN_LEN, so that half-deleted BLOBs can be detected after
crash recovery.
btr_copy_externally_stored_field_prefix(): Return 0 if the BLOB has been
half-deleted.
row_upd_ext_fetch(): Assert that the externally stored column exists.
row_ext_cache_fill(): Allow btr_copy_externally_stored_field_prefix()
to return 0.
row_sel_sec_rec_is_for_blob(): Return FALSE if the BLOB has been half-deleted.
This is correct, because the clustered index record would have been deleted
or purged last, after any secondary index records referring to it had been
deleted.
------------------------------------------------------------------------
2008-10-15 12:09:17 +00:00
|
|
|
/* out: the length of the copied field,
|
|
|
|
or 0 if the column was being or has been
|
|
|
|
deleted */
|
2006-09-26 06:22:16 +00:00
|
|
|
byte* buf, /* out: the field, or a prefix of it */
|
|
|
|
ulint len, /* in: length of buf, in bytes */
|
|
|
|
ulint zip_size,/* in: nonzero=compressed BLOB page size,
|
|
|
|
zero for uncompressed BLOBs */
|
|
|
|
const byte* data, /* in: 'internally' stored part of the
|
|
|
|
field containing also the reference to
|
2008-01-16 10:45:14 +00:00
|
|
|
the external part; must be protected by
|
|
|
|
a lock or a page latch */
|
2006-09-26 06:22:16 +00:00
|
|
|
ulint local_len)/* in: length of data, in bytes */
|
|
|
|
{
|
|
|
|
ulint space_id;
|
|
|
|
ulint page_no;
|
|
|
|
ulint offset;
|
|
|
|
|
|
|
|
ut_a(local_len >= BTR_EXTERN_FIELD_REF_SIZE);
|
|
|
|
|
|
|
|
local_len -= BTR_EXTERN_FIELD_REF_SIZE;
|
|
|
|
|
|
|
|
if (UNIV_UNLIKELY(local_len >= len)) {
|
|
|
|
memcpy(buf, data, len);
|
|
|
|
return(len);
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(buf, data, local_len);
|
|
|
|
data += local_len;
|
|
|
|
|
2007-11-27 09:11:45 +00:00
|
|
|
ut_a(memcmp(data, field_ref_zero, BTR_EXTERN_FIELD_REF_SIZE));
|
|
|
|
|
branches/innodb+: Merge revisions 2774:2799 from branches/zip:
------------------------------------------------------------------------
r2781 | marko | 2008-10-13 13:40:57 +0300 (Mon, 13 Oct 2008) | 1 line
branches/zip: page_cur_delete_rec(): Call page_zip_validate_low().
------------------------------------------------------------------------
r2783 | vasil | 2008-10-13 18:34:34 +0300 (Mon, 13 Oct 2008) | 9 lines
branches/zip:
Remove mysql-test/patches/bug37312.diff because MySQL "fixed"
Bug#37312 by removing the test.
http://bugs.mysql.com/37312
http://lists.mysql.com/commits/54462
------------------------------------------------------------------------
r2784 | marko | 2008-10-13 21:35:30 +0300 (Mon, 13 Oct 2008) | 1 line
branches/zip: Add missing NULL check to the assertion added in r2781.
------------------------------------------------------------------------
r2785 | marko | 2008-10-13 22:29:12 +0300 (Mon, 13 Oct 2008) | 2 lines
branches/zip: page_cur_delete_rec(): Remove the bogus page_zip_validate_low()
assertion that was added in r2781 and explain why it was bogus.
------------------------------------------------------------------------
r2786 | calvin | 2008-10-14 19:14:47 +0300 (Tue, 14 Oct 2008) | 7 lines
branches/zip: fix Mantis issue #96 Problem compiling ha_innodb.cc
on 64-bit Windows
Change the definition of srv_replication_delay from ulint to ulong.
ulint is 64-bit on Win64.
Approved by: Heikki (on IM)
------------------------------------------------------------------------
r2787 | calvin | 2008-10-14 19:19:41 +0300 (Tue, 14 Oct 2008) | 7 lines
branches/zip: fix compiler warning
Change the definition of add_on from ulint to ullint, to eliminate
the warning in .\btr\btr0cur.c:
conversion from 'ullint' to 'ulint', possible loss of data
Approved by: Heikki (on IM)
------------------------------------------------------------------------
r2793 | marko | 2008-10-15 10:00:06 +0300 (Wed, 15 Oct 2008) | 2 lines
branches/zip: row_create_table_for_mysql(), row_create_index_for_mysql():
Note that the dictionary object will be freed.
------------------------------------------------------------------------
r2794 | marko | 2008-10-15 10:32:40 +0300 (Wed, 15 Oct 2008) | 9 lines
branches/zip: When invoking page_zip_copy_recs(), update the lock table
and the adaptive hash index. This should fix Issue #95 and Issue #87.
page_zip_copy_recs(): Copy PAGE_MAX_TRX_ID as well, to have similar behavior
to page_copy_rec_list_start() and page_copy_rec_list_end().
btr_root_raise_and_insert(), btr_page_split_and_insert(), btr_lift_page_up():
Update the lock table and the adaptive hash index.
------------------------------------------------------------------------
r2797 | marko | 2008-10-15 13:21:54 +0300 (Wed, 15 Oct 2008) | 3 lines
branches/zip: Introduce UNIV_ZIP_COPY for invoking page_zip_copy_recs()
more often in B-tree operations.
------------------------------------------------------------------------
r2799 | marko | 2008-10-15 14:27:42 +0300 (Wed, 15 Oct 2008) | 25 lines
branches/zip: When the server crashes while freeing an externally stored
column of a compressed table, the BTR_EXTERN_LEN field in the BLOB pointer
will be written as 0. Tolerate this in the functions that deal with
externally stored columns. This fixes Issue #80 and was posted at rb://26.
Note that the clustered index record is always deleted or purged last,
after any secondary index records referring to it have been deleted.
btr_free_externally_stored_field(): On an uncompressed table, zero out
the BTR_EXTERN_LEN, so that half-deleted BLOBs can be detected after
crash recovery.
btr_copy_externally_stored_field_prefix(): Return 0 if the BLOB has been
half-deleted.
row_upd_ext_fetch(): Assert that the externally stored column exists.
row_ext_cache_fill(): Allow btr_copy_externally_stored_field_prefix()
to return 0.
row_sel_sec_rec_is_for_blob(): Return FALSE if the BLOB has been half-deleted.
This is correct, because the clustered index record would have been deleted
or purged last, after any secondary index records referring to it had been
deleted.
------------------------------------------------------------------------
2008-10-15 12:09:17 +00:00
|
|
|
if (!mach_read_from_4(data + BTR_EXTERN_LEN + 4)) {
|
|
|
|
/* The externally stored part of the column has been
|
|
|
|
(partially) deleted. Signal the half-deleted BLOB
|
|
|
|
to the caller. */
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2006-09-26 07:39:02 +00:00
|
|
|
space_id = mach_read_from_4(data + BTR_EXTERN_SPACE_ID);
|
2006-09-26 06:22:16 +00:00
|
|
|
|
2006-09-26 07:39:02 +00:00
|
|
|
page_no = mach_read_from_4(data + BTR_EXTERN_PAGE_NO);
|
2006-09-26 06:22:16 +00:00
|
|
|
|
2006-09-26 07:39:02 +00:00
|
|
|
offset = mach_read_from_4(data + BTR_EXTERN_OFFSET);
|
2006-09-26 06:22:16 +00:00
|
|
|
|
|
|
|
return(local_len
|
|
|
|
+ btr_copy_externally_stored_field_prefix_low(buf + local_len,
|
|
|
|
len - local_len,
|
|
|
|
zip_size,
|
|
|
|
space_id, page_no,
|
|
|
|
offset));
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2008-01-16 10:45:14 +00:00
|
|
|
Copies an externally stored field of a record to mem heap. The
|
|
|
|
clustered index record must be protected by a lock or a page latch. */
|
2006-09-26 06:22:16 +00:00
|
|
|
static
|
|
|
|
byte*
|
|
|
|
btr_copy_externally_stored_field(
|
|
|
|
/*=============================*/
|
|
|
|
/* out: the whole field copied to heap */
|
|
|
|
ulint* len, /* out: length of the whole field */
|
2006-09-26 07:39:02 +00:00
|
|
|
const byte* data, /* in: 'internally' stored part of the
|
2006-09-26 06:22:16 +00:00
|
|
|
field containing also the reference to
|
2008-01-16 10:45:14 +00:00
|
|
|
the external part; must be protected by
|
|
|
|
a lock or a page latch */
|
2006-09-26 06:22:16 +00:00
|
|
|
ulint zip_size,/* in: nonzero=compressed BLOB page size,
|
|
|
|
zero for uncompressed BLOBs */
|
|
|
|
ulint local_len,/* in: length of data */
|
|
|
|
mem_heap_t* heap) /* in: mem heap */
|
|
|
|
{
|
|
|
|
ulint space_id;
|
|
|
|
ulint page_no;
|
|
|
|
ulint offset;
|
|
|
|
ulint extern_len;
|
|
|
|
byte* buf;
|
|
|
|
|
|
|
|
ut_a(local_len >= BTR_EXTERN_FIELD_REF_SIZE);
|
|
|
|
|
|
|
|
local_len -= BTR_EXTERN_FIELD_REF_SIZE;
|
|
|
|
|
|
|
|
space_id = mach_read_from_4(data + local_len + BTR_EXTERN_SPACE_ID);
|
|
|
|
|
|
|
|
page_no = mach_read_from_4(data + local_len + BTR_EXTERN_PAGE_NO);
|
|
|
|
|
|
|
|
offset = mach_read_from_4(data + local_len + BTR_EXTERN_OFFSET);
|
|
|
|
|
|
|
|
/* Currently a BLOB cannot be bigger than 4 GB; we
|
|
|
|
leave the 4 upper bytes in the length field unused */
|
|
|
|
|
|
|
|
extern_len = mach_read_from_4(data + local_len + BTR_EXTERN_LEN + 4);
|
|
|
|
|
|
|
|
buf = mem_heap_alloc(heap, local_len + extern_len);
|
|
|
|
|
|
|
|
memcpy(buf, data, local_len);
|
|
|
|
*len = local_len
|
|
|
|
+ btr_copy_externally_stored_field_prefix_low(buf + local_len,
|
|
|
|
extern_len,
|
|
|
|
zip_size,
|
|
|
|
space_id,
|
|
|
|
page_no, offset);
|
|
|
|
|
|
|
|
return(buf);
|
|
|
|
}
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/***********************************************************************
|
|
|
|
Copies an externally stored field of a record to mem heap. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
byte*
|
|
|
|
btr_rec_copy_externally_stored_field(
|
|
|
|
/*=================================*/
|
|
|
|
/* out: the field copied to heap */
|
2008-01-16 10:45:14 +00:00
|
|
|
const rec_t* rec, /* in: record in a clustered index;
|
|
|
|
must be protected by a lock or a page latch */
|
2005-10-27 07:29:40 +00:00
|
|
|
const ulint* offsets,/* in: array returned by rec_get_offsets() */
|
2006-07-31 06:43:25 +00:00
|
|
|
ulint zip_size,/* in: nonzero=compressed BLOB page size,
|
|
|
|
zero for uncompressed BLOBs */
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint no, /* in: field number */
|
|
|
|
ulint* len, /* out: length of the field */
|
|
|
|
mem_heap_t* heap) /* in: mem heap */
|
|
|
|
{
|
2006-04-05 13:41:12 +00:00
|
|
|
ulint local_len;
|
2007-06-21 08:58:41 +00:00
|
|
|
const byte* data;
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
ut_a(rec_offs_nth_extern(offsets, no));
|
|
|
|
|
|
|
|
/* An externally stored field can contain some initial
|
|
|
|
data from the field, and in the last 20 bytes it has the
|
|
|
|
space id, page number, and offset where the rest of the
|
|
|
|
field data is stored, and the data length in addition to
|
|
|
|
the data stored locally. We may need to store some data
|
|
|
|
locally to get the local record length above the 128 byte
|
|
|
|
limit so that field offsets are stored in two bytes, and
|
|
|
|
the extern bit is available in those two bytes. */
|
|
|
|
|
|
|
|
data = rec_get_nth_field(rec, offsets, no, &local_len);
|
|
|
|
|
2006-02-16 12:58:18 +00:00
|
|
|
return(btr_copy_externally_stored_field(len, data,
|
2006-08-29 09:30:31 +00:00
|
|
|
zip_size, local_len, heap));
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|