InnoDB Plugin  1.0
page0page.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1994, 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 page0page_h
27 #define page0page_h
28 
29 #include "univ.i"
30 
31 #include "page0types.h"
32 #include "fil0fil.h"
33 #include "buf0buf.h"
34 #include "data0data.h"
35 #include "dict0dict.h"
36 #include "rem0rec.h"
37 #include "fsp0fsp.h"
38 #include "mtr0mtr.h"
39 
40 #ifdef UNIV_MATERIALIZE
41 #undef UNIV_INLINE
42 #define UNIV_INLINE
43 #endif
44 
45 /* PAGE HEADER
46  ===========
47 
48 Index page header starts at the first offset left free by the FIL-module */
49 
50 typedef byte page_header_t;
51 
52 #define PAGE_HEADER FSEG_PAGE_DATA /* index page header starts at this
53  offset */
54 /*-----------------------------*/
55 #define PAGE_N_DIR_SLOTS 0 /* number of slots in page directory */
56 #define PAGE_HEAP_TOP 2 /* pointer to record heap top */
57 #define PAGE_N_HEAP 4 /* number of records in the heap,
58  bit 15=flag: new-style compact page format */
59 #define PAGE_FREE 6 /* pointer to start of page free record list */
60 #define PAGE_GARBAGE 8 /* number of bytes in deleted records */
61 #define PAGE_LAST_INSERT 10 /* pointer to the last inserted record, or
62  NULL if this info has been reset by a delete,
63  for example */
64 #define PAGE_DIRECTION 12 /* last insert direction: PAGE_LEFT, ... */
65 #define PAGE_N_DIRECTION 14 /* number of consecutive inserts to the same
66  direction */
67 #define PAGE_N_RECS 16 /* number of user records on the page */
68 #define PAGE_MAX_TRX_ID 18 /* highest id of a trx which may have modified
69  a record on the page; trx_id_t; defined only
70  in secondary indexes and in the insert buffer
71  tree */
72 #define PAGE_HEADER_PRIV_END 26 /* end of private data structure of the page
73  header which are set in a page create */
74 /*----*/
75 #define PAGE_LEVEL 26 /* level of the node in an index tree; the
76  leaf level is the level 0. This field should
77  not be written to after page creation. */
78 #define PAGE_INDEX_ID 28 /* index id where the page belongs.
79  This field should not be written to after
80  page creation. */
81 #define PAGE_BTR_SEG_LEAF 36 /* file segment header for the leaf pages in
82  a B-tree: defined only on the root page of a
83  B-tree, but not in the root of an ibuf tree */
84 #define PAGE_BTR_IBUF_FREE_LIST PAGE_BTR_SEG_LEAF
85 #define PAGE_BTR_IBUF_FREE_LIST_NODE PAGE_BTR_SEG_LEAF
86  /* in the place of PAGE_BTR_SEG_LEAF and _TOP
87  there is a free list base node if the page is
88  the root page of an ibuf tree, and at the same
89  place is the free list node if the page is in
90  a free list */
91 #define PAGE_BTR_SEG_TOP (36 + FSEG_HEADER_SIZE)
92  /* file segment header for the non-leaf pages
93  in a B-tree: defined only on the root page of
94  a B-tree, but not in the root of an ibuf
95  tree */
96 /*----*/
97 #define PAGE_DATA (PAGE_HEADER + 36 + 2 * FSEG_HEADER_SIZE)
98  /* start of data on the page */
99 
100 #define PAGE_OLD_INFIMUM (PAGE_DATA + 1 + REC_N_OLD_EXTRA_BYTES)
101  /* offset of the page infimum record on an
102  old-style page */
103 #define PAGE_OLD_SUPREMUM (PAGE_DATA + 2 + 2 * REC_N_OLD_EXTRA_BYTES + 8)
104  /* offset of the page supremum record on an
105  old-style page */
106 #define PAGE_OLD_SUPREMUM_END (PAGE_OLD_SUPREMUM + 9)
107  /* offset of the page supremum record end on
108  an old-style page */
109 #define PAGE_NEW_INFIMUM (PAGE_DATA + REC_N_NEW_EXTRA_BYTES)
110  /* offset of the page infimum record on a
111  new-style compact page */
112 #define PAGE_NEW_SUPREMUM (PAGE_DATA + 2 * REC_N_NEW_EXTRA_BYTES + 8)
113  /* offset of the page supremum record on a
114  new-style compact page */
115 #define PAGE_NEW_SUPREMUM_END (PAGE_NEW_SUPREMUM + 8)
116  /* offset of the page supremum record end on
117  a new-style compact page */
118 /*-----------------------------*/
119 
120 /* Heap numbers */
121 #define PAGE_HEAP_NO_INFIMUM 0 /* page infimum */
122 #define PAGE_HEAP_NO_SUPREMUM 1 /* page supremum */
123 #define PAGE_HEAP_NO_USER_LOW 2 /* first user record in
124  creation (insertion) order,
125  not necessarily collation order;
126  this record may have been deleted */
127 
128 /* Directions of cursor movement */
129 #define PAGE_LEFT 1
130 #define PAGE_RIGHT 2
131 #define PAGE_SAME_REC 3
132 #define PAGE_SAME_PAGE 4
133 #define PAGE_NO_DIRECTION 5
134 
135 /* PAGE DIRECTORY
136  ==============
137 */
138 
139 typedef byte page_dir_slot_t;
140 typedef page_dir_slot_t page_dir_t;
141 
142 /* Offset of the directory start down from the page end. We call the
143 slot with the highest file address directory start, as it points to
144 the first record in the list of records. */
145 #define PAGE_DIR FIL_PAGE_DATA_END
146 
147 /* We define a slot in the page directory as two bytes */
148 #define PAGE_DIR_SLOT_SIZE 2
149 
150 /* The offset of the physically lower end of the directory, counted from
151 page end, when the page is empty */
152 #define PAGE_EMPTY_DIR_START (PAGE_DIR + 2 * PAGE_DIR_SLOT_SIZE)
153 
154 /* The maximum and minimum number of records owned by a directory slot. The
155 number may drop below the minimum in the first and the last slot in the
156 directory. */
157 #define PAGE_DIR_SLOT_MAX_N_OWNED 8
158 #define PAGE_DIR_SLOT_MIN_N_OWNED 4
159 
160 /************************************************************/
163 UNIV_INLINE
164 page_t*
165 page_align(
166 /*=======*/
167  const void* ptr)
168  __attribute__((const));
169 /************************************************************/
172 UNIV_INLINE
173 ulint
175 /*========*/
176  const void* ptr)
177  __attribute__((const));
178 /*************************************************************/
180 UNIV_INLINE
181 trx_id_t
183 /*================*/
184  const page_t* page);
185 /*************************************************************/
187 UNIV_INTERN
188 void
190 /*================*/
191  buf_block_t* block,
192  page_zip_des_t* page_zip,
193  trx_id_t trx_id,
194  mtr_t* mtr);
195 /*************************************************************/
198 UNIV_INLINE
199 void
201 /*===================*/
202  buf_block_t* block,
203  page_zip_des_t* page_zip,
205  trx_id_t trx_id,
206  mtr_t* mtr);
207 /*************************************************************/
209 UNIV_INLINE
210 ulint
212 /*==================*/
213  const page_t* page,
214  ulint field);
215 /*************************************************************/
217 UNIV_INLINE
218 void
220 /*==================*/
221  page_t* page,
222  page_zip_des_t* page_zip,
224  ulint field,
225  ulint val);
226 /*************************************************************/
229 UNIV_INLINE
230 ulint
232 /*=================*/
233  const page_t* page,
234  ulint field)
235  __attribute__((nonnull, pure));
236 
237 /*************************************************************/
239 #define page_header_get_ptr(page, field) \
240  (page_header_get_offs(page, field) \
241  ? page + page_header_get_offs(page, field) : NULL)
242 /*************************************************************/
244 UNIV_INLINE
245 void
247 /*================*/
248  page_t* page,
249  page_zip_des_t* page_zip,
251  ulint field,
252  const byte* ptr);
253 #ifndef UNIV_HOTBACKUP
254 /*************************************************************/
257 UNIV_INLINE
258 void
260 /*==========================*/
261  page_t* page,
262  page_zip_des_t* page_zip,
264  mtr_t* mtr);
265 #endif /* !UNIV_HOTBACKUP */
266 /************************************************************/
269 UNIV_INLINE
270 ulint
272 /*====================*/
273  const page_t* page);
274 /************************************************************/
277 UNIV_INLINE
278 ulint
280 /*=====================*/
281  const page_t* page);
282 #define page_get_infimum_rec(page) ((page) + page_get_infimum_offset(page))
283 #define page_get_supremum_rec(page) ((page) + page_get_supremum_offset(page))
284 
285 /************************************************************/
289 UNIV_INTERN
290 const rec_t*
292 /*===================*/
293  const page_t* page,
294  ulint nth)
295  __attribute__((nonnull, warn_unused_result));
296 /************************************************************/
300 UNIV_INLINE
301 rec_t*
303 /*=============*/
304  page_t* page, /*< in: page */
305  ulint nth)
306  __attribute__((nonnull, warn_unused_result));
307 
308 #ifndef UNIV_HOTBACKUP
309 /************************************************************/
314 UNIV_INLINE
315 rec_t*
317 /*================*/
318  page_t* page)
319  __attribute__((nonnull, warn_unused_result));
320 /*************************************************************/
328 UNIV_INLINE
329 int
331 /*===========================*/
332  const dtuple_t* dtuple,
333  const rec_t* rec,
337  const ulint* offsets,
338  ulint* matched_fields,
341  ulint* matched_bytes);
345 #endif /* !UNIV_HOTBACKUP */
346 /*************************************************************/
349 UNIV_INLINE
350 ulint
352 /*=============*/
353  const page_t* page);
354 /*************************************************************/
357 UNIV_INLINE
358 ulint
360 /*==============*/
361  const page_t* page);
362 /*************************************************************/
366 UNIV_INLINE
367 ulint
369 /*============*/
370  const page_t* page);
371 /***************************************************************/
376 UNIV_INTERN
377 ulint
379 /*=======================*/
380  const rec_t* rec);
381 /*************************************************************/
384 UNIV_INLINE
385 ulint
387 /*================*/
388  const page_t* page);
389 /*************************************************************/
391 UNIV_INLINE
392 void
394 /*================*/
395  page_t* page,
396  page_zip_des_t* page_zip,
401  ulint n_heap);
402 /*************************************************************/
405 UNIV_INLINE
406 ulint
408 /*=================*/
409  const page_t* page);
410 /*************************************************************/
412 UNIV_INLINE
413 void
415 /*=================*/
416  page_t* page,
417  page_zip_des_t* page_zip,
419  ulint n_slots);
420 #ifdef UNIV_DEBUG
421 /*************************************************************/
424 UNIV_INLINE
425 page_dir_slot_t*
427 /*==================*/
428  const page_t* page,
429  ulint n);
430 #else /* UNIV_DEBUG */
431 # define page_dir_get_nth_slot(page, n) \
432  ((page) + UNIV_PAGE_SIZE - PAGE_DIR \
433  - (n + 1) * PAGE_DIR_SLOT_SIZE)
434 #endif /* UNIV_DEBUG */
435 /**************************************************************/
438 UNIV_INLINE
439 ibool
441 /*===========*/
442  const rec_t* rec);
443 /***************************************************************/
446 UNIV_INLINE
447 const rec_t*
449 /*==================*/
450  const page_dir_slot_t* slot);
451 /***************************************************************/
453 UNIV_INLINE
454 void
456 /*==================*/
457  page_dir_slot_t* slot,
458  rec_t* rec);
459 /***************************************************************/
462 UNIV_INLINE
463 ulint
465 /*======================*/
466  const page_dir_slot_t* slot);
467 /***************************************************************/
469 UNIV_INLINE
470 void
472 /*======================*/
473  page_dir_slot_t*slot,
474  page_zip_des_t* page_zip,
475  ulint n);
476 /************************************************************/
481 UNIV_INLINE
482 ulint
484 /*=========================*/
485  ulint n_recs);
486 /***************************************************************/
489 UNIV_INTERN
490 ulint
492 /*=====================*/
493  const rec_t* rec);
494 /************************************************************/
498 UNIV_INLINE
499 ulint
501 /*=========*/
502  const page_t* page);
503 /************************************************************/
506 UNIV_INLINE
507 ulint
509 /*=============*/
510  const rec_t* rec);
511 /***************************************************************/
514 UNIV_INLINE
515 ulint
517 /*=================*/
518  const rec_t* rec);
519 /************************************************************/
522 UNIV_INLINE
523 bool
525 /*=========*/
526  const page_t* page)
527  __attribute__((nonnull, pure));
528 /************************************************************/
531 UNIV_INLINE
532 bool
534 /*==========*/
535  const page_t* page)
536  __attribute__((nonnull, pure));
537 /************************************************************/
540 UNIV_INLINE
541 bool
543 /*=============*/
544  const page_t* page)
545  __attribute__((nonnull, pure));
546 /************************************************************/
549 UNIV_INLINE
550 const rec_t*
552 /*==================*/
553  const rec_t* rec,
554  ulint comp);
555 /************************************************************/
558 UNIV_INLINE
559 rec_t*
561 /*==============*/
562  rec_t* rec);
563 /************************************************************/
566 UNIV_INLINE
567 const rec_t*
569 /*====================*/
570  const rec_t* rec);
571 /************************************************************/
576 UNIV_INLINE
577 const rec_t*
579 /*=============================*/
580  const rec_t* rec);
581 /************************************************************/
583 UNIV_INLINE
584 void
586 /*==============*/
587  rec_t* rec,
589  const rec_t* next);
591 /************************************************************/
594 UNIV_INLINE
595 const rec_t*
597 /*====================*/
598  const rec_t* rec);
600 /************************************************************/
603 UNIV_INLINE
604 rec_t*
606 /*==============*/
607  rec_t* rec);
609 /************************************************************/
612 UNIV_INLINE
613 ibool
615 /*=====================*/
616  ulint offset)
617  __attribute__((const));
618 /************************************************************/
621 UNIV_INLINE
622 ibool
624 /*=====================*/
625  ulint offset)
626  __attribute__((const));
627 /************************************************************/
630 UNIV_INLINE
631 ibool
633 /*====================*/
634  ulint offset)
635  __attribute__((const));
636 
637 /************************************************************/
640 UNIV_INLINE
641 ibool
643 /*=================*/
644  const rec_t* rec)
645  __attribute__((const));
646 /************************************************************/
649 UNIV_INLINE
650 ibool
652 /*=================*/
653  const rec_t* rec)
654  __attribute__((const));
655 
656 /************************************************************/
659 UNIV_INLINE
660 ibool
662 /*================*/
663  const rec_t* rec)
664  __attribute__((const));
665 /***************************************************************/
668 UNIV_INLINE
669 rec_t*
671 /*====================*/
672  rec_t* rec);
673 #ifndef UNIV_HOTBACKUP
674 /***********************************************************************/
676 UNIV_INLINE
677 void
679 /*=================*/
680  rec_t* rec,
681  ulint i,
682  ulint val,
683  mtr_t* mtr)
684  __attribute__((nonnull));
685 #endif /* !UNIV_HOTBACKUP */
686 /************************************************************/
690 UNIV_INLINE
691 ulint
693 /*=====================*/
694  const page_t* page,
695  ulint n_recs);
696 /************************************************************/
700 UNIV_INLINE
701 ulint
703 /*======================================*/
704  const page_t* page,
705  ulint n_recs);
706 /*************************************************************/
709 UNIV_INLINE
710 ulint
712 /*=========================*/
713  ulint comp)
714  __attribute__((const));
715 /**********************************************************/
719 UNIV_INLINE
720 ulint
722 /*=========================*/
723  const rec_t* rec);
724 /************************************************************/
728 UNIV_INLINE
729 ulint
731 /*===============*/
732  const page_t* page);
733 /************************************************************/
736 UNIV_INLINE
737 void
739 /*================*/
740  page_t* page,
741  page_zip_des_t* page_zip,
744  rec_t* next_rec,
746  ulint need);
747 /************************************************************/
750 UNIV_INTERN
751 byte*
753 /*================*/
754  page_t* page,
755  page_zip_des_t* page_zip,
758  ulint need,
759  ulint* heap_no);
762 /************************************************************/
764 UNIV_INLINE
765 void
767 /*==========*/
768  page_t* page,
769  page_zip_des_t* page_zip,
771  rec_t* rec,
773  const dict_index_t* index,
774  const ulint* offsets);
776 /**********************************************************/
779 UNIV_INTERN
780 page_t*
782 /*========*/
783  buf_block_t* block,
785  mtr_t* mtr,
786  ulint comp);
787 /**********************************************************/
790 UNIV_INTERN
791 page_t*
793 /*============*/
794  buf_block_t* block,
796  dict_index_t* index,
797  ulint level,
798  trx_id_t max_trx_id,
799  mtr_t* mtr)
800  __attribute__((nonnull));
801 /**********************************************************/
803 UNIV_INTERN
804 void
806 /*==============*/
807  buf_block_t* block,
808  dict_index_t* index,
809  mtr_t* mtr)
810  __attribute__((nonnull(1,2)));
811 /*************************************************************/
819 UNIV_INTERN
820 void
822 /*============================*/
823  buf_block_t* new_block,
824  buf_block_t* block,
825  rec_t* rec,
826  dict_index_t* index,
827  mtr_t* mtr);
828 /*************************************************************/
840 UNIV_INTERN
841 rec_t*
843 /*===================*/
844  buf_block_t* new_block,
845  buf_block_t* block,
846  rec_t* rec,
847  dict_index_t* index,
848  mtr_t* mtr)
849  __attribute__((nonnull));
850 /*************************************************************/
862 UNIV_INTERN
863 rec_t*
865 /*=====================*/
866  buf_block_t* new_block,
867  buf_block_t* block,
868  rec_t* rec,
869  dict_index_t* index,
870  mtr_t* mtr)
871  __attribute__((nonnull));
872 /*************************************************************/
875 UNIV_INTERN
876 void
878 /*=====================*/
879  rec_t* rec,
880  buf_block_t* block,
881  dict_index_t* index,
882  ulint n_recs,
884  ulint size,
887  mtr_t* mtr)
888  __attribute__((nonnull));
889 /*************************************************************/
892 UNIV_INTERN
893 void
895 /*=======================*/
896  rec_t* rec,
897  buf_block_t* block,
898  dict_index_t* index,
899  mtr_t* mtr)
900  __attribute__((nonnull));
901 /*************************************************************/
912 UNIV_INTERN
913 ibool
915 /*===================*/
916  buf_block_t* new_block,
917  buf_block_t* block,
918  rec_t* split_rec,
919  dict_index_t* index,
920  mtr_t* mtr)
921  __attribute__((nonnull(1, 2, 4, 5)));
922 /*************************************************************/
932 UNIV_INTERN
933 ibool
935 /*=====================*/
936  buf_block_t* new_block,
937  buf_block_t* block,
938  rec_t* split_rec,
939  dict_index_t* index,
940  mtr_t* mtr)
941  __attribute__((nonnull(1, 2, 4, 5)));
942 /****************************************************************/
944 UNIV_INTERN
945 void
947 /*================*/
948  page_t* page,
949  page_zip_des_t* page_zip,
951  ulint slot_no)
952  __attribute__((nonnull(1)));
953 /*************************************************************/
958 UNIV_INTERN
959 void
961 /*==================*/
962  page_t* page,
963  page_zip_des_t* page_zip,
964  ulint slot_no)
965  __attribute__((nonnull(1)));
966 /**********************************************************/
969 UNIV_INTERN
970 byte*
972 /*=======================*/
973  byte type,
977  byte* ptr,
978  byte* end_ptr,
979  buf_block_t* block,
980  dict_index_t* index,
981  mtr_t* mtr);
982 /***********************************************************/
985 UNIV_INTERN
986 byte*
988 /*==============*/
989  byte* ptr,
990  byte* end_ptr,
991  ulint comp,
992  buf_block_t* block,
993  mtr_t* mtr);
994 #ifndef UNIV_HOTBACKUP
995 /************************************************************/
998 UNIV_INTERN
999 void
1001 /*===========*/
1002  const rec_t* rec,
1003  const ulint* offsets);
1004 # ifdef UNIV_BTR_PRINT
1005 /***************************************************************/
1008 UNIV_INTERN
1009 void
1010 page_dir_print(
1011 /*===========*/
1012  page_t* page,
1013  ulint pr_n);
1014 /***************************************************************/
1017 UNIV_INTERN
1018 void
1019 page_print_list(
1020 /*============*/
1021  buf_block_t* block,
1022  dict_index_t* index,
1023  ulint pr_n);
1024 /***************************************************************/
1026 UNIV_INTERN
1027 void
1028 page_header_print(
1029 /*==============*/
1030  const page_t* page);
1031 /***************************************************************/
1034 UNIV_INTERN
1035 void
1036 page_print(
1037 /*=======*/
1038  buf_block_t* block,
1039  dict_index_t* index,
1040  ulint dn,
1042  ulint rn);
1044 # endif /* UNIV_BTR_PRINT */
1045 #endif /* !UNIV_HOTBACKUP */
1046 /***************************************************************/
1051 UNIV_INTERN
1052 ibool
1054 /*==============*/
1055  const rec_t* rec,
1056  const ulint* offsets);
1057 /***************************************************************/
1061 UNIV_INTERN
1062 void
1064 /*===========*/
1065  const page_t* page);
1066 /***************************************************************/
1071 UNIV_INTERN
1072 ibool
1074 /*=====================*/
1075  const page_t* page);
1076 /***************************************************************/
1081 UNIV_INTERN
1082 ibool
1084 /*=====================*/
1085  const page_t* page);
1086 /***************************************************************/
1089 UNIV_INTERN
1090 ibool
1092 /*==========*/
1093  const page_t* page,
1094  dict_index_t* index);
1096 /***************************************************************/
1100 const rec_t*
1102 /*=======================*/
1103  const page_t* page,
1104  ulint heap_no);
1110 const rec_t*
1112  const page_t* page);
1113 #ifdef UNIV_MATERIALIZE
1114 #undef UNIV_INLINE
1115 #define UNIV_INLINE UNIV_INLINE_ORIGINAL
1116 #endif
1117 
1118 #ifndef UNIV_NONINL
1119 #include "page0page.ic"
1120 #endif
1121 
1122 #endif