MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ibuf0ibuf.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1997, 2013, Oracle and/or its affiliates. All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free Software
7 Foundation; version 2 of the License.
8 
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License along with
14 this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
16 
17 *****************************************************************************/
18 
19 /**************************************************/
26 #ifndef ibuf0ibuf_h
27 #define ibuf0ibuf_h
28 
29 #include "univ.i"
30 
31 #include "mtr0mtr.h"
32 #include "dict0mem.h"
33 #include "fsp0fsp.h"
34 
35 #ifndef UNIV_HOTBACKUP
36 # include "ibuf0types.h"
37 
40 #define CHANGE_BUFFER_DEFAULT_SIZE (25)
41 
42 /* Possible operations buffered in the insert/whatever buffer. See
43 ibuf_insert(). DO NOT CHANGE THE VALUES OF THESE, THEY ARE STORED ON DISK. */
44 typedef enum {
45  IBUF_OP_INSERT = 0,
46  IBUF_OP_DELETE_MARK = 1,
47  IBUF_OP_DELETE = 2,
48 
49  /* Number of different operation types. */
50  IBUF_OP_COUNT = 3
51 } ibuf_op_t;
52 
56 typedef enum {
57  IBUF_USE_NONE = 0,
58  IBUF_USE_INSERT, /* insert */
59  IBUF_USE_DELETE_MARK, /* delete */
60  IBUF_USE_INSERT_DELETE_MARK, /* insert+delete */
61  IBUF_USE_DELETE, /* delete+purge */
62  IBUF_USE_ALL, /* insert+delete+purge */
63 
64  IBUF_USE_COUNT /* number of entries in ibuf_use_t */
65 } ibuf_use_t;
66 
68 extern ibuf_use_t ibuf_use;
69 
70 #if defined UNIV_DEBUG || defined UNIV_IBUF_DEBUG
71 
72 extern uint ibuf_debug;
73 #endif /* UNIV_DEBUG || UNIV_IBUF_DEBUG */
74 
76 extern ibuf_t* ibuf;
77 
78 /* The purpose of the insert buffer is to reduce random disk access.
79 When we wish to insert a record into a non-unique secondary index and
80 the B-tree leaf page where the record belongs to is not in the buffer
81 pool, we insert the record into the insert buffer B-tree, indexed by
82 (space_id, page_no). When the page is eventually read into the buffer
83 pool, we look up the insert buffer B-tree for any modifications to the
84 page, and apply these upon the completion of the read operation. This
85 is called the insert buffer merge. */
86 
87 /* The insert buffer merge must always succeed. To guarantee this,
88 the insert buffer subsystem keeps track of the free space in pages for
89 which it can buffer operations. Two bits per page in the insert
90 buffer bitmap indicate the available space in coarse increments. The
91 free bits in the insert buffer bitmap must never exceed the free space
92 on a page. It is safe to decrement or reset the bits in the bitmap in
93 a mini-transaction that is committed before the mini-transaction that
94 affects the free space. It is unsafe to increment the bits in a
95 separately committed mini-transaction, because in crash recovery, the
96 free bits could momentarily be set too high. */
97 
98 /******************************************************************/
100 UNIV_INTERN
101 void
103 /*=======================*/
104 /*********************************************************************/
106 UNIV_INTERN
107 void
109 /*=================*/
110  ulint new_val);
112 /*********************************************************************/
115 UNIV_INTERN
116 void
118 /*===============================*/
119 /***************************************************************/
121 UNIV_INLINE
122 void
124 /*===========*/
125  mtr_t* mtr)
126  __attribute__((nonnull));
127 /***************************************************************/
129 UNIV_INLINE
130 void
132 /*============*/
133  mtr_t* mtr)
134  __attribute__((nonnull));
135 /*********************************************************************/
137 UNIV_INTERN
138 void
140 /*==================*/
141  buf_block_t* block,
142  mtr_t* mtr);
143 /************************************************************************/
152 UNIV_INTERN
153 void
155 /*=================*/
156  buf_block_t* block);
159 /************************************************************************/
172 UNIV_INLINE
173 void
175 /*==========================*/
176  buf_block_t* block,
181  ulint max_ins_size,
184  ulint increase);
187 /**********************************************************************/
195 UNIV_INTERN
196 void
198 /*======================*/
199  const buf_block_t* block,
200  ulint max_ins_size,
205  mtr_t* mtr);
206 /**********************************************************************/
214 UNIV_INTERN
215 void
217 /*======================*/
218  buf_block_t* block,
219  mtr_t* mtr);
220 /**********************************************************************/
227 UNIV_INTERN
228 void
230 /*====================================*/
231  ulint zip_size,
233  buf_block_t* block1,
234  buf_block_t* block2,
235  mtr_t* mtr);
236 /**********************************************************************/
239 UNIV_INLINE
240 ibool
242 /*============*/
244  ulint ignore_sec_unique);
248 /******************************************************************/
255 UNIV_INLINE
256 ibool
258 /*========*/
259  const mtr_t* mtr)
260  __attribute__((nonnull, pure));
261 /***********************************************************************/
264 UNIV_INLINE
265 ibool
267 /*=============*/
268  ulint zip_size,
270  ulint page_no);
271 /***********************************************************************/
275 UNIV_INTERN
276 ibool
278 /*==========*/
279  ulint space,
280  ulint zip_size,
281  ulint page_no,
282 #ifdef UNIV_DEBUG
283  ibool x_latch,
285 #endif /* UNIV_DEBUG */
286  const char* file,
287  ulint line,
288  mtr_t* mtr)
293  __attribute__((warn_unused_result));
294 #ifdef UNIV_DEBUG
295 
302 # define ibuf_page(space, zip_size, page_no, mtr) \
303  ibuf_page_low(space, zip_size, page_no, TRUE, __FILE__, __LINE__, mtr)
304 #else /* UVIV_DEBUG */
305 
312 # define ibuf_page(space, zip_size, page_no, mtr) \
313  ibuf_page_low(space, zip_size, page_no, __FILE__, __LINE__, mtr)
314 #endif /* UVIV_DEBUG */
315 /***********************************************************************/
319 UNIV_INTERN
320 void
322 /*========================*/
323 /*********************************************************************/
328 UNIV_INTERN
329 ibool
331 /*========*/
332  ibuf_op_t op,
333  const dtuple_t* entry,
335  ulint space,
336  ulint zip_size,
337  ulint page_no,
338  que_thr_t* thr);
339 /*********************************************************************/
346 UNIV_INTERN
347 void
349 /*==========================*/
350  buf_block_t* block,
353  ulint space,
354  ulint page_no,
355  ulint zip_size,
357  ibool update_ibuf_bitmap);
362 /*********************************************************************/
367 UNIV_INTERN
368 void
370 /*============================*/
371  ulint space);
372 /*********************************************************************/
377 UNIV_INTERN
378 ulint
380 /*========================*/
381  table_id_t table_id,
384  ibool full);
389 #endif /* !UNIV_HOTBACKUP */
390 /*********************************************************************/
393 UNIV_INTERN
394 byte*
396 /*===================*/
397  byte* ptr,
398  byte* end_ptr,
399  buf_block_t* block,
400  mtr_t* mtr);
401 #ifndef UNIV_HOTBACKUP
402 #ifdef UNIV_IBUF_COUNT_DEBUG
403 /******************************************************************/
407 UNIV_INTERN
408 ulint
409 ibuf_count_get(
410 /*===========*/
411  ulint space,
412  ulint page_no);
413 #endif
414 /******************************************************************/
417 UNIV_INTERN
418 bool
419 ibuf_is_empty(void);
420 /*===============*/
421 /******************************************************************/
423 UNIV_INTERN
424 void
425 ibuf_print(
426 /*=======*/
427  FILE* file);
428 /********************************************************************
429 Read the first two bytes from a record's fourth field (counter field in new
430 records; something else in older records).
431 @return "counter" field, or ULINT_UNDEFINED if for some reason it can't be read */
432 UNIV_INTERN
433 ulint
435 /*=================*/
436  const rec_t* rec);
437 /******************************************************************/
439 UNIV_INTERN
440 void
441 ibuf_close(void);
442 /*============*/
443 
444 /******************************************************************/
447 UNIV_INTERN
448 dberr_t
450 /*========================*/
451  const trx_t* trx,
452  ulint space_id)
453  __attribute__((nonnull, warn_unused_result));
454 
455 #define IBUF_HEADER_PAGE_NO FSP_IBUF_HEADER_PAGE_NO
456 #define IBUF_TREE_ROOT_PAGE_NO FSP_IBUF_TREE_ROOT_PAGE_NO
457 
458 #endif /* !UNIV_HOTBACKUP */
459 
460 /* The ibuf header page currently contains only the file segment header
461 for the file segment from which the pages for the ibuf tree are allocated */
462 #define IBUF_HEADER PAGE_DATA
463 #define IBUF_TREE_SEG_HEADER 0 /* fseg header for ibuf tree */
464 
465 /* The insert buffer tree itself is always located in space 0. */
466 #define IBUF_SPACE_ID 0
467 
468 #ifndef UNIV_NONINL
469 #include "ibuf0ibuf.ic"
470 #endif
471 
472 #endif