MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  mem_heap_t** heap,
444  const char* file,
445  ulint line)
446  __attribute__((nonnull(1,2,5,6),warn_unused_result));
447 
448 #define rec_get_offsets(rec,index,offsets,n,heap) \
449  rec_get_offsets_func(rec,index,offsets,n,heap,__FILE__,__LINE__)
450 
451 /******************************************************/
454 UNIV_INTERN
455 void
457 /*====================*/
458  const byte* extra,
462  const dict_index_t* index,
463  ulint node_ptr,
465  ulint* offsets)
467  __attribute__((nonnull));
468 #ifdef UNIV_DEBUG
469 /************************************************************/
472 UNIV_INLINE
473 ibool
474 rec_offs_validate(
475 /*==============*/
476  const rec_t* rec,
477  const dict_index_t* index,
478  const ulint* offsets)
480  __attribute__((nonnull(3), warn_unused_result));
481 /************************************************************/
484 UNIV_INLINE
485 void
486 rec_offs_make_valid(
487 /*================*/
488  const rec_t* rec,
489  const dict_index_t* index,
490  ulint* offsets)
492  __attribute__((nonnull));
493 #else
494 # define rec_offs_make_valid(rec, index, offsets) ((void) 0)
495 #endif /* UNIV_DEBUG */
496 
497 /************************************************************/
501 UNIV_INTERN
502 ulint
504 /*=======================*/
505  const rec_t* rec,
506  ulint n,
507  ulint* len)
509  __attribute__((nonnull));
510 #define rec_get_nth_field_old(rec, n, len) \
511 ((rec) + rec_get_nth_field_offs_old(rec, n, len))
512 /************************************************************/
517 UNIV_INLINE
518 ulint
520 /*===================*/
521  const rec_t* rec,
522  ulint n)
523  __attribute__((nonnull, pure, warn_unused_result));
524 /************************************************************/
528 UNIV_INLINE
529 ulint
531 /*===================*/
532  const ulint* offsets,
533  ulint n,
534  ulint* len)
536  __attribute__((nonnull));
537 #define rec_get_nth_field(rec, offsets, n, len) \
538 ((rec) + rec_get_nth_field_offs(offsets, n, len))
539 /******************************************************/
543 UNIV_INLINE
544 ulint
546 /*==========*/
547  const ulint* offsets)
548  __attribute__((nonnull, pure, warn_unused_result));
549 /******************************************************/
553 UNIV_INLINE
554 ulint
556 /*================*/
557  const ulint* offsets)
558  __attribute__((nonnull, pure, warn_unused_result));
559 /******************************************************/
562 UNIV_INLINE
563 const byte*
565 /*=====================*/
566  const rec_t* rec,
567  const ulint* offsets)
568  __attribute__((nonnull, pure, warn_unused_result));
569 /******************************************************/
572 UNIV_INLINE
573 ulint
575 /*================*/
576  const ulint* offsets,
577  ulint n)
578  __attribute__((nonnull, pure, warn_unused_result));
579 /******************************************************/
582 UNIV_INLINE
583 ulint
585 /*==================*/
586  const ulint* offsets,
587  ulint n)
588  __attribute__((nonnull, pure, warn_unused_result));
589 /******************************************************/
592 UNIV_INLINE
593 ulint
595 /*==============*/
596  const ulint* offsets,
597  ulint n)
598  __attribute__((nonnull, pure, warn_unused_result));
599 
600 /******************************************************/
603 UNIV_INLINE
604 ulint
606 /*==============*/
607  const ulint* offsets)
608  __attribute__((nonnull, pure, warn_unused_result));
609 /***********************************************************/
615 UNIV_INLINE
616 void
618 /*==============*/
619  rec_t* rec,
620  const ulint* offsets,
621  ulint n,
622  const void* data,
623  ulint len)
628  __attribute__((nonnull(1,2)));
629 /**********************************************************/
635 UNIV_INLINE
636 ulint
638 /*==================*/
639  const rec_t* rec)
640  __attribute__((nonnull, pure, warn_unused_result));
641 /**********************************************************/
645 UNIV_INLINE
646 ulint
648 /*=================*/
649  const ulint* offsets)
650  __attribute__((nonnull, pure, warn_unused_result));
651 /**********************************************************/
654 UNIV_INLINE
655 void
657 /*=================*/
658  ulint* offsets,
660  ulint n_alloc)
661  __attribute__((nonnull));
662 #define rec_offs_init(offsets) \
663  rec_offs_set_n_alloc(offsets, (sizeof offsets) / sizeof *offsets)
664 /**********************************************************/
667 UNIV_INLINE
668 ulint
670 /*==============*/
671  const ulint* offsets)
672  __attribute__((nonnull, pure, warn_unused_result));
673 /**********************************************************/
679 UNIV_INLINE
680 ulint
682 /*===============*/
683  const ulint* offsets)
684  __attribute__((nonnull, pure, warn_unused_result));
685 /**********************************************************/
690 UNIV_INLINE
691 ulint
693 /*================*/
694  const ulint* offsets)
695  __attribute__((nonnull, pure, warn_unused_result));
696 /**********************************************************/
699 UNIV_INLINE
700 ulint
702 /*==========*/
703  const ulint* offsets)
704  __attribute__((nonnull, pure, warn_unused_result));
705 #ifdef UNIV_DEBUG
706 /**********************************************************/
709 UNIV_INLINE
710 byte*
711 rec_get_start(
712 /*==========*/
713  const rec_t* rec,
714  const ulint* offsets)
715  __attribute__((nonnull, pure, warn_unused_result));
716 /**********************************************************/
719 UNIV_INLINE
720 byte*
721 rec_get_end(
722 /*========*/
723  const rec_t* rec,
724  const ulint* offsets)
725  __attribute__((nonnull, pure, warn_unused_result));
726 #else /* UNIV_DEBUG */
727 # define rec_get_start(rec, offsets) ((rec) - rec_offs_extra_size(offsets))
728 # define rec_get_end(rec, offsets) ((rec) + rec_offs_data_size(offsets))
729 #endif /* UNIV_DEBUG */
730 /***************************************************************/
733 UNIV_INLINE
734 rec_t*
735 rec_copy(
736 /*=====*/
737  void* buf,
738  const rec_t* rec,
739  const ulint* offsets)
740  __attribute__((nonnull));
741 #ifndef UNIV_HOTBACKUP
742 /**********************************************************/
745 UNIV_INTERN
746 ulint
748 /*========================*/
749  const dict_index_t* index,
750  const dfield_t* fields,
751  ulint n_fields,
752  ulint* extra)
753  __attribute__((warn_unused_result, nonnull));
754 
755 /******************************************************/
758 UNIV_INTERN
759 void
761 /*==================*/
762  const rec_t* rec,
763  const dict_index_t* index,
764  ulint* offsets)
766  __attribute__((nonnull));
767 
768 /*********************************************************/
771 UNIV_INTERN
772 void
774 /*=======================*/
775  rec_t* rec,
776  const dict_index_t* index,
777  const dfield_t* fields,
778  ulint n_fields)
779  __attribute__((nonnull));
780 
781 /**************************************************************/
785 UNIV_INTERN
786 rec_t*
788 /*===================*/
789  const rec_t* rec,
790  const dict_index_t* index,
791  ulint n_fields,
793  byte** buf,
796  ulint* buf_size)
797  __attribute__((nonnull));
798 /************************************************************/
801 UNIV_INLINE
802 ulint
803 rec_fold(
804 /*=====*/
805  const rec_t* rec,
806  const ulint* offsets,
808  ulint n_fields,
810  ulint n_bytes,
812  index_id_t tree_id)
813  __attribute__((nonnull, pure, warn_unused_result));
814 #endif /* !UNIV_HOTBACKUP */
815 /*********************************************************/
819 UNIV_INTERN
820 rec_t*
822 /*======================*/
823  byte* buf,
825  const dict_index_t* index,
826  const dtuple_t* dtuple,
827  ulint n_ext)
829  __attribute__((nonnull, warn_unused_result));
830 /**********************************************************/
834 UNIV_INLINE
835 ulint
837 /*=========================*/
838  ulint data_size,
839  ulint n_fields,
840  ulint n_ext)
841  __attribute__((const));
842 /**********************************************************/
845 UNIV_INTERN
846 ulint
848 /*===============================*/
849  const dict_index_t* index,
850  const dfield_t* fields,
851  ulint n_fields,
852  ulint* extra)
853  __attribute__((warn_unused_result, nonnull(1,2)));
854 /**********************************************************/
857 UNIV_INTERN
858 ulint
860 /*========================*/
861  const dict_index_t* index,
865  ulint status,
866  const dfield_t* fields,
867  ulint n_fields,
868  ulint* extra)
869  __attribute__((nonnull(1,3)));
870 /**********************************************************/
874 UNIV_INLINE
875 ulint
877 /*===================*/
879  const dtuple_t* dtuple,
880  ulint n_ext)
881  __attribute__((warn_unused_result, nonnull));
882 #ifndef UNIV_HOTBACKUP
883 /**************************************************************/
886 UNIV_INTERN
887 void
889 /*======================*/
890  dtuple_t* tuple,
891  const rec_t* rec,
892  const dict_index_t* index,
893  ulint n_fields,
895  mem_heap_t* heap)
896  __attribute__((nonnull));
897 #endif /* !UNIV_HOTBACKUP */
898 /***************************************************************/
901 UNIV_INTERN
902 ibool
904 /*=========*/
905  const rec_t* rec,
906  const ulint* offsets)
907  __attribute__((nonnull));
908 /***************************************************************/
910 UNIV_INTERN
911 void
913 /*==========*/
914  FILE* file,
915  const rec_t* rec)
916  __attribute__((nonnull));
917 #ifndef UNIV_HOTBACKUP
918 /***************************************************************/
921 UNIV_INTERN
922 void
924 /*===========*/
925  FILE* file,
926  const rec_t* rec,
927  const ulint* offsets)
928  __attribute__((nonnull));
929 /***************************************************************/
931 UNIV_INTERN
932 void
934 /*==========*/
935  FILE* file,
936  const rec_t* rec,
937  const ulint* offsets)
938  __attribute__((nonnull));
939 /***************************************************************/
941 UNIV_INTERN
942 void
943 rec_print(
944 /*======*/
945  FILE* file,
946  const rec_t* rec,
947  const dict_index_t* index)
948  __attribute__((nonnull));
949 
950 # ifdef UNIV_DEBUG
951 /************************************************************/
954 UNIV_INTERN
955 trx_id_t
956 rec_get_trx_id(
957 /*===========*/
958  const rec_t* rec,
959  const dict_index_t* index)
960  __attribute__((nonnull, warn_unused_result));
961 # endif /* UNIV_DEBUG */
962 #endif /* UNIV_HOTBACKUP */
963 
964 /* Maximum lengths for the data in a physical record if the offsets
965 are given in one byte (resp. two byte) format. */
966 #define REC_1BYTE_OFFS_LIMIT 0x7FUL
967 #define REC_2BYTE_OFFS_LIMIT 0x7FFFUL
968 
969 /* The data size of record must be smaller than this because we reserve
970 two upmost bits in a two byte offset for special purposes */
971 #define REC_MAX_DATA_SIZE (16 * 1024)
972 
973 #ifndef UNIV_NONINL
974 #include "rem0rec.ic"
975 #endif
976 
977 #endif