1
/******************************************************
6
Created 7/19/1997 Heikki Tuuri
7
*******************************************************/
15
#include "dict0dict.h"
17
#include "que0types.h"
18
#include "ibuf0types.h"
23
/**********************************************************************
24
Creates the insert buffer data struct for a single tablespace. Reads the
25
root page of the insert buffer tree in the tablespace. This function can
26
be called only after the dictionary system has been initialized, as this
27
creates also the insert buffer table and index for this tablespace. */
30
ibuf_data_init_for_space(
31
/*=====================*/
32
/* out, own: ibuf data struct, linked to the list
33
in ibuf control structure. */
34
ulint space); /* in: space id */
35
/**********************************************************************
36
Creates the insert buffer data structure at a database startup and
37
initializes the data structures for the insert buffer of each tablespace. */
40
ibuf_init_at_db_start(void);
41
/*=======================*/
42
/*************************************************************************
43
Reads the biggest tablespace id from the high end of the insert buffer
44
tree and updates the counter in fil_system. */
47
ibuf_update_max_tablespace_id(void);
48
/*===============================*/
49
/*************************************************************************
50
Initializes an ibuf bitmap page. */
53
ibuf_bitmap_page_init(
54
/*==================*/
55
buf_block_t* block, /* in: bitmap page */
56
mtr_t* mtr); /* in: mtr */
57
/****************************************************************************
58
Resets the free bits of the page in the ibuf bitmap. This is done in a
59
separate mini-transaction, hence this operation does not restrict further
60
work to only ibuf bitmap operations, which would result if the latch to the
61
bitmap page were kept. */
66
buf_block_t* block); /* in: index page; free bits are set to 0
67
if the index is a non-clustered
68
non-unique, and page level is 0 */
69
/****************************************************************************
70
Updates the free bits of an uncompressed page in the ibuf bitmap if
71
there is not enough free on the page any more. This is done in a
72
separate mini-transaction, hence this operation does not restrict
73
further work to only ibuf bitmap operations, which would result if the
74
latch to the bitmap page were kept. */
77
ibuf_update_free_bits_if_full(
78
/*==========================*/
79
buf_block_t* block, /* in: index page to which we have added new
80
records; the free bits are updated if the
81
index is non-clustered and non-unique and
82
the page level is 0, and the page becomes
84
ulint max_ins_size,/* in: value of maximum insert size with
85
reorganize before the latest operation
86
performed to the page */
87
ulint increase);/* in: upper limit for the additional space
88
used in the latest operation, if known, or
90
/**************************************************************************
91
Updates the free bits for an uncompressed page to reflect the present state.
92
Does this in the mtr given, which means that the latching order rules virtually
93
prevent any further operations for this OS thread until mtr is committed. */
96
ibuf_update_free_bits_low(
97
/*======================*/
98
const buf_block_t* block, /* in: index page */
99
ulint max_ins_size, /* in: value of
101
with reorganize before
103
performed to the page */
104
mtr_t* mtr); /* in/out: mtr */
105
/**************************************************************************
106
Updates the free bits for a compressed page to reflect the present state.
107
Does this in the mtr given, which means that the latching order rules virtually
108
prevent any further operations for this OS thread until mtr is committed. */
111
ibuf_update_free_bits_zip(
112
/*======================*/
113
buf_block_t* block, /* in/out: index page */
114
mtr_t* mtr); /* in/out: mtr */
115
/**************************************************************************
116
Updates the free bits for the two pages to reflect the present state. Does
117
this in the mtr given, which means that the latching order rules virtually
118
prevent any further operations until mtr is committed. */
121
ibuf_update_free_bits_for_two_pages_low(
122
/*====================================*/
123
ulint zip_size,/* in: compressed page size in bytes;
124
0 for uncompressed pages */
125
buf_block_t* block1, /* in: index page */
126
buf_block_t* block2, /* in: index page */
127
mtr_t* mtr); /* in: mtr */
128
/**************************************************************************
129
A basic partial test if an insert to the insert buffer could be possible and
135
dict_index_t* index, /* in: index where to insert */
136
ulint ignore_sec_unique); /* in: if != 0, we should
137
ignore UNIQUE constraint on
138
a secondary index when we
140
/**********************************************************************
141
Returns TRUE if the current OS thread is performing an insert buffer
147
/* out: TRUE if inside an insert buffer routine: for instance,
148
a read-ahead of non-ibuf pages is then forbidden */
149
/***************************************************************************
150
Checks if a page address is an ibuf bitmap page (level 3 page) address. */
155
/* out: TRUE if a bitmap page */
156
ulint zip_size,/* in: compressed page size in bytes;
157
0 for uncompressed pages */
158
ulint page_no);/* in: page number */
159
/***************************************************************************
160
Checks if a page is a level 2 or 3 page in the ibuf hierarchy of pages. */
165
/* out: TRUE if level 2 or level 3 page */
166
ulint space, /* in: space id */
167
ulint zip_size,/* in: compressed page size in bytes, or 0 */
168
ulint page_no);/* in: page number */
169
/***************************************************************************
170
Checks if a page is a level 2 or 3 page in the ibuf hierarchy of pages. */
175
/* out: TRUE if level 2 or level 3 page */
176
ulint space, /* in: space id */
177
ulint zip_size,/* in: compressed page size in bytes, or 0 */
178
ulint page_no,/* in: page number */
179
mtr_t* mtr); /* in: mtr which will contain an x-latch to the
180
bitmap page if the page is not one of the fixed
181
address ibuf pages */
182
/***************************************************************************
183
Frees excess pages from the ibuf free list. This function is called when an OS
184
thread calls fsp services to allocate a new file segment, or a new page to a
185
file segment, and the thread did not own the fsp latch before this call. */
188
ibuf_free_excess_pages(
189
/*===================*/
190
ulint space); /* in: space id */
191
/*************************************************************************
192
Makes an index insert to the insert buffer, instead of directly to the disk
193
page, if this is possible. Does not do insert if the index is clustered
199
/* out: TRUE if success */
200
const dtuple_t* entry, /* in: index entry to insert */
201
dict_index_t* index, /* in: index where to insert */
202
ulint space, /* in: space id where to insert */
203
ulint zip_size,/* in: compressed page size in bytes, or 0 */
204
ulint page_no,/* in: page number where to insert */
205
que_thr_t* thr); /* in: query thread */
206
/*************************************************************************
207
When an index page is read from a disk to the buffer pool, this function
208
inserts to the page the possible index entries buffered in the insert buffer.
209
The entries are deleted from the insert buffer. If the page is not read, but
210
created in the buffer pool, this function deletes its buffered entries from
211
the insert buffer; there can exist entries for such a page if the page
212
belonged to an index which subsequently was dropped. */
215
ibuf_merge_or_delete_for_page(
216
/*==========================*/
217
buf_block_t* block, /* in: if page has been read from
218
disk, pointer to the page x-latched,
220
ulint space, /* in: space id of the index page */
221
ulint page_no,/* in: page number of the index page */
222
ulint zip_size,/* in: compressed page size in bytes,
224
ibool update_ibuf_bitmap);/* in: normally this is set
225
to TRUE, but if we have deleted or are
226
deleting the tablespace, then we
227
naturally do not want to update a
228
non-existent bitmap page */
229
/*************************************************************************
230
Deletes all entries in the insert buffer for a given space id. This is used
231
in DISCARD TABLESPACE and IMPORT TABLESPACE.
232
NOTE: this does not update the page free bitmaps in the space. The space will
233
become CORRUPT when you call this function! */
236
ibuf_delete_for_discarded_space(
237
/*============================*/
238
ulint space); /* in: space id */
239
/*************************************************************************
240
Contracts insert buffer trees by reading pages to the buffer pool. */
245
/* out: a lower limit for the combined size in bytes
246
of entries which will be merged from ibuf trees to the
247
pages read, 0 if ibuf is empty */
248
ibool sync); /* in: TRUE if the caller wants to wait for the
249
issued read with the highest tablespace address
251
/*************************************************************************
252
Contracts insert buffer trees by reading pages to the buffer pool. */
255
ibuf_contract_for_n_pages(
256
/*======================*/
257
/* out: a lower limit for the combined size in bytes
258
of entries which will be merged from ibuf trees to the
259
pages read, 0 if ibuf is empty */
260
ibool sync, /* in: TRUE if the caller wants to wait for the
261
issued read with the highest tablespace address
263
ulint n_pages);/* in: try to read at least this many pages to
264
the buffer pool and merge the ibuf contents to
266
/*************************************************************************
267
Parses a redo log record of an ibuf bitmap page init. */
270
ibuf_parse_bitmap_init(
271
/*===================*/
272
/* out: end of log record or NULL */
273
byte* ptr, /* in: buffer */
274
byte* end_ptr,/* in: buffer end */
275
buf_block_t* block, /* in: block or NULL */
276
mtr_t* mtr); /* in: mtr or NULL */
277
#ifdef UNIV_IBUF_COUNT_DEBUG
278
/**********************************************************************
279
Gets the ibuf count for a given page. */
284
/* out: number of entries in the insert buffer
285
currently buffered for this page */
286
ulint space, /* in: space id */
287
ulint page_no);/* in: page number */
289
/**********************************************************************
290
Looks if the insert buffer is empty. */
295
/* out: TRUE if empty */
296
/**********************************************************************
297
Prints info of ibuf. */
302
FILE* file); /* in: file where to print */
304
#define IBUF_HEADER_PAGE_NO FSP_IBUF_HEADER_PAGE_NO
305
#define IBUF_TREE_ROOT_PAGE_NO FSP_IBUF_TREE_ROOT_PAGE_NO
307
/* The ibuf header page currently contains only the file segment header
308
for the file segment from which the pages for the ibuf tree are allocated */
309
#define IBUF_HEADER PAGE_DATA
310
#define IBUF_TREE_SEG_HEADER 0 /* fseg header for ibuf tree */
313
#include "ibuf0ibuf.ic"