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
Initializes an ibuf bitmap page. */
46
ibuf_bitmap_page_init(
47
/*==================*/
48
page_t* page, /* in: bitmap page */
49
mtr_t* mtr); /* in: mtr */
50
/****************************************************************************
51
Resets the free bits of the page in the ibuf bitmap. This is done in a
52
separate mini-transaction, hence this operation does not restrict further
53
work to only ibuf bitmap operations, which would result if the latch to the
54
bitmap page were kept. */
57
ibuf_reset_free_bits_with_type(
58
/*===========================*/
59
ulint type, /* in: index type */
60
page_t* page); /* in: index page; free bits are set to 0 if the index
61
is non-clustered and non-unique and the page level is
63
/****************************************************************************
64
Resets the free bits of the page in the ibuf bitmap. This is done in a
65
separate mini-transaction, hence this operation does not restrict further
66
work to solely ibuf bitmap operations, which would result if the latch to
67
the bitmap page were kept. */
72
dict_index_t* index, /* in: index */
73
page_t* page); /* in: index page; free bits are set to 0 if
74
the index is non-clustered and non-unique and
75
the page level is 0 */
76
/****************************************************************************
77
Updates the free bits of the page in the ibuf bitmap if there is not enough
78
free on the page any more. This is done in a separate mini-transaction, hence
79
this operation does not restrict further work to only ibuf bitmap operations,
80
which would result if the latch to the bitmap page were kept. */
83
ibuf_update_free_bits_if_full(
84
/*==========================*/
85
dict_index_t* index, /* in: index */
86
page_t* page, /* in: index page to which we have added new
87
records; the free bits are updated if the
88
index is non-clustered and non-unique and
89
the page level is 0, and the page becomes
91
ulint max_ins_size,/* in: value of maximum insert size with
92
reorganize before the latest operation
93
performed to the page */
94
ulint increase);/* in: upper limit for the additional space
95
used in the latest operation, if known, or
97
/**************************************************************************
98
Updates the free bits for the page to reflect the present state. Does this
99
in the mtr given, which means that the latching order rules virtually
100
prevent any further operations for this OS thread until mtr is committed. */
103
ibuf_update_free_bits_low(
104
/*======================*/
105
dict_index_t* index, /* in: index */
106
page_t* page, /* in: index page */
107
ulint max_ins_size, /* in: value of maximum insert size
108
with reorganize before the latest
109
operation performed to the page */
110
mtr_t* mtr); /* in: mtr */
111
/**************************************************************************
112
Updates the free bits for the two pages to reflect the present state. Does
113
this in the mtr given, which means that the latching order rules virtually
114
prevent any further operations until mtr is committed. */
117
ibuf_update_free_bits_for_two_pages_low(
118
/*====================================*/
119
dict_index_t* index, /* in: index */
120
page_t* page1, /* in: index page */
121
page_t* page2, /* in: index page */
122
mtr_t* mtr); /* in: mtr */
123
/**************************************************************************
124
A basic partial test if an insert to the insert buffer could be possible and
130
dict_index_t* index); /* in: index where to insert */
131
/**********************************************************************
132
Returns TRUE if the current OS thread is performing an insert buffer
138
/* out: TRUE if inside an insert buffer routine: for instance,
139
a read-ahead of non-ibuf pages is then forbidden */
140
/***************************************************************************
141
Checks if a page address is an ibuf bitmap page (level 3 page) address. */
146
/* out: TRUE if a bitmap page */
147
ulint page_no);/* in: page number */
148
/***************************************************************************
149
Checks if a page is a level 2 or 3 page in the ibuf hierarchy of pages. */
154
/* out: TRUE if level 2 or level 3 page */
155
ulint space, /* in: space id */
156
ulint page_no);/* in: page number */
157
/***************************************************************************
158
Checks if a page is a level 2 or 3 page in the ibuf hierarchy of pages. */
163
/* out: TRUE if level 2 or level 3 page */
164
ulint space, /* in: space id */
165
ulint page_no,/* in: page number */
166
mtr_t* mtr); /* in: mtr which will contain an x-latch to the
167
bitmap page if the page is not one of the fixed
168
address ibuf pages */
169
/*************************************************************************
170
Checks if an index page has so much free space that the free bit should
171
be set TRUE in the ibuf bitmap. */
174
ibuf_index_page_has_free(
175
/*=====================*/
176
/* out: TRUE if there is enough free space */
177
page_t* page); /* in: non-unique secondary index page */
178
/***************************************************************************
179
Frees excess pages from the ibuf free list. This function is called when an OS
180
thread calls fsp services to allocate a new file segment, or a new page to a
181
file segment, and the thread did not own the fsp latch before this call. */
184
ibuf_free_excess_pages(
185
/*===================*/
186
ulint space); /* in: space id */
187
/*************************************************************************
188
Makes an index insert to the insert buffer, instead of directly to the disk
189
page, if this is possible. Does not do insert if the index is clustered
195
/* out: TRUE if success */
196
dtuple_t* entry, /* in: index entry to insert */
197
dict_index_t* index, /* in: index where to insert */
198
ulint space, /* in: space id where to insert */
199
ulint page_no,/* in: page number where to insert */
200
que_thr_t* thr); /* in: query thread */
201
/*************************************************************************
202
When an index page is read from a disk to the buffer pool, this function
203
inserts to the page the possible index entries buffered in the insert buffer.
204
The entries are deleted from the insert buffer. If the page is not read, but
205
created in the buffer pool, this function deletes its buffered entries from
206
the insert buffer; note that there can exist entries if the page belonged to
207
an index which was dropped. */
210
ibuf_merge_or_delete_for_page(
211
/*==========================*/
212
page_t* page, /* in: if page has been read from disk, pointer to
213
the page x-latched, else NULL */
214
ulint space, /* in: space id of the index page */
215
ulint page_no);/* in: page number of the index page */
216
/*************************************************************************
217
Contracts insert buffer trees by reading pages to the buffer pool. */
222
/* out: a lower limit for the combined size in bytes
223
of entries which will be merged from ibuf trees to the
224
pages read, 0 if ibuf is empty */
225
ibool sync); /* in: TRUE if the caller wants to wait for the
226
issued read with the highest tablespace address
228
/*************************************************************************
229
Parses a redo log record of an ibuf bitmap page init. */
232
ibuf_parse_bitmap_init(
233
/*===================*/
234
/* out: end of log record or NULL */
235
byte* ptr, /* in: buffer */
236
byte* end_ptr,/* in: buffer end */
237
page_t* page, /* in: page or NULL */
238
mtr_t* mtr); /* in: mtr or NULL */
239
/**********************************************************************
240
Gets the ibuf count for a given page. */
245
/* out: number of entries in the insert buffer
246
currently buffered for this page */
247
ulint space, /* in: space id */
248
ulint page_no);/* in: page number */
249
/**********************************************************************
250
Prints info of ibuf. */
256
#define IBUF_HEADER_PAGE_NO FSP_IBUF_HEADER_PAGE_NO
257
#define IBUF_TREE_ROOT_PAGE_NO FSP_IBUF_TREE_ROOT_PAGE_NO
259
/* The ibuf header page currently contains only the file segment header
260
for the file segment from which the pages for the ibuf tree are allocated */
261
#define IBUF_HEADER PAGE_DATA
262
#define IBUF_TREE_SEG_HEADER 0 /* fseg header for ibuf tree */
265
#include "ibuf0ibuf.ic"