InnoDB Plugin  1.0
btr0btr.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1994, 2013, Oracle and/or its affiliates. All Rights Reserved.
4 Copyright (c) 2012, Facebook Inc.
5 
6 This program is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free Software
8 Foundation; version 2 of the License.
9 
10 This program is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
17 
18 *****************************************************************************/
19 
20 /**************************************************/
27 #ifndef btr0btr_h
28 #define btr0btr_h
29 
30 #include "univ.i"
31 
32 #include "dict0dict.h"
33 #include "data0data.h"
34 #include "page0cur.h"
35 #include "mtr0mtr.h"
36 #include "btr0types.h"
37 
38 #ifndef UNIV_HOTBACKUP
39 
41 #define BTR_PAGE_MAX_REC_SIZE (UNIV_PAGE_SIZE / 2 - 200)
42 
52 #define BTR_MAX_LEVELS 100
53 
57  BTR_SEARCH_LEAF = RW_S_LATCH,
59  BTR_MODIFY_LEAF = RW_X_LATCH,
61  BTR_NO_LATCHES = RW_NO_LATCH,
70 };
71 
72 /* BTR_INSERT, BTR_DELETE and BTR_DELETE_MARK are mutually exclusive. */
73 
77 #define BTR_INSERT 512
78 
81 #define BTR_ESTIMATE 1024
82 
86 #define BTR_IGNORE_SEC_UNIQUE 2048
87 
90 #define BTR_DELETE_MARK 4096
91 
94 #define BTR_DELETE 8192
95 
98 #define BTR_ALREADY_S_LATCHED 16384
99 
100 #define BTR_LATCH_MODE_WITHOUT_FLAGS(latch_mode) \
101  ((latch_mode) & ~(BTR_INSERT \
102  | BTR_DELETE_MARK \
103  | BTR_DELETE \
104  | BTR_ESTIMATE \
105  | BTR_IGNORE_SEC_UNIQUE \
106  | BTR_ALREADY_S_LATCHED))
107 #endif /* UNIV_HOTBACKUP */
108 
109 /**************************************************************/
111 UNIV_INTERN
112 void
114 /*==================*/
115  const buf_block_t* block,
116  const dict_index_t* index)
117  UNIV_COLD __attribute__((nonnull));
118 
122 #define btr_assert_not_corrupted(block, index) \
123  if ((ibool) !!page_is_comp(buf_block_get_frame(block)) \
124  != dict_table_is_comp((index)->table)) { \
125  btr_corruption_report(block, index); \
126  ut_error; \
127  }
128 
129 #ifndef UNIV_HOTBACKUP
130 #ifdef UNIV_BLOB_DEBUG
131 # include "ut0rbt.h"
133 struct btr_blob_dbg_t
134 {
135  unsigned blob_page_no:32;
136  unsigned ref_page_no:32;
137  unsigned ref_heap_no:16;
138  unsigned ref_field_no:10;
139  unsigned owner:1;
140  unsigned always_owner:1;
144  unsigned del:1;
146 };
147 
148 /**************************************************************/
150 UNIV_INTERN
151 void
152 btr_blob_dbg_add_blob(
153 /*==================*/
154  const rec_t* rec,
155  ulint field_no,
156  ulint page_no,
157  dict_index_t* index,
158  const char* ctx)
159  __attribute__((nonnull));
160 /**************************************************************/
164 UNIV_INTERN
165 void
166 btr_blob_dbg_print(
167 /*===============*/
168  const dict_index_t* index)
169  __attribute__((nonnull));
170 /**************************************************************/
174 UNIV_INTERN
175 ibool
176 btr_blob_dbg_is_empty(
177 /*==================*/
178  dict_index_t* index,
179  ulint page_no)
180  __attribute__((nonnull, warn_unused_result));
181 
182 /**************************************************************/
184 UNIV_INTERN
185 void
186 btr_blob_dbg_set_deleted_flag(
187 /*==========================*/
188  const rec_t* rec,
189  dict_index_t* index,
190  const ulint* offsets,
191  ibool del)
192  __attribute__((nonnull));
193 /**************************************************************/
195 UNIV_INTERN
196 void
197 btr_blob_dbg_owner(
198 /*===============*/
199  const rec_t* rec,
200  dict_index_t* index,
201  const ulint* offsets,
202  ulint i,
203  ibool own)
204  __attribute__((nonnull));
206 # define btr_blob_dbg_assert_empty(index, page_no) \
207  ut_a(btr_blob_dbg_is_empty(index, page_no))
208 #else /* UNIV_BLOB_DEBUG */
209 # define btr_blob_dbg_add_blob(rec, field_no, page, index, ctx) ((void) 0)
210 # define btr_blob_dbg_set_deleted_flag(rec, index, offsets, del)((void) 0)
211 # define btr_blob_dbg_owner(rec, index, offsets, i, val) ((void) 0)
212 # define btr_blob_dbg_assert_empty(index, page_no) ((void) 0)
213 #endif /* UNIV_BLOB_DEBUG */
214 
215 /**************************************************************/
218 UNIV_INTERN
219 page_t*
221 /*=========*/
222  const dict_index_t* index,
223  mtr_t* mtr)
224  __attribute__((nonnull));
225 
226 /**************************************************************/
229 UNIV_INTERN
230 dberr_t
232 /*======================*/
233  const dict_index_t* index)
234  __attribute__((nonnull, warn_unused_result));
235 
236 /**************************************************************/
241 UNIV_INTERN
242 ulint
244 /*===========*/
245  dict_index_t* index,
246  mtr_t* mtr)
247  __attribute__((nonnull, warn_unused_result));
248 /**************************************************************/
250 UNIV_INLINE
253 /*===============*/
254  ulint space,
255  ulint zip_size,
257  ulint page_no,
258  ulint mode,
259  const char* file,
260  ulint line,
261 # ifdef UNIV_SYNC_DEBUG
262  const dict_index_t* index,
264 # endif /* UNIV_SYNC_DEBUG */
265  mtr_t* mtr);
266 # ifdef UNIV_SYNC_DEBUG
267 
275 # define btr_block_get(space,zip_size,page_no,mode,index,mtr) \
276  btr_block_get_func(space,zip_size,page_no,mode, \
277  __FILE__,__LINE__,index,mtr)
278 # else /* UNIV_SYNC_DEBUG */
279 
287 # define btr_block_get(space,zip_size,page_no,mode,idx,mtr) \
288  btr_block_get_func(space,zip_size,page_no,mode,__FILE__,__LINE__,mtr)
289 # endif /* UNIV_SYNC_DEBUG */
290 
298 # define btr_page_get(space,zip_size,page_no,mode,idx,mtr) \
299  buf_block_get_frame(btr_block_get(space,zip_size,page_no,mode,idx,mtr))
300 #endif /* !UNIV_HOTBACKUP */
301 /**************************************************************/
304 UNIV_INLINE
305 index_id_t
307 /*==================*/
308  const page_t* page)
309  __attribute__((nonnull, pure, warn_unused_result));
310 #ifndef UNIV_HOTBACKUP
311 /********************************************************/
314 UNIV_INLINE
315 ulint
317 /*===================*/
318  const page_t* page)
319  __attribute__((nonnull, pure, warn_unused_result));
320 #define btr_page_get_level(page, mtr) btr_page_get_level_low(page)
321 /********************************************************/
324 UNIV_INLINE
325 ulint
327 /*==============*/
328  const page_t* page,
329  mtr_t* mtr)
330  __attribute__((nonnull, warn_unused_result));
331 /********************************************************/
334 UNIV_INLINE
335 ulint
337 /*==============*/
338  const page_t* page,
339  mtr_t* mtr)
340  __attribute__((nonnull, warn_unused_result));
341 /*************************************************************/
345 UNIV_INTERN
346 rec_t*
348 /*==================*/
349  rec_t* rec,
350  mtr_t* mtr)
352  __attribute__((nonnull, warn_unused_result));
353 /*************************************************************/
357 UNIV_INTERN
358 rec_t*
360 /*==================*/
361  rec_t* rec,
362  mtr_t* mtr)
364  __attribute__((nonnull, warn_unused_result));
365 /**************************************************************/
367 UNIV_INLINE
368 void
370 /*==================*/
371  buf_block_t* block,
372  ulint latch_mode,
374  mtr_t* mtr)
375  __attribute__((nonnull));
376 /**************************************************************/
383 UNIV_INLINE
384 ulint
386 /*===========================*/
387  const rec_t* rec,
388  const ulint* offsets)
389  __attribute__((nonnull, pure, warn_unused_result));
390 /************************************************************/
393 UNIV_INTERN
394 ulint
395 btr_create(
396 /*=======*/
397  ulint type,
398  ulint space,
399  ulint zip_size,
401  index_id_t index_id,
402  dict_index_t* index,
403  mtr_t* mtr)
404  __attribute__((nonnull));
405 /************************************************************/
408 UNIV_INTERN
409 void
411 /*==================*/
412  ulint space,
413  ulint zip_size,
415  ulint root_page_no);
416 /************************************************************/
418 UNIV_INTERN
419 void
421 /*==========*/
422  ulint space,
423  ulint zip_size,
425  ulint root_page_no,
426  mtr_t* mtr)
427  __attribute__((nonnull));
428 /*************************************************************/
435 UNIV_INTERN
436 rec_t*
438 /*======================*/
439  ulint flags,
440  btr_cur_t* cursor,
444  ulint** offsets,
445  mem_heap_t** heap,
447  const dtuple_t* tuple,
448  ulint n_ext,
449  mtr_t* mtr)
450  __attribute__((nonnull, warn_unused_result));
451 /*************************************************************/
462 UNIV_INTERN
463 bool
465 /*====================*/
466  bool recovery,
471  ulint z_level,
473  page_cur_t* cursor,
474  dict_index_t* index,
475  mtr_t* mtr)
476  __attribute__((nonnull, warn_unused_result));
477 /*************************************************************/
488 UNIV_INTERN
489 bool
491 /*================*/
492  page_cur_t* cursor,
493  dict_index_t* index,
494  mtr_t* mtr)
495  __attribute__((nonnull));
496 /*************************************************************/
500 UNIV_INTERN
501 ibool
503 /*===========================*/
504  btr_cur_t* cursor,
505  rec_t** split_rec)
508  __attribute__((nonnull, warn_unused_result));
509 /*************************************************************/
513 UNIV_INTERN
514 ibool
516 /*============================*/
517  btr_cur_t* cursor,
518  rec_t** split_rec)
521  __attribute__((nonnull, warn_unused_result));
522 /*************************************************************/
531 UNIV_INTERN
532 rec_t*
534 /*======================*/
535  ulint flags,
536  btr_cur_t* cursor,
539  ulint** offsets,
540  mem_heap_t** heap,
542  const dtuple_t* tuple,
543  ulint n_ext,
544  mtr_t* mtr)
545  __attribute__((nonnull, warn_unused_result));
546 /*******************************************************/
549 UNIV_INTERN
550 void
552 /*==============================*/
553  ulint flags,
554  dict_index_t* index,
555  ulint level,
556  dtuple_t* tuple,
557  const char* file,
558  ulint line,
559  mtr_t* mtr)
560  __attribute__((nonnull));
561 # define btr_insert_on_non_leaf_level(f,i,l,t,m) \
562  btr_insert_on_non_leaf_level_func(f,i,l,t,__FILE__,__LINE__,m)
563 #endif /* !UNIV_HOTBACKUP */
564 /****************************************************************/
566 UNIV_INTERN
567 void
569 /*=================*/
570  rec_t* rec,
571  mtr_t* mtr)
572  __attribute__((nonnull));
573 #ifndef UNIV_HOTBACKUP
574 /*************************************************************/
576 UNIV_INTERN
577 void
579 /*================*/
580  dict_index_t* index,
581  buf_block_t* block,
582  mtr_t* mtr)
583  __attribute__((nonnull));
584 #ifdef UNIV_DEBUG
585 /************************************************************/
588 UNIV_INTERN
589 ibool
591 /*===============*/
592  dict_index_t* index,
593  buf_block_t* block,
594  mtr_t* mtr)
595  __attribute__((nonnull, warn_unused_result));
596 #endif /* UNIV_DEBUG */
597 /*************************************************************/
607 UNIV_INTERN
608 ibool
610 /*=========*/
611  btr_cur_t* cursor,
615  ibool adjust,
617  mtr_t* mtr)
618  __attribute__((nonnull));
619 /*************************************************************/
623 UNIV_INTERN
624 void
626 /*=============*/
627  btr_cur_t* cursor,
629  mtr_t* mtr)
630  __attribute__((nonnull));
631 #endif /* !UNIV_HOTBACKUP */
632 /****************************************************************/
636 UNIV_INTERN
637 byte*
639 /*=======================*/
640  byte* ptr,
641  byte* end_ptr,
642  ulint comp,
643  page_t* page,
644  mtr_t* mtr)
645  __attribute__((nonnull(1,2), warn_unused_result));
646 /***********************************************************/
649 UNIV_INTERN
650 byte*
652 /*======================*/
653  byte* ptr,
654  byte* end_ptr,
655  dict_index_t* index,
656  bool compressed,
657  buf_block_t* block,
658  mtr_t* mtr)
659  __attribute__((nonnull(1,2,3), warn_unused_result));
660 #ifndef UNIV_HOTBACKUP
661 /**************************************************************/
664 UNIV_INTERN
665 ulint
667 /*=========*/
668  dict_index_t* index,
669  ulint flag,
670  mtr_t* mtr)
672  __attribute__((nonnull, warn_unused_result));
673 /**************************************************************/
680 UNIV_INTERN
683 /*===========*/
684  dict_index_t* index,
685  ulint hint_page_no,
686  byte file_direction,
688  ulint level,
690  mtr_t* mtr,
692  mtr_t* init_mtr)
695  __attribute__((nonnull, warn_unused_result));
696 /**************************************************************/
699 UNIV_INTERN
700 void
702 /*==========*/
703  dict_index_t* index,
704  buf_block_t* block,
705  mtr_t* mtr)
706  __attribute__((nonnull));
707 /**************************************************************/
711 UNIV_INTERN
712 void
714 /*==============*/
715  dict_index_t* index,
716  buf_block_t* block,
717  ulint level,
718  mtr_t* mtr)
719  __attribute__((nonnull));
720 #ifdef UNIV_BTR_PRINT
721 /*************************************************************/
723 UNIV_INTERN
724 void
725 btr_print_size(
726 /*===========*/
727  dict_index_t* index)
728  __attribute__((nonnull));
729 /**************************************************************/
731 UNIV_INTERN
732 void
733 btr_print_index(
734 /*============*/
735  dict_index_t* index,
736  ulint width)
738  __attribute__((nonnull));
739 #endif /* UNIV_BTR_PRINT */
740 /************************************************************/
744 UNIV_INTERN
745 ibool
747 /*===================*/
748  const rec_t* rec,
749  const dict_index_t* index,
750  ibool dump_on_error)
753  __attribute__((nonnull, warn_unused_result));
754 /**************************************************************/
757 UNIV_INTERN
758 bool
760 /*===============*/
761  dict_index_t* index,
762  const trx_t* trx)
763  __attribute__((nonnull(1), warn_unused_result));
764 
765 #define BTR_N_LEAF_PAGES 1
766 #define BTR_TOTAL_SIZE 2
767 #endif /* !UNIV_HOTBACKUP */
768 
769 #ifndef UNIV_NONINL
770 #include "btr0btr.ic"
771 #endif
772 
773 #endif