MySQL 9.6.0
Source Code Documentation
rec.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1994, 2025, 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/* Compact flag ORed to the extra size returned by rec_get_offsets() */
71constexpr uint32_t REC_OFFS_COMPACT = 1U << 31;
72/* SQL NULL flag in offsets returned by rec_get_offsets() */
73constexpr uint32_t REC_OFFS_SQL_NULL = 1U << 31;
74/* External flag in offsets returned by rec_get_offsets() */
75constexpr uint32_t REC_OFFS_EXTERNAL = 1 << 30;
76/* Default value flag in offsets returned by rec_get_offsets() */
77constexpr uint32_t REC_OFFS_DEFAULT = 1 << 29;
78/* An INSTANT DROP flag in offsets returned by rec_get_offsets() */
79constexpr uint32_t REC_OFFS_DROP = 1 << 28;
80/* Mask for offsets returned by rec_get_offsets() */
81constexpr uint32_t REC_OFFS_MASK = REC_OFFS_DROP - 1;
82
83/* The offset of heap_no in a compact record */
84constexpr uint32_t REC_NEW_HEAP_NO = 4;
85/* The shift of heap_no in a compact record.
86The status is stored in the low-order bits. */
87constexpr uint32_t REC_HEAP_NO_SHIFT = 3;
88
89/* We list the byte offsets from the origin of the record, the mask,
90and the shift needed to obtain each bit-field of the record. */
91
92constexpr uint32_t REC_NEXT = 2;
93constexpr uint32_t REC_NEXT_MASK = 0xFFFFUL;
94constexpr uint32_t REC_NEXT_SHIFT = 0;
95
96constexpr uint32_t REC_OLD_SHORT = 3; /* This is single byte bit-field */
97constexpr uint32_t REC_OLD_SHORT_MASK = 0x1UL;
98constexpr uint32_t REC_OLD_SHORT_SHIFT = 0;
99
100constexpr uint32_t REC_OLD_N_FIELDS = 4;
101constexpr uint32_t REC_OLD_N_FIELDS_MASK = 0x7FEUL;
102constexpr uint32_t REC_OLD_N_FIELDS_SHIFT = 1;
103
104constexpr uint32_t REC_NEW_STATUS = 3; /* This is single byte bit-field */
105constexpr uint32_t REC_NEW_STATUS_MASK = 0x7UL;
106constexpr uint32_t REC_NEW_STATUS_SHIFT = 0;
107
108constexpr uint32_t REC_OLD_HEAP_NO = 5;
109constexpr uint32_t REC_HEAP_NO_MASK = 0xFFF8UL;
110#if 0 /* defined in rem0rec.h for use of page0zip.cc */
111#define REC_NEW_HEAP_NO 4
112#define REC_HEAP_NO_SHIFT 3
113#endif
114
115constexpr uint32_t REC_OLD_N_OWNED = 6; /* This is single byte bit-field */
116constexpr uint32_t REC_NEW_N_OWNED = 5; /* This is single byte bit-field */
117constexpr uint32_t REC_N_OWNED_MASK = 0xFUL;
118constexpr uint32_t REC_N_OWNED_SHIFT = 0;
119
120constexpr uint32_t REC_OLD_INFO_BITS = 6; /* This is single byte bit-field */
121constexpr uint32_t REC_NEW_INFO_BITS = 5; /* This is single byte bit-field */
122constexpr uint32_t REC_TMP_INFO_BITS = 1; /* This is single byte bit-field */
123constexpr uint32_t REC_INFO_BITS_MASK = 0xF0UL;
124constexpr uint32_t REC_INFO_BITS_SHIFT = 0;
125
126static_assert((REC_OLD_SHORT_MASK << (8 * (REC_OLD_SHORT - 3)) ^
128 REC_HEAP_NO_MASK << (8 * (REC_OLD_HEAP_NO - 4)) ^
129 REC_N_OWNED_MASK << (8 * (REC_OLD_N_OWNED - 3)) ^
131 0xFFFFFFFFUL) == 0,
132 "sum of old-style masks != 0xFFFFFFFFUL");
133static_assert((REC_NEW_STATUS_MASK << (8 * (REC_NEW_STATUS - 3)) ^
134 REC_HEAP_NO_MASK << (8 * (REC_NEW_HEAP_NO - 4)) ^
135 REC_N_OWNED_MASK << (8 * (REC_NEW_N_OWNED - 3)) ^
137 0xFFFFFFUL) == 0,
138 "sum of new-style masks != 0xFFFFFFUL");
139
140/* Info bit denoting the predefined minimum record: this bit is set
141if and only if the record is the first user record on a non-leaf
142B-tree page that is the leftmost page on its level
143(PAGE_LEVEL is nonzero and FIL_PAGE_PREV is FIL_NULL). */
144constexpr uint32_t REC_INFO_MIN_REC_FLAG = 0x10UL;
145/** The deleted flag in info bits; when bit is set to 1, it means the record has
146 been delete marked */
147constexpr uint32_t REC_INFO_DELETED_FLAG = 0x20UL;
148/* Use this bit to indicate record has version */
149constexpr uint32_t REC_INFO_VERSION_FLAG = 0x40UL;
150/** The instant ADD COLUMN flag. When it is set to 1, it means this record
151was inserted/updated after an instant ADD COLUMN. */
152constexpr uint32_t REC_INFO_INSTANT_FLAG = 0x80UL;
153
154/* Number of extra bytes in an old-style record,
155in addition to the data and the offsets */
156constexpr uint32_t REC_N_OLD_EXTRA_BYTES = 6;
157/* Number of extra bytes in a new-style record,
158in addition to the data and the offsets */
159constexpr int32_t REC_N_NEW_EXTRA_BYTES = 5;
160/* Number of extra bytes in a new-style temporary record,
161in addition to the data and the offsets.
162This is used only after instant ADD COLUMN. */
163constexpr uint32_t REC_N_TMP_EXTRA_BYTES = 1;
164
165#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
166/** Maximum number of records in a page */
168
169/* We use decltype(A.load()) not decltype(A)::value_type, as some compilers
170don't have it implemented, even as they should have this with the C++17
171implementation. Maybe this will be available on all compilers with C++20. */
172static_assert(MAX_REC_PER_PAGE <=
173 std::numeric_limits<
174 decltype(buf_block_t::ahi_t::n_pointers.load())>::max());
175
176#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
177
178/* Record status values */
179constexpr uint32_t REC_STATUS_ORDINARY = 0;
180constexpr uint32_t REC_STATUS_NODE_PTR = 1;
181constexpr uint32_t REC_STATUS_INFIMUM = 2;
182constexpr uint32_t REC_STATUS_SUPREMUM = 3;
183
184/* The following four constants are needed in page0zip.cc in order to
185efficiently compress and decompress pages. */
186
187/* Length of a B-tree node pointer, in bytes */
188constexpr uint32_t REC_NODE_PTR_SIZE = 4;
189
190/** SQL null flag in a 1-byte offset of ROW_FORMAT=REDUNDANT records */
191constexpr uint32_t REC_1BYTE_SQL_NULL_MASK = 0x80UL;
192/** SQL null flag in a 2-byte offset of ROW_FORMAT=REDUNDANT records */
193constexpr uint32_t REC_2BYTE_SQL_NULL_MASK = 0x8000UL;
194
195/** In a 2-byte offset of ROW_FORMAT=REDUNDANT records, the second most
196significant bit denotes that the tail of a field is stored off-page. */
197constexpr uint32_t REC_2BYTE_EXTERN_MASK = 0x4000UL;
198
199#ifdef UNIV_DEBUG
200/* Length of the rec_get_offsets() header */
201constexpr uint32_t REC_OFFS_HEADER_SIZE = 4;
202#else /* UNIV_DEBUG */
203/* Length of the rec_get_offsets() header */
204constexpr uint32_t REC_OFFS_HEADER_SIZE = 2;
205#endif /* UNIV_DEBUG */
206
207/* Number of elements that should be initially allocated for the
208offsets[] array, first passed to rec_get_offsets() */
209constexpr uint32_t REC_OFFS_NORMAL_SIZE = 100;
210constexpr uint32_t REC_OFFS_SMALL_SIZE = 10;
211
212/** Instant state of a record. Determined by instant and version bit in info
213 * bits. */
215 /* Record is neither instant nor versioned: Instant: 0, Version: 0 */
217 /* Record is versioned but not instant: Instant: 0, Version: 1 */
219 /* Record is instant but not versioned: Instant: 1, Version: 0 */
221};
222
223/* Get the base address of offsets. The extra_size is stored at
224this position, and following positions hold the end offsets of
225the fields. */
226
227static inline const ulint *rec_offs_base(const ulint *offsets) {
228 return offsets + REC_OFFS_HEADER_SIZE;
229}
230
231static inline ulint *rec_offs_base(ulint *offsets) {
232 return offsets + REC_OFFS_HEADER_SIZE;
233}
234
235/** Number of fields flag which means it occupies two bytes */
236static const uint8_t REC_N_FIELDS_TWO_BYTES_FLAG = 0x80;
237
238/** Max number of fields which can be stored in one byte */
239static const uint8_t REC_N_FIELDS_ONE_BYTE_MAX = 0x7F;
240
241/** The following function determines the offsets to each field
242 in the record. It can reuse a previously allocated array.
243 Note that after instant ADD COLUMN, if this is a record
244 from clustered index, fields in the record may be less than
245 the fields defined in the clustered index. So the offsets
246 size is allocated according to the clustered index fields.
247 @param[in] rec physical record
248 @param[in] index record descriptor
249 @param[in,out] offsets array consisting of offsets[0] allocated elements, or an
250 array from rec_get_offsets(), or NULL
251 @param[in] n_fields maximum number of initialized fields (ULINT_UNDEFINED is
252 all fields)
253 @param[in] location location where called
254 @param[in,out] heap memory heap
255 @return the new offsets */
256[[nodiscard]] ulint *rec_get_offsets(const rec_t *rec,
257 const dict_index_t *index, ulint *offsets,
258 ulint n_fields, ut::Location location,
259 mem_heap_t **heap);
260
261/** The following function determines the offsets to each field
262 in the record. It can reuse a previously allocated array. */
264 const byte *extra, /*!< in: the extra bytes of a
265 compact record in reverse order,
266 excluding the fixed-size
267 REC_N_NEW_EXTRA_BYTES */
268 const dict_index_t *index, /*!< in: record descriptor */
269 ulint node_ptr, /*!< in: nonzero=node pointer,
270 0=leaf node */
271 ulint *offsets); /*!< in/out: array consisting of
272 offsets[0] allocated elements */
273
274/** Gets a bit field from within 1 byte. */
276 const rec_t *rec, /*!< in: pointer to record origin */
277 ulint offs, /*!< in: offset from the origin down */
278 ulint mask, /*!< in: mask used to filter bits */
279 ulint shift) /*!< in: shift right applied after masking */
280{
281 ut_ad(rec);
282
283 return ((mach_read_from_1(rec - offs) & mask) >> shift);
284}
285
286/** Gets a bit field from within 2 bytes. */
287static inline uint16_t rec_get_bit_field_2(
288 const rec_t *rec, /*!< in: pointer to record origin */
289 ulint offs, /*!< in: offset from the origin down */
290 ulint mask, /*!< in: mask used to filter bits */
291 ulint shift) /*!< in: shift right applied after masking */
292{
293 ut_ad(rec);
294
295 return ((mach_read_from_2(rec - offs) & mask) >> shift);
296}
297
298/** The following function retrieves the status bits of a new-style record.
299 @return status bits */
300[[nodiscard]] static inline ulint rec_get_status(
301 const rec_t *rec) /*!< in: physical record */
302{
303 ulint ret;
304
305 ut_ad(rec);
306
309 ut_ad((ret & ~REC_NEW_STATUS_MASK) == 0);
310
311 return (ret);
312}
313
314#ifdef UNIV_DEBUG
315/** Check if the info bits are valid.
316@param[in] bits info bits to check
317@return true if valid */
318inline bool rec_info_bits_valid(ulint bits) {
319 return (0 == (bits & ~(REC_INFO_DELETED_FLAG | REC_INFO_MIN_REC_FLAG |
321}
322#endif /* UNIV_DEBUG */
323
324/** The following function is used to retrieve the info bits of a record.
325@param[in] rec physical record
326@param[in] comp nonzero=compact page format
327@return info bits */
328static inline ulint rec_get_info_bits(const rec_t *rec, ulint comp) {
329 const ulint val =
333 return (val);
334}
335
336/** The following function is used to retrieve the info bits of a temporary
337record.
338@param[in] rec physical record
339@return info bits */
340static inline ulint rec_get_info_bits_temp(const rec_t *rec) {
341 const ulint val = rec_get_bit_field_1(
344 return (val);
345}
346
347/** The following function is used to get the number of fields
348 in an old-style record, which is stored in the rec
349 @return number of data fields */
350[[nodiscard]] static inline uint16_t rec_get_n_fields_old_raw(
351 const rec_t *rec) /*!< in: physical record */
352{
353 uint16_t n_fields;
354
355 ut_ad(rec);
356
359
360 ut_ad(n_fields <= REC_MAX_N_FIELDS);
361 ut_ad(n_fields > 0);
362
363 return (n_fields);
364}
365
366/** The following function is used to get the number of fields
367in an old-style record. Have to consider the case that after
368instant ADD COLUMN, this record may have less fields than
369current index.
370@param[in] rec physical record
371@param[in] index index where the record resides
372@return number of data fields */
373[[nodiscard]] static inline uint16_t rec_get_n_fields_old(
374 const rec_t *rec, const dict_index_t *index) {
375 uint16_t n = rec_get_n_fields_old_raw(rec);
376
377 if (index->has_instant_cols_or_row_versions()) {
378 if (strcmp(index->name, RECOVERY_INDEX_TABLE_NAME) == 0) {
379 /* In recovery, index is not completely built. Skip validation. */
380 if (n > 1) /* For infimum/supremum, n is 1 */ {
381 n = static_cast<uint16_t>(dict_index_get_n_fields(index));
382 }
383 return n;
384 }
385
387
388 ut_ad(index->is_clustered());
390 ut_ad(n_uniq > 0);
391 /* Only when it's infimum or supremum, n is 1.
392 If n is exact n_uniq, this should be a record copied with prefix during
393 search.
394 And if it's node pointer, n is n_uniq + 1, which should be always less
395 than the number of fields in any leaf page, even if the record in
396 leaf page is before instant ADD COLUMN. This is because any record in
397 leaf page must have at least n_uniq + 2 (system columns) fields */
398 ut_ad(n == 1 || n >= n_uniq);
399 ut_ad(static_cast<uint16_t>(dict_index_get_n_fields(index)) > n_uniq + 1);
400 if (n > n_uniq + 1) {
401 /* This is leaf node. If table has INSTANT columns, then it is possible
402 that record might not have all the fields in index. So get it now from
403 index. */
404#ifdef UNIV_DEBUG
405 if (index->has_instant_cols() && !index->has_row_versions()) {
407 ulint rec_diff = dict_index_get_n_fields(index) - n;
408 ulint col_diff = index->table->n_cols - index->table->n_instant_cols;
409 ut_ad(rec_diff <= col_diff);
410 }
411
413 ut_ad(index->has_instant_cols_or_row_versions());
414 }
415#endif /* UNIV_DEBUG */
416 n = static_cast<uint16_t>(dict_index_get_n_fields(index));
417 }
418 }
419
420 return (n);
421}
422
423/** The following function is used to get the number of fields
424 in a record. If it's REDUNDANT record, the returned number
425 would be a logic one which considers the fact that after
426 instant ADD COLUMN, some records may have less fields than
427 index.
428 @return number of data fields */
430 const rec_t *rec, /*!< in: physical record */
431 const dict_index_t *index) /*!< in: record descriptor */
432{
433 ut_ad(rec);
434 ut_ad(index);
435
436 if (!dict_table_is_comp(index->table)) {
437 return (rec_get_n_fields_old(rec, index));
438 }
439
440 switch (rec_get_status(rec)) {
447 return (1);
448 default:
449 ut_error;
450 }
451}
452
453/** Confirms the n_fields of the entry is sane with comparing the other
454record in the same page specified
455@param[in] index index
456@param[in] rec record of the same page
457@param[in] entry index entry
458@return true if n_fields is sane */
459static inline bool rec_n_fields_is_sane(dict_index_t *index, const rec_t *rec,
460 const dtuple_t *entry) {
462}
463
464/** The following function returns the number of allocated elements
465 for an array of offsets.
466 @return number of elements */
467[[nodiscard]] static inline ulint rec_offs_get_n_alloc(
468 const ulint *offsets) /*!< in: array for rec_get_offsets() */
469{
470 ulint n_alloc;
471 ut_ad(offsets);
472 n_alloc = offsets[0];
473 ut_ad(n_alloc > REC_OFFS_HEADER_SIZE);
474 UNIV_MEM_ASSERT_W(offsets, n_alloc * sizeof *offsets);
475 return (n_alloc);
476}
477
478/** The following function sets the number of allocated elements
479 for an array of offsets. */
480static inline void rec_offs_set_n_alloc(
481 ulint *offsets, /*!< out: array for rec_get_offsets(),
482 must be allocated */
483 ulint n_alloc) /*!< in: number of elements */
484{
485 ut_ad(offsets);
486 ut_ad(n_alloc > REC_OFFS_HEADER_SIZE);
487 UNIV_MEM_ASSERT_AND_ALLOC(offsets, n_alloc * sizeof *offsets);
488 offsets[0] = n_alloc;
489}
490
491/** The following function sets the number of fields in offsets. */
492static inline void rec_offs_set_n_fields(
493 ulint *offsets, /*!< in/out: array returned by
494 rec_get_offsets() */
495 ulint n_fields) /*!< in: number of fields */
496{
497 ut_ad(offsets);
498 ut_ad(n_fields > 0);
499 ut_ad(n_fields <= REC_MAX_N_FIELDS);
500 ut_ad(n_fields + REC_OFFS_HEADER_SIZE <= rec_offs_get_n_alloc(offsets));
501 offsets[1] = n_fields;
502}
503
504/** The following function returns the number of fields in a record.
505 @return number of fields */
506[[nodiscard]] static inline ulint rec_offs_n_fields(
507 const ulint *offsets) /*!< in: array returned by rec_get_offsets() */
508{
509 ulint n_fields;
510 ut_ad(offsets);
511 n_fields = offsets[1];
512 ut_ad(n_fields > 0);
513 ut_ad(n_fields <= REC_MAX_N_FIELDS);
514 ut_ad(n_fields + REC_OFFS_HEADER_SIZE <= rec_offs_get_n_alloc(offsets));
515 return (n_fields);
516}
517
518/** Determine the offset of a specified field in the record, when this
519field is a field added after an instant ADD COLUMN
520@param[in] index Clustered index where the record resides
521@param[in] n Nth field to get offset
522@param[in] offs Last offset before current field
523@return The offset of the specified field */
524static inline uint64_t rec_get_instant_offset(const dict_index_t *index,
525 ulint n, uint64_t offs) {
526 ut_ad(index->has_instant_cols_or_row_versions());
527
529 index->get_nth_default(n, &length);
530
531 if (length == UNIV_SQL_NULL) {
532 return (offs | REC_OFFS_DEFAULT | REC_OFFS_SQL_NULL);
533 } else {
534 return (offs | REC_OFFS_DEFAULT);
535 }
536}
537
538/** The following function determines the offsets to each field in the record.
539The offsets are written to a previously allocated array of ulint, where
540rec_offs_n_fields(offsets) has been initialized to the number of fields in the
541record. The rest of the array will be initialized by this function.
542- rec_offs_base(offsets)[0] will be set to the extra size
543 (if REC_OFFS_COMPACT is set, the record is in the new format;
544 if REC_OFFS_EXTERNAL is set, the record contains externally stored columns).
545- rec_offs_base(offsets)[1..n_fields] will be set to offsets past the end of
546 fields 0..n_fields, or to the beginning of fields 1..n_fields+1.
547- If the high-order bit of the offset at [i+1] is set (REC_OFFS_SQL_NULL),
548 the field i is NULL.
549- If the second high-order bit of the offset at [i+1] is set
550(REC_OFFS_EXTERNAL), the field i is being stored externally.
551@param[in] rec physical record
552@param[in] index record descriptor
553@param[in,out] offsets array of offsets */
554void rec_init_offsets(const rec_t *rec, const dict_index_t *index,
555 ulint *offsets);
556
557#ifdef UNIV_DEBUG
558/** Validates offsets returned by rec_get_offsets().
559@param[in] rec record whose offsets are being validated or nullptr.
560@param[in] index index to which record belongs or nullptr.
561@param[in] offsets the record offsets array returned by rec_get_offsets()
562@param[in] check_status if true, check status bits of the record.
563@return true if valid */
564[[nodiscard]] static inline bool rec_offs_validate(
565 const rec_t *rec, const dict_index_t *index, const ulint *offsets,
566 const bool check_status = true) {
567 ulint i = rec_offs_n_fields(offsets);
568 ulint last = ULINT_MAX;
569 ulint comp = *rec_offs_base(offsets) & REC_OFFS_COMPACT;
570
571 if (rec) {
572 /* The offsets array might be:
573 - specific to the `rec`, in which case its address is stored in offsets[2],
574 - cached and shared by many records, in which case we've passed rec=nullptr
575 when preparing the offsets array.
576 We use caching only for the ROW_FORMAT=COMPACT format. */
577 ut_ad((ulint)rec == offsets[2] ||
578 ((ulint) nullptr == offsets[2] &&
579 (index != nullptr && offsets == index->rec_cache.offsets)));
580 if (!comp && index != nullptr) {
581 ut_a(rec_get_n_fields_old(rec, index) >= i);
582 }
583 }
584
585 if (index) {
586 ulint max_n_fields;
587 ut_ad((ulint)index == offsets[3]);
589 ulint n_unique_in_tree = dict_index_get_n_unique_in_tree(index) + 1;
590 max_n_fields = std::max(n_fields, n_unique_in_tree);
591 if (!comp && rec != nullptr && rec_get_n_fields_old_raw(rec) < i) {
592 ut_a(index->has_instant_cols_or_row_versions());
593 }
594
595 /* In the case of mrec_t the status will not be there. */
596 if (check_status) {
597 if (comp && rec) {
598 switch (rec_get_status(rec)) {
600 break;
602 max_n_fields = dict_index_get_n_unique_in_tree(index) + 1;
603 break;
606 max_n_fields = 1;
607 break;
608 default:
609 ut_error;
610 }
611 }
612 }
613
614 /* index->n_def == 0 for dummy indexes if !comp */
615 ut_a(!comp || index->n_def);
616 ut_a(!index->n_def || i <= max_n_fields);
617 }
618 while (i--) {
619 ulint curr = rec_offs_base(offsets)[1 + i] & REC_OFFS_MASK;
620 ut_a(curr <= last);
621 last = curr;
622 }
623 return true;
624}
625
626/** Updates debug data in offsets, in order to avoid bogus
627 rec_offs_validate() failures. */
628static inline void rec_offs_make_valid(
629 const rec_t *rec, /*!< in: record */
630 const dict_index_t *index, /*!< in: record descriptor */
631 ulint *offsets) /*!< in: array returned by
632 rec_get_offsets() */
633{
634 /* offsets are either intended for this particular rec, or to be cached */
635 ut_ad(rec || offsets == index->rec_cache.offsets);
636 ut_ad(index);
637 ut_ad(offsets);
638 ut_ad(rec == nullptr ||
639 rec_get_n_fields(rec, index) >= rec_offs_n_fields(offsets));
640 offsets[2] = (ulint)rec;
641 offsets[3] = (ulint)index;
642}
643
644/** Check if the given two record offsets are identical.
645@param[in] offsets1 field offsets of a record
646@param[in] offsets2 field offsets of a record
647@return true if they are identical, false otherwise. */
648bool rec_offs_cmp(ulint *offsets1, ulint *offsets2);
649
650/** Print the record offsets.
651@param[in] out the output stream to which offsets are printed.
652@param[in] offsets the field offsets of the record.
653@return the output stream. */
654std::ostream &rec_offs_print(std::ostream &out, const ulint *offsets);
655#else
656#define rec_offs_make_valid(rec, index, offsets) ((void)0)
657#endif /* UNIV_DEBUG */
658
659/** The following function tells if a new-style record is instant record.
660@param[in] rec new-style record
661@return true if it is instant affected */
662static inline bool rec_get_instant_flag_new(const rec_t *rec) {
663 ulint info = rec_get_info_bits(rec, true);
664 return ((info & REC_INFO_INSTANT_FLAG) != 0);
665}
666
667/** The following function tells if a new-style temp record is instant record.
668@param[in] rec new-style temp record
669@return true if it is instant affected */
670static inline bool rec_get_instant_flag_new_temp(const rec_t *rec) {
671 ulint info = rec_get_info_bits_temp(rec);
672 return ((info & REC_INFO_INSTANT_FLAG) != 0);
673}
674
675/** A simplified variant rec_init_offsets(rec, index, offsets) for the case in
676which the rec contains only fixed-length columns and non-NULL values in them,
677thus we can compute the offsets without looking at the rec. Such offsets can be
678cached and reused for many recs which don't contain NULLs.
679@see rec_init_offsets for more details
680@param[in] index The index for which we want to cache the fixed offsets
681@param[in,out] offsets The already allocated array to store the offsets.
682 It should already have been initialized with
683 rec_offs_set_n_alloc() and rec_offs_set_n_fields() before
684 the call.
685 This function will fill all the other elements. */
686inline void rec_init_fixed_offsets(const dict_index_t *index, ulint *offsets) {
687 ut_ad(!index->has_instant_cols_or_row_versions());
688
689 rec_offs_make_valid(nullptr, index, offsets);
690 rec_offs_base(offsets)[0] =
693 const auto n_fields = rec_offs_n_fields(offsets);
694 auto field_end = rec_offs_base(offsets) + 1;
695 for (size_t i = 0; i < n_fields; i++) {
696 field_end[i] = (i ? field_end[i - 1] : 0) + index->get_field(i)->fixed_len;
697 }
698}
699
700/** The following function tells if a new-style record is versioned.
701@param[in] rec new-style (COMPACT/DYNAMIC) record
702@return true if it is versioned */
703static inline bool rec_new_is_versioned(const rec_t *rec) {
704 ulint info = rec_get_info_bits(rec, true);
705 return ((info & REC_INFO_VERSION_FLAG) != 0);
706}
707
708/** The following function tells if an old-style record is versioned.
709@param[in] rec old-style (REDUNDANT) record
710@return true if it's versioned */
711static inline bool rec_old_is_versioned(const rec_t *rec) {
712 ulint info = rec_get_info_bits(rec, false);
713 return ((info & REC_INFO_VERSION_FLAG) != 0);
714}
715
716/** The following function tells if a temporary record is versioned.
717@param[in] rec new-style temporary record
718@return true if it's instant affected */
719static inline bool rec_new_temp_is_versioned(const rec_t *rec) {
720 ulint info = rec_get_info_bits_temp(rec);
721 return ((info & REC_INFO_VERSION_FLAG) != 0);
722}
723
724/** Get the number of fields for one new style leaf page record.
725This is only needed for table after instant ADD COLUMN.
726@param[in] rec leaf page record
727@param[in] extra_bytes extra bytes of this record
728@param[in,out] length length of number of fields
729@return number of fields */
730static inline uint32_t rec_get_n_fields_instant(const rec_t *rec,
731 const ulint extra_bytes,
732 uint16_t *length) {
733 uint16_t n_fields;
734 const byte *ptr;
735
736 ptr = rec - (extra_bytes + 1);
737
738 if ((*ptr & REC_N_FIELDS_TWO_BYTES_FLAG) == 0) {
739 *length = 1;
740 return (*ptr);
741 }
742
743 *length = 2;
744 n_fields = ((*ptr-- & REC_N_FIELDS_ONE_BYTE_MAX) << 8);
745 n_fields |= *ptr;
746 ut_ad(n_fields < REC_MAX_N_FIELDS);
747 ut_ad(n_fields != 0);
748
749 return (n_fields);
750}
751
752/* For INSTANT ADD/DROP, we may have following 5 types of rec for table :
753 +----------------------------------------------------------------------------+
754 | SCENARIO | STATE |
755 |----------------------------------+------------+---------+------------------|
756 | Row property | V <= 8.0.28| Bit set | Stored on row |
757 +----------------------------------+------------+---------+------------------+
758 | INSERTED before 1st INSTANT ADD | Y | NONE | N/A |
759 |----------------------------------+------------+---------+------------------|
760 | INSERTED after 1st INSTANT ADD | Y | INSTANT | # of fields |
761 |----------------------------------+------------+---------+------------------|
762 | INSERTED before INSTANT ADD/DROP | Y | VERSION | Version = 0 |
763 |----------------------------------+------------+---------+------------------|
764 | INSERTED before INSTANT ADD/DROP | N | NONE | N/A |
765 |----------------------------------+------------+---------+------------------|
766 | INSERTED after INSTANT ADD/DROP | Y/N | VERSION | row version |
767 +----------------------------------------------------------------------------+
768*/
770 /* Record was inserted before first instant add done in the earlier
771 implementation. */
773 /* Record was inserted after first instant add done in the earlier
774 implementation. */
776 /* Record was inserted after upgrade but before first instant add done in the
777 new implementation. */
779 /* Record was inserted before first instant add/drop done in the new
780 implementation. */
782 /* Record was inserted after first instant add/drop done in the new
783 implementation. */
785 /* Record belongs to table with no verison no instant */
787 NONE
789
791 const dict_index_t *index, const rec_t *rec, bool temp) {
792 ut_ad(dict_table_is_comp(index->table) || temp);
793
794 if (!index->has_instant_cols_or_row_versions()) {
796 }
797
798 /* Position just before info-bits where version will be there if any */
799 const byte *v_ptr =
800 (byte *)rec -
802 const bool is_versioned =
804 const row_version_t version =
805 (is_versioned) ? static_cast<row_version_t>(*v_ptr) : INVALID_ROW_VERSION;
806
807 const bool is_instant = (temp) ? rec_get_instant_flag_new_temp(rec)
809
810 /* Only one of the two bits could be set */
811 DBUG_EXECUTE_IF("innodb_rec_instant_version_bit_set", {
812 ib::error() << "Record has both instant and version bit set in Table '"
813 << index->table_name << "', Index '" << index->name()
814 << "'. This indicates that the table may be corrupt. Please "
815 "run CHECK TABLE before proceeding.";
816 });
817
818 if (is_versioned && is_instant) {
819 ib::error() << "Record has both instant and version bit set in Table '"
820 << index->table_name << "', Index '" << index->name()
821 << "'. This indicates that the table may be corrupt. Please "
822 "run CHECK TABLE before proceeding.";
823 }
824 ut_ad(!is_versioned || !is_instant);
825
826 enum REC_INSERT_STATE rec_insert_state = REC_INSERT_STATE::NONE;
827 if (is_versioned) {
829 if (version == 0) {
830 ut_ad(index->has_instant_cols());
831 rec_insert_state =
833 } else {
834 ut_ad(index->has_row_versions());
836 }
837 } else if (is_instant) {
838 ut_ad(index->table->has_instant_cols());
840 } else if (index->table->has_instant_cols()) {
842 } else {
844 }
845
846 ut_ad(rec_insert_state != REC_INSERT_STATE::NONE);
847 return rec_insert_state;
848}
849
850/* Following function is to set NULLS and LENS pointers correctly for a temp
851record generated for a record from REDUNDANT FORAMT
852@param[in] index record descriptor
853@param[in,out] rec temp record
854@param[out] n_null number of nullable columns in record
855@param[out] nulls pointer to nullbit map in temp record
856@param[out] lens pointer to lens in temp record
857@returns the row version stored in record or nondefault fields in record */
859 const dict_index_t *index, const rec_t *rec, uint16_t *n_null,
860 const byte **nulls, const byte **lens, uint16_t &non_default_fields,
861 row_version_t &row_version) {
863
864 non_default_fields = static_cast<uint16_t>(dict_index_get_n_fields(index));
865
866 row_version = INVALID_ROW_VERSION;
867
868 /* Set nulls just before the record */
869 *nulls = rec - 1;
870
871 enum REC_INSERT_STATE rec_insert_state =
872 get_rec_insert_state(index, rec, true);
873
874 if (rec_insert_state == INSERTED_INTO_TABLE_WITH_NO_INSTANT_NO_VERSION) {
875 *n_null = index->n_nullable;
876 *lens = *nulls - UT_BITS_IN_BYTES(*n_null);
877 return rec_insert_state;
878 }
879
880 /* info-bits must be present. Shift nulls before that. */
881 *nulls -= REC_N_TMP_EXTRA_BYTES;
882
883 switch (rec_insert_state) {
887 *n_null = index->get_nullable_in_version(0);
888 *lens = *nulls - UT_BITS_IN_BYTES(*n_null);
889 } break;
890
893 /* Read the version information */
894 row_version = (uint8_t)(**nulls);
895 ut_a(is_valid_row_version(row_version));
896
897 /* Shift nulls before the record version */
898 *nulls -= 1;
899 *n_null = index->get_nullable_in_version(row_version);
900 } break;
901
903 default:
904 ut_a(0);
905 }
906
907 *lens = *nulls - UT_BITS_IN_BYTES(*n_null);
908 return rec_insert_state;
909}
910
911/** Determines the information about null bytes and variable length bytes
912for a new-style temporary record
913@param[in] rec physical record
914@param[in] index index where the record resides
915@param[out] nulls the start of null bytes
916@param[out] lens the start of variable length bytes
917@param[out] n_null number of null fields
918@param[out] non_default_fields non default fields from record
919@param[out] row_version row version of the record
920@return the row inserted state */
922 const rec_t *rec, const dict_index_t *index, const byte **nulls,
923 const byte **lens, uint16_t *n_null, uint16_t &non_default_fields,
924 row_version_t &row_version) {
925 /* Following is the format for TEMP record.
926 +----+----+-------------------+--------------------+
927 | OP | ES |<-- Extra info --> | F1 | F2 | ... | Fn|
928 +----+----+-------------------+--------------------+
929 |
930 v
931 +--------------------+-------+---------+-----------+
932 | LN | ... | L2 | L1 | nulls | version | info-bits |
933 +--------------------+-------+---------+-----------+
934 <------ LENS ------>
935
936 where
937 info-bits => Present iff table has INSTANT/VERSION
938 version => version number iff version bit is set.
939 */
940
941 /* Redundant format */
942 if (!dict_table_is_comp(index->table)) {
943 return init_nulls_lens_for_temp_redundant(index, rec, n_null, nulls, lens,
944 non_default_fields, row_version);
945 }
946
947 non_default_fields = static_cast<uint16_t>(dict_index_get_n_fields(index));
948
949 row_version = INVALID_ROW_VERSION;
950
951 /* Set nulls just before the record */
952 *nulls = rec - 1;
953
954 const enum REC_INSERT_STATE rec_insert_state =
955 get_rec_insert_state(index, rec, true);
956
957 if (rec_insert_state == INSERTED_INTO_TABLE_WITH_NO_INSTANT_NO_VERSION) {
958 *n_null = index->n_nullable;
959 *lens = *nulls - UT_BITS_IN_BYTES(*n_null);
960 return rec_insert_state;
961 }
962
963 /* info-bits must be present. Shift nulls before that. */
964 *nulls -= REC_N_TMP_EXTRA_BYTES;
965
966 switch (rec_insert_state) {
969 /* Read the version information */
970 row_version = (uint8_t)(**nulls);
971 ut_a(is_valid_row_version(row_version));
972
973 /* Shift nulls before the record version */
974 *nulls -= 1;
975
976 *n_null = index->get_nullable_in_version(row_version);
977 } break;
978
980 /* Row inserted after first instant ADD COLUMN V1 */
981 ut_ad(index->table->has_instant_cols());
982 uint16_t length;
983 non_default_fields =
985 ut_ad(length == 1 || length == 2);
986
987 /* Shift nulls before "number of fields" */
988 *nulls -= length;
989 *n_null = index->get_n_nullable_before(non_default_fields);
990 } break;
991
993 *n_null = index->get_nullable_before_instant_add_drop();
994 non_default_fields = index->get_instant_fields();
995 } break;
996
998 /* Row inserted before first INSTANT ADD/DROP in V2 */
999 *n_null = index->get_nullable_before_instant_add_drop();
1000 } break;
1001
1003 default:
1004 ut_a(0);
1005 }
1006
1007 /* Position lens */
1008 *lens = *nulls - UT_BITS_IN_BYTES(*n_null);
1009
1010 return (rec_insert_state);
1011}
1012
1013/** Determines the information about null bytes and variable length bytes
1014for a new style record
1015@param[in] rec physical record
1016@param[in] index index where the record resides
1017@param[out] nulls the start of null bytes
1018@param[out] lens the start of variable length bytes
1019@param[out] n_null number of null fields
1020@param[out] non_default_fields non default fields from record
1021@param[out] row_version row version of the record
1022@return number of fields with no default or the row version of record */
1024 const rec_t *rec, const dict_index_t *index, const byte **nulls,
1025 const byte **lens, uint16_t *n_null, uint16_t &non_default_fields,
1026 row_version_t &row_version) {
1027 non_default_fields = static_cast<uint16_t>(dict_index_get_n_fields(index));
1028
1029 row_version = INVALID_ROW_VERSION;
1030
1031 /* Position nulls */
1032 *nulls = rec - (REC_N_NEW_EXTRA_BYTES + 1);
1033
1034 const enum REC_INSERT_STATE rec_insert_state =
1035 get_rec_insert_state(index, rec, false);
1036
1037 switch (rec_insert_state) {
1041
1042 *n_null = index->n_nullable;
1043 } break;
1044
1047 /* Read the row version from record */
1048 row_version = (uint8_t)(**nulls);
1049 ut_ad(is_valid_row_version(row_version));
1050
1051#ifdef UNIV_DEBUG
1052 if (strcmp(index->name, RECOVERY_INDEX_TABLE_NAME) != 0) {
1053 if (row_version > 0) {
1054 /* Row inserted after first instant ADD/DROP COLUMN V2 */
1055 ut_ad(index->table->has_row_versions());
1056 } else {
1057 /* Upgraded table. Row inserted before V2 INSTANT ADD/DROP */
1058 ut_ad(index->table->is_upgraded_instant());
1059 }
1060 }
1061#endif
1062
1063 /* Reposition nulls to skip version */
1064 *nulls -= 1;
1065 *n_null = index->get_nullable_in_version(row_version);
1066 } break;
1067
1069 /* Row inserted after first instant ADD COLUMN V1 */
1070 uint16_t length;
1071 non_default_fields =
1073 ut_ad(length == 1 || length == 2);
1074
1075 /* Reposition nulls to skip number of fields */
1076 *nulls -= length;
1077 *n_null = index->calculate_n_instant_nullable(non_default_fields);
1078 } break;
1079
1081 *n_null = index->get_nullable_before_instant_add_drop();
1082 non_default_fields = index->get_instant_fields();
1083 } break;
1084
1086 /* Row inserted before first INSTANT ADD/DROP in V2 */
1087 *n_null = index->get_nullable_before_instant_add_drop();
1088 } break;
1089
1090 default:
1091 ut_ad(false);
1092 }
1093
1094 /* Position lens */
1095 *lens = *nulls - UT_BITS_IN_BYTES(*n_null);
1096
1097 /* Return record version or non_default_field stored */
1098 return (rec_insert_state);
1099}
1100
1101/** Determine the offset to each field in a leaf-page record in
1102ROW_FORMAT=COMPACT. This is a special case of rec_init_offsets() and
1103rec_get_offsets().
1104@param[in] rec physical record in ROW_FORMAT=COMPACT
1105@param[in] temp whether to use the format for temporary files in index
1106 creation
1107@param[in] index record descriptor
1108@param[in,out] offsets array of offsets
1109@note This long method is made inline because it is on performance sensitive hot
1110path. One must run performance tests if they intend to improve this method. */
1111inline void rec_init_offsets_comp_ordinary(const rec_t *rec, bool temp,
1112 const dict_index_t *index,
1113 ulint *offsets) {
1114#ifdef UNIV_DEBUG
1115 /* We cannot invoke rec_offs_make_valid() here if temp=true.
1116 Similarly, rec_offs_validate() will fail in that case, because
1117 it invokes rec_get_status(). */
1118 offsets[2] = (ulint)rec;
1119 offsets[3] = (ulint)index;
1120#endif /* UNIV_DEBUG */
1121
1122 const byte *nulls = nullptr;
1123 const byte *lens = nullptr;
1124 uint16_t n_null = 0;
1125 enum REC_INSERT_STATE rec_insert_state = REC_INSERT_STATE::NONE;
1126 row_version_t row_version = INVALID_ROW_VERSION;
1127 uint16_t non_default_fields = 0;
1128
1129 if (temp) {
1130 rec_insert_state = rec_init_null_and_len_temp(
1131 rec, index, &nulls, &lens, &n_null, non_default_fields, row_version);
1132 } else {
1133 rec_insert_state = rec_init_null_and_len_comp(
1134 rec, index, &nulls, &lens, &n_null, non_default_fields, row_version);
1135 }
1136
1137 ut_ad(temp || dict_table_is_comp(index->table));
1138
1139 if (temp) {
1140 if (dict_table_is_comp(index->table)) {
1141 /* No need to do adjust fixed_len=0. We only need to
1142 adjust it for ROW_FORMAT=REDUNDANT. */
1143 temp = false;
1144 } else {
1145 /* Redundant temp row. Old instant record is logged as version 0. */
1146 if (rec_insert_state == INSERTED_BEFORE_INSTANT_ADD_OLD_IMPLEMENTATION ||
1149 ut_ad(row_version == INVALID_ROW_VERSION);
1150 }
1151 }
1152 }
1153
1154 /* read the lengths of fields 0..n */
1155 ulint offs = 0;
1156 ulint any_ext = 0;
1157 ulint null_mask = 1;
1158 uint16_t i = 0;
1159 do {
1160 /* Fields are stored on disk in version they are added in and are
1161 maintained in fields_array in the same order. Get the right field. */
1162 const dict_field_t *field = index->get_physical_field(i);
1163 const dict_col_t *col = field->col;
1164 uint64_t len;
1165
1166 switch (rec_insert_state) {
1168 ut_ad(!index->has_instant_cols_or_row_versions());
1169 break;
1170
1172 ut_ad(row_version == INVALID_ROW_VERSION || row_version == 0);
1173 ut_ad(index->has_row_versions() || temp);
1174 /* Record has to be interpreted in v0. */
1175 row_version = 0;
1176 }
1177 [[fallthrough]];
1180 ut_ad(is_valid_row_version(row_version));
1181 /* A record may have version=0 if it's from upgrade table */
1182 ut_ad(index->has_row_versions() ||
1183 (index->table->is_upgraded_instant() && row_version == 0));
1184
1185 /* Based on the record version and column information, see if this
1186 column is there in this record or not. */
1187 if (col->is_dropped_in_or_before(row_version)) {
1188 /* This columns is dropped before or on this row version so its data
1189 won't be there on row. So no need to store the length. Instead, store
1190 offs ORed with REC_OFFS_DROP to indicate the same. */
1191 len = offs | REC_OFFS_DROP;
1192 goto resolved;
1193
1194 /* NOTE : Existing rows, which have data for this column, would still
1195 need to process this column, so don't skip and store the correct
1196 length there. Though it will be skipped while fetching row. */
1197 } else if (col->is_added_after(row_version)) {
1198 /* This columns is added after this row version. In this case no need
1199 to store the length. Instead store only if it is NULL or DEFAULT
1200 value. */
1201 len = rec_get_instant_offset(index, i, offs);
1202
1203 goto resolved;
1204 }
1205 } break;
1206
1209 ut_ad(non_default_fields > 0);
1210 ut_ad(index->has_instant_cols());
1211 ut_ad(!is_valid_row_version(row_version));
1212
1213 if (i >= non_default_fields) {
1214 /* This would be the case when column doesn't exists in the row. In
1215 this case we need not to store the length. Instead we store only if
1216 the column is NULL or DEFAULT value. */
1217 len = rec_get_instant_offset(index, i, offs);
1218
1219 goto resolved;
1220 }
1221
1222 /* Note : Even if the column has been dropped, this row in V1 would
1223 definitely have the value of this column. */
1224 } break;
1225
1226 default:
1227 ut_ad(false);
1228 }
1229
1230 if (!(col->prtype & DATA_NOT_NULL)) {
1231 /* nullable field => read the null flag */
1232 ut_ad(n_null--);
1233
1234 if (UNIV_UNLIKELY(!(byte)null_mask)) {
1235 nulls--;
1236 null_mask = 1;
1237 }
1238
1239 if (*nulls & null_mask) {
1240 null_mask <<= 1;
1241 /* No length is stored for NULL fields.
1242 We do not advance offs, and we set
1243 the length to zero and enable the
1244 SQL NULL flag in offsets[]. */
1245 len = offs | REC_OFFS_SQL_NULL;
1246 goto resolved;
1247 }
1248 null_mask <<= 1;
1249 }
1250
1251 if (!field->fixed_len || (temp && !col->get_fixed_size(temp))) {
1252 ut_ad(col->mtype != DATA_POINT);
1253 /* Variable-length field: read the length */
1254 len = *lens--;
1255 /* If the maximum length of the field is up
1256 to 255 bytes, the actual length is always
1257 stored in one byte. If the maximum length is
1258 more than 255 bytes, the actual length is
1259 stored in one byte for 0..127. The length
1260 will be encoded in two bytes when it is 128 or
1261 more, or when the field is stored externally. */
1262 if (DATA_BIG_COL(col)) {
1263 if (len & 0x80) {
1264 /* 1exxxxxxx xxxxxxxx */
1265 len <<= 8;
1266 len |= *lens--;
1267
1268 offs += len & 0x3fff;
1269 if (UNIV_UNLIKELY(len & 0x4000)) {
1270 ut_ad(index->is_clustered());
1271 any_ext = REC_OFFS_EXTERNAL;
1272 len = offs | REC_OFFS_EXTERNAL;
1273 } else {
1274 len = offs;
1275 }
1276
1277 goto resolved;
1278 }
1279 }
1280
1281 len = offs += len;
1282 } else {
1283 len = offs += field->fixed_len;
1284 }
1285 resolved:
1286 rec_offs_base(offsets)[i + 1] = len;
1287 } while (++i < rec_offs_n_fields(offsets));
1288
1289 *rec_offs_base(offsets) = (rec - (lens + 1)) | REC_OFFS_COMPACT | any_ext;
1290}
1291
1292/** The following function is used to test whether the data offsets in the
1293 record are stored in one-byte or two-byte format.
1294 @return true if 1-byte form */
1295[[nodiscard]] static inline bool rec_get_1byte_offs_flag(
1296 const rec_t *rec) /*!< in: physical record */
1297{
1300}
1301
1302#endif
The class error is used to emit error messages.
Definition: ut0log.h:231
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:920
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
bool rec_info_bits_valid(ulint bits)
Check if the info bits are valid.
Definition: rec.h:318
constexpr uint32_t REC_INFO_INSTANT_FLAG
The instant ADD COLUMN flag.
Definition: rec.h:152
static const uint8_t REC_N_FIELDS_TWO_BYTES_FLAG
Number of fields flag which means it occupies two bytes.
Definition: rec.h:236
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:287
constexpr uint32_t REC_N_OWNED_MASK
Definition: rec.h:117
constexpr uint32_t REC_OFFS_EXTERNAL
Definition: rec.h:75
constexpr uint32_t REC_OFFS_HEADER_SIZE
Definition: rec.h:201
constexpr uint32_t REC_OFFS_DEFAULT
Definition: rec.h:77
constexpr uint32_t REC_NEW_HEAP_NO
Definition: rec.h:84
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:1111
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:686
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:921
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:670
constexpr uint32_t REC_NEXT
Definition: rec.h:92
constexpr uint32_t REC_N_OLD_EXTRA_BYTES
Definition: rec.h:156
constexpr uint32_t REC_STATUS_SUPREMUM
Definition: rec.h:182
constexpr uint32_t REC_NODE_PTR_SIZE
Definition: rec.h:188
constexpr uint32_t REC_INFO_BITS_SHIFT
Definition: rec.h:124
constexpr uint32_t REC_OFFS_DROP
Definition: rec.h:79
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:1023
constexpr uint32_t REC_INFO_MIN_REC_FLAG
Definition: rec.h:144
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:328
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:121
constexpr uint32_t REC_OLD_INFO_BITS
Definition: rec.h:120
constexpr uint32_t REC_OFFS_MASK
Definition: rec.h:81
constexpr uint32_t REC_OLD_SHORT_MASK
Definition: rec.h:97
constexpr uint32_t REC_OLD_SHORT_SHIFT
Definition: rec.h:98
Rec_instant_state
Instant state of a record.
Definition: rec.h:214
constexpr uint32_t REC_INFO_BITS_MASK
Definition: rec.h:123
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:340
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:524
static const uint8_t REC_N_FIELDS_ONE_BYTE_MAX
Max number of fields which can be stored in one byte.
Definition: rec.h:239
constexpr uint32_t REC_HEAP_NO_MASK
Definition: rec.h:109
REC_INSERT_STATE
Definition: rec.h:769
@ INSERTED_AFTER_UPGRADE_BEFORE_INSTANT_ADD_NEW_IMPLEMENTATION
Definition: rec.h:778
@ INSERTED_AFTER_INSTANT_ADD_OLD_IMPLEMENTATION
Definition: rec.h:775
@ INSERTED_AFTER_INSTANT_ADD_NEW_IMPLEMENTATION
Definition: rec.h:784
@ INSERTED_BEFORE_INSTANT_ADD_NEW_IMPLEMENTATION
Definition: rec.h:781
@ INSERTED_INTO_TABLE_WITH_NO_INSTANT_NO_VERSION
Definition: rec.h:786
@ NONE
Definition: rec.h:787
@ INSERTED_BEFORE_INSTANT_ADD_OLD_IMPLEMENTATION
Definition: rec.h:772
constexpr uint32_t REC_TMP_INFO_BITS
Definition: rec.h:122
constexpr uint32_t REC_HEAP_NO_SHIFT
Definition: rec.h:87
constexpr uint32_t REC_STATUS_ORDINARY
Definition: rec.h:179
static enum REC_INSERT_STATE get_rec_insert_state(const dict_index_t *index, const rec_t *rec, bool temp)
Definition: rec.h:790
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:467
constexpr uint32_t REC_STATUS_INFIMUM
Definition: rec.h:181
constexpr uint32_t REC_NEW_STATUS
Definition: rec.h:104
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:628
static bool rec_new_is_versioned(const rec_t *rec)
The following function tells if a new-style record is versioned.
Definition: rec.h:703
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:147
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:373
constexpr uint32_t REC_1BYTE_SQL_NULL_MASK
SQL null flag in a 1-byte offset of ROW_FORMAT=REDUNDANT records.
Definition: rec.h:191
constexpr uint32_t REC_OLD_N_FIELDS
Definition: rec.h:100
constexpr auto MAX_REC_PER_PAGE
Maximum number of records in a page.
Definition: rec.h:167
constexpr uint32_t REC_OFFS_COMPACT
NOTE: The functions in this file should only use functions from other files in library.
Definition: rec.h:71
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:480
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:564
static bool rec_new_temp_is_versioned(const rec_t *rec)
The following function tells if a temporary record is versioned.
Definition: rec.h:719
constexpr uint32_t REC_NEW_STATUS_MASK
Definition: rec.h:105
constexpr uint32_t REC_OFFS_SQL_NULL
Definition: rec.h:73
constexpr uint32_t REC_N_TMP_EXTRA_BYTES
Definition: rec.h:163
constexpr uint32_t REC_OLD_N_OWNED
Definition: rec.h:115
static ulint rec_offs_n_fields(const ulint *offsets)
The following function returns the number of fields in a record.
Definition: rec.h:506
static const ulint * rec_offs_base(const ulint *offsets)
Definition: rec.h:227
constexpr int32_t REC_N_NEW_EXTRA_BYTES
Definition: rec.h:159
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:858
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:350
constexpr uint32_t REC_NEXT_MASK
Definition: rec.h:93
constexpr uint32_t REC_2BYTE_SQL_NULL_MASK
SQL null flag in a 2-byte offset of ROW_FORMAT=REDUNDANT records.
Definition: rec.h:193
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:149
constexpr uint32_t REC_NEW_N_OWNED
Definition: rec.h:116
constexpr uint32_t REC_OLD_N_FIELDS_SHIFT
Definition: rec.h:102
constexpr uint32_t REC_OLD_HEAP_NO
Definition: rec.h:108
static bool rec_old_is_versioned(const rec_t *rec)
The following function tells if an old-style record is versioned.
Definition: rec.h:711
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:1295
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:416
constexpr uint32_t REC_N_OWNED_SHIFT
Definition: rec.h:118
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:730
constexpr uint32_t REC_STATUS_NODE_PTR
Definition: rec.h:180
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:459
constexpr uint32_t REC_OLD_SHORT
Definition: rec.h:96
constexpr uint32_t REC_NEXT_SHIFT
Definition: rec.h:94
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:492
constexpr uint32_t REC_OFFS_NORMAL_SIZE
Definition: rec.h:209
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:275
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:197
constexpr uint32_t REC_NEW_STATUS_SHIFT
Definition: rec.h:106
bool rec_offs_cmp(ulint *offsets1, ulint *offsets2)
Check if the given two record offsets are identical.
Definition: rec.cc:535
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:429
std::ostream & rec_offs_print(std::ostream &out, const ulint *offsets)
Print the record offsets.
Definition: rec.cc:567
static ulint rec_get_status(const rec_t *rec)
The following function retrieves the status bits of a new-style record.
Definition: rec.h:300
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:662
constexpr uint32_t REC_OLD_N_FIELDS_MASK
Definition: rec.h:101
constexpr uint32_t REC_OFFS_SMALL_SIZE
Definition: rec.h:210
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:1842
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:1067
Structure for an SQL data tuple of fields (logical record)
Definition: data0data.h:696
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:302
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:618
#define UNIV_UNLIKELY(cond)
Definition: univ.i:521
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:463
#define UNIV_MEM_ASSERT_AND_ALLOC(addr, size)
Definition: univ.i:630
constexpr ulint ULINT_MAX
Maximum value for a ulint.
Definition: univ.i:440
unsigned long int ulint
Definition: univ.i:406
constexpr size_t UNIV_PAGE_SIZE_MAX
Maximum page size InnoDB currently supports.
Definition: univ.i:323
#define ut_error
Abort execution.
Definition: ut0dbg.h:101
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:105
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:93
#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