Drizzled Public API Documentation

page0page.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (C) 1994, 2009, Innobase Oy. 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., 51 Franklin
15 St, Fifth Floor, Boston, MA 02110-1301 USA
16 
17 *****************************************************************************/
18 
19 /**************************************************/
26 #pragma once
27 #ifndef page0page_h
28 #define page0page_h
29 
30 #include "univ.i"
31 
32 #include "page0types.h"
33 #include "fil0fil.h"
34 #include "buf0buf.h"
35 #include "data0data.h"
36 #include "dict0dict.h"
37 #include "rem0rec.h"
38 #include "fsp0fsp.h"
39 #include "mtr0mtr.h"
40 
41 #ifdef UNIV_MATERIALIZE
42 #undef UNIV_INLINE
43 #define UNIV_INLINE
44 #endif
45 
46 /* PAGE HEADER
47  ===========
48 
49 Index page header starts at the first offset left free by the FIL-module */
50 
51 typedef byte page_header_t;
52 
53 #define PAGE_HEADER FSEG_PAGE_DATA /* index page header starts at this
54  offset */
55 /*-----------------------------*/
56 #define PAGE_N_DIR_SLOTS 0 /* number of slots in page directory */
57 #define PAGE_HEAP_TOP 2 /* pointer to record heap top */
58 #define PAGE_N_HEAP 4 /* number of records in the heap,
59  bit 15=flag: new-style compact page format */
60 #define PAGE_FREE 6 /* pointer to start of page free record list */
61 #define PAGE_GARBAGE 8 /* number of bytes in deleted records */
62 #define PAGE_LAST_INSERT 10 /* pointer to the last inserted record, or
63  NULL if this info has been reset by a delete,
64  for example */
65 #define PAGE_DIRECTION 12 /* last insert direction: PAGE_LEFT, ... */
66 #define PAGE_N_DIRECTION 14 /* number of consecutive inserts to the same
67  direction */
68 #define PAGE_N_RECS 16 /* number of user records on the page */
69 #define PAGE_MAX_TRX_ID 18 /* highest id of a trx which may have modified
70  a record on the page; trx_id_t; defined only
71  in secondary indexes and in the insert buffer
72  tree; NOTE: this may be modified only
73  when the thread has an x-latch to the page,
74  and ALSO an x-latch to btr_search_latch
75  if there is a hash index to the page! */
76 #define PAGE_HEADER_PRIV_END 26 /* end of private data structure of the page
77  header which are set in a page create */
78 /*----*/
79 #define PAGE_LEVEL 26 /* level of the node in an index tree; the
80  leaf level is the level 0. This field should
81  not be written to after page creation. */
82 #define PAGE_INDEX_ID 28 /* index id where the page belongs.
83  This field should not be written to after
84  page creation. */
85 #define PAGE_BTR_SEG_LEAF 36 /* file segment header for the leaf pages in
86  a B-tree: defined only on the root page of a
87  B-tree, but not in the root of an ibuf tree */
88 #define PAGE_BTR_IBUF_FREE_LIST PAGE_BTR_SEG_LEAF
89 #define PAGE_BTR_IBUF_FREE_LIST_NODE PAGE_BTR_SEG_LEAF
90  /* in the place of PAGE_BTR_SEG_LEAF and _TOP
91  there is a free list base node if the page is
92  the root page of an ibuf tree, and at the same
93  place is the free list node if the page is in
94  a free list */
95 #define PAGE_BTR_SEG_TOP (36 + FSEG_HEADER_SIZE)
96  /* file segment header for the non-leaf pages
97  in a B-tree: defined only on the root page of
98  a B-tree, but not in the root of an ibuf
99  tree */
100 /*----*/
101 #define PAGE_DATA (PAGE_HEADER + 36 + 2 * FSEG_HEADER_SIZE)
102  /* start of data on the page */
103 
104 #define PAGE_OLD_INFIMUM (PAGE_DATA + 1 + REC_N_OLD_EXTRA_BYTES)
105  /* offset of the page infimum record on an
106  old-style page */
107 #define PAGE_OLD_SUPREMUM (PAGE_DATA + 2 + 2 * REC_N_OLD_EXTRA_BYTES + 8)
108  /* offset of the page supremum record on an
109  old-style page */
110 #define PAGE_OLD_SUPREMUM_END (PAGE_OLD_SUPREMUM + 9)
111  /* offset of the page supremum record end on
112  an old-style page */
113 #define PAGE_NEW_INFIMUM (PAGE_DATA + REC_N_NEW_EXTRA_BYTES)
114  /* offset of the page infimum record on a
115  new-style compact page */
116 #define PAGE_NEW_SUPREMUM (PAGE_DATA + 2 * REC_N_NEW_EXTRA_BYTES + 8)
117  /* offset of the page supremum record on a
118  new-style compact page */
119 #define PAGE_NEW_SUPREMUM_END (PAGE_NEW_SUPREMUM + 8)
120  /* offset of the page supremum record end on
121  a new-style compact page */
122 /*-----------------------------*/
123 
124 /* Heap numbers */
125 #define PAGE_HEAP_NO_INFIMUM 0 /* page infimum */
126 #define PAGE_HEAP_NO_SUPREMUM 1 /* page supremum */
127 #define PAGE_HEAP_NO_USER_LOW 2 /* first user record in
128  creation (insertion) order,
129  not necessarily collation order;
130  this record may have been deleted */
131 
132 /* Directions of cursor movement */
133 #define PAGE_LEFT 1
134 #define PAGE_RIGHT 2
135 #define PAGE_SAME_REC 3
136 #define PAGE_SAME_PAGE 4
137 #define PAGE_NO_DIRECTION 5
138 
139 /* PAGE DIRECTORY
140  ==============
141 */
142 
143 typedef byte page_dir_slot_t;
144 typedef page_dir_slot_t page_dir_t;
145 
146 /* Offset of the directory start down from the page end. We call the
147 slot with the highest file address directory start, as it points to
148 the first record in the list of records. */
149 #define PAGE_DIR FIL_PAGE_DATA_END
150 
151 /* We define a slot in the page directory as two bytes */
152 #define PAGE_DIR_SLOT_SIZE 2
153 
154 /* The offset of the physically lower end of the directory, counted from
155 page end, when the page is empty */
156 #define PAGE_EMPTY_DIR_START (PAGE_DIR + 2 * PAGE_DIR_SLOT_SIZE)
157 
158 /* The maximum and minimum number of records owned by a directory slot. The
159 number may drop below the minimum in the first and the last slot in the
160 directory. */
161 #define PAGE_DIR_SLOT_MAX_N_OWNED 8
162 #define PAGE_DIR_SLOT_MIN_N_OWNED 4
163 
164 /************************************************************/
167 UNIV_INLINE
168 page_t*
169 page_align(
170 /*=======*/
171  const void* ptr)
172  __attribute__((const));
173 /************************************************************/
176 UNIV_INLINE
177 ulint
179 /*========*/
180  const void* ptr)
181  __attribute__((const));
182 /*************************************************************/
184 UNIV_INLINE
185 trx_id_t
187 /*================*/
188  const page_t* page);
189 /*************************************************************/
191 UNIV_INTERN
192 void
194 /*================*/
195  buf_block_t* block,
196  page_zip_des_t* page_zip,
197  trx_id_t trx_id,
198  mtr_t* mtr);
199 /*************************************************************/
202 UNIV_INLINE
203 void
205 /*===================*/
206  buf_block_t* block,
207  page_zip_des_t* page_zip,
209  trx_id_t trx_id,
210  mtr_t* mtr);
211 /*************************************************************/
213 UNIV_INLINE
214 ulint
216 /*==================*/
217  const page_t* page,
218  ulint field);
219 /*************************************************************/
221 UNIV_INLINE
222 void
224 /*==================*/
225  page_t* page,
226  page_zip_des_t* page_zip,
228  ulint field,
229  ulint val);
230 /*************************************************************/
233 UNIV_INLINE
234 ulint
236 /*=================*/
237  const page_t* page,
238  ulint field)
239  __attribute__((nonnull, pure));
240 
241 /*************************************************************/
243 #define page_header_get_ptr(page, field) \
244  (page_header_get_offs(page, field) \
245  ? page + page_header_get_offs(page, field) : NULL)
246 /*************************************************************/
248 UNIV_INLINE
249 void
251 /*================*/
252  page_t* page,
253  page_zip_des_t* page_zip,
255  ulint field,
256  const byte* ptr);
257 #ifndef UNIV_HOTBACKUP
258 /*************************************************************/
261 UNIV_INLINE
262 void
264 /*==========================*/
265  page_t* page,
266  page_zip_des_t* page_zip,
268  mtr_t* mtr);
269 #endif /* !UNIV_HOTBACKUP */
270 /************************************************************/
273 UNIV_INLINE
274 ulint
276 /*====================*/
277  const page_t* page);
278 /************************************************************/
281 UNIV_INLINE
282 ulint
284 /*=====================*/
285  const page_t* page);
286 #define page_get_infimum_rec(page) ((page) + page_get_infimum_offset(page))
287 #define page_get_supremum_rec(page) ((page) + page_get_supremum_offset(page))
288 /************************************************************/
292 UNIV_INTERN
293 rec_t*
295 /*================*/
296  page_t* page);
297 #ifndef UNIV_HOTBACKUP
298 /*************************************************************/
306 UNIV_INLINE
307 int
309 /*===========================*/
310  const dtuple_t* dtuple,
311  const rec_t* rec,
315  const ulint* offsets,
316  ulint* matched_fields,
319  ulint* matched_bytes);
323 #endif /* !UNIV_HOTBACKUP */
324 /*************************************************************/
327 UNIV_INLINE
328 ulint
330 /*=============*/
331  const page_t* page);
332 /*************************************************************/
335 UNIV_INLINE
336 ulint
338 /*==============*/
339  const page_t* page);
340 /*************************************************************/
344 UNIV_INLINE
345 ulint
347 /*============*/
348  const page_t* page);
349 /***************************************************************/
353 UNIV_INTERN
354 ulint
356 /*=======================*/
357  const rec_t* rec);
358 /*************************************************************/
361 UNIV_INLINE
362 ulint
364 /*================*/
365  const page_t* page);
366 /*************************************************************/
368 UNIV_INLINE
369 void
371 /*================*/
372  page_t* page,
373  page_zip_des_t* page_zip,
378  ulint n_heap);
379 /*************************************************************/
382 UNIV_INLINE
383 ulint
385 /*=================*/
386  const page_t* page);
387 /*************************************************************/
389 UNIV_INLINE
390 void
392 /*=================*/
393  page_t* page,
394  page_zip_des_t* page_zip,
396  ulint n_slots);
397 #ifdef UNIV_DEBUG
398 /*************************************************************/
401 UNIV_INLINE
402 page_dir_slot_t*
403 page_dir_get_nth_slot(
404 /*==================*/
405  const page_t* page,
406  ulint n);
407 #else /* UNIV_DEBUG */
408 # define page_dir_get_nth_slot(page, n) \
409  ((page) + UNIV_PAGE_SIZE - PAGE_DIR \
410  - (n + 1) * PAGE_DIR_SLOT_SIZE)
411 #endif /* UNIV_DEBUG */
412 /**************************************************************/
415 UNIV_INLINE
416 ibool
418 /*===========*/
419  const rec_t* rec);
420 /***************************************************************/
423 UNIV_INLINE
424 const rec_t*
426 /*==================*/
427  const page_dir_slot_t* slot);
428 /***************************************************************/
430 UNIV_INLINE
431 void
433 /*==================*/
434  page_dir_slot_t* slot,
435  rec_t* rec);
436 /***************************************************************/
439 UNIV_INLINE
440 ulint
442 /*======================*/
443  const page_dir_slot_t* slot);
444 /***************************************************************/
446 UNIV_INLINE
447 void
449 /*======================*/
450  page_dir_slot_t*slot,
451  page_zip_des_t* page_zip,
452  ulint n);
453 /************************************************************/
458 UNIV_INLINE
459 ulint
461 /*=========================*/
462  ulint n_recs);
463 /***************************************************************/
466 UNIV_INTERN
467 ulint
469 /*=====================*/
470  const rec_t* rec);
471 /************************************************************/
475 UNIV_INLINE
476 ulint
478 /*=========*/
479  const page_t* page);
480 /************************************************************/
483 UNIV_INLINE
484 ulint
486 /*=============*/
487  const rec_t* rec);
488 /***************************************************************/
491 UNIV_INLINE
492 ulint
494 /*=================*/
495  const rec_t* rec);
496 /************************************************************/
499 UNIV_INLINE
500 ibool
502 /*=========*/
503  const page_t* page)
504  __attribute__((nonnull, pure));
505 /************************************************************/
508 UNIV_INLINE
509 const rec_t*
511 /*==================*/
512  const rec_t* rec,
513  ulint comp);
514 /************************************************************/
517 UNIV_INLINE
518 rec_t*
520 /*==============*/
521  rec_t* rec);
522 /************************************************************/
525 UNIV_INLINE
526 const rec_t*
528 /*====================*/
529  const rec_t* rec);
530 /************************************************************/
532 UNIV_INLINE
533 void
535 /*==============*/
536  rec_t* rec,
538  rec_t* next);
540 /************************************************************/
543 UNIV_INLINE
544 const rec_t*
546 /*====================*/
547  const rec_t* rec);
549 /************************************************************/
552 UNIV_INLINE
553 rec_t*
555 /*==============*/
556  rec_t* rec);
558 /************************************************************/
561 UNIV_INLINE
562 ibool
564 /*=====================*/
565  ulint offset)
566  __attribute__((const));
567 /************************************************************/
570 UNIV_INLINE
571 ibool
573 /*=====================*/
574  ulint offset)
575  __attribute__((const));
576 /************************************************************/
579 UNIV_INLINE
580 ibool
582 /*====================*/
583  ulint offset)
584  __attribute__((const));
585 
586 /************************************************************/
589 UNIV_INLINE
590 ibool
592 /*=================*/
593  const rec_t* rec)
594  __attribute__((const));
595 /************************************************************/
598 UNIV_INLINE
599 ibool
601 /*=================*/
602  const rec_t* rec)
603  __attribute__((const));
604 
605 /************************************************************/
608 UNIV_INLINE
609 ibool
611 /*================*/
612  const rec_t* rec)
613  __attribute__((const));
614 /***************************************************************/
617 UNIV_INLINE
618 rec_t*
620 /*====================*/
621  rec_t* rec);
622 /***********************************************************************/
626 UNIV_INTERN
627 void
629 /*=========================*/
630  rec_t* rec,
631  ulint i,
632  ulint page_no,
633  mtr_t* mtr);
634 /************************************************************/
638 UNIV_INLINE
639 ulint
641 /*=====================*/
642  const page_t* page,
643  ulint n_recs);
644 /************************************************************/
648 UNIV_INLINE
649 ulint
651 /*======================================*/
652  const page_t* page,
653  ulint n_recs);
654 /*************************************************************/
657 UNIV_INLINE
658 ulint
660 /*=========================*/
661  ulint comp)
662  __attribute__((const));
663 /**********************************************************/
667 UNIV_INLINE
668 ulint
670 /*=========================*/
671  const rec_t* rec);
672 /************************************************************/
676 UNIV_INLINE
677 ulint
679 /*===============*/
680  const page_t* page);
681 /************************************************************/
684 UNIV_INLINE
685 void
687 /*================*/
688  page_t* page,
689  page_zip_des_t* page_zip,
692  rec_t* next_rec,
694  ulint need);
695 /************************************************************/
698 UNIV_INTERN
699 byte*
701 /*================*/
702  page_t* page,
703  page_zip_des_t* page_zip,
706  ulint need,
707  ulint* heap_no);
710 /************************************************************/
712 UNIV_INLINE
713 void
715 /*==========*/
716  page_t* page,
717  page_zip_des_t* page_zip,
718  rec_t* rec,
719  dict_index_t* index,
720  const ulint* offsets);
721 /**********************************************************/
724 UNIV_INTERN
725 page_t*
727 /*========*/
728  buf_block_t* block,
730  mtr_t* mtr,
731  ulint comp);
732 /**********************************************************/
735 UNIV_INTERN
736 page_t*
738 /*============*/
739  buf_block_t* block,
741  dict_index_t* index,
742  ulint level,
743  mtr_t* mtr);
745 /*************************************************************/
748 UNIV_INTERN
749 void
751 /*============================*/
752  buf_block_t* new_block,
753  buf_block_t* block,
754  rec_t* rec,
755  dict_index_t* index,
756  mtr_t* mtr);
757 /*************************************************************/
763 UNIV_INTERN
764 rec_t*
766 /*===================*/
767  buf_block_t* new_block,
768  buf_block_t* block,
769  rec_t* rec,
770  dict_index_t* index,
771  mtr_t* mtr)
772  __attribute__((nonnull));
773 /*************************************************************/
779 UNIV_INTERN
780 rec_t*
782 /*=====================*/
783  buf_block_t* new_block,
784  buf_block_t* block,
785  rec_t* rec,
786  dict_index_t* index,
787  mtr_t* mtr)
788  __attribute__((nonnull));
789 /*************************************************************/
792 UNIV_INTERN
793 void
795 /*=====================*/
796  rec_t* rec,
797  buf_block_t* block,
798  dict_index_t* index,
799  ulint n_recs,
801  ulint size,
804  mtr_t* mtr)
805  __attribute__((nonnull));
806 /*************************************************************/
809 UNIV_INTERN
810 void
812 /*=======================*/
813  rec_t* rec,
814  buf_block_t* block,
815  dict_index_t* index,
816  mtr_t* mtr)
817  __attribute__((nonnull));
818 /*************************************************************/
823 UNIV_INTERN
824 ibool
826 /*===================*/
827  buf_block_t* new_block,
828  buf_block_t* block,
829  rec_t* split_rec,
830  dict_index_t* index,
831  mtr_t* mtr)
832  __attribute__((nonnull(1, 2, 4, 5)));
833 /*************************************************************/
837 UNIV_INTERN
838 ibool
840 /*=====================*/
841  buf_block_t* new_block,
842  buf_block_t* block,
843  rec_t* split_rec,
844  dict_index_t* index,
845  mtr_t* mtr)
846  __attribute__((nonnull(1, 2, 4, 5)));
847 /****************************************************************/
849 UNIV_INTERN
850 void
852 /*================*/
853  page_t* page,
854  page_zip_des_t* page_zip,
856  ulint slot_no)
857  __attribute__((nonnull(1)));
858 /*************************************************************/
863 UNIV_INTERN
864 void
866 /*==================*/
867  page_t* page,
868  page_zip_des_t* page_zip,
869  ulint slot_no)
870  __attribute__((nonnull(1)));
871 /**********************************************************/
874 UNIV_INTERN
875 byte*
877 /*=======================*/
878  byte type,
882  byte* ptr,
883  byte* end_ptr,
884  buf_block_t* block,
885  dict_index_t* index,
886  mtr_t* mtr);
887 /***********************************************************/
890 UNIV_INTERN
891 byte*
893 /*==============*/
894  byte* ptr,
895  byte* end_ptr,
896  ulint comp,
897  buf_block_t* block,
898  mtr_t* mtr);
899 /************************************************************/
902 UNIV_INTERN
903 void
905 /*===========*/
906  const rec_t* rec,
907  const ulint* offsets);
908 /***************************************************************/
911 UNIV_INTERN
912 void
914 /*===========*/
915  page_t* page,
916  ulint pr_n);
917 /***************************************************************/
920 UNIV_INTERN
921 void
923 /*============*/
924  buf_block_t* block,
925  dict_index_t* index,
926  ulint pr_n);
927 /***************************************************************/
929 UNIV_INTERN
930 void
932 /*==============*/
933  const page_t* page);
934 /***************************************************************/
937 UNIV_INTERN
938 void
939 page_print(
940 /*=======*/
941  buf_block_t* block,
942  dict_index_t* index,
943  ulint dn,
945  ulint rn);
947 /***************************************************************/
952 UNIV_INTERN
953 ibool
955 /*==============*/
956  const rec_t* rec,
957  const ulint* offsets);
958 /***************************************************************/
962 UNIV_INTERN
963 void
965 /*===========*/
966  const page_t* page);
967 /***************************************************************/
972 UNIV_INTERN
973 ibool
975 /*=====================*/
976  const page_t* page);
977 /***************************************************************/
982 UNIV_INTERN
983 ibool
985 /*=====================*/
986  const page_t* page);
987 /***************************************************************/
990 UNIV_INTERN
991 ibool
993 /*==========*/
994  const page_t* page,
995  dict_index_t* index);
997 /***************************************************************/
1001 const rec_t*
1003 /*=======================*/
1004  const page_t* page,
1005  ulint heap_no);
1007 #ifdef UNIV_MATERIALIZE
1008 #undef UNIV_INLINE
1009 #define UNIV_INLINE UNIV_INLINE_ORIGINAL
1010 #endif
1011 
1012 #ifndef UNIV_NONINL
1013 #include "page0page.ic"
1014 #endif
1015 
1016 #endif