Debian Codegraph @

storage/innobase/include/rem0rec.h

raw
1 /*****************************************************************************
2
3 Copyright (c) 1994, 2026, Oracle and/or its affiliates.
4
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8
9 This program is designed to work with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have either included with
15 the program or referenced in the documentation.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20 for more details.
21
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26 *****************************************************************************/
27
28 /** @file include/rem0rec.h
29 Record manager
30
31 Created 5/30/1994 Heikki Tuuri
32 *************************************************************************/
33
34 #ifndef rem0rec_h
35 #define rem0rec_h
36
37 #include <ostream>
38 #include <sstream>
39
40 #include "univ.i"
41
42 #include "data0data.h"
43 #include "mtr0types.h"
44 #include "page0types.h"
45 #include "rem/rec.h"
46 #include "rem0types.h"
47 #include "trx0types.h"
48 #include "ut0class_life_cycle.h"
49
50 #include "rem0wrec.h"
51
52 /** The following function is used to get the pointer of the next chained record
53 on the same page.
54 @param[in] rec Physical record.
55 @param[in] comp Nonzero=compact page format.
56 @return pointer to the next chained record, or nullptr if none */
57 [[nodiscard]] static inline const rec_t *rec_get_next_ptr_const(
58 const rec_t *rec, ulint comp);
59 /** The following function is used to get the pointer of the next chained record
60 on the same page.
61 @param[in] rec Physical record.
62 @param[in] comp Nonzero=compact page format.
63 @return pointer to the next chained record, or nullptr if none */
64 [[nodiscard]] static inline rec_t *rec_get_next_ptr(rec_t *rec, ulint comp);
65 /** The following function is used to get the offset of the
66 next chained record on the same page.
67 @param[in] rec Physical record.
68 @param[in] comp Nonzero=compact page format.
69 @return the page offset of the next chained record, or 0 if none */
70 [[nodiscard]] static inline ulint rec_get_next_offs(const rec_t *rec,
71 ulint comp);
72
73 /** The following function is used to set the next record offset field of an
74 old-style record.
75 @param[in] rec old-style physical record
76 @param[in] next offset of the next record */
77 static inline void rec_set_next_offs_old(rec_t *rec, ulint next);
78
79 /** The following function is used to set the next record offset field of a
80 new-style record. */
81 static inline void rec_set_next_offs_new(rec_t *rec, ulint next);
82
83 /** The following function is used to get the number of records owned by the
84 previous directory record.
85 @return number of owned records */
86 [[nodiscard]] static inline ulint rec_get_n_owned_old(
87 const rec_t *rec); /*!< in: old-style physical record */
88
89 /** The following function is used to set the number of owned records.
90 @param[in] rec old-style physical record
91 @param[in] n_owned the number of owned */
92 static inline void rec_set_n_owned_old(rec_t *rec, ulint n_owned);
93
94 /** The following function is used to get the number of records owned by the
95 previous directory record.
96 @return number of owned records */
97 [[nodiscard]] static inline ulint rec_get_n_owned_new(
98 const rec_t *rec); /*!< in: new-style physical record */
99
100 /** The following function is used to set the number of owned records.
101 @param[in,out] rec new-style physical record
102 @param[in,out] page_zip compressed page, or NULL
103 @param[in] n_owned the number of owned */
104 static inline void rec_set_n_owned_new(rec_t *rec, page_zip_des_t *page_zip,
105 ulint n_owned);
106
107 /** The following function is used to set the info bits of a record.
108 @param[in] rec old-style physical record
109 @param[in] bits info bits */
110 static inline void rec_set_info_bits_old(rec_t *rec, ulint bits);
111
112 /** The following function is used to set the info bits of a record.
113 @param[in,out] rec new-style physical record
114 @param[in] bits info bits */
115 static inline void rec_set_info_bits_new(rec_t *rec, ulint bits);
116
117 /** The following function is used to set the status bits of a new-style record.
118 @param[in,out] rec physical record
119 @param[in] bits info bits */
120 static inline void rec_set_status(rec_t *rec, ulint bits);
121
122 /** The following function is used to retrieve the info and status
123 bits of a record. (Only compact records have status bits.)
124 @param[in] rec Physical record.
125 @param[in] comp Nonzero=compact page format.
126 @return info bits */
127 [[nodiscard]] static inline ulint rec_get_info_and_status_bits(const rec_t *rec,
128 bool comp);
129
130 /** The following function is used to set the info and status bits of a record.
131 (Only compact records have status bits.)
132 @param[in,out] rec compact physical record
133 @param[in] bits info bits */
134 static inline void rec_set_info_and_status_bits(rec_t *rec, ulint bits);
135
136 /** The following function tells if record is delete marked.
137 @param[in] rec Physical record.
138 @param[in] comp Nonzero=compact page format.
139 @return nonzero if delete marked */
140 [[nodiscard]] static inline bool rec_get_deleted_flag(const rec_t *rec,
141 bool comp);
142
143 /** The following function is used to set the deleted bit.
144 @param[in] rec old-style physical record
145 @param[in] flag true if delete marked */
146 static inline void rec_set_deleted_flag_old(rec_t *rec, bool flag);
147
148 /** The following function is used to set the deleted bit.
149 @param[in,out] rec new-style physical record
150 @param[in,out] page_zip compressed page, or NULL
151 @param[in] flag true if delete marked */
152 static inline void rec_set_deleted_flag_new(rec_t *rec,
153 page_zip_des_t *page_zip,
154 bool flag);
155
156 /** The following function is used to set the instant bit.
157 @param[in,out] rec new-style physical record */
158 static inline void rec_new_set_instant(rec_t *rec);
159
160 /** The following function is used to set the row version bit.
161 @param[in,out] rec new-style (COMPACT/DYNAMIC) physical record */
162 static inline void rec_new_set_versioned(rec_t *rec);
163
164 /** The following function is used to reset the instant bit and the row version
165 bit.
166 @param[in,out] rec new-style (COMPACT/DYNAMIC) physical record */
167 static inline void rec_new_reset_instant_version(rec_t *rec);
168
169 /** The following function is used to set the instant bit.
170 @param[in,out] rec old-style (REDUNDANT) physical record
171 @param[in] flag set the bit to this flag */
172 static inline void rec_old_set_versioned(rec_t *rec, bool flag);
173
174 /** The following function tells if a new-style record is a node pointer.
175 @return true if node pointer */
176 [[nodiscard]] static inline bool rec_get_node_ptr_flag(
177 const rec_t *rec); /*!< in: physical record */
178
179 /** The following function is used to set the heap number field in an old-style
180 record.
181 @param[in] rec physical record
182 @param[in] heap_no the heap number */
183 static inline void rec_set_heap_no_old(rec_t *rec, ulint heap_no);
184
185 /** The following function is used to set the heap number field in a new-style
186 record.
187 @param[in,out] rec physical record
188 @param[in] heap_no the heap number */
189 static inline void rec_set_heap_no_new(rec_t *rec, ulint heap_no);
190
191 /** The following function is used to set the 1-byte offsets flag.
192 @param[in] rec physical record
193 @param[in] flag true if 1byte form */
194 static inline void rec_set_1byte_offs_flag(rec_t *rec, bool flag);
195
196 /** Determine how many of the first n columns in a compact
197 physical record are stored externally.
198 @param[in] rec compact physical record
199 @param[in] index record descriptor
200 @param[in] n number of columns to scan
201 @return number of externally stored columns */
202 [[nodiscard]] ulint rec_get_n_extern_new(const rec_t *rec,
203 const dict_index_t *index, ulint n);
204
205 /** Gets the value of the specified field in the record in old style.
206 This is only used for record from instant index, which is clustered
207 index and has some instantly added columns.
208 @param[in] rec physical record
209 @param[in] n index of the field
210 @param[in] index clustered index where the record resides
211 @param[out] len length of the field, UNIV_SQL if SQL null
212 @return value of the field, could be either pointer to rec or default value */
213 static inline const byte *rec_get_nth_field_old_instant(
214 const rec_t *rec, uint16_t n, const dict_index_t *index, ulint *len);
215
216 /** Gets the value of the specified field in the record.
217 This is only used when there is possibility that the record comes from the
218 clustered index, which has some instantly added columns.
219 @param[in] rec physical record
220 @param[in] offsets array returned by rec_get_offsets()
221 @param[in] n index of the field
222 @param[in] index clustered index where the record resides, or nullptr
223 if the record doesn't have instantly added columns
224 for sure
225 @param[out] len length of the field, UNIV_SQL_NULL if SQL null
226 @return value of the field, could be either pointer to rec or default value */
227 static inline const byte *rec_get_nth_field_instant(const rec_t *rec,
228 const ulint *offsets,
229 ulint n,
230 const dict_index_t *index,
231 ulint *len);
232
233 /** Determine if the field is not NULL and not having default value
234 after instant ADD COLUMN
235 @param[in] len length of a field
236 @return true if not NULL and not having default value */
237 static inline bool rec_field_not_null_not_add_col_def(ulint len);
238
239 /** Determine if the offsets are for a record in the new compact format.
240 @param[in] offsets array returned by rec_get_offsets()
241 @return nonzero if compact format */
242 [[nodiscard]] static inline bool rec_offs_comp(const ulint *offsets);
243
244 /** Determine if the offsets are for a record containing externally stored
245 columns.
246 @param[in] offsets array returned by rec_get_offsets()
247 @return nonzero if externally stored */
248 [[nodiscard]] static inline bool rec_offs_any_extern(const ulint *offsets);
249
250 /** Determine if the offsets are for a record containing null BLOB pointers.
251 @param[in] index record descriptor
252 @param[in] rec record
253 @param[in] offsets array returned by rec_get_offsets()
254 @return first field containing a null BLOB pointer, or NULL if none found */
255 [[nodiscard]] static inline const byte *rec_offs_any_null_extern(
256 const dict_index_t *index, const rec_t *rec, const ulint *offsets);
257
258 /** Returns the number of extern bits set in a record.
259 @param[in] index record descriptor
260 @param[in] offsets array returned by rec_get_offsets()
261 @return number of externally stored fields */
262 [[nodiscard]] static inline ulint rec_offs_n_extern(const dict_index_t *index,
263 const ulint *offsets);
264
265 #define rec_offs_init(offsets) \
266 rec_offs_set_n_alloc(offsets, (sizeof offsets) / sizeof *offsets)
267
268 /**
269 A helper RAII wrapper for otherwise difficult to use sequence of:
270
271 ulint offsets_[REC_OFFS_NORMAL_SIZE];
272 rec_offs_init(offsets_);
273 mem_heap_t *heap = nullptr;
274
275 const ulint *offsets =
276 rec_get_offsets(rec, index, offsets_, ULINT_UNDEFINED, &heap);
277
278 DO_SOMETHING(offsets);
279
280 if (heap != nullptr) {
281 mem_heap_free(heap);
282 }
283
284 With this helper you can simply do:
285
286 DO_SOMETHING(Rec_offsets().compute(rec,index));
287
288 And if you need to reuse the memory allocated offsets several times you can:
289 Rec_offsets offsets;
290 for(rec: recs) DO_SOMTHING(offsets.compute(rec,index))
291 */
292 class Rec_offsets : private ut::Non_copyable {
293 public:
294 /** Prepares offsets to initially point to the fixed-size buffer, and marks
295 the memory as allocated, but uninitialized. You first need to call compute()
296 to use it */
297 Rec_offsets() { rec_offs_init(m_preallocated_buffer); }
298
299 /** Computes offsets for given record. Returned array is owned by this
300 instance. You can use its value as long as this object does not go out of
301 scope (which can free the buffer), and you don't call compute() again (which
302 can overwrite the offsets).
303 @param[in] rec The record for which you want to compute the offsets
304 @param[in] index The index which contains the record
305 @param[in] n_fields Number of columns to scan
306 @return A pointer to offsets array owned by this instance. Valid till next
307 call to compute() or end of this instance lifetime.
308 */
309 const ulint *compute(const rec_t *rec, const dict_index_t *index,
310 const ulint n_fields = ULINT_UNDEFINED) {
311 m_offsets = rec_get_offsets(rec, index, m_offsets, n_fields,
312 UT_LOCATION_HERE, &m_heap);
313 return m_offsets;
314 }
315 /** Deallocated dynamically allocated memory, if any. */
316 ~Rec_offsets() {
317 if (m_heap) {
318 mem_heap_free(m_heap);
319 m_heap = nullptr;
320 }
321 }
322
323 private:
324 /** Pointer to heap used by rec_get_offsets(). Initially nullptr. If row is
325 really big, rec_get_offsets() may need to allocate new buffer for offsets.
326 At, first, when heap is null, rec_get_offsets() will create new heap, and pass
327 it back via reference. On subsequent calls, we will pass this heap, so it
328 is reused if needed. Therefore all allocated buffers are in this heap, if it
329 is not nullptr */
330 mem_heap_t *m_heap{nullptr};
331
332 /** Buffer with size large enough to handle common cases without having to use
333 heap. This is the initial value of m_offsets.*/
334 ulint m_preallocated_buffer[REC_OFFS_NORMAL_SIZE];
335
336 /* Initially points to m_preallocated_buffer (which is uninitialized memory).
337 After each call to compute() contains the pointer to the most recently
338 computed offsets.
339 We pass it back to rec_get_offsets() on subsequent calls to compute() to reuse
340 the same memory if possible. */
341 ulint *m_offsets{m_preallocated_buffer};
342 };
343
344 /** The following function returns the data size of a physical
345 record, that is the sum of field lengths. SQL null fields
346 are counted as length 0 fields. The value returned by the function
347 is the distance from record origin to record end in bytes.
348 @param[in] offsets array returned by rec_get_offsets()
349 @return size */
350 [[nodiscard]] static inline ulint rec_offs_data_size(const ulint *offsets);
351
352 /** Returns the total size of record minus data size of record.
353 The value returned by the function is the distance from record
354 start to record origin in bytes.
355 @param[in] offsets array returned by rec_get_offsets()
356 @return size */
357 [[nodiscard]] static inline ulint rec_offs_extra_size(const ulint *offsets);
358
359 /** Returns the total size of a physical record.
360 @param[in] offsets array returned by rec_get_offsets()
361 @return size */
362 [[nodiscard]] static inline ulint rec_offs_size(const ulint *offsets);
363
364 #ifdef UNIV_DEBUG
365 /** Returns a pointer to the start of the record.
366 @param[in] rec pointer to record
367 @param[in] offsets array returned by rec_get_offsets()
368 @return pointer to start */
369 [[nodiscard]] static inline byte *rec_get_start(const rec_t *rec,
370 const ulint *offsets);
371
372 /** Returns a pointer to the end of the record.
373 @param[in] rec pointer to record
374 @param[in] offsets array returned by rec_get_offsets()
375 @return pointer to end */
376 [[nodiscard]] static inline byte *rec_get_end(const rec_t *rec,
377 const ulint *offsets);
378 #else /* UNIV_DEBUG */
379 #define rec_get_start(rec, offsets) ((rec)-rec_offs_extra_size(offsets))
380 #define rec_get_end(rec, offsets) ((rec) + rec_offs_data_size(offsets))
381 #endif /* UNIV_DEBUG */
382
383 /** Copy a physical record to a buffer.
384 @param[in] buf buffer
385 @param[in] rec physical record
386 @param[in] offsets array returned by rec_get_offsets()
387 @return pointer to the origin of the copy */
388 static inline rec_t *rec_copy(void *buf, const rec_t *rec,
389 const ulint *offsets);
390
391 #ifndef UNIV_HOTBACKUP
392 /** Determines the size of a data tuple prefix in a temporary file.
393 @param[in] index record descriptor
394 @param[in] fields array of data fields
395 @param[in] n_fields number of data fields
396 @param[in] v_entry dtuple contains virtual column data
397 @param[out] extra extra size
398 @param[in] rec_version row version of record
399 @return total size */
400 [[nodiscard]] ulint rec_get_serialize_size(const dict_index_t *index,
401 const dfield_t *fields,
402 ulint n_fields,
403 const dtuple_t *v_entry,
404 ulint *extra, uint8_t rec_version);
405
406 /** Determine the offset to each field in temporary file.
407 @param[in] rec temporary file record
408 @param[in] index record descriptor
409 @param[in,out] offsets array of offsets
410 @see rec_serialize_dtuple() */
411 void rec_deserialize_init_offsets(const rec_t *rec, const dict_index_t *index,
412 ulint *offsets);
413
414 /** Builds a temporary file record out of a data tuple.
415 @param[out] rec record
416 @param[in] index record descriptor
417 @param[in] fields array of data fields
418 @param[in] n_fields number of fields
419 @param[in] v_entry dtuple contains virtual column data
420 @param[in] rec_version rec version
421 @see rec_deserialize_init_offsets() */
422 void rec_serialize_dtuple(rec_t *rec, const dict_index_t *index,
423 const dfield_t *fields, ulint n_fields,
424 const dtuple_t *v_entry, uint8_t rec_version);
425
426 /** Copies the first n fields of a physical record to a new physical record in
427 a buffer.
428 @param[in] rec physical record
429 @param[in] index record descriptor
430 @param[in] n_fields number of fields to copy
431 @param[in,out] buf memory buffer for the copied prefix, or NULL
432 @param[in,out] buf_size buffer size
433 @return own: copied record */
434 rec_t *rec_copy_prefix_to_buf(const rec_t *rec, const dict_index_t *index,
435 ulint n_fields, byte **buf, size_t *buf_size);
436
437 /** Compute a hash value of a prefix of a leaf page record.
438 @param[in] rec leaf page record
439 @param[in] offsets rec_get_offsets(rec)
440 @param[in] n_fields number of complete fields to hash
441 @param[in] n_bytes number of bytes to hash in the last field
442 @param[in] hashed_value hash value of the index identifier
443 @param[in] index index where the record resides
444 @return the hashed value */
445 [[nodiscard]] static inline uint64_t rec_hash(const rec_t *rec,
446 const ulint *offsets,
447 ulint n_fields, ulint n_bytes,
448 uint64_t hashed_value,
449 const dict_index_t *index);
450 #endif /* !UNIV_HOTBACKUP */
451
452 /** Builds a physical record out of a data tuple and stores it into the given
453 buffer.
454 @param[in] buf start address of the physical record
455 @param[in] index record descriptor
456 @param[in] dtuple data tuple
457 @return pointer to the origin of physical record */
458 [[nodiscard]] rec_t *rec_convert_dtuple_to_rec(byte *buf,
459 const dict_index_t *index,
460 const dtuple_t *dtuple);
461
462 /** Returns the extra size of an old-style physical record if we know its
463 data size and number of fields.
464 @param[in] data_size data size
465 @param[in] n_fields number of fields
466 @param[in] has_ext true if tuple has ext fields
467 @return extra size */
468 static inline ulint rec_get_converted_extra_size(ulint data_size,
469 ulint n_fields, bool has_ext);
470
471 /** Determines the size of a data tuple prefix in ROW_FORMAT=COMPACT.
472 @param[in] index record descriptor
473 @param[in] fields array of data fields
474 @param[in] n_fields number of data fields
475 @param[out] extra extra size
476 @return total size */
477 [[nodiscard]] ulint rec_get_converted_size_comp_prefix(
478 const dict_index_t *index, const dfield_t *fields, ulint n_fields,
479 ulint *extra);
480
481 /** Determines the size of a data tuple in ROW_FORMAT=COMPACT.
482 @param[in] index record descriptor; dict_table_is_comp() is
483 assumed to hold, even if it does not
484 @param[in] status status bits of the record
485 @param[in] fields array of data fields
486 @param[in] n_fields number of data fields
487 @param[out] extra extra size
488 @return total size */
489 ulint rec_get_converted_size_comp(const dict_index_t *index, ulint status,
490 const dfield_t *fields, ulint n_fields,
491 ulint *extra);
492
493 /** The following function returns the size of a data tuple when converted to
494 a physical record.
495 @param[in] index record descriptor
496 @param[in] dtuple data tuple
497 @return size */
498 [[nodiscard]] static inline ulint rec_get_converted_size(
499 const dict_index_t *index, const dtuple_t *dtuple);
500
501 #ifndef UNIV_HOTBACKUP
502 /** Copies the first n fields of a physical record to a data tuple.
503 The fields are copied to the memory heap.
504 @param[out] tuple data tuple
505 @param[in] rec physical record
506 @param[in] index record descriptor
507 @param[in] n_fields number of fields to copy
508 @param[in] heap memory heap */
509 void rec_copy_prefix_to_dtuple(dtuple_t *tuple, const rec_t *rec,
510 const dict_index_t *index, ulint n_fields,
511 mem_heap_t *heap);
512 #endif /* !UNIV_HOTBACKUP */
513
514 /** Get the length of the number of fields for any new style record.
515 @param[in] n_fields number of fields in the record
516 @return length of specified number of fields */
517 static inline uint8_t rec_get_n_fields_length(ulint n_fields);
518
519 /** Set the row version on one new style leaf page record.
520 This is only needed for table after instant ADD/DROP COLUMN.
521 @param[in,out] rec leaf page record
522 @param[in] version row version */
523 static inline void rec_set_instant_row_version_new(rec_t *rec, uint8_t version);
524
525 /** Set the row version on one old style leaf page record.
526 This is only needed for table after instant ADD/DROP COLUMN.
527 @param[in,out] rec leaf page record
528 @param[in] version row version */
529 static inline void rec_set_instant_row_version_old(rec_t *rec, uint8_t version);
530
531 /** Validates the consistency of a physical record.
532 @param[in] rec physical record
533 @param[in] offsets array returned by rec_get_offsets()
534 @return true if ok */
535 bool rec_validate(const rec_t *rec, const ulint *offsets);
536
537 /** Prints an old-style physical record.
538 @param[in] file File where to print
539 @param[in] rec Physical record */
540 void rec_print_old(FILE *file, const rec_t *rec);
541
542 #ifndef UNIV_HOTBACKUP
543
544 /** Prints a spatial index record.
545 @param[in] file File where to print
546 @param[in] rec Physical record
547 @param[in] offsets Array returned by rec_get_offsets() */
548 void rec_print_mbr_rec(FILE *file, const rec_t *rec, const ulint *offsets);
549
550 /** Prints a physical record.
551 @param[in] file file where to print
552 @param[in] rec physical record
553 @param[in] offsets array returned by rec_get_offsets() */
554 void rec_print_new(FILE *file, const rec_t *rec, const ulint *offsets);
555
556 /** Prints a physical record.
557 @param[in] file File where to print
558 @param[in] rec Physical record
559 @param[in] index Record descriptor */
560 void rec_print(FILE *file, const rec_t *rec, const dict_index_t *index);
561
562 /** Pretty-print a record.
563 @param[in,out] o output stream
564 @param[in] rec physical record
565 @param[in] info rec_get_info_bits(rec)
566 @param[in] offsets rec_get_offsets(rec) */
567 void rec_print(std::ostream &o, const rec_t *rec, ulint info,
568 const ulint *offsets);
569
570 /** Wrapper for pretty-printing a record */
571 struct rec_index_print {
572 /** Constructor */
573 rec_index_print(const rec_t *rec, const dict_index_t *index)
574 : m_rec(rec), m_index(index) {}
575
576 /** Record */
577 const rec_t *m_rec;
578 /** Index */
579 const dict_index_t *m_index;
580 };
581
582 /** Display a record.
583 @param[in,out] o output stream
584 @param[in] r record to display
585 @return the output stream */
586 std::ostream &operator<<(std::ostream &o, const rec_index_print &r);
587
588 /** Wrapper for pretty-printing a record */
589 struct rec_offsets_print {
590 /** Constructor */
591 rec_offsets_print(const rec_t *rec, const ulint *offsets)
592 : m_rec(rec), m_offsets(offsets) {}
593
594 /** Record */
595 const rec_t *m_rec;
596 /** Offsets to each field */
597 const ulint *m_offsets;
598 };
599
600 /** Display a record.
601 @param[in,out] o output stream
602 @param[in] r record to display
603 @return the output stream */
604 std::ostream &operator<<(std::ostream &o, const rec_offsets_print &r);
605
606 #ifdef UNIV_DEBUG
607 /** Pretty-printer of records and tuples */
608 class rec_printer : public std::ostringstream {
609 public:
610 /** Construct a pretty-printed record.
611 @param rec record with header
612 @param offsets rec_get_offsets(rec, ...) */
613 rec_printer(const rec_t *rec, const ulint *offsets) : std::ostringstream() {
614 rec_print(*this, rec, rec_get_info_bits(rec, rec_offs_comp(offsets)),
615 offsets);
616 }
617
618 /** Construct a pretty-printed record.
619 @param rec record, possibly lacking header
620 @param info rec_get_info_bits(rec)
621 @param offsets rec_get_offsets(rec, ...) */
622 rec_printer(const rec_t *rec, ulint info, const ulint *offsets)
623 : std::ostringstream() {
624 rec_print(*this, rec, info, offsets);
625 }
626
627 /** Construct a pretty-printed tuple.
628 @param tuple data tuple */
629 rec_printer(const dtuple_t *tuple) : std::ostringstream() {
630 dtuple_print(*this, tuple);
631 }
632
633 /** Construct a pretty-printed tuple.
634 @param field array of data tuple fields
635 @param n number of fields */
636 rec_printer(const dfield_t *field, ulint n) : std::ostringstream() {
637 dfield_print(*this, field, n);
638 }
639
640 /** Destructor */
641 virtual ~rec_printer() = default;
642
643 private:
644 /** Copy constructor */
645 rec_printer(const rec_printer &other);
646 /** Assignment operator */
647 rec_printer &operator=(const rec_printer &other);
648 };
649 #endif /* UNIV_DEBUG */
650
651 /** Reads the DB_TRX_ID of a clustered index record.
652 @param[in] rec record
653 @param[in] index clustered index
654 @return the value of DB_TRX_ID */
655 [[nodiscard]] trx_id_t rec_get_trx_id(const rec_t *rec,
656 const dict_index_t *index);
657 #endif /* UNIV_HOTBACKUP */
658
659 /* Maximum lengths for the data in a physical record if the offsets
660 are given in one byte (resp. two byte) format. */
661 constexpr ulint REC_1BYTE_OFFS_LIMIT = 0x7FUL;
662 constexpr ulint REC_2BYTE_OFFS_LIMIT = 0x7FFFUL;
663
664 /* The data size of record must be smaller than this because we reserve
665 two upmost bits in a two byte offset for special purposes */
666 constexpr ulint REC_MAX_DATA_SIZE = 16384;
667
668 /** For a given clustered index, version is to be stored on physical record.
669 @param[in] index clustered index
670 @param[in] n_tuple_fields number of fields in tuple
671 @return true, if version is to be stored */
672 bool is_store_version(const dict_index_t *index, size_t n_tuple_fields);
673
674 /* A temp record, generated for a REDUNDANT row record, will have info bits
675 iff table has INSTANT ADD columns. And if record has row version, then it will
676 also be stored on temp record header. Following function finds the number of
677 more bytes needed in record header to store this info.
678 @param[in] index record descriptor
679 @param[in] valid_version true if record has version
680 @return number of bytes NULL pointer should be adjusted. */
681 size_t get_extra_bytes_for_temp_redundant(const dict_index_t *index,
682 bool valid_version);
683 #include "rem0rec.ic"
684
685 #endif