17
17
*****************************************************************************/
19
/******************************************************
19
/**************************************************//**
20
@file include/ibuf0ibuf.ic
22
23
Created 7/19/1997 Heikki Tuuri
23
24
*******************************************************/
26
26
#include "page0page.h"
27
27
#include "page0zip.h"
28
#ifndef UNIV_HOTBACKUP
31
/** Counter for ibuf_should_try() */
29
32
extern ulint ibuf_flush_count;
31
/* If this number is n, an index page must contain at least the page size
32
per n bytes of free space for ibuf to try to buffer inserts to this page.
33
If there is this much of free space, the corresponding bits are set in the
34
/** An index page must contain at least UNIV_PAGE_SIZE /
35
IBUF_PAGE_SIZE_PER_FREE_SPACE bytes of free space for ibuf to try to
36
buffer inserts to this page. If there is this much of free space, the
37
corresponding bits are set in the ibuf bitmap. */
35
38
#define IBUF_PAGE_SIZE_PER_FREE_SPACE 32
37
/* Insert buffer struct */
40
/** Insert buffer struct */
39
41
struct ibuf_struct{
40
ulint size; /* current size of the ibuf index
42
ulint size; /*!< current size of the ibuf index
42
ulint max_size; /* recommended maximum size of the
44
ulint max_size; /*!< recommended maximum size of the
43
45
ibuf index tree, in pages */
44
ulint seg_size; /* allocated pages of the file
46
ulint seg_size; /*!< allocated pages of the file
45
47
segment containing ibuf header and
47
ibool empty; /* after an insert to the ibuf tree
49
ibool empty; /*!< after an insert to the ibuf tree
48
50
is performed, this is set to FALSE,
49
51
and if a contract operation finds
50
52
the tree empty, this is set to
52
ulint free_list_len; /* length of the free list */
53
ulint height; /* tree height */
54
dict_index_t* index; /* insert buffer index */
54
ulint free_list_len; /*!< length of the free list */
55
ulint height; /*!< tree height */
56
dict_index_t* index; /*!< insert buffer index */
56
ulint n_inserts; /* number of inserts made to
58
ulint n_inserts; /*!< number of inserts made to
57
59
the insert buffer */
58
ulint n_merges; /* number of pages merged */
59
ulint n_merged_recs; /* number of records merged */
60
ulint n_merges; /*!< number of pages merged */
61
ulint n_merged_recs; /*!< number of records merged */
62
/****************************************************************************
64
/************************************************************************//**
63
65
Sets the free bit of the page in the ibuf bitmap. This is done in a separate
64
66
mini-transaction, hence this operation does not restrict further work to only
65
67
ibuf bitmap operations, which would result if the latch to the bitmap page
69
71
ibuf_set_free_bits_func(
70
72
/*====================*/
71
buf_block_t* block, /* in: index page of a non-clustered index;
73
buf_block_t* block, /*!< in: index page of a non-clustered index;
72
74
free bit is reset if page level is 0 */
73
75
#ifdef UNIV_IBUF_DEBUG
74
ulint max_val,/* in: ULINT_UNDEFINED or a maximum
76
ulint max_val,/*!< in: ULINT_UNDEFINED or a maximum
75
77
value which the bits must have before
76
78
setting; this is for debugging */
77
79
#endif /* UNIV_IBUF_DEBUG */
78
ulint val); /* in: value to set: < 4 */
80
ulint val); /*!< in: value to set: < 4 */
79
81
#ifdef UNIV_IBUF_DEBUG
80
82
# define ibuf_set_free_bits(b,v,max) ibuf_set_free_bits_func(b,max,v)
81
83
#else /* UNIV_IBUF_DEBUG */
82
84
# define ibuf_set_free_bits(b,v,max) ibuf_set_free_bits_func(b,v)
83
85
#endif /* UNIV_IBUF_DEBUG */
85
/**************************************************************************
87
/**********************************************************************//**
86
88
A basic partial test if an insert to the insert buffer could be possible and
92
dict_index_t* index, /* in: index where to insert */
93
ulint ignore_sec_unique) /* in: if != 0, we should
94
dict_index_t* index, /*!< in: index where to insert */
95
ulint ignore_sec_unique) /*!< in: if != 0, we should
94
96
ignore UNIQUE constraint on
95
97
a secondary index when we
115
/***************************************************************************
116
Checks if a page address is an ibuf bitmap page address. */
117
/***********************************************************************//**
118
Checks if a page address is an ibuf bitmap page address.
119
@return TRUE if a bitmap page */
119
122
ibuf_bitmap_page(
120
123
/*=============*/
121
/* out: TRUE if a bitmap page */
122
ulint zip_size,/* in: compressed page size in bytes;
124
ulint zip_size,/*!< in: compressed page size in bytes;
123
125
0 for uncompressed pages */
124
ulint page_no)/* in: page number */
126
ulint page_no)/*!< in: page number */
126
128
ut_ad(ut_is_2pow(zip_size));
134
136
== FSP_IBUF_BITMAP_OFFSET));
137
/*************************************************************************
138
Translates the free space on a page to a value in the ibuf bitmap.*/
139
/*********************************************************************//**
140
Translates the free space on a page to a value in the ibuf bitmap.
141
@return value for ibuf bitmap bits */
141
144
ibuf_index_page_calc_free_bits(
142
145
/*===========================*/
143
/* out: value for ibuf bitmap bits */
144
ulint zip_size, /* in: compressed page size in bytes;
146
ulint zip_size, /*!< in: compressed page size in bytes;
145
147
0 for uncompressed pages */
146
ulint max_ins_size) /* in: maximum insert size after reorganize
148
ulint max_ins_size) /*!< in: maximum insert size after reorganize
173
/*************************************************************************
174
Translates the ibuf free bits to the free space on a page in bytes. */
175
/*********************************************************************//**
176
Translates the ibuf free bits to the free space on a page in bytes.
177
@return maximum insert size after reorganize for the page */
177
180
ibuf_index_page_calc_free_from_bits(
178
181
/*================================*/
179
/* out: maximum insert size after reorganize for the
181
ulint zip_size,/* in: compressed page size in bytes;
182
ulint zip_size,/*!< in: compressed page size in bytes;
182
183
0 for uncompressed pages */
183
ulint bits) /* in: value for ibuf bitmap bits */
184
ulint bits) /*!< in: value for ibuf bitmap bits */
186
187
ut_ad(ut_is_2pow(zip_size));
202
203
return(bits * (UNIV_PAGE_SIZE / IBUF_PAGE_SIZE_PER_FREE_SPACE));
205
/*************************************************************************
206
Translates the free space on a compressed page to a value in the ibuf bitmap.*/
206
/*********************************************************************//**
207
Translates the free space on a compressed page to a value in the ibuf bitmap.
208
@return value for ibuf bitmap bits */
209
211
ibuf_index_page_calc_free_zip(
210
212
/*==========================*/
211
/* out: value for ibuf bitmap bits */
213
/* in: compressed page size in bytes */
214
const buf_block_t* block) /* in: buffer block */
214
/*!< in: compressed page size in bytes */
215
const buf_block_t* block) /*!< in: buffer block */
216
217
ulint max_ins_size;
217
218
const page_zip_des_t* page_zip;
236
237
return(ibuf_index_page_calc_free_bits(zip_size, max_ins_size));
239
/*************************************************************************
240
Translates the free space on a page to a value in the ibuf bitmap.*/
240
/*********************************************************************//**
241
Translates the free space on a page to a value in the ibuf bitmap.
242
@return value for ibuf bitmap bits */
243
245
ibuf_index_page_calc_free(
244
246
/*======================*/
245
/* out: value for ibuf bitmap bits */
246
ulint zip_size,/* in: compressed page size in bytes;
247
ulint zip_size,/*!< in: compressed page size in bytes;
247
248
0 for uncompressed pages */
248
const buf_block_t* block) /* in: buffer block */
249
const buf_block_t* block) /*!< in: buffer block */
250
251
ut_ad(zip_size == buf_block_get_zip_size(block));
279
280
ibuf_update_free_bits_if_full(
280
281
/*==========================*/
281
buf_block_t* block, /* in: index page to which we have added new
282
buf_block_t* block, /*!< in: index page to which we have added new
282
283
records; the free bits are updated if the
283
284
index is non-clustered and non-unique and
284
285
the page level is 0, and the page becomes
286
ulint max_ins_size,/* in: value of maximum insert size with
287
ulint max_ins_size,/*!< in: value of maximum insert size with
287
288
reorganize before the latest operation
288
289
performed to the page */
289
ulint increase)/* in: upper limit for the additional space
290
ulint increase)/*!< in: upper limit for the additional space
290
291
used in the latest operation, if known, or
291
292
ULINT_UNDEFINED */