InnoDB Plugin  1.0
rem0rec.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1994, 2012, 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 rem0rec_h
27 #define rem0rec_h
28 
29 #include "univ.i"
30 #include "data0data.h"
31 #include "rem0types.h"
32 #include "mtr0types.h"
33 #include "page0types.h"
34 
35 /* Info bit denoting the predefined minimum record: this bit is set
36 if and only if the record is the first user record on a non-leaf
37 B-tree page that is the leftmost page on its level
38 (PAGE_LEVEL is nonzero and FIL_PAGE_PREV is FIL_NULL). */
39 #define REC_INFO_MIN_REC_FLAG 0x10UL
40 /* The deleted flag in info bits */
41 #define REC_INFO_DELETED_FLAG 0x20UL /* when bit is set to 1, it means the
42  record has been delete marked */
43 
44 /* Number of extra bytes in an old-style record,
45 in addition to the data and the offsets */
46 #define REC_N_OLD_EXTRA_BYTES 6
47 /* Number of extra bytes in a new-style record,
48 in addition to the data and the offsets */
49 #define REC_N_NEW_EXTRA_BYTES 5
50 
51 /* Record status values */
52 #define REC_STATUS_ORDINARY 0
53 #define REC_STATUS_NODE_PTR 1
54 #define REC_STATUS_INFIMUM 2
55 #define REC_STATUS_SUPREMUM 3
56 
57 /* The following four constants are needed in page0zip.cc in order to
58 efficiently compress and decompress pages. */
59 
60 /* The offset of heap_no in a compact record */
61 #define REC_NEW_HEAP_NO 4
62 /* The shift of heap_no in a compact record.
63 The status is stored in the low-order bits. */
64 #define REC_HEAP_NO_SHIFT 3
65 
66 /* Length of a B-tree node pointer, in bytes */
67 #define REC_NODE_PTR_SIZE 4
68 
70 #define REC_1BYTE_SQL_NULL_MASK 0x80UL
71 
72 #define REC_2BYTE_SQL_NULL_MASK 0x8000UL
73 
76 #define REC_2BYTE_EXTERN_MASK 0x4000UL
77 
78 #ifdef UNIV_DEBUG
79 /* Length of the rec_get_offsets() header */
80 # define REC_OFFS_HEADER_SIZE 4
81 #else /* UNIV_DEBUG */
82 /* Length of the rec_get_offsets() header */
83 # define REC_OFFS_HEADER_SIZE 2
84 #endif /* UNIV_DEBUG */
85 
86 /* Number of elements that should be initially allocated for the
87 offsets[] array, first passed to rec_get_offsets() */
88 #define REC_OFFS_NORMAL_SIZE 100
89 #define REC_OFFS_SMALL_SIZE 10
90 
91 /******************************************************/
95 UNIV_INLINE
96 const rec_t*
98 /*===================*/
99  const rec_t* rec,
100  ulint comp)
101  __attribute__((nonnull, pure, warn_unused_result));
102 /******************************************************/
106 UNIV_INLINE
107 rec_t*
109 /*=============*/
110  rec_t* rec,
111  ulint comp)
112  __attribute__((nonnull, pure, warn_unused_result));
113 /******************************************************/
117 UNIV_INLINE
118 ulint
120 /*==============*/
121  const rec_t* rec,
122  ulint comp)
123  __attribute__((nonnull, pure, warn_unused_result));
124 /******************************************************/
127 UNIV_INLINE
128 void
130 /*==================*/
131  rec_t* rec,
132  ulint next)
133  __attribute__((nonnull));
134 /******************************************************/
137 UNIV_INLINE
138 void
140 /*==================*/
141  rec_t* rec,
142  ulint next)
143  __attribute__((nonnull));
144 /******************************************************/
148 UNIV_INLINE
149 ulint
151 /*=================*/
152  const rec_t* rec)
153  __attribute__((nonnull, pure, warn_unused_result));
154 /******************************************************/
158 UNIV_INLINE
159 ulint
161 /*=============*/
162  const rec_t* rec,
163  const dict_index_t* index)
164  __attribute__((nonnull, pure, warn_unused_result));
165 /******************************************************/
169 UNIV_INLINE
170 ulint
172 /*================*/
173  const rec_t* rec)
174  __attribute__((nonnull, pure, warn_unused_result));
175 /******************************************************/
177 UNIV_INLINE
178 void
180 /*================*/
181  rec_t* rec,
182  ulint n_owned)
183  __attribute__((nonnull));
184 /******************************************************/
188 UNIV_INLINE
189 ulint
191 /*================*/
192  const rec_t* rec)
193  __attribute__((nonnull, pure, warn_unused_result));
194 /******************************************************/
196 UNIV_INLINE
197 void
199 /*================*/
200  rec_t* rec,
201  page_zip_des_t* page_zip,
202  ulint n_owned)
203  __attribute__((nonnull(1)));
204 /******************************************************/
208 UNIV_INLINE
209 ulint
211 /*==============*/
212  const rec_t* rec,
213  ulint comp)
214  __attribute__((nonnull, pure, warn_unused_result));
215 /******************************************************/
217 UNIV_INLINE
218 void
220 /*==================*/
221  rec_t* rec,
222  ulint bits)
223  __attribute__((nonnull));
224 /******************************************************/
226 UNIV_INLINE
227 void
229 /*==================*/
230  rec_t* rec,
231  ulint bits)
232  __attribute__((nonnull));
233 /******************************************************/
236 UNIV_INLINE
237 ulint
239 /*===========*/
240  const rec_t* rec)
241  __attribute__((nonnull, pure, warn_unused_result));
242 
243 /******************************************************/
245 UNIV_INLINE
246 void
248 /*===========*/
249  rec_t* rec,
250  ulint bits)
251  __attribute__((nonnull));
252 
253 /******************************************************/
257 UNIV_INLINE
258 ulint
260 /*=========================*/
261  const rec_t* rec,
262  ulint comp)
263  __attribute__((nonnull, pure, warn_unused_result));
264 /******************************************************/
267 UNIV_INLINE
268 void
270 /*=========================*/
271  rec_t* rec,
272  ulint bits)
273  __attribute__((nonnull));
274 
275 /******************************************************/
278 UNIV_INLINE
279 ulint
281 /*=================*/
282  const rec_t* rec,
283  ulint comp)
284  __attribute__((nonnull, pure, warn_unused_result));
285 /******************************************************/
287 UNIV_INLINE
288 void
290 /*=====================*/
291  rec_t* rec,
292  ulint flag)
293  __attribute__((nonnull));
294 /******************************************************/
296 UNIV_INLINE
297 void
299 /*=====================*/
300  rec_t* rec,
301  page_zip_des_t* page_zip,
302  ulint flag)
303  __attribute__((nonnull(1)));
304 /******************************************************/
307 UNIV_INLINE
308 ibool
310 /*==================*/
311  const rec_t* rec)
312  __attribute__((nonnull, pure, warn_unused_result));
313 /******************************************************/
317 UNIV_INLINE
318 ulint
320 /*================*/
321  const rec_t* rec)
322  __attribute__((nonnull, pure, warn_unused_result));
323 /******************************************************/
326 UNIV_INLINE
327 void
329 /*================*/
330  rec_t* rec,
331  ulint heap_no)
332  __attribute__((nonnull));
333 /******************************************************/
337 UNIV_INLINE
338 ulint
340 /*================*/
341  const rec_t* rec)
342  __attribute__((nonnull, pure, warn_unused_result));
343 /******************************************************/
346 UNIV_INLINE
347 void
349 /*================*/
350  rec_t* rec,
351  ulint heap_no)
352  __attribute__((nonnull));
353 /******************************************************/
357 UNIV_INLINE
358 ibool
360 /*====================*/
361  const rec_t* rec)
362  __attribute__((nonnull, pure, warn_unused_result));
363 
364 /******************************************************/
366 UNIV_INLINE
367 void
369 /*====================*/
370  rec_t* rec,
371  ibool flag)
372  __attribute__((nonnull));
373 
374 /******************************************************/
379 UNIV_INLINE
380 ulint
382 /*=====================*/
383  const rec_t* rec,
384  ulint n)
385  __attribute__((nonnull, pure, warn_unused_result));
386 
387 /******************************************************/
393 UNIV_INLINE
394 ulint
396 /*=====================*/
397  const rec_t* rec,
398  ulint n)
399  __attribute__((nonnull, pure, warn_unused_result));
400 
401 /******************************************************/
405 UNIV_INLINE
406 ulint
408 /*==================*/
409  const rec_t* rec,
410  ulint n)
411  __attribute__((nonnull, pure, warn_unused_result));
412 
413 /******************************************************/
417 UNIV_INTERN
418 ulint
420 /*=================*/
421  const rec_t* rec,
422  const dict_index_t* index,
423  ulint n)
424  __attribute__((nonnull, warn_unused_result));
425 
426 /******************************************************/
430 UNIV_INTERN
431 ulint*
433 /*=================*/
434  const rec_t* rec,
435  const dict_index_t* index,
436  ulint* offsets,
440  ulint n_fields,
443 #ifdef UNIV_DEBUG
444  const char* file,
445  ulint line,
446 #endif /* UNIV_DEBUG */
447  mem_heap_t** heap)
448 #ifdef UNIV_DEBUG
449  __attribute__((nonnull(1,2,5,7),warn_unused_result));
450 #else /* UNIV_DEBUG */
451  __attribute__((nonnull(1,2,5),warn_unused_result));
452 #endif /* UNIV_DEBUG */
453 
454 #ifdef UNIV_DEBUG
455 # define rec_get_offsets(rec,index,offsets,n,heap) \
456  rec_get_offsets_func(rec,index,offsets,n,__FILE__,__LINE__,heap)
457 #else /* UNIV_DEBUG */
458 # define rec_get_offsets(rec, index, offsets, n, heap) \
459  rec_get_offsets_func(rec, index, offsets, n, heap)
460 #endif /* UNIV_DEBUG */
461 
462 /******************************************************/
465 UNIV_INTERN
466 void
468 /*====================*/
469  const byte* extra,
473  const dict_index_t* index,
474  ulint node_ptr,
476  ulint* offsets)
478  __attribute__((nonnull));
479 #ifdef UNIV_DEBUG
480 /************************************************************/
483 UNIV_INLINE
484 ibool
486 /*==============*/
487  const rec_t* rec,
488  const dict_index_t* index,
489  const ulint* offsets)
491  __attribute__((nonnull(3), warn_unused_result));
492 /************************************************************/
495 UNIV_INLINE
496 void
498 /*================*/
499  const rec_t* rec,
500  const dict_index_t* index,
501  ulint* offsets)
503  __attribute__((nonnull));
504 #else
505 # define rec_offs_make_valid(rec, index, offsets) ((void) 0)
506 #endif /* UNIV_DEBUG */
507 
508 /************************************************************/
512 UNIV_INTERN
513 ulint
515 /*=======================*/
516  const rec_t* rec,
517  ulint n,
518  ulint* len)
520  __attribute__((nonnull));
521 #define rec_get_nth_field_old(rec, n, len) \
522 ((rec) + rec_get_nth_field_offs_old(rec, n, len))
523 /************************************************************/
528 UNIV_INLINE
529 ulint
531 /*===================*/
532  const rec_t* rec,
533  ulint n)
534  __attribute__((nonnull, pure, warn_unused_result));
535 /************************************************************/
539 UNIV_INLINE
540 ulint
542 /*===================*/
543  const ulint* offsets,
544  ulint n,
545  ulint* len)
547  __attribute__((nonnull));
548 #define rec_get_nth_field(rec, offsets, n, len) \
549 ((rec) + rec_get_nth_field_offs(offsets, n, len))
550 /******************************************************/
554 UNIV_INLINE
555 ulint
557 /*==========*/
558  const ulint* offsets)
559  __attribute__((nonnull, pure, warn_unused_result));
560 /******************************************************/
564 UNIV_INLINE
565 ulint
567 /*================*/
568  const ulint* offsets)
569  __attribute__((nonnull, pure, warn_unused_result));
570 /******************************************************/
573 UNIV_INLINE
574 const byte*
576 /*=====================*/
577  const rec_t* rec,
578  const ulint* offsets)
579  __attribute__((nonnull, pure, warn_unused_result));
580 /******************************************************/
583 UNIV_INLINE
584 ulint
586 /*================*/
587  const ulint* offsets,
588  ulint n)
589  __attribute__((nonnull, pure, warn_unused_result));
590 /******************************************************/
593 UNIV_INLINE
594 ulint
596 /*==================*/
597  const ulint* offsets,
598  ulint n)
599  __attribute__((nonnull, pure, warn_unused_result));
600 /******************************************************/
603 UNIV_INLINE
604 ulint
606 /*==============*/
607  const ulint* offsets,
608  ulint n)
609  __attribute__((nonnull, pure, warn_unused_result));
610 
611 /******************************************************/
614 UNIV_INLINE
615 ulint
617 /*==============*/
618  const ulint* offsets)
619  __attribute__((nonnull, pure, warn_unused_result));
620 /***********************************************************/
626 UNIV_INLINE
627 void
629 /*==============*/
630  rec_t* rec,
631  const ulint* offsets,
632  ulint n,
633  const void* data,
634  ulint len)
639  __attribute__((nonnull(1,2)));
640 /**********************************************************/
646 UNIV_INLINE
647 ulint
649 /*==================*/
650  const rec_t* rec)
651  __attribute__((nonnull, pure, warn_unused_result));
652 /**********************************************************/
656 UNIV_INLINE
657 ulint
659 /*=================*/
660  const ulint* offsets)
661  __attribute__((nonnull, pure, warn_unused_result));
662 /**********************************************************/
665 UNIV_INLINE
666 void
668 /*=================*/
669  ulint* offsets,
671  ulint n_alloc)
672  __attribute__((nonnull));
673 #define rec_offs_init(offsets) \
674  rec_offs_set_n_alloc(offsets, (sizeof offsets) / sizeof *offsets)
675 /**********************************************************/
678 UNIV_INLINE
679 ulint
681 /*==============*/
682  const ulint* offsets)
683  __attribute__((nonnull, pure, warn_unused_result));
684 /**********************************************************/
690 UNIV_INLINE
691 ulint
693 /*===============*/
694  const ulint* offsets)
695  __attribute__((nonnull, pure, warn_unused_result));
696 /**********************************************************/
701 UNIV_INLINE
702 ulint
704 /*================*/
705  const ulint* offsets)
706  __attribute__((nonnull, pure, warn_unused_result));
707 /**********************************************************/
710 UNIV_INLINE
711 ulint
713 /*==========*/
714  const ulint* offsets)
715  __attribute__((nonnull, pure, warn_unused_result));
716 #ifdef UNIV_DEBUG
717 /**********************************************************/
720 UNIV_INLINE
721 byte*
723 /*==========*/
724  const rec_t* rec,
725  const ulint* offsets)
726  __attribute__((nonnull, pure, warn_unused_result));
727 /**********************************************************/
730 UNIV_INLINE
731 byte*
733 /*========*/
734  const rec_t* rec,
735  const ulint* offsets)
736  __attribute__((nonnull, pure, warn_unused_result));
737 #else /* UNIV_DEBUG */
738 # define rec_get_start(rec, offsets) ((rec) - rec_offs_extra_size(offsets))
739 # define rec_get_end(rec, offsets) ((rec) + rec_offs_data_size(offsets))
740 #endif /* UNIV_DEBUG */
741 /***************************************************************/
744 UNIV_INLINE
745 rec_t*
746 rec_copy(
747 /*=====*/
748  void* buf,
749  const rec_t* rec,
750  const ulint* offsets)
751  __attribute__((nonnull));
752 #ifndef UNIV_HOTBACKUP
753 /**********************************************************/
756 UNIV_INTERN
757 ulint
759 /*========================*/
760  const dict_index_t* index,
761  const dfield_t* fields,
762  ulint n_fields,
763  ulint* extra)
764  __attribute__((warn_unused_result, nonnull));
765 
766 /******************************************************/
769 UNIV_INTERN
770 void
772 /*==================*/
773  const rec_t* rec,
774  const dict_index_t* index,
775  ulint* offsets)
777  __attribute__((nonnull));
778 
779 /*********************************************************/
782 UNIV_INTERN
783 void
785 /*=======================*/
786  rec_t* rec,
787  const dict_index_t* index,
788  const dfield_t* fields,
789  ulint n_fields)
790  __attribute__((nonnull));
791 
792 /**************************************************************/
796 UNIV_INTERN
797 rec_t*
799 /*===================*/
800  const rec_t* rec,
801  const dict_index_t* index,
802  ulint n_fields,
804  byte** buf,
807  ulint* buf_size)
808  __attribute__((nonnull));
809 /************************************************************/
812 UNIV_INLINE
813 ulint
814 rec_fold(
815 /*=====*/
816  const rec_t* rec,
817  const ulint* offsets,
819  ulint n_fields,
821  ulint n_bytes,
823  index_id_t tree_id)
824  __attribute__((nonnull, pure, warn_unused_result));
825 #endif /* !UNIV_HOTBACKUP */
826 /*********************************************************/
830 UNIV_INTERN
831 rec_t*
833 /*======================*/
834  byte* buf,
836  const dict_index_t* index,
837  const dtuple_t* dtuple,
838  ulint n_ext)
840  __attribute__((nonnull, warn_unused_result));
841 /**********************************************************/
845 UNIV_INLINE
846 ulint
848 /*=========================*/
849  ulint data_size,
850  ulint n_fields,
851  ulint n_ext)
852  __attribute__((const));
853 /**********************************************************/
856 UNIV_INTERN
857 ulint
859 /*===============================*/
860  const dict_index_t* index,
861  const dfield_t* fields,
862  ulint n_fields,
863  ulint* extra)
864  __attribute__((warn_unused_result, nonnull(1,2)));
865 /**********************************************************/
868 UNIV_INTERN
869 ulint
871 /*========================*/
872  const dict_index_t* index,
876  ulint status,
877  const dfield_t* fields,
878  ulint n_fields,
879  ulint* extra)
880  __attribute__((nonnull(1,3)));
881 /**********************************************************/
885 UNIV_INLINE
886 ulint
888 /*===================*/
889  dict_index_t* index,
890  const dtuple_t* dtuple,
891  ulint n_ext)
892  __attribute__((warn_unused_result, nonnull));
893 #ifndef UNIV_HOTBACKUP
894 /**************************************************************/
897 UNIV_INTERN
898 void
900 /*======================*/
901  dtuple_t* tuple,
902  const rec_t* rec,
903  const dict_index_t* index,
904  ulint n_fields,
906  mem_heap_t* heap)
907  __attribute__((nonnull));
908 #endif /* !UNIV_HOTBACKUP */
909 /***************************************************************/
912 UNIV_INTERN
913 ibool
915 /*=========*/
916  const rec_t* rec,
917  const ulint* offsets)
918  __attribute__((nonnull));
919 /***************************************************************/
921 UNIV_INTERN
922 void
924 /*==========*/
925  FILE* file,
926  const rec_t* rec)
927  __attribute__((nonnull));
928 #ifndef UNIV_HOTBACKUP
929 /***************************************************************/
932 UNIV_INTERN
933 void
935 /*===========*/
936  FILE* file,
937  const rec_t* rec,
938  const ulint* offsets)
939  __attribute__((nonnull));
940 /***************************************************************/
942 UNIV_INTERN
943 void
945 /*==========*/
946  FILE* file,
947  const rec_t* rec,
948  const ulint* offsets)
949  __attribute__((nonnull));
950 /***************************************************************/
952 UNIV_INTERN
953 void
954 rec_print(
955 /*======*/
956  FILE* file,
957  const rec_t* rec,
958  const dict_index_t* index)
959  __attribute__((nonnull));
960 
961 # ifdef UNIV_DEBUG
962 /************************************************************/
965 UNIV_INTERN
966 trx_id_t
968 /*===========*/
969  const rec_t* rec,
970  const dict_index_t* index)
971  __attribute__((nonnull, warn_unused_result));
972 # endif /* UNIV_DEBUG */
973 #endif /* UNIV_HOTBACKUP */
974 
975 /* Maximum lengths for the data in a physical record if the offsets
976 are given in one byte (resp. two byte) format. */
977 #define REC_1BYTE_OFFS_LIMIT 0x7FUL
978 #define REC_2BYTE_OFFS_LIMIT 0x7FFFUL
979 
980 /* The data size of record must be smaller than this because we reserve
981 two upmost bits in a two byte offset for special purposes */
982 #define REC_MAX_DATA_SIZE (16 * 1024)
983 
984 #ifndef UNIV_NONINL
985 #include "rem0rec.ic"
986 #endif
987 
988 #endif