MySQL 26.10.0
Source Code Documentation
rec.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1994, 2026, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is designed to work with certain software (including
10but not limited to OpenSSL) that is licensed under separate terms,
11as designated in a particular file or component or in included license
12documentation. The authors of MySQL hereby grant you an additional
13permission to link the program and your derivative works with the
14separately licensed software that they have either included with
15the program or referenced in the documentation.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20for more details.
21
22You should have received a copy of the GNU General Public License along with
23this program; if not, write to the Free Software Foundation, Inc.,
2451 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26*****************************************************************************/
27
28/** @file rem/rec.h
29 Record manager
30
31 Created 5/30/1994 Heikki Tuuri
32 *************************************************************************/
33
34/** NOTE: The functions in this file should only use functions from
35other files in library. The code in this file is used to make a library for
36external tools. */
37
38/**
39Extra Bytes in Redudant Row Format
40
41The extra bytes of the redundant row format (old row format) is explained here.
42It contains a total of 6 bytes that occurs before the record origin. These
43bits and bytes are accessed with reference to the record origin. So when we
44say 3rd byte, it means that it is 3rd byte from the record origin.
45
46 byte 6 byte 5 byte 4 byte 3 byte 2 byte 1
47[iiiioooo][hhhhhhhh][hhhhhfff][fffffffs][pppppppp][pppppppp]+
48
491. The + is the record origin.
502. The next record pointer is given by the bits marked as 'p'. This takes
51 2 bytes - 1st and 2nd byte.
523. One bit is used to indicate whether the field offsets array uses 1 byte or
53 2 bytes each. This is given by the bit 's' in 3rd byte.
544. The total number of fields is given by the bits marked as 'f'. It spans
55 the 4th and 3rd bytes. It uses a total of 10 bits.
565. The heap number of the record is given by the bits marked as 'h'. It spans
57 the 5th and 4th bytes. It uses a total of 13 bits.
586. The record owned (by dir slot) information is given by bits marked as 'o'.
59 It uses a total of 4 bits. It is available in the 6th byte.
607. The info bits are given by the bits marked as 'i'. It uses a total of 4
61 bits. It is available in the 6th byte.
62*/
63
64#ifndef rem_rec_h
65#define rem_rec_h
66
67#include "dict0boot.h"
68#include "dict0dict.h"
69
70#include <optional>
71
72/* Compact flag ORed to the extra size returned by rec_get_offsets() */
73constexpr uint32_t REC_OFFS_COMPACT = 1U << 31;
74/* SQL NULL flag in offsets returned by rec_get_offsets() */
75constexpr uint32_t REC_OFFS_SQL_NULL = 1U << 31;
76/* External flag in offsets returned by rec_get_offsets() */
77constexpr uint32_t REC_OFFS_EXTERNAL = 1 << 30;
78/* Default value flag in offsets returned by rec_get_offsets() */
79constexpr uint32_t REC_OFFS_DEFAULT = 1 << 29;
80/* An INSTANT DROP flag in offsets returned by rec_get_offsets() */
81constexpr uint32_t REC_OFFS_DROP = 1 << 28;
82/* Mask for offsets returned by rec_get_offsets() */
83constexpr uint32_t REC_OFFS_MASK = REC_OFFS_DROP - 1;
84
85/* The offset of heap_no in a compact record */
86constexpr uint32_t REC_NEW_HEAP_NO = 4;
87/* The shift of heap_no in a compact record.
88The status is stored in the low-order bits. */
89constexpr uint32_t REC_HEAP_NO_SHIFT = 3;
90
91/* We list the byte offsets from the origin of the record, the mask,
92and the shift needed to obtain each bit-field of the record. */
93
94constexpr uint32_t REC_NEXT = 2;
95constexpr uint32_t REC_NEXT_MASK = 0xFFFFUL;
96constexpr uint32_t REC_NEXT_SHIFT = 0;
97
98constexpr uint32_t REC_OLD_SHORT = 3; /* This is single byte bit-field */
99constexpr uint32_t REC_OLD_SHORT_MASK = 0x1UL;
100constexpr uint32_t REC_OLD_SHORT_SHIFT = 0;
101
102constexpr uint32_t REC_OLD_N_FIELDS = 4;
103constexpr uint32_t REC_OLD_N_FIELDS_MASK = 0x7FEUL;
104constexpr uint32_t REC_OLD_N_FIELDS_SHIFT = 1;
105
106constexpr uint32_t REC_NEW_STATUS = 3; /* This is single byte bit-field */
107constexpr uint32_t REC_NEW_STATUS_MASK = 0x7UL;
108constexpr uint32_t REC_NEW_STATUS_SHIFT = 0;
109
110constexpr uint32_t REC_OLD_HEAP_NO = 5;
111constexpr uint32_t REC_HEAP_NO_MASK = 0xFFF8UL;
112#if 0 /* defined in rem0rec.h for use of page0zip.cc */
113#define REC_NEW_HEAP_NO 4
114#define REC_HEAP_NO_SHIFT 3
115#endif
116
117constexpr uint32_t REC_OLD_N_OWNED = 6; /* This is single byte bit-field */
118constexpr uint32_t REC_NEW_N_OWNED = 5; /* This is single byte bit-field */
119constexpr uint32_t REC_N_OWNED_MASK = 0xFUL;
120constexpr uint32_t REC_N_OWNED_SHIFT = 0;
121
122constexpr uint32_t REC_OLD_INFO_BITS = 6; /* This is single byte bit-field */
123constexpr uint32_t REC_NEW_INFO_BITS = 5; /* This is single byte bit-field */
124constexpr uint32_t REC_TMP_INFO_BITS = 1; /* This is single byte bit-field */
125constexpr uint32_t REC_INFO_BITS_MASK = 0xF0UL;
126constexpr uint32_t REC_INFO_BITS_SHIFT = 0;
127
128static_assert((REC_OLD_SHORT_MASK << (8 * (REC_OLD_SHORT - 3)) ^
130 REC_HEAP_NO_MASK << (8 * (REC_OLD_HEAP_NO - 4)) ^
131 REC_N_OWNED_MASK << (8 * (REC_OLD_N_OWNED - 3)) ^
133 0xFFFFFFFFUL) == 0,
134 "sum of old-style masks != 0xFFFFFFFFUL");
135static_assert((REC_NEW_STATUS_MASK << (8 * (REC_NEW_STATUS - 3)) ^
136 REC_HEAP_NO_MASK << (8 * (REC_NEW_HEAP_NO - 4)) ^
137 REC_N_OWNED_MASK << (8 * (REC_NEW_N_OWNED - 3)) ^
139 0xFFFFFFUL) == 0,
140 "sum of new-style masks != 0xFFFFFFUL");
141
142/* Info bit denoting the predefined minimum record: this bit is set
143if and only if the record is the first user record on a non-leaf
144B-tree page that is the leftmost page on its level
145(PAGE_LEVEL is nonzero and FIL_PAGE_PREV is FIL_NULL). */
146constexpr uint32_t REC_INFO_MIN_REC_FLAG = 0x10UL;
147/** The deleted flag in info bits; when bit is set to 1, it means the record has
148 been delete marked */
149constexpr uint32_t REC_INFO_DELETED_FLAG = 0x20UL;
150/* Use this bit to indicate record has version */
151constexpr uint32_t REC_INFO_VERSION_FLAG = 0x40UL;
152/** The instant ADD COLUMN flag. When it is set to 1, it means this record
153was inserted/updated after an instant ADD COLUMN. */
154constexpr uint32_t REC_INFO_INSTANT_FLAG = 0x80UL;
155
156/* Number of extra bytes in an old-style record,
157in addition to the data and the offsets */
158constexpr uint32_t REC_N_OLD_EXTRA_BYTES = 6;
159/* Number of extra bytes in a new-style record,
160in addition to the data and the offsets */
161constexpr int32_t REC_N_NEW_EXTRA_BYTES = 5;
162/* Number of extra bytes in a new-style temporary record,
163in addition to the data and the offsets.
164This is used only after instant ADD COLUMN. */
165constexpr uint32_t REC_N_TMP_EXTRA_BYTES = 1;
166
167#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
168/** Maximum number of records in a page */
170
171/* We use decltype(A.load()) not decltype(A)::value_type, as some compilers
172don't have it implemented, even as they should have this with the C++17
173implementation. Maybe this will be available on all compilers with C++20. */
174static_assert(MAX_REC_PER_PAGE <=
175 std::numeric_limits<
176 decltype(buf_block_t::ahi_t::n_pointers.load())>::max());
177
178#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
179
180/* Record status values */
181constexpr uint32_t REC_STATUS_ORDINARY = 0;
182constexpr uint32_t REC_STATUS_NODE_PTR = 1;
183constexpr uint32_t REC_STATUS_INFIMUM = 2;
184constexpr uint32_t REC_STATUS_SUPREMUM = 3;
185
186/* The following four constants are needed in page0zip.cc in order to
187efficiently compress and decompress pages. */
188
189/* Length of a B-tree node pointer, in bytes */
190constexpr uint32_t REC_NODE_PTR_SIZE = 4;
191
192/** SQL null flag in a 1-byte offset of ROW_FORMAT=REDUNDANT records */
193constexpr uint32_t REC_1BYTE_SQL_NULL_MASK = 0x80UL;
194/** SQL null flag in a 2-byte offset of ROW_FORMAT=REDUNDANT records */
195constexpr uint32_t REC_2BYTE_SQL_NULL_MASK = 0x8000UL;
196
197/** In a 2-byte offset of ROW_FORMAT=REDUNDANT records, the second most
198significant bit denotes that the tail of a field is stored off-page. */
199constexpr uint32_t REC_2BYTE_EXTERN_MASK = 0x4000UL;
200
201#ifdef UNIV_DEBUG
202/* Length of the rec_get_offsets() header */
203constexpr uint32_t REC_OFFS_HEADER_SIZE = 4;
204#else /* UNIV_DEBUG */
205/* Length of the rec_get_offsets() header */
206constexpr uint32_t REC_OFFS_HEADER_SIZE = 2;
207#endif /* UNIV_DEBUG */
208
209/* Number of elements that should be initially allocated for the
210offsets[] array, first passed to rec_get_offsets() */
211constexpr uint32_t REC_OFFS_NORMAL_SIZE = 100;
212constexpr uint32_t REC_OFFS_SMALL_SIZE = 10;
213
214/** Instant state of a record. Determined by instant and version bit in info
215 * bits. */
217 /* Record is neither instant nor versioned: Instant: 0, Version: 0 */
219 /* Record is versioned but not instant: Instant: 0, Version: 1 */
221 /* Record is instant but not versioned: Instant: 1, Version: 0 */
223};
224
225/* Get the base address of offsets. The extra_size is stored at
226this position, and following positions hold the end offsets of
227the fields. */
228
229static inline const ulint *rec_offs_base(const ulint *offsets) {
230 return offsets + REC_OFFS_HEADER_SIZE;
231}
232
233static inline ulint *rec_offs_base(ulint *offsets) {
234 return offsets + REC_OFFS_HEADER_SIZE;
235}
236
237/** Number of fields flag which means it occupies two bytes */
238static const uint8_t REC_N_FIELDS_TWO_BYTES_FLAG = 0x80;
239
240/** Max number of fields which can be stored in one byte */
241static const uint8_t REC_N_FIELDS_ONE_BYTE_MAX = 0x7F;
242
243/** The following function determines the offsets to each field
244 in the record. It can reuse a previously allocated array.
245 Note that after instant ADD COLUMN, if this is a record
246 from clustered index, fields in the record may be less than
247 the fields defined in the clustered index. So the offsets
248 size is allocated according to the clustered index fields.
249 @param[in] rec physical record
250 @param[in] index record descriptor
251 @param[in,out] offsets array consisting of offsets[0] allocated elements, or an
252 array from rec_get_offsets(), or NULL
253 @param[in] n_fields maximum number of initialized fields (ULINT_UNDEFINED is
254 all fields)
255 @param[in] location location where called
256 @param[in,out] heap memory heap
257 @return the new offsets */
258[[nodiscard]] ulint *rec_get_offsets(const rec_t *rec,
259 const dict_index_t *index, ulint *offsets,
260 ulint n_fields, ut::Location location,
261 mem_heap_t **heap);
262
263/** The following function determines the offsets to each field
264 in the record. It can reuse a previously allocated array. */
266 const byte *extra, /*!< in: the extra bytes of a
267 compact record in reverse order,
268 excluding the fixed-size
269 REC_N_NEW_EXTRA_BYTES */
270 const dict_index_t *index, /*!< in: record descriptor */
271 ulint node_ptr, /*!< in: nonzero=node pointer,
272 0=leaf node */
273 ulint *offsets); /*!< in/out: array consisting of
274 offsets[0] allocated elements */
275
276/** Gets a bit field from within 1 byte. */
278 const rec_t *rec, /*!< in: pointer to record origin */
279 ulint offs, /*!< in: offset from the origin down */
280 ulint mask, /*!< in: mask used to filter bits */
281 ulint shift) /*!< in: shift right applied after masking */
282{
283 ut_ad(rec);
284
285 return ((mach_read_from_1(rec - offs) & mask) >> shift);
286}
287
288/** Gets a bit field from within 2 bytes. */
289static inline uint16_t rec_get_bit_field_2(
290 const rec_t *rec, /*!< in: pointer to record origin */
291 ulint offs, /*!< in: offset from the origin down */
292 ulint mask, /*!< in: mask used to filter bits */
293 ulint shift) /*!< in: shift right applied after masking */
294{
295 ut_ad(rec);
296
297 return ((mach_read_from_2(rec - offs) & mask) >> shift);
298}
299
300/** The following function retrieves the status bits of a new-style record.
301 @return status bits */
302[[nodiscard]] static inline ulint rec_get_status(
303 const rec_t *rec) /*!< in: physical record */
304{
305 ulint ret;
306
307 ut_ad(rec);
308
311 ut_ad((ret & ~REC_NEW_STATUS_MASK) == 0);
312
313 return (ret);
314}
315
316#ifdef UNIV_DEBUG
317/** Check if the info bits are valid.
318@param[in] bits info bits to check
319@return true if valid */
320inline bool rec_info_bits_valid(ulint bits) {
321 return (0 == (bits & ~(REC_INFO_DELETED_FLAG | REC_INFO_MIN_REC_FLAG |
323}
324#endif /* UNIV_DEBUG */
325
326/** The following function is used to retrieve the info bits of a record.
327@param[in] rec physical record
328@param[in] comp nonzero=compact page format
329@return info bits */
330static inline ulint rec_get_info_bits(const rec_t *rec, ulint comp) {
331 const ulint val =
335 return (val);
336}
337
338/** The following function is used to retrieve the info bits of a temporary
339record.
340@param[in] rec physical record
341@return info bits */
342static inline ulint rec_get_info_bits_temp(const rec_t *rec) {
343 const ulint val = rec_get_bit_field_1(
346 return (val);
347}
348
349/** The following function is used to get the number of fields
350 in an old-style record, which is stored in the rec
351 @return number of data fields */
352[[nodiscard]] static inline uint16_t rec_get_n_fields_old_raw(
353 const rec_t *rec) /*!< in: physical record */
354{
355 uint16_t n_fields;
356
357 ut_ad(rec);
358
361
362 ut_ad(n_fields <= REC_MAX_N_FIELDS);
363 ut_ad(n_fields > 0);
364
365 return (n_fields);
366}
367
368/** The following function is used to get the number of fields
369in an old-style record. Have to consider the case that after
370instant ADD COLUMN, this record may have less fields than
371current index.
372@param[in] rec physical record
373@param[in] index index where the record resides
374@return number of data fields */
375[[nodiscard]] static inline uint16_t rec_get_n_fields_old(
376 const rec_t *rec, const dict_index_t *index) {
377 uint16_t n = rec_get_n_fields_old_raw(rec);
378
379 if (index->has_instant_cols_or_row_versions()) {
380 if (strcmp(index->name, RECOVERY_INDEX_TABLE_NAME) == 0) {
381 /* In recovery, index is not completely built. Skip validation. */
382 if (n > 1) /* For infimum/supremum, n is 1 */ {
383 n = static_cast<uint16_t>(dict_index_get_n_fields(index));
384 }
385 return n;
386 }
387
389
390 ut_ad(index->is_clustered());
392 ut_ad(n_uniq > 0);
393 /* Only when it's infimum or supremum, n is 1.
394 If n is exact n_uniq, this should be a record copied with prefix during
395 search.
396 And if it's node pointer, n is n_uniq + 1, which should be always less
397 than the number of fields in any leaf page, even if the record in
398 leaf page is before instant ADD COLUMN. This is because any record in
399 leaf page must have at least n_uniq + 2 (system columns) fields */
400 ut_ad(n == 1 || n >= n_uniq);
401 ut_ad(static_cast<uint16_t>(dict_index_get_n_fields(index)) > n_uniq + 1);
402 if (n > n_uniq + 1) {
403 /* This is leaf node. If table has INSTANT columns, then it is possible
404 that record might not have all the fields in index. So get it now from
405 index. */
406#ifdef UNIV_DEBUG
407 if (index->has_instant_cols() && !index->has_row_versions()) {
409 ulint rec_diff = dict_index_get_n_fields(index) - n;
410 ulint col_diff = index->table->n_cols - index->table->n_instant_cols;
411 ut_ad(rec_diff <= col_diff);
412 }
413
415 ut_ad(index->has_instant_cols_or_row_versions());
416 }
417#endif /* UNIV_DEBUG */
418 n = static_cast<uint16_t>(dict_index_get_n_fields(index));
419 }
420 }
421
422 return (n);
423}
424
425/** The following function is used to get the number of fields
426 in a record. If it's REDUNDANT record, the returned number
427 would be a logic one which considers the fact that after
428 instant ADD COLUMN, some records may have less fields than
429 index.
430 @return number of data fields */
432 const rec_t *rec, /*!< in: physical record */
433 const dict_index_t *index) /*!< in: record descriptor */
434{
435 ut_ad(rec);
436 ut_ad(index);
437
438 if (!dict_table_is_comp(index->table)) {
439 return (rec_get_n_fields_old(rec, index));
440 }
441
442 switch (rec_get_status(rec)) {
449 return (1);
450 default:
451 ut_error;
452 }
453}
454
455/** Confirms the n_fields of the entry is sane with comparing the other
456record in the same page specified
457@param[in] index index
458@param[in] rec record of the same page
459@param[in] entry index entry
460@return true if n_fields is sane */
461static inline bool rec_n_fields_is_sane(dict_index_t *index, const rec_t *rec,
462 const dtuple_t *entry) {
464}
465
466/** The following function returns the number of allocated elements
467 for an array of offsets.
468 @return number of elements */
469[[nodiscard]] static inline ulint rec_offs_get_n_alloc(
470 const ulint *offsets) /*!< in: array for rec_get_offsets() */
471{
472 ulint n_alloc;
473 ut_ad(offsets);
474 n_alloc = offsets[0];
475 ut_ad(n_alloc > REC_OFFS_HEADER_SIZE);
476 UNIV_MEM_ASSERT_W(offsets, n_alloc * sizeof *offsets);
477 return (n_alloc);
478}
479
480/** The following function sets the number of allocated elements
481 for an array of offsets. */
482static inline void rec_offs_set_n_alloc(
483 ulint *offsets, /*!< out: array for rec_get_offsets(),
484 must be allocated */
485 ulint n_alloc) /*!< in: number of elements */
486{
487 ut_ad(offsets);
488 ut_ad(n_alloc > REC_OFFS_HEADER_SIZE);
489 UNIV_MEM_ASSERT_AND_ALLOC(offsets, n_alloc * sizeof *offsets);
490 offsets[0] = n_alloc;
491}
492
493/** The following function sets the number of fields in offsets. */
494static inline void rec_offs_set_n_fields(
495 ulint *offsets, /*!< in/out: array returned by
496 rec_get_offsets() */
497 ulint n_fields) /*!< in: number of fields */
498{
499 ut_ad(offsets);
500 ut_ad(n_fields > 0);
501 ut_ad(n_fields <= REC_MAX_N_FIELDS);
502 ut_ad(n_fields + REC_OFFS_HEADER_SIZE <= rec_offs_get_n_alloc(offsets));
503 offsets[1] = n_fields;
504}
505
506/** The following function returns the number of fields in a record.
507 @return number of fields */
508[[nodiscard]] static inline ulint rec_offs_n_fields(
509 const ulint *offsets) /*!< in: array returned by rec_get_offsets() */
510{
511 ulint n_fields;
512 ut_ad(offsets);
513 n_fields = offsets[1];
514 ut_ad(n_fields > 0);
515 ut_ad(n_fields <= REC_MAX_N_FIELDS);
516 ut_ad(n_fields + REC_OFFS_HEADER_SIZE <= rec_offs_get_n_alloc(offsets));
517 return (n_fields);
518}
519
520/** Determine the offset of a specified field in the record, when this
521field is a field added after an instant ADD COLUMN
522@param[in] index Clustered index where the record resides
523@param[in] n Nth field to get offset
524@param[in] offs Last offset before current field
525@return The offset of the specified field */
526static inline uint64_t rec_get_instant_offset(const dict_index_t *index,
527 ulint n, uint64_t offs) {
528 ut_ad(index->has_instant_cols_or_row_versions());
529
531 index->get_nth_default(n, &length);
532
533 if (length == UNIV_SQL_NULL) {
534 return (offs | REC_OFFS_DEFAULT | REC_OFFS_SQL_NULL);
535 } else {
536 return (offs | REC_OFFS_DEFAULT);
537 }
538}
539
540/** The following function determines the offsets to each field in the record.
541The offsets are written to a previously allocated array of ulint, where
542rec_offs_n_fields(offsets) has been initialized to the number of fields in the
543record. The rest of the array will be initialized by this function.
544- rec_offs_base(offsets)[0] will be set to the extra size
545 (if REC_OFFS_COMPACT is set, the record is in the new format;
546 if REC_OFFS_EXTERNAL is set, the record contains externally stored columns).
547- rec_offs_base(offsets)[1..n_fields] will be set to offsets past the end of
548 fields 0..n_fields, or to the beginning of fields 1..n_fields+1.
549- If the high-order bit of the offset at [i+1] is set (REC_OFFS_SQL_NULL),
550 the field i is NULL.
551- If the second high-order bit of the offset at [i+1] is set
552(REC_OFFS_EXTERNAL), the field i is being stored externally.
553@param[in] rec physical record
554@param[in] index record descriptor
555@param[in,out] offsets array of offsets */
556void rec_init_offsets(const rec_t *rec, const dict_index_t *index,
557 ulint *offsets);
558
559#ifdef UNIV_DEBUG
560/** Validates offsets returned by rec_get_offsets().
561@param[in] rec record whose offsets are being validated or nullptr.
562@param[in] index index to which record belongs or nullptr.
563@param[in] offsets the record offsets array returned by rec_get_offsets()
564@param[in] check_status if true, check status bits of the record.
565@return true if valid */
566[[nodiscard]] static inline bool rec_offs_validate(
567 const rec_t *rec, const dict_index_t *index, const ulint *offsets,
568 const bool check_status = true) {
569 ulint i = rec_offs_n_fields(offsets);
570 ulint last = ULINT_MAX;
571 ulint comp = *rec_offs_base(offsets) & REC_OFFS_COMPACT;
572
573 if (rec) {
574 /* The offsets array might be:
575 - specific to the `rec`, in which case its address is stored in offsets[2],
576 - cached and shared by many records, in which case we've passed rec=nullptr
577 when preparing the offsets array.
578 We use caching only for the ROW_FORMAT=COMPACT format. */
579 ut_ad((ulint)rec == offsets[2] ||
580 ((ulint) nullptr == offsets[2] &&
581 (index != nullptr && offsets == index->rec_cache.offsets)));
582 if (!comp && index != nullptr) {
583 ut_a(rec_get_n_fields_old(rec, index) >= i);
584 }
585 }
586
587 if (index) {
588 ulint max_n_fields;
589 ut_ad((ulint)index == offsets[3]);
591 ulint n_unique_in_tree = dict_index_get_n_unique_in_tree(index) + 1;
592 max_n_fields = std::max(n_fields, n_unique_in_tree);
593 if (!comp && rec != nullptr && rec_get_n_fields_old_raw(rec) < i) {
594 ut_a(index->has_instant_cols_or_row_versions());
595 }
596
597 /* In the case of mrec_t the status will not be there. */
598 if (check_status) {
599 if (comp && rec) {
600 switch (rec_get_status(rec)) {
602 break;
604 max_n_fields = dict_index_get_n_unique_in_tree(index) + 1;
605 break;
608 max_n_fields = 1;
609 break;
610 default:
611 ut_error;
612 }
613 }
614 }
615
616 /* index->n_def == 0 for dummy indexes if !comp */
617 ut_a(!comp || index->n_def);
618 ut_a(!index->n_def || i <= max_n_fields);
619 }
620 while (i--) {
621 ulint curr = rec_offs_base(offsets)[1 + i] & REC_OFFS_MASK;
622 ut_a(curr <= last);
623 last = curr;
624 }
625 return true;
626}
627
628/** Updates debug data in offsets, in order to avoid bogus
629 rec_offs_validate() failures. */
630static inline void rec_offs_make_valid(
631 const rec_t *rec, /*!< in: record */
632 const dict_index_t *index, /*!< in: record descriptor */
633 ulint *offsets) /*!< in: array returned by
634 rec_get_offsets() */
635{
636 /* offsets are either intended for this particular rec, or to be cached */
637 ut_ad(rec || offsets == index->rec_cache.offsets);
638 ut_ad(index);
639 ut_ad(offsets);
640 ut_ad(rec == nullptr ||
641 rec_get_n_fields(rec, index) >= rec_offs_n_fields(offsets));
642 offsets[2] = (ulint)rec;
643 offsets[3] = (ulint)index;
644}
645
646/** Check if the given two record offsets are identical.
647@param[in] offsets1 field offsets of a record
648@param[in] offsets2 field offsets of a record
649@return true if they are identical, false otherwise. */
650bool rec_offs_cmp(ulint *offsets1, ulint *offsets2);
651
652/** Print the record offsets.
653@param[in] out the output stream to which offsets are printed.
654@param[in] offsets the field offsets of the record.
655@return the output stream. */
656std::ostream &rec_offs_print(std::ostream &out, const ulint *offsets);
657#else
658#define rec_offs_make_valid(rec, index, offsets) ((void)0)
659#endif /* UNIV_DEBUG */
660
661/** The following function tells if a new-style record is instant record.
662@param[in] rec new-style record
663@return true if it is instant affected */
664static inline bool rec_get_instant_flag_new(const rec_t *rec) {
665 ulint info = rec_get_info_bits(rec, true);
666 return ((info & REC_INFO_INSTANT_FLAG) != 0);
667}
668
669/** The following function tells if a new-style temp record is instant record.
670@param[in] rec new-style temp record
671@return true if it is instant affected */
672static inline bool rec_get_instant_flag_new_temp(const rec_t *rec) {
674 return ((info & REC_INFO_INSTANT_FLAG) != 0);
675}
676
677/** A simplified variant rec_init_offsets(rec, index, offsets) for the case in
678which the rec contains only fixed-length columns and non-NULL values in them,
679thus we can compute the offsets without looking at the rec. Such offsets can be
680cached and reused for many recs which don't contain NULLs.
681@see rec_init_offsets for more details
682@param[in] index The index for which we want to cache the fixed offsets
683@param[in,out] offsets The already allocated array to store the offsets.
684 It should already have been initialized with
685 rec_offs_set_n_alloc() and rec_offs_set_n_fields() before
686 the call.
687 This function will fill all the other elements. */
688inline void rec_init_fixed_offsets(const dict_index_t *index, ulint *offsets) {
689 ut_ad(!index->has_instant_cols_or_row_versions());
690
691 rec_offs_make_valid(nullptr, index, offsets);
692 rec_offs_base(offsets)[0] =
695 const auto n_fields = rec_offs_n_fields(offsets);
696 auto field_end = rec_offs_base(offsets) + 1;
697 for (size_t i = 0; i < n_fields; i++) {
698 field_end[i] = (i ? field_end[i - 1] : 0) + index->get_field(i)->fixed_len;
699 }
700}
701
702/** The following function tells if a new-style record is versioned.
703@param[in] rec new-style (COMPACT/DYNAMIC) record
704@return true if it is versioned */
705static inline bool rec_new_is_versioned(const rec_t *rec) {
706 ulint info = rec_get_info_bits(rec, true);
707 return ((info & REC_INFO_VERSION_FLAG) != 0);
708}
709
710/** The following function tells if an old-style record is versioned.
711@param[in] rec old-style (REDUNDANT) record
712@return true if it's versioned */
713static inline bool rec_old_is_versioned(const rec_t *rec) {
714 ulint info = rec_get_info_bits(rec, false);
715 return ((info & REC_INFO_VERSION_FLAG) != 0);
716}
717
718/** The following function tells if a temporary record is versioned.
719@param[in] rec new-style temporary record
720@return true if it's instant affected */
721static inline bool rec_new_temp_is_versioned(const rec_t *rec) {
723 return ((info & REC_INFO_VERSION_FLAG) != 0);
724}
725
726#if defined(UNIV_DEBUG) && !defined(UNIV_LIBRARY) && !defined(UNIV_HOTBACKUP)
727#define UNIV_ROW_IMPORT_DBG
728/* Declarations of methods from row0import that are less efficient but check
729against page corruptions. */
730
732 const page_t *page, const byte *ptr, uint16_t *n_fields, uint16_t *length,
733 bool force_page_boundary_check);
734
736 const rec_t *rec);
737
739 const rec_t *rec);
740
742 const dict_index_t *index);
743
745 const page_t *page, const dict_index_t *index);
746#endif
747
749#ifdef UNIV_ROW_IMPORT_DBG
750 public:
753
755 delete;
757 const Row_import_metadata_check_guard &) = delete;
758#endif
759};
760
761/** Get the number of fields for one new style leaf page record.
762This is only needed for table after instant ADD COLUMN.
763@param[in] rec leaf page record
764@param[in] extra_bytes extra bytes of this record
765@param[in,out] length length of number of fields
766@return number of fields */
767static inline uint32_t rec_get_n_fields_instant(const rec_t *rec,
768 const ulint extra_bytes,
769 uint16_t *length) {
770 uint16_t n_fields;
771 const byte *ptr;
772
773 ptr = rec - (extra_bytes + 1);
774
775 ut_d(std::optional<uint32_t> checked_result);
776 ut_d(uint16_t checked_length{});
777#ifdef UNIV_ROW_IMPORT_DBG
778 /* This helper is also used for compact temporary records. Only normal
779 compact page records use REC_N_NEW_EXTRA_BYTES and have the record layout
780 validated by row import. */
781 if (extra_bytes == REC_N_NEW_EXTRA_BYTES) {
782 uint16_t checked_fields;
784 (const page_t *)ut_align_down(rec, UNIV_PAGE_SIZE), ptr,
785 &checked_fields, &checked_length, false);
786 ut_a(res);
787 checked_result = checked_fields;
788 }
789#endif
790
791 if ((*ptr & REC_N_FIELDS_TWO_BYTES_FLAG) == 0) {
792 *length = 1;
793 ut_ad(!checked_result || (checked_result == *ptr && checked_length == 1));
794 return (*ptr);
795 }
796
797 *length = 2;
798 n_fields = ((*ptr-- & REC_N_FIELDS_ONE_BYTE_MAX) << 8);
799 n_fields |= *ptr;
800 ut_ad(n_fields < REC_MAX_N_FIELDS);
801 ut_ad(n_fields != 0);
802
803 ut_ad(!checked_result ||
804 (checked_result == n_fields && checked_length == *length));
805 return (n_fields);
806}
807
808/* For INSTANT ADD/DROP, we may have following 5 types of rec for table :
809 +----------------------------------------------------------------------------+
810 | SCENARIO | STATE |
811 |----------------------------------+------------+---------+------------------|
812 | Row property | V <= 8.0.28| Bit set | Stored on row |
813 +----------------------------------+------------+---------+------------------+
814 | INSERTED before 1st INSTANT ADD | Y | NONE | N/A |
815 |----------------------------------+------------+---------+------------------|
816 | INSERTED after 1st INSTANT ADD | Y | INSTANT | # of fields |
817 |----------------------------------+------------+---------+------------------|
818 | INSERTED before INSTANT ADD/DROP | Y | VERSION | Version = 0 |
819 |----------------------------------+------------+---------+------------------|
820 | INSERTED before INSTANT ADD/DROP | N | NONE | N/A |
821 |----------------------------------+------------+---------+------------------|
822 | INSERTED after INSTANT ADD/DROP | Y/N | VERSION | row version |
823 +----------------------------------------------------------------------------+
824*/
826 /* Record was inserted before first instant add done in the earlier
827 implementation. */
829 /* Record was inserted after first instant add done in the earlier
830 implementation. */
832 /* Record was inserted after upgrade but before first instant add done in the
833 new implementation. */
835 /* Record was inserted before first instant add/drop done in the new
836 implementation. */
838 /* Record was inserted after first instant add/drop done in the new
839 implementation. */
841 /* Record belongs to table with no verison no instant */
843 NONE
845
847 const dict_index_t *index, const rec_t *rec, bool temp) {
848 ut_ad(dict_table_is_comp(index->table) || temp);
849
850 if (!index->has_instant_cols_or_row_versions()) {
852 }
853
854 /* Position just before info-bits where version will be there if any */
855 const byte *v_ptr =
856 (byte *)rec -
858 const bool is_versioned =
860 const row_version_t version =
861 (is_versioned) ? static_cast<row_version_t>(*v_ptr) : INVALID_ROW_VERSION;
862
863 const bool is_instant = (temp) ? rec_get_instant_flag_new_temp(rec)
865
866 /* Only one of the two bits could be set */
867 DBUG_EXECUTE_IF("innodb_rec_instant_version_bit_set", {
868 ib::error() << "Record has both instant and version bit set in Table '"
869 << index->table_name << "', Index '" << index->name()
870 << "'. This indicates that the table may be corrupt. Please "
871 "run CHECK TABLE before proceeding.";
872 });
873
874 if (is_versioned && is_instant) {
875 ib::error() << "Record has both instant and version bit set in Table '"
876 << index->table_name << "', Index '" << index->name()
877 << "'. This indicates that the table may be corrupt. Please "
878 "run CHECK TABLE before proceeding.";
879 }
880 ut_ad(!is_versioned || !is_instant);
881
882 enum REC_INSERT_STATE rec_insert_state = REC_INSERT_STATE::NONE;
883 if (is_versioned) {
885 if (version == 0) {
886 ut_ad(index->has_instant_cols());
887 rec_insert_state =
889 } else {
890 ut_ad(index->has_row_versions());
892 }
893 } else if (is_instant) {
894 ut_ad(index->table->has_instant_cols());
896 } else if (index->table->has_instant_cols()) {
898 } else {
900 }
901
902 ut_ad(rec_insert_state != REC_INSERT_STATE::NONE);
903 return rec_insert_state;
904}
905
906/* Following function is to set NULLS and LENS pointers correctly for a temp
907record generated for a record from REDUNDANT FORAMT
908@param[in] index record descriptor
909@param[in,out] rec temp record
910@param[out] n_null number of nullable columns in record
911@param[out] nulls pointer to nullbit map in temp record
912@param[out] lens pointer to lens in temp record
913@returns the row version stored in record or nondefault fields in record */
915 const dict_index_t *index, const rec_t *rec, uint16_t *n_null,
916 const byte **nulls, const byte **lens, uint16_t &non_default_fields,
917 row_version_t &row_version) {
919
920 non_default_fields = static_cast<uint16_t>(dict_index_get_n_fields(index));
921
922 row_version = INVALID_ROW_VERSION;
923
924 /* Set nulls just before the record */
925 *nulls = rec - 1;
926
927 enum REC_INSERT_STATE rec_insert_state =
928 get_rec_insert_state(index, rec, true);
929
930 if (rec_insert_state == INSERTED_INTO_TABLE_WITH_NO_INSTANT_NO_VERSION) {
931 *n_null = index->n_nullable;
932 *lens = *nulls - UT_BITS_IN_BYTES(*n_null);
933 return rec_insert_state;
934 }
935
936 /* info-bits must be present. Shift nulls before that. */
937 *nulls -= REC_N_TMP_EXTRA_BYTES;
938
939 switch (rec_insert_state) {
943 *n_null = index->get_nullable_in_version(0);
944 *lens = *nulls - UT_BITS_IN_BYTES(*n_null);
945 } break;
946
949 /* Read the version information */
950 row_version = (uint8_t)(**nulls);
951 ut_a(is_valid_row_version(row_version));
952
953 /* Shift nulls before the record version */
954 *nulls -= 1;
955 *n_null = index->get_nullable_in_version(row_version);
956 } break;
957
959 default:
960 ut_a(0);
961 }
962
963 *lens = *nulls - UT_BITS_IN_BYTES(*n_null);
964 return rec_insert_state;
965}
966
967/** Determines the information about null bytes and variable length bytes
968for a new-style temporary record
969@param[in] rec physical record
970@param[in] index index where the record resides
971@param[out] nulls the start of null bytes
972@param[out] lens the start of variable length bytes
973@param[out] n_null number of null fields
974@param[out] non_default_fields non default fields from record
975@param[out] row_version row version of the record
976@return the row inserted state */
978 const rec_t *rec, const dict_index_t *index, const byte **nulls,
979 const byte **lens, uint16_t *n_null, uint16_t &non_default_fields,
980 row_version_t &row_version) {
981 /* Following is the format for TEMP record.
982 +----+----+-------------------+--------------------+
983 | OP | ES |<-- Extra info --> | F1 | F2 | ... | Fn|
984 +----+----+-------------------+--------------------+
985 |
986 v
987 +--------------------+-------+---------+-----------+
988 | LN | ... | L2 | L1 | nulls | version | info-bits |
989 +--------------------+-------+---------+-----------+
990 <------ LENS ------>
991
992 where
993 info-bits => Present iff table has INSTANT/VERSION
994 version => version number iff version bit is set.
995 */
996
997 /* Redundant format */
998 if (!dict_table_is_comp(index->table)) {
999 return init_nulls_lens_for_temp_redundant(index, rec, n_null, nulls, lens,
1000 non_default_fields, row_version);
1001 }
1002
1003 non_default_fields = static_cast<uint16_t>(dict_index_get_n_fields(index));
1004
1005 row_version = INVALID_ROW_VERSION;
1006
1007 /* Set nulls just before the record */
1008 *nulls = rec - 1;
1009
1010 const enum REC_INSERT_STATE rec_insert_state =
1011 get_rec_insert_state(index, rec, true);
1012
1013 if (rec_insert_state == INSERTED_INTO_TABLE_WITH_NO_INSTANT_NO_VERSION) {
1014 *n_null = index->n_nullable;
1015 *lens = *nulls - UT_BITS_IN_BYTES(*n_null);
1016 return rec_insert_state;
1017 }
1018
1019 /* info-bits must be present. Shift nulls before that. */
1020 *nulls -= REC_N_TMP_EXTRA_BYTES;
1021
1022 switch (rec_insert_state) {
1025 /* Read the version information */
1026 row_version = (uint8_t)(**nulls);
1027 ut_a(is_valid_row_version(row_version));
1028
1029 /* Shift nulls before the record version */
1030 *nulls -= 1;
1031
1032 *n_null = index->get_nullable_in_version(row_version);
1033 } break;
1034
1036 /* Row inserted after first instant ADD COLUMN V1 */
1037 ut_ad(index->table->has_instant_cols());
1038 uint16_t length;
1039 non_default_fields =
1041 ut_ad(length == 1 || length == 2);
1042
1043 /* Shift nulls before "number of fields" */
1044 *nulls -= length;
1045 *n_null = index->get_n_nullable_before(non_default_fields);
1046 } break;
1047
1049 *n_null = index->get_nullable_before_instant_add_drop();
1050 non_default_fields = index->get_instant_fields();
1051 } break;
1052
1054 /* Row inserted before first INSTANT ADD/DROP in V2 */
1055 *n_null = index->get_nullable_before_instant_add_drop();
1056 } break;
1057
1059 default:
1060 ut_a(0);
1061 }
1062
1063 /* Position lens */
1064 *lens = *nulls - UT_BITS_IN_BYTES(*n_null);
1065
1066 return (rec_insert_state);
1067}
1068
1069/** Determines the information about null bytes and variable length bytes
1070for a new style record
1071@param[in] rec physical record
1072@param[in] index index where the record resides
1073@param[out] nulls the start of null bytes
1074@param[out] lens the start of variable length bytes
1075@param[out] n_null number of null fields
1076@param[out] non_default_fields non default fields from record
1077@param[out] row_version row version of the record
1078@return number of fields with no default or the row version of record */
1080 const rec_t *rec, const dict_index_t *index, const byte **nulls,
1081 const byte **lens, uint16_t *n_null, uint16_t &non_default_fields,
1082 row_version_t &row_version) {
1083 non_default_fields = static_cast<uint16_t>(dict_index_get_n_fields(index));
1084
1085 row_version = INVALID_ROW_VERSION;
1086
1087 /* Position nulls */
1088 *nulls = rec - (REC_N_NEW_EXTRA_BYTES + 1);
1089
1090 const enum REC_INSERT_STATE rec_insert_state =
1091 get_rec_insert_state(index, rec, false);
1092
1093 switch (rec_insert_state) {
1097
1098 *n_null = index->n_nullable;
1099 } break;
1100
1103 /* Read the row version from record */
1104 row_version = (uint8_t)(**nulls);
1105 ut_ad(is_valid_row_version(row_version));
1106
1107#ifdef UNIV_DEBUG
1108 if (strcmp(index->name, RECOVERY_INDEX_TABLE_NAME) != 0) {
1109 if (row_version > 0) {
1110 /* Row inserted after first instant ADD/DROP COLUMN V2 */
1111 ut_ad(index->table->has_row_versions());
1112 } else {
1113 /* Upgraded table. Row inserted before V2 INSTANT ADD/DROP */
1114 ut_ad(index->table->is_upgraded_instant());
1115 }
1116 }
1117#endif
1118
1119 /* Reposition nulls to skip version */
1120 *nulls -= 1;
1121 *n_null = index->get_nullable_in_version(row_version);
1122 } break;
1123
1125 /* Row inserted after first instant ADD COLUMN V1 */
1126 uint16_t length;
1127 non_default_fields =
1129 ut_ad(length == 1 || length == 2);
1130
1131 /* Reposition nulls to skip number of fields */
1132 *nulls -= length;
1133 *n_null = index->calculate_n_instant_nullable(non_default_fields);
1134 } break;
1135
1137 *n_null = index->get_nullable_before_instant_add_drop();
1138 non_default_fields = index->get_instant_fields();
1139 } break;
1140
1142 /* Row inserted before first INSTANT ADD/DROP in V2 */
1143 *n_null = index->get_nullable_before_instant_add_drop();
1144 } break;
1145
1146 default:
1147 ut_ad(false);
1148 }
1149
1150 /* Position lens */
1151 *lens = *nulls - UT_BITS_IN_BYTES(*n_null);
1152
1153 /* Return record version or non_default_field stored */
1154 return (rec_insert_state);
1155}
1156
1157/** Determine the offset to each field in a leaf-page record in
1158ROW_FORMAT=COMPACT. This is a special case of rec_init_offsets() and
1159rec_get_offsets().
1160@param[in] rec physical record in ROW_FORMAT=COMPACT
1161@param[in] temp whether to use the format for temporary files in index
1162 creation
1163@param[in] index record descriptor
1164@param[in,out] offsets array of offsets
1165@note This long method is made inline because it is on performance sensitive hot
1166path. One must run performance tests if they intend to improve this method. */
1167inline void rec_init_offsets_comp_ordinary(const rec_t *rec, bool temp,
1168 const dict_index_t *index,
1169 ulint *offsets) {
1170#ifdef UNIV_DEBUG
1171 /* We cannot invoke rec_offs_make_valid() here if temp=true.
1172 Similarly, rec_offs_validate() will fail in that case, because
1173 it invokes rec_get_status(). */
1174 offsets[2] = (ulint)rec;
1175 offsets[3] = (ulint)index;
1176#endif /* UNIV_DEBUG */
1177
1178 const byte *nulls = nullptr;
1179 const byte *lens = nullptr;
1180 uint16_t n_null = 0;
1181 enum REC_INSERT_STATE rec_insert_state = REC_INSERT_STATE::NONE;
1182 row_version_t row_version = INVALID_ROW_VERSION;
1183 uint16_t non_default_fields = 0;
1184
1185 if (temp) {
1186 rec_insert_state = rec_init_null_and_len_temp(
1187 rec, index, &nulls, &lens, &n_null, non_default_fields, row_version);
1188 } else {
1189 rec_insert_state = rec_init_null_and_len_comp(
1190 rec, index, &nulls, &lens, &n_null, non_default_fields, row_version);
1191 }
1192
1193 ut_ad(temp || dict_table_is_comp(index->table));
1194
1195 if (temp) {
1196 if (dict_table_is_comp(index->table)) {
1197 /* No need to do adjust fixed_len=0. We only need to
1198 adjust it for ROW_FORMAT=REDUNDANT. */
1199 temp = false;
1200 } else {
1201 /* Redundant temp row. Old instant record is logged as version 0. */
1202 if (rec_insert_state == INSERTED_BEFORE_INSTANT_ADD_OLD_IMPLEMENTATION ||
1205 ut_ad(row_version == INVALID_ROW_VERSION);
1206 }
1207 }
1208 }
1209
1210 /* read the lengths of fields 0..n */
1211 ulint offs = 0;
1212 ulint any_ext = 0;
1213 ulint null_mask = 1;
1214 uint16_t i = 0;
1215 do {
1216 /* Fields are stored on disk in version they are added in and are
1217 maintained in fields_array in the same order. Get the right field. */
1218 const dict_field_t *field = index->get_physical_field(i);
1219 const dict_col_t *col = field->col;
1220 uint64_t len;
1221
1222 switch (rec_insert_state) {
1224 ut_ad(!index->has_instant_cols_or_row_versions());
1225 break;
1226
1228 ut_ad(row_version == INVALID_ROW_VERSION || row_version == 0);
1229 ut_ad(index->has_row_versions() || temp);
1230 /* Record has to be interpreted in v0. */
1231 row_version = 0;
1232 }
1233 [[fallthrough]];
1236 ut_ad(is_valid_row_version(row_version));
1237 /* A record may have version=0 if it's from upgrade table */
1238 ut_ad(index->has_row_versions() ||
1239 (index->table->is_upgraded_instant() && row_version == 0));
1240
1241 /* Based on the record version and column information, see if this
1242 column is there in this record or not. */
1243 if (col->is_dropped_in_or_before(row_version)) {
1244 /* This columns is dropped before or on this row version so its data
1245 won't be there on row. So no need to store the length. Instead, store
1246 offs ORed with REC_OFFS_DROP to indicate the same. */
1247 len = offs | REC_OFFS_DROP;
1248 goto resolved;
1249
1250 /* NOTE : Existing rows, which have data for this column, would still
1251 need to process this column, so don't skip and store the correct
1252 length there. Though it will be skipped while fetching row. */
1253 } else if (col->is_added_after(row_version)) {
1254 /* This columns is added after this row version. In this case no need
1255 to store the length. Instead store only if it is NULL or DEFAULT
1256 value. */
1257 len = rec_get_instant_offset(index, i, offs);
1258
1259 goto resolved;
1260 }
1261 } break;
1262
1265 ut_ad(non_default_fields > 0);
1266 ut_ad(index->has_instant_cols());
1267 ut_ad(!is_valid_row_version(row_version));
1268
1269 if (i >= non_default_fields) {
1270 /* This would be the case when column doesn't exists in the row. In
1271 this case we need not to store the length. Instead we store only if
1272 the column is NULL or DEFAULT value. */
1273 len = rec_get_instant_offset(index, i, offs);
1274
1275 goto resolved;
1276 }
1277
1278 /* Note : Even if the column has been dropped, this row in V1 would
1279 definitely have the value of this column. */
1280 } break;
1281
1282 default:
1283 ut_ad(false);
1284 }
1285
1286 if (!(col->prtype & DATA_NOT_NULL)) {
1287 /* nullable field => read the null flag */
1288 ut_ad(n_null--);
1289
1290 if (UNIV_UNLIKELY(!(byte)null_mask)) {
1291 nulls--;
1292 null_mask = 1;
1293 }
1294
1295 if (*nulls & null_mask) {
1296 null_mask <<= 1;
1297 /* No length is stored for NULL fields.
1298 We do not advance offs, and we set
1299 the length to zero and enable the
1300 SQL NULL flag in offsets[]. */
1301 len = offs | REC_OFFS_SQL_NULL;
1302 goto resolved;
1303 }
1304 null_mask <<= 1;
1305 }
1306
1307 if (!field->fixed_len || (temp && !col->get_fixed_size(temp))) {
1308 ut_ad(col->mtype != DATA_POINT);
1309 /* Variable-length field: read the length */
1310 len = *lens--;
1311 /* If the maximum length of the field is up
1312 to 255 bytes, the actual length is always
1313 stored in one byte. If the maximum length is
1314 more than 255 bytes, the actual length is
1315 stored in one byte for 0..127. The length
1316 will be encoded in two bytes when it is 128 or
1317 more, or when the field is stored externally. */
1318 if (DATA_BIG_COL(col)) {
1319 if (len & 0x80) {
1320 /* 1exxxxxxx xxxxxxxx */
1321 len <<= 8;
1322 len |= *lens--;
1323
1324 offs += len & 0x3fff;
1325 if (UNIV_UNLIKELY(len & 0x4000)) {
1326 ut_ad(index->is_clustered());
1327 any_ext = REC_OFFS_EXTERNAL;
1328 len = offs | REC_OFFS_EXTERNAL;
1329 } else {
1330 len = offs;
1331 }
1332
1333 goto resolved;
1334 }
1335 }
1336
1337 len = offs += len;
1338 } else {
1339 len = offs += field->fixed_len;
1340 }
1341 resolved:
1342 rec_offs_base(offsets)[i + 1] = len;
1343 } while (++i < rec_offs_n_fields(offsets));
1344
1345 *rec_offs_base(offsets) = (rec - (lens + 1)) | REC_OFFS_COMPACT | any_ext;
1346}
1347
1348/** The following function is used to test whether the data offsets in the
1349 record are stored in one-byte or two-byte format.
1350 @return true if 1-byte form */
1351[[nodiscard]] static inline bool rec_get_1byte_offs_flag(
1352 const rec_t *rec) /*!< in: physical record */
1353{
1356}
1357
1358#endif
Definition: rec.h:748
Row_import_metadata_check_guard(const Row_import_metadata_check_guard &)=delete
Row_import_metadata_check_guard & operator=(const Row_import_metadata_check_guard &)=delete
The class error is used to emit error messages.
Definition: ut0log.h:225
int page
Definition: ctype-mb.cc:1226
static ulint dtuple_get_n_fields(const dtuple_t *tuple)
Gets number of fields in a data tuple.
constexpr uint32_t DATA_POINT
geometry datatype of fixed length POINT
Definition: data0type.h:107
constexpr uint32_t DATA_NOT_NULL
this is ORed to the precise type when the column is declared as NOT NULL
Definition: data0type.h:207
#define DATA_BIG_COL(col)
Definition: data0type.h:286
Data dictionary creation and booting.
Data dictionary system.
uint16_t dict_index_get_n_fields(const dict_index_t *index)
Gets the number of fields in the internal representation of an index, including fields added by the d...
Definition: dict0dict.ic:545
static bool dict_table_is_comp(const dict_table_t *table)
Check whether the table uses the compact page format.
uint16_t dict_index_get_n_unique_in_tree_nonleaf(const dict_index_t *index)
Gets the number of fields on nonleaf page level in the internal representation of an index which uniq...
Definition: dict0dict.ic:602
uint16_t dict_index_get_n_unique_in_tree(const dict_index_t *index)
Gets the number of fields in the internal representation of an index which uniquely determine the pos...
Definition: dict0dict.ic:580
static bool is_valid_row_version(const row_version_t version)
Definition: dict0mem.h:423
constexpr char RECOVERY_INDEX_TABLE_NAME[]
index/table name used while applying REDO logs during recovery
Definition: dict0mem.h:90
static bool is_instant(const Alter_inplace_info *ha_alter_info)
Determine if this is an instant ALTER TABLE.
Definition: handler0alter.cc:929
static uint16_t mach_read_from_2(const byte *b)
The following function is used to fetch data from 2 consecutive bytes.
static uint8_t mach_read_from_1(const byte *b)
The following function is used to fetch data from one byte.
static mi_bit_type mask[]
Definition: mi_packrec.cc:141
#define DBUG_EXECUTE_IF(keyword, a1)
Definition: my_dbug.h:171
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
bool index(const std::string &value, const String &search_for, uint32_t *idx)
Definition: contains.h:76
ValueType max(X &&first)
Definition: gtid.h:103
byte page_t
Type of the index page.
Definition: page0types.h:152
bool rec_info_bits_valid(ulint bits)
Check if the info bits are valid.
Definition: rec.h:320
constexpr uint32_t REC_INFO_INSTANT_FLAG
The instant ADD COLUMN flag.
Definition: rec.h:154
void row_import_assert_index_page_records_links_and_types_valid(const page_t *page, const dict_index_t *index)
bool row_import_rec_check_comp_metadata(const dict_index_t *index, const rec_t *rec)
Validate compact record metadata on imported page, not assuming page correctness.
Definition: row0import.cc:2699
static const uint8_t REC_N_FIELDS_TWO_BYTES_FLAG
Number of fields flag which means it occupies two bytes.
Definition: rec.h:238
static uint16_t rec_get_bit_field_2(const rec_t *rec, ulint offs, ulint mask, ulint shift)
Gets a bit field from within 2 bytes.
Definition: rec.h:289
constexpr uint32_t REC_N_OWNED_MASK
Definition: rec.h:119
constexpr uint32_t REC_OFFS_EXTERNAL
Definition: rec.h:77
constexpr uint32_t REC_OFFS_HEADER_SIZE
Definition: rec.h:203
constexpr uint32_t REC_OFFS_DEFAULT
Definition: rec.h:79
constexpr uint32_t REC_NEW_HEAP_NO
Definition: rec.h:86
void rec_init_offsets_comp_ordinary(const rec_t *rec, bool temp, const dict_index_t *index, ulint *offsets)
Determine the offset to each field in a leaf-page record in ROW_FORMAT=COMPACT.
Definition: rec.h:1167
void rec_init_fixed_offsets(const dict_index_t *index, ulint *offsets)
A simplified variant rec_init_offsets(rec, index, offsets) for the case in which the rec contains onl...
Definition: rec.h:688
static enum REC_INSERT_STATE rec_init_null_and_len_temp(const rec_t *rec, const dict_index_t *index, const byte **nulls, const byte **lens, uint16_t *n_null, uint16_t &non_default_fields, row_version_t &row_version)
Determines the information about null bytes and variable length bytes for a new-style temporary recor...
Definition: rec.h:977
static bool rec_get_instant_flag_new_temp(const rec_t *rec)
The following function tells if a new-style temp record is instant record.
Definition: rec.h:672
constexpr uint32_t REC_NEXT
Definition: rec.h:94
constexpr uint32_t REC_N_OLD_EXTRA_BYTES
Definition: rec.h:158
constexpr uint32_t REC_STATUS_SUPREMUM
Definition: rec.h:184
constexpr uint32_t REC_NODE_PTR_SIZE
Definition: rec.h:190
constexpr uint32_t REC_INFO_BITS_SHIFT
Definition: rec.h:126
constexpr uint32_t REC_OFFS_DROP
Definition: rec.h:81
static enum REC_INSERT_STATE rec_init_null_and_len_comp(const rec_t *rec, const dict_index_t *index, const byte **nulls, const byte **lens, uint16_t *n_null, uint16_t &non_default_fields, row_version_t &row_version)
Determines the information about null bytes and variable length bytes for a new style record.
Definition: rec.h:1079
constexpr uint32_t REC_INFO_MIN_REC_FLAG
Definition: rec.h:146
static ulint rec_get_info_bits(const rec_t *rec, ulint comp)
The following function is used to retrieve the info bits of a record.
Definition: rec.h:330
void rec_init_offsets(const rec_t *rec, const dict_index_t *index, ulint *offsets)
The following function determines the offsets to each field in the record.
Definition: rec.cc:348
constexpr uint32_t REC_NEW_INFO_BITS
Definition: rec.h:123
constexpr uint32_t REC_OLD_INFO_BITS
Definition: rec.h:122
constexpr uint32_t REC_OFFS_MASK
Definition: rec.h:83
constexpr uint32_t REC_OLD_SHORT_MASK
Definition: rec.h:99
constexpr uint32_t REC_OLD_SHORT_SHIFT
Definition: rec.h:100
void row_import_assert_rec_metadata_valid(const rec_t *rec, const dict_index_t *index)
Rec_instant_state
Instant state of a record.
Definition: rec.h:216
constexpr uint32_t REC_INFO_BITS_MASK
Definition: rec.h:125
bool row_import_rec_check_old_metadata(const dict_index_t *index, const rec_t *rec)
Validate REDUNDANT record metadata on imported page, not assuming page correctness.
Definition: row0import.cc:2633
static ulint rec_get_info_bits_temp(const rec_t *rec)
The following function is used to retrieve the info bits of a temporary record.
Definition: rec.h:342
static uint64_t rec_get_instant_offset(const dict_index_t *index, ulint n, uint64_t offs)
Determine the offset of a specified field in the record, when this field is a field added after an in...
Definition: rec.h:526
static const uint8_t REC_N_FIELDS_ONE_BYTE_MAX
Max number of fields which can be stored in one byte.
Definition: rec.h:241
constexpr uint32_t REC_HEAP_NO_MASK
Definition: rec.h:111
REC_INSERT_STATE
Definition: rec.h:825
@ INSERTED_AFTER_UPGRADE_BEFORE_INSTANT_ADD_NEW_IMPLEMENTATION
Definition: rec.h:834
@ INSERTED_AFTER_INSTANT_ADD_OLD_IMPLEMENTATION
Definition: rec.h:831
@ INSERTED_AFTER_INSTANT_ADD_NEW_IMPLEMENTATION
Definition: rec.h:840
@ INSERTED_BEFORE_INSTANT_ADD_NEW_IMPLEMENTATION
Definition: rec.h:837
@ INSERTED_INTO_TABLE_WITH_NO_INSTANT_NO_VERSION
Definition: rec.h:842
@ NONE
Definition: rec.h:843
@ INSERTED_BEFORE_INSTANT_ADD_OLD_IMPLEMENTATION
Definition: rec.h:828
constexpr uint32_t REC_TMP_INFO_BITS
Definition: rec.h:124
constexpr uint32_t REC_HEAP_NO_SHIFT
Definition: rec.h:89
constexpr uint32_t REC_STATUS_ORDINARY
Definition: rec.h:181
static enum REC_INSERT_STATE get_rec_insert_state(const dict_index_t *index, const rec_t *rec, bool temp)
Definition: rec.h:846
static ulint rec_offs_get_n_alloc(const ulint *offsets)
The following function returns the number of allocated elements for an array of offsets.
Definition: rec.h:469
constexpr uint32_t REC_STATUS_INFIMUM
Definition: rec.h:183
constexpr uint32_t REC_NEW_STATUS
Definition: rec.h:106
static void rec_offs_make_valid(const rec_t *rec, const dict_index_t *index, ulint *offsets)
Updates debug data in offsets, in order to avoid bogus rec_offs_validate() failures.
Definition: rec.h:630
static bool rec_new_is_versioned(const rec_t *rec)
The following function tells if a new-style record is versioned.
Definition: rec.h:705
constexpr uint32_t REC_INFO_DELETED_FLAG
The deleted flag in info bits; when bit is set to 1, it means the record has been delete marked.
Definition: rec.h:149
static uint16_t rec_get_n_fields_old(const rec_t *rec, const dict_index_t *index)
The following function is used to get the number of fields in an old-style record.
Definition: rec.h:375
constexpr uint32_t REC_1BYTE_SQL_NULL_MASK
SQL null flag in a 1-byte offset of ROW_FORMAT=REDUNDANT records.
Definition: rec.h:193
constexpr uint32_t REC_OLD_N_FIELDS
Definition: rec.h:102
constexpr auto MAX_REC_PER_PAGE
Maximum number of records in a page.
Definition: rec.h:169
constexpr uint32_t REC_OFFS_COMPACT
NOTE: The functions in this file should only use functions from other files in library.
Definition: rec.h:73
static void rec_offs_set_n_alloc(ulint *offsets, ulint n_alloc)
The following function sets the number of allocated elements for an array of offsets.
Definition: rec.h:482
static bool rec_offs_validate(const rec_t *rec, const dict_index_t *index, const ulint *offsets, const bool check_status=true)
Validates offsets returned by rec_get_offsets().
Definition: rec.h:566
static bool rec_new_temp_is_versioned(const rec_t *rec)
The following function tells if a temporary record is versioned.
Definition: rec.h:721
bool row_import_rec_get_n_fields_instant_checked(const page_t *page, const byte *ptr, uint16_t *n_fields, uint16_t *length, bool force_page_boundary_check)
Decode the number of fields for one new-style leaf-page record without asserting on malformed metadat...
Definition: row0import.cc:2543
constexpr uint32_t REC_NEW_STATUS_MASK
Definition: rec.h:107
constexpr uint32_t REC_OFFS_SQL_NULL
Definition: rec.h:75
constexpr uint32_t REC_N_TMP_EXTRA_BYTES
Definition: rec.h:165
constexpr uint32_t REC_OLD_N_OWNED
Definition: rec.h:117
static ulint rec_offs_n_fields(const ulint *offsets)
The following function returns the number of fields in a record.
Definition: rec.h:508
static const ulint * rec_offs_base(const ulint *offsets)
Definition: rec.h:229
constexpr int32_t REC_N_NEW_EXTRA_BYTES
Definition: rec.h:161
static enum REC_INSERT_STATE init_nulls_lens_for_temp_redundant(const dict_index_t *index, const rec_t *rec, uint16_t *n_null, const byte **nulls, const byte **lens, uint16_t &non_default_fields, row_version_t &row_version)
Definition: rec.h:914
static uint16_t rec_get_n_fields_old_raw(const rec_t *rec)
The following function is used to get the number of fields in an old-style record,...
Definition: rec.h:352
constexpr uint32_t REC_NEXT_MASK
Definition: rec.h:95
constexpr uint32_t REC_2BYTE_SQL_NULL_MASK
SQL null flag in a 2-byte offset of ROW_FORMAT=REDUNDANT records.
Definition: rec.h:195
ulint * rec_get_offsets(const rec_t *rec, const dict_index_t *index, ulint *offsets, ulint n_fields, ut::Location location, mem_heap_t **heap)
The following function determines the offsets to each field in the record.
Definition: rec.cc:359
constexpr uint32_t REC_INFO_VERSION_FLAG
Definition: rec.h:151
constexpr uint32_t REC_NEW_N_OWNED
Definition: rec.h:118
constexpr uint32_t REC_OLD_N_FIELDS_SHIFT
Definition: rec.h:104
constexpr uint32_t REC_OLD_HEAP_NO
Definition: rec.h:110
static bool rec_old_is_versioned(const rec_t *rec)
The following function tells if an old-style record is versioned.
Definition: rec.h:713
static bool rec_get_1byte_offs_flag(const rec_t *rec)
The following function is used to test whether the data offsets in the record are stored in one-byte ...
Definition: rec.h:1351
void rec_get_offsets_reverse(const byte *extra, const dict_index_t *index, ulint node_ptr, ulint *offsets)
The following function determines the offsets to each field in the record.
Definition: rec.cc:419
constexpr uint32_t REC_N_OWNED_SHIFT
Definition: rec.h:120
static uint32_t rec_get_n_fields_instant(const rec_t *rec, const ulint extra_bytes, uint16_t *length)
Get the number of fields for one new style leaf page record.
Definition: rec.h:767
constexpr uint32_t REC_STATUS_NODE_PTR
Definition: rec.h:182
static bool rec_n_fields_is_sane(dict_index_t *index, const rec_t *rec, const dtuple_t *entry)
Confirms the n_fields of the entry is sane with comparing the other record in the same page specified...
Definition: rec.h:461
constexpr uint32_t REC_OLD_SHORT
Definition: rec.h:98
constexpr uint32_t REC_NEXT_SHIFT
Definition: rec.h:96
static void rec_offs_set_n_fields(ulint *offsets, ulint n_fields)
The following function sets the number of fields in offsets.
Definition: rec.h:494
constexpr uint32_t REC_OFFS_NORMAL_SIZE
Definition: rec.h:211
static ulint rec_get_bit_field_1(const rec_t *rec, ulint offs, ulint mask, ulint shift)
Gets a bit field from within 1 byte.
Definition: rec.h:277
constexpr uint32_t REC_2BYTE_EXTERN_MASK
In a 2-byte offset of ROW_FORMAT=REDUNDANT records, the second most significant bit denotes that the ...
Definition: rec.h:199
constexpr uint32_t REC_NEW_STATUS_SHIFT
Definition: rec.h:108
bool rec_offs_cmp(ulint *offsets1, ulint *offsets2)
Check if the given two record offsets are identical.
Definition: rec.cc:538
static ulint rec_get_n_fields(const rec_t *rec, const dict_index_t *index)
The following function is used to get the number of fields in a record.
Definition: rec.h:431
std::ostream & rec_offs_print(std::ostream &out, const ulint *offsets)
Print the record offsets.
Definition: rec.cc:570
static ulint rec_get_status(const rec_t *rec)
The following function retrieves the status bits of a new-style record.
Definition: rec.h:302
static bool rec_get_instant_flag_new(const rec_t *rec)
The following function tells if a new-style record is instant record.
Definition: rec.h:664
constexpr uint32_t REC_OLD_N_FIELDS_MASK
Definition: rec.h:103
constexpr uint32_t REC_OFFS_SMALL_SIZE
Definition: rec.h:212
const row_version_t INVALID_ROW_VERSION
Definition: rem0types.h:56
byte rec_t
Definition: rem0types.h:41
constexpr uint32_t REC_MAX_N_FIELDS
Definition: rem0types.h:59
uint16_t row_version_t
Definition: rem0types.h:53
required uint64 version
Definition: replication_group_member_actions.proto:41
Definition: completion_hash.h:35
std::atomic< uint16_t > n_pointers
Used in debugging.
Definition: buf0buf.h:1837
Data structure for a column in a table.
Definition: dict0mem.h:485
bool is_dropped_in_or_before(row_version_t version) const
Check if column is dropped before the given version.
Definition: dict0mem.h:736
unsigned mtype
main data type
Definition: dict0mem.h:502
ulint get_fixed_size(ulint comp) const
Returns the size of a fixed size column, 0 if not a fixed size column.
Definition: dict0mem.h:694
bool is_added_after(row_version_t version) const
Check if column is added after the current version.
Definition: dict0mem.h:749
unsigned prtype
precise type; MySQL data type, charset code, flags to indicate nullability, signedness,...
Definition: dict0mem.h:495
Data structure for a field in an index.
Definition: dict0mem.h:891
dict_col_t * col
pointer to the table column
Definition: dict0mem.h:894
unsigned fixed_len
0 or the fixed length of the column if smaller than DICT_ANTELOPE_MAX_INDEX_COL_LEN
Definition: dict0mem.h:904
Data structure for an index.
Definition: dict0mem.h:1069
Structure for an SQL data tuple of fields (logical record)
Definition: data0data.h:706
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:295
Part of traditional "extra" column or related hierarchical property.
Definition: opt_explain_format.h:267
Definition: ut0core.h:36
#define UNIV_MEM_ASSERT_W(addr, size)
Definition: univ.i:621
#define UNIV_UNLIKELY(cond)
Definition: univ.i:524
#define UNIV_PAGE_SIZE
The universal page size of the database.
Definition: univ.i:291
constexpr uint32_t UNIV_SQL_NULL
The following number as the length of a logical field means that the field has the SQL NULL as its va...
Definition: univ.i:466
#define UNIV_MEM_ASSERT_AND_ALLOC(addr, size)
Definition: univ.i:633
constexpr ulint ULINT_MAX
Maximum value for a ulint.
Definition: univ.i:437
unsigned long int ulint
Definition: univ.i:403
constexpr size_t UNIV_PAGE_SIZE_MAX
Maximum page size InnoDB currently supports.
Definition: univ.i:320
static void * ut_align_down(const void *ptr, ulint align_no)
The following function rounds down a pointer to the nearest aligned address.
#define ut_error
Abort execution.
Definition: ut0dbg.h:105
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:109
#define ut_d(EXPR)
Debug statement.
Definition: ut0dbg.h:111
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:97
#define UT_BITS_IN_BYTES(b)
Determine how many bytes (groups of 8 bits) are needed to store the given number of bits.
Definition: ut0ut.h:195
int n
Definition: xcom_base.cc:509