1
/******************************************************
6
Created 7/19/1997 Heikki Tuuri
7
*******************************************************/
10
#include "page0page.h"
12
extern ulint ibuf_flush_count;
14
/* If this number is n, an index page must contain at least the page size
15
per n bytes of free space for ibuf to try to buffer inserts to this page.
16
If there is this much of free space, the corresponding bits are set in the
18
#define IBUF_PAGE_SIZE_PER_FREE_SPACE 32
20
/* Insert buffer data struct for a single tablespace */
21
struct ibuf_data_struct{
22
ulint space; /* space id */
23
ulint seg_size;/* allocated pages if the file segment
24
containing ibuf header and tree */
25
ulint size; /* size of the insert buffer tree in pages */
26
ibool empty; /* after an insert to the ibuf tree is
27
performed, this is set to FALSE, and if a
28
contract operation finds the tree empty, this
31
/* length of the free list */
32
ulint height; /* tree height */
33
dict_index_t* index; /* insert buffer index */
34
UT_LIST_NODE_T(ibuf_data_t) data_list;
35
/* list of ibuf data structs */
36
ulint n_inserts;/* number of inserts made to the insert
38
ulint n_merges;/* number of pages merged */
39
ulint n_merged_recs;/* number of records merged */
43
ulint size; /* current size of the ibuf index
45
ulint max_size; /* recommended maximum size in pages
46
for the ibuf index tree */
47
UT_LIST_BASE_NODE_T(ibuf_data_t) data_list;
48
/* list of ibuf data structs for
52
/****************************************************************************
53
Sets the free bit of the page in the ibuf bitmap. This is done in a separate
54
mini-transaction, hence this operation does not restrict further work to only
55
ibuf bitmap operations, which would result if the latch to the bitmap page
61
ulint type, /* in: index type */
62
page_t* page, /* in: index page; free bit is reset if the index is
63
a non-clustered non-unique, and page level is 0 */
64
ulint val, /* in: value to set: < 4 */
65
ulint max_val);/* in: ULINT_UNDEFINED or a maximum value which
66
the bits must have before setting; this is for
69
/**************************************************************************
70
A basic partial test if an insert to the insert buffer could be possible and
76
dict_index_t* index, /* in: index where to insert */
77
ulint ignore_sec_unique) /* in: if != 0, we should
78
ignore UNIQUE constraint on
79
a secondary index when we
82
if (!(index->type & DICT_CLUSTERED)
83
&& (ignore_sec_unique || !(index->type & DICT_UNIQUE))) {
87
if (ibuf_flush_count % 8 == 0) {
89
buf_LRU_try_free_flushed_blocks();
98
/***************************************************************************
99
Checks if a page address is an ibuf bitmap page address. */
104
/* out: TRUE if a bitmap page */
105
ulint page_no)/* in: page number */
107
if (page_no % XDES_DESCRIBED_PER_PAGE == FSP_IBUF_BITMAP_OFFSET) {
115
/*************************************************************************
116
Translates the free space on a page to a value in the ibuf bitmap.*/
119
ibuf_index_page_calc_free_bits(
120
/*===========================*/
121
/* out: value for ibuf bitmap bits */
122
ulint max_ins_size) /* in: maximum insert size after reorganize
127
n = max_ins_size / (UNIV_PAGE_SIZE / IBUF_PAGE_SIZE_PER_FREE_SPACE);
140
/*************************************************************************
141
Translates the ibuf free bits to the free space on a page in bytes. */
144
ibuf_index_page_calc_free_from_bits(
145
/*================================*/
146
/* out: maximum insert size after reorganize for the
148
ulint bits) /* in: value for ibuf bitmap bits */
153
return(4 * UNIV_PAGE_SIZE / IBUF_PAGE_SIZE_PER_FREE_SPACE);
156
return(bits * UNIV_PAGE_SIZE / IBUF_PAGE_SIZE_PER_FREE_SPACE);
159
/*************************************************************************
160
Translates the free space on a page to a value in the ibuf bitmap.*/
163
ibuf_index_page_calc_free(
164
/*======================*/
165
/* out: value for ibuf bitmap bits */
166
page_t* page) /* in: non-unique secondary index page */
168
return(ibuf_index_page_calc_free_bits(
169
page_get_max_insert_size_after_reorganize(page, 1)));
172
/****************************************************************************
173
Updates the free bits of the page in the ibuf bitmap if there is not enough
174
free on the page any more. This is done in a separate mini-transaction, hence
175
this operation does not restrict further work to only ibuf bitmap operations,
176
which would result if the latch to the bitmap page were kept. */
179
ibuf_update_free_bits_if_full(
180
/*==========================*/
181
dict_index_t* index, /* in: index */
182
page_t* page, /* in: index page to which we have added new
183
records; the free bits are updated if the
184
index is non-clustered and non-unique and
185
the page level is 0, and the page becomes
187
ulint max_ins_size,/* in: value of maximum insert size with
188
reorganize before the latest operation
189
performed to the page */
190
ulint increase)/* in: upper limit for the additional space
191
used in the latest operation, if known, or
197
before = ibuf_index_page_calc_free_bits(max_ins_size);
199
if (max_ins_size >= increase) {
200
#if ULINT32_UNDEFINED <= UNIV_PAGE_SIZE
201
# error "ULINT32_UNDEFINED <= UNIV_PAGE_SIZE"
203
after = ibuf_index_page_calc_free_bits(max_ins_size
205
#ifdef UNIV_IBUF_DEBUG
206
ut_a(after <= ibuf_index_page_calc_free(page));
209
after = ibuf_index_page_calc_free(page);
213
/* We move the page to the front of the buffer pool LRU list:
214
the purpose of this is to prevent those pages to which we
215
cannot make inserts using the insert buffer from slipping
216
out of the buffer pool */
218
buf_page_make_young(page);
221
if (before > after) {
222
ibuf_set_free_bits(index->type, page, after, before);