MySQL 9.0.0
Source Code Documentation
lob0lob.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2015, 2024, 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#ifndef lob0lob_h
28#define lob0lob_h
29
30#include <my_dbug.h>
31#include "btr0pcur.h"
32#include "dict0mem.h"
33#include "page0page.h"
34#include "row0log.h"
35#include "univ.i"
36
37/* Uncomment the following line to generate debug data, useful to analyze
38LOB issues. */
39/* #define LOB_DEBUG */
40/* #define ZLOB_DEBUG */
41
42struct upd_t;
43typedef std::map<page_no_t, buf_block_t *> BlockCache;
44
45/**
46@file
47@brief Implements the large objects (LOB) module.
48
49InnoDB supports large objects (LOB). Previously, the LOB was called as
50externally stored fields. A large object contains a singly linked list of
51database pages, aka LOB pages. A reference to the first LOB page is stored
52along with the clustered index record. This reference is called the LOB
53reference (lob::ref_t). A single clustered index record can have many LOB
54references. Secondary indexes cannot have LOB references.
55
56There are two types of LOB - compressed and uncompressed.
57
58The main operations implemented for LOB are - INSERT, DELETE and FETCH. To
59carry out these main operations the following classes are provided.
60
61Inserter - for inserting uncompressed LOB data.
62zInserter - for inserting compressed LOB data.
63BaseInserter - a base class containing common state and functions useful for
64 both Inserter and zInserter. Inserter and zInserter derives
65 from this base class.
66Reader - for reading uncompressed LOB data.
67zReader - for reading compressed LOB data.
68Deleter - for deleting both compressed and uncompressed LOB data.
69
70For each main operation, the context information is identified separately.
71They are as follows:
72
73InsertContext - context information for doing insert of LOB. `
74DeleteContext - context information for doing delete of LOB. `
75ReadContext - context information for doing fetch of LOB. `
76
77*/
78
79/** Provides the large objects (LOB) module. Previously, the LOB was called as
80externally stored fields. */
81namespace lob {
82
83/** The maximum size possible for an LOB */
85
86/** The compressed LOB is stored as a collection of zlib streams. The
87uncompressed LOB is divided into chunks of size Z_CHUNK_SIZE and each of
88these chunks are compressed individually and stored as compressed LOB.
89data. */
90constexpr uint32_t KB128 = 128 * 1024;
91constexpr uint32_t Z_CHUNK_SIZE = KB128;
92
93/** The reference in a field for which data is stored on a different page.
94The reference is at the end of the 'locally' stored part of the field.
95'Locally' means storage in the index record.
96We store locally a long enough prefix of each column so that we can determine
97the ordering parts of each index record without looking into the externally
98stored part. */
99/*-------------------------------------- @{ */
100
101/** Space identifier where stored. */
103
104/** page number where stored */
106
107/** offset of BLOB header on that page */
109
110/** Version number of LOB (LOB in new format)*/
112
113/** 8 bytes containing the length of the externally stored part of the LOB.
114The 2 highest bits are reserved to the flags below. */
116
117/*-------------------------------------- @} */
118
119/** The most significant bit of BTR_EXTERN_LEN (i.e., the most
120significant bit of the byte at smallest address) is set to 1 if this
121field does not 'own' the externally stored field; only the owner field
122is allowed to free the field in purge! */
124
125/** If the second most significant bit of BTR_EXTERN_LEN (i.e., the
126second most significant bit of the byte at smallest address) is 1 then
127it means that the externally stored field was inherited from an
128earlier version of the row. In rollback we are not allowed to free an
129inherited external field. */
131
132/** If the 3rd most significant bit of BTR_EXTERN_LEN is 1, then it
133means that the externally stored field is currently being modified.
134This is mainly used by the READ UNCOMMITTED transaction to avoid returning
135inconsistent blob data. */
137
138/** The structure of uncompressed LOB page header */
139
140/** Offset within header of LOB length on this page. */
142
143/** Offset within header of next BLOB part page no.
144FIL_NULL if none */
146
147/** Size of an uncompressed LOB page header, in bytes */
149
150/** Start of the data on an LOB page */
152
153/** In memory representation of the LOB reference. */
154struct ref_mem_t {
155 /** Space Identifier of the clustered index. */
157
158 /** Page number of first LOB page. */
160
161 /** Offset within m_page_no where LOB begins. */
163
164 /** Length of LOB */
166
167 /** Whether the LOB is null. */
168 bool m_null;
169
170 /** Whether the clustered index record owns this LOB. */
172
173 /** Whether the clustered index record inherited this LOB from
174 another clustered index record. */
176
177 /** Whether the LOB is partially updated. */
179
180 /** Whether the blob is being modified. */
182
183 /** Check if the LOB has already been purged.
184 @return true if LOB has been purged, false otherwise. */
185 bool is_purged() const {
186 return ((m_page_no == FIL_NULL) && (m_length == 0));
187 }
188};
189
190extern const byte field_ref_almost_zero[FIELD_REF_SIZE];
191
192/** The struct 'lob::ref_t' represents an external field reference. The
193reference in a field for which data is stored on a different page. The
194reference is at the end of the 'locally' stored part of the field. 'Locally'
195means storage in the index record. We store locally a long enough prefix of
196each column so that we can determine the ordering parts of each index record
197without looking into the externally stored part. */
198struct ref_t {
199 private:
200 /** If the LOB size is equal to or above this limit (in physical page
201 size terms), then the LOB is big enough to be partially updated. Only
202 in this case LOB index needs to be built. */
204
205 public:
206 /** If the total number of bytes modified in an LOB, in an update
207 operation, is less than or equal to this threshold LOB_SMALL_CHANGE_THRESHOLD,
208 then it is considered as a small change. For small changes to LOB,
209 the changes are undo logged like any other update operation. */
211
212 /** Constructor.
213 @param[in] ptr Pointer to the external field reference. */
214 explicit ref_t(byte *ptr) : m_ref(ptr) {}
215
216 /** For compressed LOB, if the length is less than or equal to Z_CHUNK_SIZE
217 then use the older single z stream format to store the LOB. */
218 bool use_single_z_stream() const { return (length() <= Z_CHUNK_SIZE); }
219
220 /** For compressed LOB, if the length is less than or equal to Z_CHUNK_SIZE
221 then use the older single z stream format to store the LOB. */
222 static bool use_single_z_stream(ulint len) { return (len <= Z_CHUNK_SIZE); }
223
224 /** Check if this LOB is big enough to do partial update.
225 @param[in] page_size the page size
226 @param[in] lob_length the size of BLOB in bytes.
227 @return true if LOB is big enough, false otherwise. */
228 static bool is_big(const page_size_t &page_size [[maybe_unused]],
229 const ulint lob_length [[maybe_unused]]) {
230 /* Disable a performance optimization */
231 return true;
232 }
233
234 /** Check if this LOB is big enough to do partial update.
235 @param[in] page_size the page size
236 @return true if LOB is big enough, false otherwise. */
237 bool is_big(const page_size_t &page_size [[maybe_unused]]) const {
238 /* Disable a performance optimization */
239 return true;
240 }
241
242 /** Parse the LOB reference object and copy data into the given
243 ref_mem_t object.
244 @param[out] obj LOB reference memory object. */
245 void parse(ref_mem_t &obj) const {
246 obj.m_space_id = space_id();
247 obj.m_page_no = page_no();
248 obj.m_offset = offset();
249 obj.m_length = length();
250 obj.m_null = is_null();
251 obj.m_owner = is_owner();
252 obj.m_inherit = is_inherited();
254 }
255
256 /** Copy the LOB reference into the given memory location.
257 @param[out] field_ref write LOB reference in this
258 location.*/
259 void copy(byte *field_ref) const { memcpy(field_ref, m_ref, SIZE); }
260
261 /** Check whether the stored external field reference is equal to the
262 given field reference.
263 @param[in] ptr supplied external field reference. */
264 bool is_equal(const byte *ptr) const { return (m_ref == ptr); }
265
266 /** Set the external field reference to the given memory location.
267 @param[in] ptr the new external field reference. */
268 void set_ref(byte *ptr) { m_ref = ptr; }
269
270 /** Check if the field reference is made of zeroes except the being_modified
271 bit.
272 @return true if field reference is made of zeroes, false otherwise. */
273 bool is_null_relaxed() const {
274 return (is_null() || memcmp(field_ref_almost_zero, m_ref, SIZE) == 0);
275 }
276
277 /** Check if the field reference is made of zeroes.
278 @return true if field reference is made of zeroes, false otherwise. */
279 bool is_null() const { return (memcmp(field_ref_zero, m_ref, SIZE) == 0); }
280
281 /** Initialize the reference object with zeroes. */
282 void init() { memset(m_ref, 0, SIZE); }
283
284#ifdef UNIV_DEBUG
285 /** Check if the LOB reference is null (all zeroes) except the "is being
286 modified" bit.
287 @param[in] ref the LOB reference.
288 @return true if the LOB reference is null (all zeros) except the "is being
289 modified" bit, false otherwise. */
290 static bool is_null_relaxed(const byte *ref) {
291 return (is_null(ref) || memcmp(field_ref_almost_zero, ref, SIZE) == 0);
292 }
293
294 /** Check if the LOB reference is null (all zeroes).
295 @param[in] ref the LOB reference.
296 @return true if the LOB reference is null (all zeros), false otherwise. */
297 static bool is_null(const byte *ref) {
298 return (memcmp(field_ref_zero, ref, SIZE) == 0);
299 }
300#endif /* UNIV_DEBUG */
301
302 /** Set the ownership flag in the blob reference.
303 @param[in] owner Whether to own or disown. If owner, unset
304 the owner flag.
305 @param[in] mtr Mini-transaction or NULL.*/
306 void set_owner(bool owner, mtr_t *mtr) {
308
309 if (owner) {
310 /* owns the blob */
311 byte_val &= ~BTR_EXTERN_OWNER_FLAG;
312 } else {
313 byte_val |= BTR_EXTERN_OWNER_FLAG;
314 }
315
317 }
318
319 /** Set the ownership flag in the blob reference.
320 @param[in] owner Whether to own or disown. If owner, unset
321 the owner flag. */
322 void set_owner(bool owner) {
324
325 if (owner) {
326 /* owns the blob */
327 byte_val &= ~BTR_EXTERN_OWNER_FLAG;
328 } else {
329 byte_val |= BTR_EXTERN_OWNER_FLAG;
330 }
331
333 }
334
335 /** Set the being_modified flag in the field reference.
336 @param[in,out] ref The LOB reference
337 @param[in] modifying true, if blob is being modified.
338 @param[in] mtr Mini-transaction context.*/
339 static void set_being_modified(byte *ref, bool modifying, mtr_t *mtr) {
341
342 if (modifying) {
344 } else {
345 byte_val &= ~BTR_EXTERN_BEING_MODIFIED_FLAG;
346 }
347
349 }
350
351 /** Set the being_modified flag in the field reference.
352 @param[in] modifying true, if blob is being modified.
353 @param[in] mtr Mini-transaction context.*/
354 void set_being_modified(bool modifying, mtr_t *mtr) {
355 set_being_modified(m_ref, modifying, mtr);
356 }
357
358 /** Check if the current blob is being modified
359 @param[in] field_ref blob field reference
360 @return true if it is being modified, false otherwise. */
361 bool static is_being_modified(const byte *field_ref) {
362 const ulint byte_val = mach_read_from_1(field_ref + BTR_EXTERN_LEN);
363 return (byte_val & BTR_EXTERN_BEING_MODIFIED_FLAG);
364 }
365
366 /** Check if the current blob is being modified
367 @return true if it is being modified, false otherwise. */
368 bool is_being_modified() const { return (is_being_modified(m_ref)); }
369
370 /** Set the inherited flag in the field reference.
371 @param[in] inherited true, if inherited.
372 @param[in] mtr Mini-transaction context.*/
373 void set_inherited(bool inherited, mtr_t *mtr) {
375
376 if (inherited) {
377 byte_val |= BTR_EXTERN_INHERITED_FLAG;
378 } else {
379 byte_val &= ~BTR_EXTERN_INHERITED_FLAG;
380 }
381
383 }
384
385 /** Check if the current row is the owner of the blob.
386 @return true if owner, false otherwise. */
387 bool is_owner() const {
389 return (!(byte_val & BTR_EXTERN_OWNER_FLAG));
390 }
391
392 /** Check if the current row inherited the blob from parent row.
393 @return true if inherited, false otherwise. */
394 bool is_inherited() const {
395 const ulint byte_val = mach_read_from_1(m_ref + BTR_EXTERN_LEN);
396 return (byte_val & BTR_EXTERN_INHERITED_FLAG);
397 }
398
399#ifdef UNIV_DEBUG
400 /** Read the space id from the given blob reference.
401 @param[in] ref the blob reference.
402 @return the space id */
403 static space_id_t space_id(const byte *ref) {
404 return (mach_read_from_4(ref));
405 }
406
407 /** Read the page no from the blob reference.
408 @return the page no */
409 static page_no_t page_no(const byte *ref) {
411 }
412#endif /* UNIV_DEBUG */
413
414 /** Read the space id from the blob reference.
415 @return the space id */
417
418 /** Read the page number from the blob reference.
419 @return the page number */
422 }
423
424 /** Read the offset of blob header from the blob reference.
425 @return the offset of the blob header */
427
428 /** Read the LOB version from the blob reference.
429 @return the LOB version number. */
430 uint32_t version() const {
432 }
433
434 /** Read the length from the blob reference.
435 @return length of the blob */
436 ulint length() const {
437 return (mach_read_from_4(m_ref + BTR_EXTERN_LEN + 4));
438 }
439
440 /** Update the information stored in the external field reference.
441 @param[in] space_id the space identifier.
442 @param[in] page_no the page number.
443 @param[in] offset the offset within the page_no
444 @param[in] mtr the mini trx or NULL. */
447 set_page_no(page_no, mtr);
448 set_offset(offset, mtr);
449 }
450
451 /** Set the space_id in the external field reference.
452 @param[in] space_id the space identifier.
453 @param[in] mtr mini-trx or NULL. */
456 }
457
458 /** Set the space_id in the external field reference.
459 @param[in] space_id the space identifier. */
462 }
463
464 /** Set the page number in the external field reference.
465 @param[in] page_no the page number.
466 @param[in] mtr mini-trx or NULL. */
467 void set_page_no(const ulint page_no, mtr_t *mtr) {
469 }
470
471 /** Set the page number in the external field reference.
472 @param[in] page_no the page number. */
475 }
476
477 /** Set the offset information in the external field reference.
478 @param[in] offset the offset.
479 @param[in] mtr mini-trx or NULL. */
480 void set_offset(const ulint offset, mtr_t *mtr) {
482 }
483
484 /** Set the version information in the external field reference.
485 @param[in] version the lob version. */
488 }
489
490 /** Set the length of blob in the external field reference.
491 @param[in] len the blob length .
492 @param[in] mtr mini-trx or NULL. */
493 void set_length(const ulint len, mtr_t *mtr) {
494 ut_ad(len <= MAX_SIZE);
496 }
497
498 /** Set the length of blob in the external field reference.
499 @param[in] len the blob length . */
500 void set_length(const ulint len) {
501 ut_ad(len <= MAX_SIZE);
503 }
504
505 /** Get the start of a page containing this blob reference.
506 @return start of the page */
507 page_t *page_align() const { return (::page_align(m_ref)); }
508
509#ifdef UNIV_DEBUG
510 /** Check if the given mtr has necessary latches to update this LOB
511 reference.
512 @param[in] mtr Mini-transaction that needs to
513 be checked.
514 @return true if valid, false otherwise. */
515 bool validate(mtr_t *mtr) {
516 ut_ad(m_ref != nullptr);
517 ut_ad(mtr != nullptr);
518
519 if (mtr->get_log_mode() == MTR_LOG_NO_REDO) {
520 return (true);
521 }
522
525 ut_ad(block != nullptr);
526 return (true);
527 }
528
529 /** Check if the space_id in the LOB reference is equal to the
530 space_id of the index to which it belongs.
531 @param[in] index the index to which LOB belongs.
532 @return true if space is valid in LOB reference, false otherwise. */
533 bool check_space_id(dict_index_t *index) const;
534#endif /* UNIV_DEBUG */
535
536 /** Check if the LOB can be partially updated. This is done by loading
537 the first page of LOB and looking at the flags.
538 @param[in] index the index to which LOB belongs.
539 @return true if LOB is partially updatable, false otherwise.*/
540 bool is_lob_partially_updatable(const dict_index_t *index) const;
541
542 /** Load the first page of the LOB and mark it as not partially
543 updatable anymore.
544 @param[in] trx Current transaction
545 @param[in] mtr Mini-transaction context.
546 @param[in] index Index dictionary object.
547 @param[in] page_size Page size information. */
549 const page_size_t &page_size);
550
551 /** Load the first page of LOB and read its page type.
552 @param[in] index the index object.
553 @param[in] page_size the page size of LOB.
554 @param[out] is_partially_updatable is the LOB partially updatable.
555 @return the page type of first page of LOB.*/
557 const page_size_t &page_size,
558 bool &is_partially_updatable) const;
559
560 /** Print this LOB reference into the given output stream.
561 @param[in] out the output stream.
562 @return the output stream. */
563 std::ostream &print(std::ostream &out) const;
564
565 /** The size of an LOB reference object (in bytes) */
566 static const uint SIZE = BTR_EXTERN_FIELD_REF_SIZE;
567
568 private:
569 /** Pointing to a memory of size BTR_EXTERN_FIELD_REF_SIZE */
570 byte *m_ref;
571};
572
573/** Overload the global output stream operator to easily print the
574lob::ref_t object into the output stream.
575@param[in,out] out the output stream.
576@param[in] obj the lob::ref_t object to be printed
577@return the output stream. */
578inline std::ostream &operator<<(std::ostream &out, const ref_t &obj) {
579 return (obj.print(out));
580}
581
582/** LOB operation code for btr_store_big_rec_extern_fields(). */
583enum opcode {
584
585 /** Store off-page columns for a freshly inserted record */
587
588 /** Store off-page columns for an insert by update */
590
591 /** Store off-page columns for an update */
593
594 /** Store off-page columns for a freshly inserted record by bulk */
596
597 /** The operation code is unknown or not important. */
600
601/** Stores the fields in big_rec_vec to the tablespace and puts pointers to
602them in rec. The extern flags in rec will have to be set beforehand. The
603fields are stored on pages allocated from leaf node file segment of the index
604tree.
605
606TODO: If the allocation extends the tablespace, it will not be redo logged, in
607any mini-transaction. Tablespace extension should be redo-logged, so that
608recovery will not fail when the big_rec was written to the extended portion of
609the file, in case the file was somehow truncated in the crash.
610@param[in] trx the trx doing LOB store. If unavailable it
611 could be nullptr.
612@param[in,out] pcur a persistent cursor. if btr_mtr is restarted,
613 then this can be repositioned.
614@param[in] upd update vector
615@param[in,out] offsets rec_get_offsets() on pcur. the "external in
616 offsets will correctly correspond storage"
617 flagsin offsets will correctly correspond to
618 rec when this function returns
619@param[in] big_rec_vec vector containing fields to be stored
620 externally
621@param[in,out] btr_mtr mtr containing the latches to the clustered
622 index. can be committed and restarted.
623@param[in] op operation code
624@return DB_SUCCESS or DB_OUT_OF_FILE_SPACE */
626 trx_t *trx, btr_pcur_t *pcur, const upd_t *upd, ulint *offsets,
627 const big_rec_t *big_rec_vec, mtr_t *btr_mtr, opcode op);
628
629/** Copies an externally stored field of a record to mem heap.
630@param[in] trx the current transaction.
631@param[in] index the clustered index
632@param[in] rec record in a clustered index; must be
633 protected by a lock or a page latch
634@param[in] offsets array returned by rec_get_offsets()
635@param[in] page_size BLOB page size
636@param[in] no field number
637@param[out] len length of the field
638@param[out] lob_version version of lob that has been copied
639@param[in] is_sdi true for SDI Indexes
640@param[in,out] heap mem heap
641@param[in] is_rebuilt true if rebuilt
642@return the field copied to heap, or NULL if the field is incomplete */
644 trx_t *trx, const dict_index_t *index, const rec_t *rec,
645 const ulint *offsets, const page_size_t &page_size, ulint no, ulint *len,
646 size_t *lob_version, IF_DEBUG(bool is_sdi, ) mem_heap_t *heap,
647 bool is_rebuilt);
648
650 trx_t *trx, const dict_index_t *index, const rec_t *rec,
651 const ulint *offsets, const page_size_t &page_size, ulint no, ulint *len,
652 size_t *ver, bool is_sdi [[maybe_unused]], mem_heap_t *heap) {
654 trx, index, rec, offsets, page_size, no, len, ver,
655 IF_DEBUG(is_sdi, ) heap, false);
656}
657
658/** Gets the offset of the pointer to the externally stored part of a field.
659@param[in] index Index
660@param[in] offsets array returned by rec_get_offsets()
661@param[in] n index of the external field
662@return offset of the pointer to the externally stored part */
664 const ulint *offsets, ulint n);
665
666/** Gets a pointer to the externally stored part of a field.
667@param[in] index index
668@param rec record
669@param offsets rec_get_offsets(rec)
670@param n index of the externally stored field
671@return pointer to the externally stored part */
672static inline const byte *btr_rec_get_field_ref(const dict_index_t *index,
673 const byte *rec,
674 const ulint *offsets, ulint n) {
675 return rec + lob::btr_rec_get_field_ref_offs(index, offsets, n);
676}
677
678/** Gets a pointer to the externally stored part of a field.
679@param index record descriptor
680@param rec record
681@param offsets rec_get_offsets(rec)
682@param n index of the externally stored field
683@return pointer to the externally stored part */
684static inline byte *btr_rec_get_field_ref(const dict_index_t *index, byte *rec,
685 const ulint *offsets, ulint n) {
686 return rec + lob::btr_rec_get_field_ref_offs(index, offsets, n);
687}
688
689/** Deallocate a buffer block that was reserved for a BLOB part.
690@param[in] index Index
691@param[in] block Buffer block
692@param[in] all true=remove also the compressed page
693 if there is one
694@param[in] mtr Mini-transaction to commit */
695void blob_free(dict_index_t *index, buf_block_t *block, bool all, mtr_t *mtr);
696
697/** The B-tree context under which the LOB operation is done. */
699 public:
700 /** Default Constructor */
702 : m_mtr(nullptr),
705 m_rec(nullptr),
710
711 /** Constructor **/
713 : m_mtr(mtr),
715 m_index(index),
716 m_rec(nullptr),
718 m_block(block),
721
722 /** Constructor **/
724 ulint *offsets, buf_block_t *block)
725 : m_mtr(mtr),
726 m_pcur(pcur),
727 m_index(index),
728 m_rec(rec),
729 m_offsets(offsets),
730 m_block(block),
733 ut_ad(m_pcur == nullptr || rec_offs_validate());
734 ut_ad(m_block == nullptr || m_rec == nullptr ||
736 ut_ad(m_pcur == nullptr || m_rec == m_pcur->get_rec());
737 }
738
739 /** Constructor **/
741 ulint *offsets, buf_block_t *block, opcode op)
742 : m_mtr(mtr),
743 m_pcur(pcur),
744 m_index(index),
745 m_rec(rec),
746 m_offsets(offsets),
747 m_block(block),
748 m_op(op),
750 ut_ad(m_pcur == nullptr || rec_offs_validate());
752 ut_ad(m_pcur == nullptr || m_rec == m_pcur->get_rec());
753 }
754
755 /** Copy Constructor **/
756 BtrContext(const BtrContext &other)
757 : m_mtr(other.m_mtr),
758 m_pcur(other.m_pcur),
759 m_index(other.m_index),
760 m_rec(other.m_rec),
761 m_offsets(other.m_offsets),
762 m_block(other.m_block),
763 m_op(other.m_op),
765
766 /** Marks non-updated off-page fields as disowned by this record.
767 The ownership must be transferred to the updated record which is
768 inserted elsewhere in the index tree. In purge only the owner of
769 externally stored field is allowed to free the field.
770 @param[in] update update vector. */
772
773 /** Sets the ownership bit of an externally stored field in a record.
774 @param[in] i field number
775 @param[in] val value to set */
777 byte *data;
778 ulint local_len;
779
780 data = const_cast<byte *>(
781 rec_get_nth_field(m_index, m_rec, m_offsets, i, &local_len));
783 ut_a(local_len >= BTR_EXTERN_FIELD_REF_SIZE);
784
785 local_len -= BTR_EXTERN_FIELD_REF_SIZE;
786
787 ref_t ref(data + local_len);
788
789 ut_a(val || ref.is_owner());
790
791 page_zip_des_t *page_zip = get_page_zip();
792
793 if (page_zip) {
794 ref.set_owner(val, nullptr);
796 } else {
797 ref.set_owner(val, m_mtr);
798 }
799 }
800
801 /** Marks all extern fields in a record as owned by the record.
802 This function should be called if the delete mark of a record is
803 removed: a not delete marked record always owns all its extern
804 fields.*/
807
809
811 return;
812 }
813
814 for (ulint i = 0; i < n; i++) {
817 }
818 }
819 }
820
821 /** Frees the externally stored fields for a record.
822 @param[in] trx_id transaction identifier whose LOB is
823 being freed.
824 @param[in] undo_no undo number within a transaction whose
825 LOB is being freed.
826 @param[in] rollback performing rollback?
827 @param[in] rec_type undo record type.
828 @param[in] node purge node or nullptr */
830 bool rollback, ulint rec_type,
831 purge_node_t *node);
832
833 /** Frees the externally stored fields for a record, if the field
834 is mentioned in the update vector.
835 @param[in] trx_id the transaction identifier.
836 @param[in] undo_no undo number within a transaction whose
837 LOB is being freed.
838 @param[in] update update vector
839 @param[in] rollback performing rollback?
840 @param[in] big_rec_vec big record vector */
841 void free_updated_extern_fields(trx_id_t trx_id, undo_no_t undo_no,
842 const upd_t *update, bool rollback,
843 big_rec_t *big_rec_vec);
844
845 /** Gets the compressed page descriptor
846 @return the compressed page descriptor. */
849 }
850
851 /** Get the page number of clustered index block.
852 @return the page number. */
855 }
856
857 /** Get the record offset within page of the clustered index record.
858 @return the record offset. */
859 ulint get_rec_offset() const { return (page_offset(m_rec)); }
860
861 /** Check if there is a need to recalculate the context information.
862 @return true if there is a need to recalculate, false otherwise. */
863 bool need_recalc() const {
864 return ((m_pcur != nullptr) && (m_rec != m_pcur->get_rec()));
865 }
866
867 /** Get the clustered index record pointer.
868 @return clustered index record pointer. */
869 rec_t *rec() const {
870 ut_ad(m_pcur == nullptr || m_rec == m_pcur->get_rec());
871 return (m_rec);
872 }
873
874 /** Get the LOB reference for the given field number.
875 @param[in] field_no field number.
876 @return LOB reference (aka external field reference).*/
877 byte *get_field_ref(ulint field_no) const {
878 return (btr_rec_get_field_ref(m_index, m_rec, get_offsets(), field_no));
879 }
880
881#ifdef UNIV_DEBUG
882 /** Validate the current BLOB context object. The BLOB context object
883 is valid if the necessary latches are being held by the
884 mini-transaction of the B-tree (btr mtr). Does not return if the
885 validation fails.
886 @return true if valid */
887 bool validate() const {
889
892 table()->is_intrinsic());
893
896 table()->is_intrinsic());
897
898 return (true);
899 }
900
901 /** Check to see if all pointers to externally stored columns in
902 the record must be valid.
903 @return true if all blob references are valid.
904 @return will not return if any blob reference is invalid. */
906 for (ulint i = 0; i < rec_offs_n_fields(m_offsets); i++) {
908 continue;
909 }
910
911 byte *field_ref = btr_rec_get_field_ref(m_index, rec(), m_offsets, i);
912
913 ref_t blobref(field_ref);
914
915 /* The pointer must not be zero if the operation
916 succeeded. */
917 ut_a(!blobref.is_null());
918
919 /* The column must not be disowned by this record. */
920 ut_a(blobref.is_owner());
921 }
922
923 return (true);
924 }
925#endif /* UNIV_DEBUG */
926
927 /** Determine whether current operation is a bulk insert operation.
928 @return true, if bulk insert operation, false otherwise. */
929 bool is_bulk() const { return (m_op == OPCODE_INSERT_BULK); }
930
931 /** Get the beginning of the B-tree clustered index page frame
932 that contains the current clustered index record (m_rec).
933 @return the page frame containing the clust rec. */
934 const page_t *rec_frame() const {
936 return (m_block->frame);
937 }
938
939 /** Commit the mini-transaction that is holding the latches
940 of the clustered index record block. */
942
943 /** Start the mini-transaction that will be holding the latches
944 of the clustered index record block. */
946 mtr_log_t log_mode = m_mtr->get_log_mode();
947 m_mtr->start();
948 m_mtr->set_log_mode(log_mode);
949 }
950
951 /** Get the page number of clustered index record.
952 @return page number of clustered index record. */
955 }
956
957#ifndef UNIV_HOTBACKUP
958
959 /** Increment the buffer fix count of the clustered index record block.
960 This is to be called before commit_btr_mtr() which decrements the count when
961 you want to prevent the block from being freed:
962 rec_block_fix(); // buf_fix_count++
963 commit_btr_mtr(); // releasing mtr internally does buf_fix_count--
964 start_btr_mtr();
965 rec_block_unfix(); // calls btr_block_get() which does buf_fix_count++ and
966 // then does buf_fix_count--
967 */
972 }
973
974 /** Decrement the buffer fix count of the clustered index record block,
975 X-latching it before, so that the overall buffer_fix_count doesn't change.
976 This is done to restore X-latch on the page after mtr restart:
977 rec_block_fix(); // buf_fix_count++
978 commit_btr_mtr(); // releasing mtr internally does buf_fix_count--
979 start_btr_mtr();
980 rec_block_unfix(); // calls btr_block_get() which does buf_fix_count++ and
981 // then does buf_fix_count--
982 */
984 space_id_t space_id = space();
985 page_id_t page_id(space_id, m_btr_page_no);
987 page_cur_t *page_cur = &m_pcur->m_btr_cur.page_cur;
988
990
991 page_cur->block = btr_block_get(page_id, page_size, RW_X_LATCH,
993
994 page_cur->rec = buf_block_get_frame(page_cur->block) + m_rec_offset;
995
996 buf_block_buf_fix_dec(page_cur->block);
997 /* This decrement above is paired with increment in rec_block_fix(), and
998 there is another increment done within btr_block_get(), so overall the block
999 should be buffer-fixed and thus safe to be used. */
1000 ut_ad(page_cur->block->page.buf_fix_count > 0);
1001 recalc();
1002 }
1003#endif /* !UNIV_HOTBACKUP */
1004
1005 /** Restore the position of the persistent cursor. */
1008 bool ret =
1010
1011 ut_a(ret);
1012
1013 recalc();
1014 }
1015
1016 /** Get the index object.
1017 @return index object */
1018 dict_index_t *index() const { return (m_index); }
1019
1020 /** Get the table object.
1021 @return table object or NULL. */
1023 dict_table_t *result = nullptr;
1024
1025 if (m_pcur != nullptr && m_pcur->index() != nullptr) {
1026 result = m_pcur->index()->table;
1027 }
1028
1029 return (result);
1030 }
1031
1032 /** Get the space id.
1033 @return space id. */
1034 space_id_t space() const { return (index()->space); }
1035
1036 /** Obtain the page size of the underlying table.
1037 @return page size of the underlying table. */
1038 const page_size_t page_size() const {
1039 return (dict_table_page_size(table()));
1040 }
1041
1042 /** Determine the extent size (in pages) for the underlying table
1043 @return extent size in pages */
1045 return (dict_table_extent_size(table()));
1046 }
1047
1048 /** Check if there is enough space in the redo log file. The btr
1049 mini-transaction will be restarted. */
1052 }
1053
1054 /** Mark the nth field as externally stored.
1055 @param[in] field_no the field number. */
1056 void make_nth_extern(ulint field_no) {
1058 }
1059
1060 /** Get the log mode of the btr mtr.
1061 @return the log mode. */
1063
1064 /** Get flush observer
1065 @return flush observer */
1067 return (m_mtr->get_flush_observer());
1068 }
1069
1070 /** Get the record offsets array.
1071 @return the record offsets array. */
1072 ulint *get_offsets() const { return (m_offsets); }
1073
1074 /** Validate the record offsets array.
1075 @return true if validation succeeds, false otherwise. */
1076 bool rec_offs_validate() const {
1077 if (m_rec != nullptr) {
1079 }
1080 return (true);
1081 }
1082
1083 /** Get the associated mini-transaction.
1084 @return the mini-transaction. */
1085 mtr_t *get_mtr() { return (m_mtr); }
1086
1087 /** Get the pointer to the clustered record block.
1088 @return pointer to the clustered rec block. */
1089 buf_block_t *block() const { return (m_block); }
1090
1091 /** Save the position of the persistent cursor. */
1093
1094 /** Check if there is enough space in log file. Commit and re-start the
1095 mini-transaction. */
1096 void check_redolog_normal();
1097
1098 /** When bulk load is being done, check if there is enough space in redo
1099 log file. */
1100 void check_redolog_bulk();
1101
1102 /** Recalculate some of the members after restoring the persistent
1103 cursor. */
1104 void recalc() {
1106 m_rec = m_pcur->get_rec();
1109
1111 }
1112
1113 /** Write a blob reference of a field into a clustered index record
1114 in a compressed leaf page. The information must already have been
1115 updated on the uncompressed page.
1116 @param[in] field_no BLOB field number
1117 @param[in] mtr Mini-transaction to update blob page. */
1118 void zblob_write_blobref(ulint field_no, mtr_t *mtr) {
1120 mtr);
1121 }
1122
1123 /** The btr mtr that is holding the latch on the B-tree index page
1124 containing the clustered index record.*/
1126
1127 /** Persistent cursor positioned on the clustered index record.*/
1134
1135 /** Record offset within the page. */
1137
1138 /** Page number where the clust rec is present. */
1140};
1141
1142/** The context for a LOB operation. It contains the necessary information
1143to carry out a LOB operation. */
1144struct InsertContext : public BtrContext {
1145 /** Constructor
1146 @param[in] btr_ctx b-tree context for lob operation.
1147 @param[in] big_rec_vec array of blobs */
1148 InsertContext(const BtrContext &btr_ctx, const big_rec_t *big_rec_vec)
1149 : BtrContext(btr_ctx), m_big_rec_vec(big_rec_vec) {}
1150
1151 /** Get the vector containing fields to be stored externally.
1152 @return the big record vector */
1154
1155 /** Get the size of vector containing fields to be stored externally.
1156 @return the big record vector size */
1158
1159 /** The B-tree Context */
1160 // const BtrContext m_btr_ctx;
1161
1162 /** vector containing fields to be stored externally */
1164};
1165
1166/** Information about data stored in one BLOB page. */
1168 /** Constructor.
1169 @param[in] page_no the BLOB page number.
1170 @param[in] bytes amount of uncompressed BLOB data
1171 in BLOB page in bytes.
1172 @param[in] zbytes amount of compressed BLOB data
1173 in BLOB page in bytes. */
1174 blob_page_info_t(page_no_t page_no, uint bytes, uint zbytes)
1175 : m_page_no(page_no), m_bytes(bytes), m_zbytes(zbytes) {}
1176
1177 /** Re-initialize the current object. */
1178 void reset() {
1179 m_page_no = 0;
1180 m_bytes = 0;
1181 m_zbytes = 0;
1182 }
1183
1184 /** Print this blob_page_into_t object into the given output stream.
1185 @param[in] out the output stream.
1186 @return the output stream. */
1187 std::ostream &print(std::ostream &out) const;
1188
1189 /** Set the compressed data size in bytes.
1190 @param[in] bytes the new compressed data size. */
1191 void set_compressed_size(uint bytes) { m_zbytes = bytes; }
1192
1193 /** Set the uncompressed data size in bytes.
1194 @param[in] bytes the new uncompressed data size. */
1195 void set_uncompressed_size(uint bytes) { m_bytes = bytes; }
1196
1197 /** Set the page number.
1198 @param[in] page_no the page number */
1199 void set_page_no(page_no_t page_no) { m_page_no = page_no; }
1200
1201 private:
1202 /** The BLOB page number */
1204
1205 /** Amount of uncompressed data (in bytes) in the BLOB page. */
1207
1208 /** Amount of compressed data (in bytes) in the BLOB page. */
1210};
1211
1212inline std::ostream &operator<<(std::ostream &out,
1213 const blob_page_info_t &obj) {
1214 return (obj.print(out));
1215}
1216
1217/** The in-memory blob directory. Each blob contains a sequence of pages.
1218This directory contains a list of those pages along with their metadata. */
1220 typedef std::vector<blob_page_info_t>::const_iterator const_iterator;
1221
1222 /** Print this blob directory into the given output stream.
1223 @param[in] out the output stream.
1224 @return the output stream. */
1225 std::ostream &print(std::ostream &out) const;
1226
1227 /** Clear the contents of this blob directory. */
1228 void clear() { m_pages.clear(); }
1229
1230 /** Append the given blob page information.
1231 @param[in] page the blob page information to be added.
1232 @return DB_SUCCESS on success, error code on failure. */
1234 m_pages.push_back(page);
1235 return (DB_SUCCESS);
1236 }
1237
1238 /** A vector of blob pages along with its metadata. */
1239 std::vector<blob_page_info_t> m_pages;
1240};
1241
1242/** Overloading the global output operator to print the blob_dir_t
1243object into an output stream.
1244@param[in,out] out the output stream.
1245@param[in] obj the object to be printed.
1246@return the output stream. */
1247inline std::ostream &operator<<(std::ostream &out, const blob_dir_t &obj) {
1248 return (obj.print(out));
1249}
1250
1251/** The context information for reading a single BLOB */
1253 /** Constructor
1254 @param[in] page_size page size information.
1255 @param[in] data 'internally' stored part of the field
1256 containing also the reference to the
1257 external part; must be protected by
1258 a lock or a page latch.
1259 @param[in] prefix_len length of BLOB data stored inline in
1260 the clustered index record, including
1261 the blob reference.
1262 @param[out] buf the output buffer.
1263 @param[in] len the output buffer length.
1264 @param[in] is_sdi true for SDI Indexes. */
1265 ReadContext(const page_size_t &page_size, const byte *data, ulint prefix_len,
1266 byte *buf, ulint len IF_DEBUG(, bool is_sdi))
1267 : m_page_size(page_size),
1268 m_data(data),
1269 m_local_len(prefix_len),
1270 m_blobref(const_cast<byte *>(data) + prefix_len -
1272 m_buf(buf),
1273 m_len(len),
1275 read_blobref();
1276 }
1277
1278 /** Read the space_id, page_no and offset information from the BLOB
1279 reference object and update the member variables. */
1284 }
1285
1286 /** Check if the BLOB reference is valid. For this particular check,
1287 if the length of the BLOB is greater than 0, it is considered
1288 valid.
1289 @return true if valid. */
1290 bool is_valid_blob() const { return (m_blobref.length() > 0); }
1291
1292 dict_index_t *index() { return (m_index); }
1293
1294 /** The page size information. */
1296
1297 /** The 'internally' stored part of the field containing also the
1298 reference to the external part; must be protected by a lock or a page
1299 latch */
1300 const byte *m_data;
1301
1302 /** Length (in bytes) of BLOB prefix stored inline in clustered
1303 index record. */
1305
1306 /** The blob reference of the blob that is being read. */
1308
1309 /** Buffer into which data is read. */
1310 byte *m_buf;
1311
1312 /** Length of the buffer m_buf. */
1314
1315 /** The identifier of the space in which blob is available. */
1317
1318 /** The page number obtained from the blob reference. */
1320
1321 /** The offset information obtained from the blob reference. */
1323
1325
1327
1328#ifdef UNIV_DEBUG
1329 /** Is it a space dictionary index (SDI)?
1330 @return true if SDI, false otherwise. */
1331 bool is_sdi() const { return (m_is_sdi); }
1332
1333 /** Is it a tablespace dictionary index (SDI)? */
1334 const bool m_is_sdi;
1335
1336 /** Assert that current trx is using isolation level read uncommitted.
1337 @return true if transaction is using read uncommitted, false otherwise. */
1338 bool assert_read_uncommitted() const;
1339#endif /* UNIV_DEBUG */
1340
1341 /** The transaction that is reading. */
1342 trx_t *m_trx = nullptr;
1343};
1344
1345/** Fetch compressed BLOB */
1346struct zReader {
1347 /** Constructor. */
1348 explicit zReader(const ReadContext &ctx) : m_rctx(ctx) {}
1349
1350 /** Fetch the BLOB.
1351 @return DB_SUCCESS on success. */
1352 dberr_t fetch();
1353
1354 /** Fetch one BLOB page.
1355 @return DB_SUCCESS on success. */
1357
1358 /** Get the length of data that has been read.
1359 @return the length of data that has been read. */
1360 ulint length() const { return (m_stream.total_out); }
1361
1362 private:
1363 /** Do setup of the zlib stream.
1364 @return code returned by zlib. */
1365 int setup_zstream();
1366
1367#ifdef UNIV_DEBUG
1368 /** Assert that the local prefix is empty. For compressed row format,
1369 there is no local prefix stored. This function doesn't return if the
1370 local prefix is non-empty.
1371 @return true if local prefix is empty*/
1373#endif /* UNIV_DEBUG */
1374
1376
1377 /** Bytes yet to be read. */
1379
1380 /** The zlib stream used to uncompress while fetching blob. */
1381 z_stream m_stream;
1382
1383 /** The memory heap that will be used by zlib allocator. */
1385
1386 /* There is no latch on m_bpage directly. Instead,
1387 m_bpage is protected by the B-tree page latch that
1388 is being held on the clustered index record, or,
1389 in row_merge_copy_blobs(), by an exclusive table lock. */
1391
1392#ifdef UNIV_DEBUG
1393 /** The expected page type. */
1395#endif /* UNIV_DEBUG */
1396};
1397
1398/** Fetch uncompressed BLOB */
1399struct Reader {
1400 /** Constructor. */
1402 : m_rctx(ctx), m_cur_block(nullptr), m_copied_len(0) {}
1403
1404 /** Fetch the complete or prefix of the uncompressed LOB data.
1405 @return bytes of LOB data fetched. */
1406 ulint fetch();
1407
1408 /** Fetch one BLOB page. */
1409 void fetch_page();
1410
1412
1413 /** Buffer block of the current BLOB page */
1415
1416 /** Total bytes of LOB data that has been copied from multiple
1417 LOB pages. This is a cumulative value. When this value reaches
1418 m_rctx.m_len, then the read operation is completed. */
1420};
1421
1422/** The context information when the delete operation on LOB is
1423taking place. */
1424struct DeleteContext : public BtrContext {
1425 /** Constructor.
1426 @param[in] btr the B-tree context of the blob operation.
1427 @param[in] field_ref reference to a blob
1428 @param[in] field_no field containing the blob.
1429 @param[in] rollback true if it is rollback, false if it is purge. */
1430 DeleteContext(const BtrContext &btr, byte *field_ref, ulint field_no,
1431 bool rollback);
1432
1433 /** Constructor.
1434 @param[in] btr the B-tree context of the blob operation.
1435 @param[in] rollback true if it is rollback, false if it is purge. */
1436 DeleteContext(const BtrContext &btr, bool rollback);
1437
1438 /** Update the delete context to point to a different blob.
1439 @param[in] field_ref blob reference
1440 @param[in] field_no the field that contains the blob. */
1441 void set_blob(byte *field_ref, ulint field_no);
1442
1443 /** Check if the blob reference is valid.
1444 @return true if valid, false otherwise. */
1445 bool is_ref_valid() const {
1447 }
1448
1449 /** Determine if it is compressed page format.
1450 @return true if compressed. */
1451 bool is_compressed() const { return (m_page_size.is_compressed()); }
1452
1453 /** Check if tablespace supports atomic blobs.
1454 @return true if tablespace has atomic blobs. */
1455 bool has_atomic_blobs() const {
1456 space_id_t space_id = m_blobref.space_id();
1457 uint32_t flags = fil_space_get_flags(space_id);
1459 }
1460
1461 bool is_delete_marked() const {
1462 rec_t *clust_rec = rec();
1463 if (clust_rec == nullptr) {
1464 return (true);
1465 }
1466 return (rec_get_deleted_flag(clust_rec, page_rec_is_comp(clust_rec)));
1467 }
1468
1469#ifdef UNIV_DEBUG
1470 /** Validate the LOB reference object.
1471 @return true if valid, false otherwise. */
1472 bool validate_blobref() const {
1473 rec_t *clust_rec = rec();
1474 if (clust_rec != nullptr) {
1475 const byte *v2 =
1477
1479 }
1480 return (true);
1481 }
1482#endif /* UNIV_DEBUG */
1483
1484 /** Acquire an x-latch on the index page containing the clustered
1485 index record, in the given mini-transaction context.
1486 @param[in] mtr Mini-transaction context. */
1487 void x_latch_rec_page(mtr_t *mtr);
1488
1489 /** the BLOB reference or external field reference. */
1491
1492 /** field number of externally stored column; ignored if rec == NULL */
1494
1495 /** Is this operation part of rollback? */
1497
1498 /** The page size of the tablespace.*/
1500
1501 /** Add a buffer block that is to be freed.
1502 @param[in] block buffer block to be freed.*/
1504
1505 /** Free all the stored lob blocks. */
1506 void free_lob_blocks();
1507
1508 /** Destructor. Just add some asserts to ensure that resources are freed. */
1510
1511 private:
1512 /** Memory copy of the original LOB reference. */
1514
1515 using Block_vector = std::vector<buf_block_t *, ut::allocator<buf_block_t *>>;
1516
1517 /** The buffer blocks of lob to be freed. */
1519
1520 /** Obtain the page size from the tablespace flags.
1521 @return the page size. */
1522 page_size_t get_page_size() const;
1523};
1524
1526 : DeleteContext(btr, nullptr, 0, rollback) {}
1527
1528inline DeleteContext::DeleteContext(const BtrContext &btr, byte *field_ref,
1529 ulint field_no, bool rollback)
1530 : BtrContext(btr),
1531 m_blobref(field_ref),
1532 m_field_no(field_no),
1533 m_rollback(rollback),
1534 m_page_size(table() == nullptr ? get_page_size()
1536 if (field_ref != nullptr) {
1538 }
1539}
1540
1541inline void DeleteContext::set_blob(byte *field_ref, ulint field_no) {
1542 m_blobref.set_ref(field_ref);
1543 m_field_no = field_no;
1544 if (field_ref != nullptr) {
1546 }
1547}
1548
1550 bool found;
1551 space_id_t space_id = m_blobref.space_id();
1552 const page_size_t &tmp = fil_space_get_page_size(space_id, &found);
1553 ut_ad(found);
1554 return tmp;
1555}
1556
1558
1561 m_lob_blocks.push_back(block);
1562}
1563
1565 for (auto block_ptr : m_lob_blocks) {
1568 }
1569 m_lob_blocks.clear();
1570}
1571
1572/** Determine if an operation on off-page columns is an update.
1573@param[in] op type of BLOB operation.
1574@return true if op != OPCODE_INSERT */
1576 switch (op) {
1577 case OPCODE_INSERT:
1578 case OPCODE_INSERT_BULK:
1579 return (false);
1581 case OPCODE_UPDATE:
1582 return (true);
1583 case OPCODE_UNKNOWN:
1584 break;
1585 }
1586
1587 ut_d(ut_error);
1588 ut_o(return false);
1589}
1590
1591/** Copies the prefix of an externally stored field of a record.
1592The clustered index record must be protected by a lock or a page latch.
1593@param[in] trx the current transaction object if available
1594or nullptr.
1595@param[in] index the clust index in which lob is read.
1596@param[out] buf the field, or a prefix of it
1597@param[in] len length of buf, in bytes
1598@param[in] page_size BLOB page size
1599@param[in] data 'internally' stored part of the field
1600 containing also the reference to the external
1601 part; must be protected by a lock or a page
1602 latch.
1603@param[in] is_sdi true for SDI indexes
1604@param[in] local_len length of data, in bytes
1605@return the length of the copied field, or 0 if the column was being
1606or has been deleted */
1608 trx_t *trx, const dict_index_t *index, byte *buf, ulint len,
1609 const page_size_t &page_size, const byte *data,
1610 IF_DEBUG(bool is_sdi, ) ulint local_len);
1611
1612/** Copies an externally stored field of a record to mem heap.
1613The clustered index record must be protected by a lock or a page latch.
1614@param[in] trx the current trx object or nullptr
1615@param[in] index the clust index in which lob is read.
1616@param[out] len length of the whole field
1617@param[out] lob_version LOB version number.
1618@param[in] data 'internally' stored part of the field
1619 containing also the reference to the external
1620 part; must be protected by a lock or a page
1621 latch.
1622@param[in] page_size BLOB page size
1623@param[in] local_len length of data
1624@param[in] is_sdi true for SDI Indexes
1625@param[in,out] heap mem heap
1626@return the whole field copied to heap */
1628 trx_t *trx, const dict_index_t *index, ulint *len, size_t *lob_version,
1629 const byte *data, const page_size_t &page_size, ulint local_len,
1630 IF_DEBUG(bool is_sdi, ) mem_heap_t *heap);
1631
1633 trx_t *trx, const dict_index_t *index, byte *buf, ulint len,
1634 const page_size_t &page_size, const byte *data, bool is_sdi,
1635 ulint local_len) {
1637 trx, index, buf, len, page_size, data, IF_DEBUG(is_sdi, ) local_len);
1638}
1640 trx_t *trx, const dict_index_t *index, ulint *len, size_t *ver,
1641 const byte *data, const page_size_t &page_size, ulint local_len,
1642 bool is_sdi, mem_heap_t *heap) {
1643 return btr_copy_externally_stored_field_func(trx, index, len, ver, data,
1644 page_size, local_len,
1645 IF_DEBUG(is_sdi, ) heap);
1646}
1647
1648/** Gets the externally stored size of a record, in units of a database page.
1649@param[in] index index
1650@param[in] rec record
1651@param[in] offsets array returned by rec_get_offsets()
1652@return externally stored part, in units of a database page */
1654 const rec_t *rec, const ulint *offsets);
1655
1656/** Purge an LOB (either of compressed or uncompressed).
1657@param[in] ctx the delete operation context information.
1658@param[in] index clustered index in which LOB is present
1659@param[in] trxid the transaction that is being purged.
1660@param[in] undo_no during rollback to savepoint, purge only up to
1661 this undo number.
1662@param[in] rec_type undo record type.
1663@param[in] uf the update vector for the field.
1664@param[in] node the purge node or nullptr. */
1665void purge(lob::DeleteContext *ctx, dict_index_t *index, trx_id_t trxid,
1666 undo_no_t undo_no, ulint rec_type, const upd_field_t *uf,
1667 purge_node_t *node);
1668
1669/** Update a portion of the given LOB.
1670@param[in] ctx update operation context information.
1671@param[in] trx the transaction that is doing the
1672modification.
1673@param[in] index the clustered index containing the LOB.
1674@param[in] upd update vector
1675@param[in] field_no the LOB field number
1676@param[in] blobref LOB reference stored in clust record.
1677@return DB_SUCCESS on success, error code on failure. */
1678dberr_t update(InsertContext &ctx, trx_t *trx, dict_index_t *index,
1679 const upd_t *upd, ulint field_no, ref_t blobref);
1680
1681/** Update a portion of the given LOB.
1682@param[in] ctx update operation context information.
1683@param[in] trx the transaction that is doing the
1684modification.
1685@param[in] index the clustered index containing the LOB.
1686@param[in] upd update vector
1687@param[in] field_no the LOB field number
1688@param[in] blobref LOB reference stored in clust record.
1689@return DB_SUCCESS on success, error code on failure. */
1690dberr_t z_update(InsertContext &ctx, trx_t *trx, dict_index_t *index,
1691 const upd_t *upd, ulint field_no, ref_t blobref);
1692
1693/** Print information about the given LOB.
1694@param[in] trx the current transaction.
1695@param[in] index the clust index that contains the LOB.
1696@param[in] out the output stream into which LOB info is printed.
1697@param[in] ref the LOB reference
1698@param[in] fatal if true assert at end of function. */
1699void print(trx_t *trx, dict_index_t *index, std::ostream &out, ref_t ref,
1700 bool fatal);
1701
1702/** Import the given LOB. Update the creator trx id and the modifier trx
1703id to the given import trx id.
1704@param[in] index clustered index containing the lob.
1705@param[in] field_ref the lob reference.
1706@param[in] trx_id the import trx id. */
1707void z_import(const dict_index_t *index, byte *field_ref, trx_id_t trx_id);
1708
1709/** Import the given LOB. Update the creator trx id and the modifier trx
1710id to the given import trx id.
1711@param[in] index clustered index containing the lob.
1712@param[in] field_ref the lob reference.
1713@param[in] trx_id the import trx id. */
1714void import(const dict_index_t *index, byte *field_ref, trx_id_t trx_id);
1715
1716#ifdef UNIV_DEBUG
1717/** Check if all the LOB references in the given clustered index record has
1718valid space_id in it.
1719@param[in] index the index to which the LOB belongs.
1720@param[in] rec the clust_rec in which the LOB references are checked.
1721@param[in] offsets the field offsets of the given rec.
1722@return true if LOB references have valid space_id, false otherwise. */
1723bool rec_check_lobref_space_id(dict_index_t *index, const rec_t *rec,
1724 const ulint *offsets);
1725#endif /* UNIV_DEBUG */
1726
1727/** Mark an LOB that it is not partially updatable anymore.
1728@param[in] trx Current transaction.
1729@param[in] index Clustered index to which the LOB belongs.
1730@param[in] update Update vector.
1731@param[in] btr_mtr Mini-transaction context holding latches on the B-tree.
1732This function does not generate redo log using this btr_mtr. It only obtains
1733the log mode.
1734@return DB_SUCCESS on success, error code on failure. */
1736 const upd_t *update, const mtr_t *btr_mtr);
1737
1738} // namespace lob
1739
1740#endif /* lob0lob_h */
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:47
uint32_t page_no_t
Page number.
Definition: api0api.h:45
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:251
void btr_page_free_low(dict_index_t *index, buf_block_t *block, ulint level, mtr_t *mtr)
Frees a file page used in an index tree.
Definition: btr0btr.cc:554
static buf_block_t * btr_block_get(const page_id_t &page_id, const page_size_t &page_size, ulint mode, ut::Location location, const dict_index_t *index, mtr_t *mtr)
Gets a buffer page and declares its latching order level.
Definition: btr0btr.h:202
The index tree persistent cursor.
@ BTR_PCUR_ON
Definition: btr0pcur.h:53
constexpr uint32_t BTR_EXTERN_FIELD_REF_SIZE
The size of a reference to data stored on a different page.
Definition: btr0types.h:66
static buf_frame_t * buf_block_get_frame(const buf_block_t *block)
Gets a pointer to the memory frame of a block.
page_zip_des_t * buf_block_get_page_zip(buf_block_t *block) noexcept
Gets the compressed page descriptor corresponding to an uncompressed page if applicable.
Definition: buf0buf.h:2762
void buf_block_buf_fix_inc(buf_block_t *b, ut::Location l)
Increments the bufferfix count.
Definition: buf0buf.h:603
static void buf_block_buf_fix_dec(buf_block_t *block)
Decrements the bufferfix count.
Definition: buf0buf.ic:805
We use Flush_observer to track flushing of non-redo logged pages in bulk create index(btr0load....
Definition: buf0flu.h:274
Definition: buf0buf.h:1153
buf_fix_count_atomic_t buf_fix_count
Count of how many fold this block is currently bufferfixed.
Definition: buf0buf.h:1382
The B-tree context under which the LOB operation is done.
Definition: lob0lob.h:698
void set_ownership_of_extern_field(ulint i, bool val)
Sets the ownership bit of an externally stored field in a record.
Definition: lob0lob.h:776
void start_btr_mtr()
Start the mini-transaction that will be holding the latches of the clustered index record block.
Definition: lob0lob.h:945
void unmark_extern_fields()
Marks all extern fields in a record as owned by the record.
Definition: lob0lob.h:805
mtr_t * get_mtr()
Get the associated mini-transaction.
Definition: lob0lob.h:1085
buf_block_t * block() const
Get the pointer to the clustered record block.
Definition: lob0lob.h:1089
void check_redolog_normal()
Check if there is enough space in log file.
Definition: lob0lob.cc:120
void make_nth_extern(ulint field_no)
Mark the nth field as externally stored.
Definition: lob0lob.h:1056
const page_t * rec_frame() const
Get the beginning of the B-tree clustered index page frame that contains the current clustered index ...
Definition: lob0lob.h:934
BtrContext(const BtrContext &other)
Copy Constructor.
Definition: lob0lob.h:756
void zblob_write_blobref(ulint field_no, mtr_t *mtr)
Write a blob reference of a field into a clustered index record in a compressed leaf page.
Definition: lob0lob.h:1118
void recalc()
Recalculate some of the members after restoring the persistent cursor.
Definition: lob0lob.h:1104
void store_position()
Save the position of the persistent cursor.
Definition: lob0lob.h:1092
mtr_t * m_mtr
The btr mtr that is holding the latch on the B-tree index page containing the clustered index record.
Definition: lob0lob.h:1125
bool are_all_blobrefs_valid() const
Check to see if all pointers to externally stored columns in the record must be valid.
Definition: lob0lob.h:905
void restore_position()
Restore the position of the persistent cursor.
Definition: lob0lob.h:1006
BtrContext(mtr_t *mtr, btr_pcur_t *pcur, dict_index_t *index, rec_t *rec, ulint *offsets, buf_block_t *block, opcode op)
Constructor.
Definition: lob0lob.h:740
mtr_log_t get_log_mode()
Get the log mode of the btr mtr.
Definition: lob0lob.h:1062
dict_table_t * table() const
Get the table object.
Definition: lob0lob.h:1022
ulint get_rec_offset() const
Get the record offset within page of the clustered index record.
Definition: lob0lob.h:859
opcode m_op
Definition: lob0lob.h:1133
space_id_t space() const
Get the space id.
Definition: lob0lob.h:1034
page_no_t get_btr_page_no() const
Get the page number of clustered index record.
Definition: lob0lob.h:953
Flush_observer * get_flush_observer() const
Get flush observer.
Definition: lob0lob.h:1066
page_no_t get_page_no() const
Get the page number of clustered index block.
Definition: lob0lob.h:853
buf_block_t * m_block
Definition: lob0lob.h:1132
rec_t * rec() const
Get the clustered index record pointer.
Definition: lob0lob.h:869
void free_updated_extern_fields(trx_id_t trx_id, undo_no_t undo_no, const upd_t *update, bool rollback, big_rec_t *big_rec_vec)
Frees the externally stored fields for a record, if the field is mentioned in the update vector.
Definition: lob0lob.cc:962
void check_redolog()
Check if there is enough space in the redo log file.
Definition: lob0lob.h:1050
page_no_t pages_in_extent() const
Determine the extent size (in pages) for the underlying table.
Definition: lob0lob.h:1044
void disown_inherited_fields(const upd_t *update)
Marks non-updated off-page fields as disowned by this record.
Definition: lob0lob.cc:82
void commit_btr_mtr()
Commit the mini-transaction that is holding the latches of the clustered index record block.
Definition: lob0lob.h:941
ulint m_rec_offset
Record offset within the page.
Definition: lob0lob.h:1136
void check_redolog_bulk()
When bulk load is being done, check if there is enough space in redo log file.
Definition: lob0lob.cc:98
ulint * m_offsets
Definition: lob0lob.h:1131
dict_index_t * m_index
Definition: lob0lob.h:1129
rec_t * m_rec
Definition: lob0lob.h:1130
BtrContext(mtr_t *mtr, dict_index_t *index, buf_block_t *block)
Constructor.
Definition: lob0lob.h:712
page_no_t m_btr_page_no
Page number where the clust rec is present.
Definition: lob0lob.h:1139
void free_externally_stored_fields(trx_id_t trx_id, undo_no_t undo_no, bool rollback, ulint rec_type, purge_node_t *node)
Frees the externally stored fields for a record.
Definition: lob0lob.cc:1103
ulint * get_offsets() const
Get the record offsets array.
Definition: lob0lob.h:1072
BtrContext()
Default Constructor.
Definition: lob0lob.h:701
void rec_block_fix()
Increment the buffer fix count of the clustered index record block.
Definition: lob0lob.h:968
byte * get_field_ref(ulint field_no) const
Get the LOB reference for the given field number.
Definition: lob0lob.h:877
BtrContext(mtr_t *mtr, btr_pcur_t *pcur, dict_index_t *index, rec_t *rec, ulint *offsets, buf_block_t *block)
Constructor.
Definition: lob0lob.h:723
bool need_recalc() const
Check if there is a need to recalculate the context information.
Definition: lob0lob.h:863
btr_pcur_t * m_pcur
Persistent cursor positioned on the clustered index record.
Definition: lob0lob.h:1128
bool validate() const
Validate the current BLOB context object.
Definition: lob0lob.h:887
void rec_block_unfix()
Decrement the buffer fix count of the clustered index record block, X-latching it before,...
Definition: lob0lob.h:983
bool is_bulk() const
Determine whether current operation is a bulk insert operation.
Definition: lob0lob.h:929
dict_index_t * index() const
Get the index object.
Definition: lob0lob.h:1018
bool rec_offs_validate() const
Validate the record offsets array.
Definition: lob0lob.h:1076
const page_size_t page_size() const
Obtain the page size of the underlying table.
Definition: lob0lob.h:1038
page_zip_des_t * get_page_zip() const
Gets the compressed page descriptor.
Definition: lob0lob.h:847
Page identifier.
Definition: buf0types.h:207
Page size descriptor.
Definition: page0size.h:50
bool is_compressed() const
Check whether the page is compressed on disk.
Definition: page0size.h:158
int page
Definition: ctype-mb.cc:1224
dberr_t
Definition: db0err.h:39
@ DB_SUCCESS
Definition: db0err.h:43
page_no_t dict_table_extent_size(const dict_table_t *table)
Determine the extent size (in pages) for the given table.
Definition: dict0dict.cc:5025
static const page_size_t dict_table_page_size(const dict_table_t *table)
Get the table page size.
static rw_lock_t * dict_index_get_lock(dict_index_t *index)
Gets the read-write lock of the index tree.
Data dictionary memory object creation.
uint32_t DICT_TF_HAS_ATOMIC_BLOBS(uint32_t flags)
Return the value of the ATOMIC_BLOBS field.
Definition: dict0mem.h:238
uint32_t fil_space_get_flags(space_id_t space_id)
Returns the flags of the space.
Definition: fil0fil.cc:3491
const page_size_t fil_space_get_page_size(space_id_t space_id, bool *found)
Returns the page size of the space and whether it is compressed or not.
Definition: fil0fil.cc:3558
constexpr page_no_t FIL_NULL
'null' (undefined) page offset in the context of file spaces
Definition: fil0fil.h:1156
constexpr uint32_t FIL_PAGE_DATA
start of the data on the page
Definition: fil0types.h:111
static int flags[50]
Definition: hp_test1.cc:40
#define UINT32_MAX
Definition: lexyy.cc:86
unsigned char byte
Blob class.
Definition: common.h:151
std::map< page_no_t, buf_block_t * > BlockCache
Definition: lob0lob.h:42
static uint32_t mach_read_from_4(const byte *b)
The following function is used to fetch data from 4 consecutive bytes.
static uint8_t mach_read_from_1(const byte *b)
The following function is used to fetch data from one byte.
static void mach_write_ulint(byte *ptr, ulint val, mlog_id_t type)
Writes 1, 2 or 4 bytes to a file page.
Definition: mach0data.h:292
void mlog_write_ulint(byte *ptr, ulint val, mlog_id_t type, mtr_t *mtr)
Writes 1, 2 or 4 bytes to a file page.
Definition: mtr0log.cc:258
#define mtr_memo_contains_flagged(m, p, l)
Definition: mtr0mtr.h:137
#define mtr_x_lock(l, m, loc)
Lock an rw-lock in x-mode.
Definition: mtr0mtr.h:129
@ MLOG_4BYTES
4 bytes ...
Definition: mtr0types.h:76
@ MLOG_1BYTE
one byte is written
Definition: mtr0types.h:70
mtr_log_t
Logging modes for a mini-transaction.
Definition: mtr0types.h:42
@ MTR_LOG_NO_REDO
Don't generate REDO log but add dirty pages to flush list.
Definition: mtr0types.h:50
@ MTR_MEMO_X_LOCK
Definition: mtr0types.h:285
@ MTR_MEMO_PAGE_X_FIX
Definition: mtr0types.h:273
@ MTR_MEMO_SX_LOCK
Definition: mtr0types.h:287
@ MTR_MEMO_PAGE_SX_FIX
Definition: mtr0types.h:275
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
Definition: buf0block_hint.cc:30
PT & ref(PT *tp)
Definition: tablespace_impl.cc:359
Provides the large objects (LOB) module.
Definition: lob0bulk.h:44
const ulint BTR_EXTERN_OWNER_FLAG
The most significant bit of BTR_EXTERN_LEN (i.e., the most significant bit of the byte at smallest ad...
Definition: lob0lob.h:123
const ulint BTR_EXTERN_SPACE_ID
The reference in a field for which data is stored on a different page.
Definition: lob0lob.h:102
const ulint BTR_EXTERN_PAGE_NO
page number where stored
Definition: lob0lob.h:105
const ulint BTR_EXTERN_BEING_MODIFIED_FLAG
If the 3rd most significant bit of BTR_EXTERN_LEN is 1, then it means that the externally stored fiel...
Definition: lob0lob.h:136
static void rollback(DeleteContext *ctx, dict_index_t *index, trx_id_t trxid, undo_no_t undo_no, ulint rec_type, const upd_field_t *uf)
Rollback modification of a uncompressed LOB.
Definition: lob0purge.cc:65
byte * btr_copy_externally_stored_field_func(trx_t *trx, const dict_index_t *index, ulint *len, size_t *lob_version, const byte *data, const page_size_t &page_size, ulint local_len, bool is_sdi, mem_heap_t *heap)
Copies an externally stored field of a record to mem heap.
Definition: lob0lob.cc:882
const ulint LOB_HDR_SIZE
Size of an uncompressed LOB page header, in bytes.
Definition: lob0lob.h:148
const ulint BTR_EXTERN_LEN
8 bytes containing the length of the externally stored part of the LOB.
Definition: lob0lob.h:115
bool rec_check_lobref_space_id(dict_index_t *index, const rec_t *rec, const ulint *offsets)
Check if all the LOB references in the given clustered index record has valid space_id in it.
Definition: lob0lob.cc:1277
dberr_t z_update(trx_t *trx, dict_index_t *index, const upd_t *upd, ulint field_no)
Update a portion of the given LOB.
static byte * btr_copy_externally_stored_field(trx_t *trx, const dict_index_t *index, ulint *len, size_t *ver, const byte *data, const page_size_t &page_size, ulint local_len, bool is_sdi, mem_heap_t *heap)
Definition: lob0lob.h:1639
dberr_t mark_not_partially_updatable(trx_t *trx, dict_index_t *index, const upd_t *update, const mtr_t *btr_mtr)
Mark an LOB that it is not partially updatable anymore.
Definition: lob0lob.cc:1317
const ulint BTR_EXTERN_VERSION
Version number of LOB (LOB in new format)
Definition: lob0lob.h:111
const ulint MAX_SIZE
The maximum size possible for an LOB.
Definition: lob0lob.h:84
opcode
LOB operation code for btr_store_big_rec_extern_fields().
Definition: lob0lob.h:583
@ OPCODE_UPDATE
Store off-page columns for an update.
Definition: lob0lob.h:592
@ OPCODE_INSERT
Store off-page columns for a freshly inserted record.
Definition: lob0lob.h:586
@ OPCODE_INSERT_UPDATE
Store off-page columns for an insert by update.
Definition: lob0lob.h:589
@ OPCODE_UNKNOWN
The operation code is unknown or not important.
Definition: lob0lob.h:598
@ OPCODE_INSERT_BULK
Store off-page columns for a freshly inserted record by bulk.
Definition: lob0lob.h:595
void z_import(const dict_index_t *index, byte *field_ref, trx_id_t trx_id)
Import the given LOB.
void print(trx_t *trx, dict_index_t *index, std::ostream &out, ref_t ref, bool fatal)
Print information about the given LOB.
Definition: lob0impl.cc:1333
const ulint LOB_HDR_NEXT_PAGE_NO
Offset within header of next BLOB part page no.
Definition: lob0lob.h:145
void purge(lob::DeleteContext *ctx, dict_index_t *index, trx_id_t trxid, undo_no_t undo_no, ulint rec_type, const upd_field_t *uf, purge_node_t *node)
Purge an LOB (either of compressed or uncompressed).
Definition: lob0purge.cc:414
static byte * btr_rec_copy_externally_stored_field(trx_t *trx, const dict_index_t *index, const rec_t *rec, const ulint *offsets, const page_size_t &page_size, ulint no, ulint *len, size_t *ver, bool is_sdi, mem_heap_t *heap)
Definition: lob0lob.h:649
dberr_t update(trx_t *trx, dict_index_t *index, const upd_t *upd, ulint field_no)
Update a portion of the given LOB.
const ulint BTR_EXTERN_INHERITED_FLAG
If the second most significant bit of BTR_EXTERN_LEN (i.e., the second most significant bit of the by...
Definition: lob0lob.h:130
static const byte * btr_rec_get_field_ref(const dict_index_t *index, const byte *rec, const ulint *offsets, ulint n)
Gets a pointer to the externally stored part of a field.
Definition: lob0lob.h:672
ulint btr_rec_get_externally_stored_len(const dict_index_t *index, const rec_t *rec, const ulint *offsets)
Gets the externally stored size of a record, in units of a database page.
Definition: lob0lob.cc:1068
byte * btr_rec_copy_externally_stored_field_func(trx_t *trx, const dict_index_t *index, const rec_t *rec, const ulint *offsets, const page_size_t &page_size, ulint no, ulint *len, size_t *lob_version, bool is_sdi, mem_heap_t *heap, bool is_rebuilt)
Copies an externally stored field of a record to mem heap.
Definition: lob0lob.cc:642
constexpr uint32_t Z_CHUNK_SIZE
Definition: lob0lob.h:91
const byte field_ref_almost_zero[FIELD_REF_SIZE]
A BLOB field reference has all the bits set to zero, except the "being modified" bit.
Definition: lob0lob.cc:53
const uint ZLOB_PAGE_DATA
Start of the data on an LOB page.
Definition: lob0lob.h:151
void blob_free(dict_index_t *index, buf_block_t *block, bool all, mtr_t *mtr)
Deallocate a buffer block that was reserved for a BLOB part.
Definition: lob0lob.cc:1028
bool btr_lob_op_is_update(opcode op)
Determine if an operation on off-page columns is an update.
Definition: lob0lob.h:1575
const ulint BTR_EXTERN_OFFSET
offset of BLOB header on that page
Definition: lob0lob.h:108
const ulint LOB_HDR_PART_LEN
The structure of uncompressed LOB page header.
Definition: lob0lob.h:141
ulint btr_copy_externally_stored_field_prefix_func(trx_t *trx, const dict_index_t *index, byte *buf, ulint len, const page_size_t &page_size, const byte *data, bool is_sdi, ulint local_len)
Copies the prefix of an externally stored field of a record.
Definition: lob0lob.cc:818
dberr_t btr_store_big_rec_extern_fields(trx_t *trx, btr_pcur_t *pcur, const upd_t *upd, ulint *offsets, const big_rec_t *big_rec_vec, mtr_t *btr_mtr, opcode op)
Stores the fields in big_rec_vec to the tablespace and puts pointers to them in rec.
Definition: lob0lob.cc:417
std::ostream & operator<<(std::ostream &out, const plist_node_t &obj)
Definition: lob0impl.h:239
static ulint btr_copy_externally_stored_field_prefix(trx_t *trx, const dict_index_t *index, byte *buf, ulint len, const page_size_t &page_size, const byte *data, bool is_sdi, ulint local_len)
Definition: lob0lob.h:1632
constexpr uint32_t KB128
The compressed LOB is stored as a collection of zlib streams.
Definition: lob0lob.h:90
ulint btr_rec_get_field_ref_offs(const dict_index_t *index, const ulint *offsets, ulint n)
Gets the offset of the pointer to the externally stored part of a field.
Definition: lob0lob.cc:64
Index page routines.
static bool page_rec_is_comp(const rec_t *rec)
true if the record is on a page in compact format.
static page_no_t page_get_page_no(const page_t *page)
Gets the page number.
static ulint page_offset(const void *ptr)
Gets the offset within a page.
static page_t * page_align(const void *ptr)
Gets the start of a page.
constexpr size_t FIELD_REF_SIZE
Definition: page0size.h:39
const byte field_ref_zero[FIELD_REF_SIZE]
A BLOB field reference full of zero, for use in assertions and tests.Initially, BLOB field references...
Definition: page0zip.cc:42
byte page_t
Type of the index page.
Definition: page0types.h:152
void page_zip_write_blob_ptr(page_zip_des_t *page_zip, const byte *rec, const dict_index_t *index, const ulint *offsets, ulint n, mtr_t *mtr)
Write a BLOB pointer of a record on the leaf page of a clustered index.
Definition: page0zip.cc:1878
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:631
static ulint rec_offs_n_fields(const ulint *offsets)
The following function returns the number of fields in a record.
Definition: rec.h:510
static bool rec_get_node_ptr_flag(const rec_t *rec)
The following function tells if a new-style record is a node pointer.
static bool rec_get_deleted_flag(const rec_t *rec, bool comp)
The following function tells if record is delete marked.
static bool rec_offs_any_extern(const ulint *offsets)
Determine if the offsets are for a record containing externally stored columns.
static bool rec_offs_comp(const ulint *offsets)
Determine if the offsets are for a record in the new compact format.
byte rec_t
Definition: rem0types.h:41
void rec_offs_make_nth_extern(dict_index_t *index, ulint *offsets, ulint n)
Mark the nth field as externally stored.
Definition: rem0wrec.cc:147
byte * rec_get_nth_field(const dict_index_t *index, const rec_t *rec, const ulint *offsets, ulint n, ulint *len)
Gets the value of the specified field in the record.
Definition: rem0wrec.cc:81
ulint rec_offs_nth_extern(const dict_index_t *index, const ulint *offsets, ulint n)
Returns nonzero if the extern bit is set in nth field of rec.
Definition: rem0wrec.cc:137
Modification log for online index creation and online table rebuild.
Storage format for overflow data in a big record, that is, a clustered index record which needs exter...
Definition: data0data.h:840
ulint n_fields
number of stored fields
Definition: data0data.h:844
page_cur_t page_cur
Page cursor.
Definition: btr0cur.h:672
Definition: btr0pcur.h:99
bool restore_position(ulint latch_mode, mtr_t *mtr, ut::Location location)
Restores the stored position of a persistent cursor bufferfixing the page and obtaining the specified...
Definition: btr0pcur.cc:147
btr_pcur_pos_t m_rel_pos
BTR_PCUR_ON, BTR_PCUR_BEFORE, or BTR_PCUR_AFTER, depending on whether cursor was on,...
Definition: btr0pcur.h:470
dict_index_t * index()
Definition: btr0pcur.h:106
buf_block_t * get_block()
Returns the current buffer block (non const version).
Definition: btr0pcur.h:656
ulint m_latch_mode
see TODO note below! BTR_SEARCH_LEAF, BTR_MODIFY_LEAF, BTR_MODIFY_TREE or BTR_NO_LATCHES,...
Definition: btr0pcur.h:456
btr_cur_t m_btr_cur
a B-tree cursor
Definition: btr0pcur.h:447
void store_position(mtr_t *mtr)
The position of the cursor is stored by taking an initial segment of the record the cursor is positio...
Definition: btr0pcur.cc:42
rec_t * get_rec()
Returns the current record (non const version).
Definition: btr0pcur.h:668
The buffer control block structure.
Definition: buf0buf.h:1747
buf_page_t page
page information; this must be the first field, so that buf_pool->page_hash can point to buf_page_t o...
Definition: buf0buf.h:1753
byte * frame
pointer to buffer frame which is of size UNIV_PAGE_SIZE, and aligned to an address divisible by UNIV_...
Definition: buf0buf.h:1769
Data structure for an index.
Definition: dict0mem.h:1046
dict_table_t * table
back pointer to table
Definition: dict0mem.h:1060
Data structure for a database table.
Definition: dict0mem.h:1909
The context information when the delete operation on LOB is taking place.
Definition: lob0lob.h:1424
bool is_ref_valid() const
Check if the blob reference is valid.
Definition: lob0lob.h:1445
bool is_compressed() const
Determine if it is compressed page format.
Definition: lob0lob.h:1451
page_size_t m_page_size
The page size of the tablespace.
Definition: lob0lob.h:1499
page_size_t get_page_size() const
Obtain the page size from the tablespace flags.
Definition: lob0lob.h:1549
~DeleteContext()
Destructor.
Definition: lob0lob.h:1557
bool m_rollback
Is this operation part of rollback?
Definition: lob0lob.h:1496
DeleteContext(const BtrContext &btr, byte *field_ref, ulint field_no, bool rollback)
Constructor.
Definition: lob0lob.h:1528
Block_vector m_lob_blocks
The buffer blocks of lob to be freed.
Definition: lob0lob.h:1518
bool is_delete_marked() const
Definition: lob0lob.h:1461
ref_mem_t m_blobref_mem
Memory copy of the original LOB reference.
Definition: lob0lob.h:1513
bool validate_blobref() const
Validate the LOB reference object.
Definition: lob0lob.h:1472
std::vector< buf_block_t *, ut::allocator< buf_block_t * > > Block_vector
Definition: lob0lob.h:1515
void x_latch_rec_page(mtr_t *mtr)
Acquire an x-latch on the index page containing the clustered index record, in the given mini-transac...
Definition: lob0lob.cc:1257
void set_blob(byte *field_ref, ulint field_no)
Update the delete context to point to a different blob.
Definition: lob0lob.h:1541
void add_lob_block(buf_block_t *block)
Add a buffer block that is to be freed.
Definition: lob0lob.h:1559
bool has_atomic_blobs() const
Check if tablespace supports atomic blobs.
Definition: lob0lob.h:1455
ref_t m_blobref
the BLOB reference or external field reference.
Definition: lob0lob.h:1490
void free_lob_blocks()
Free all the stored lob blocks.
Definition: lob0lob.h:1564
ulint m_field_no
field number of externally stored column; ignored if rec == NULL
Definition: lob0lob.h:1493
The context for a LOB operation.
Definition: lob0lob.h:1144
ulint get_big_rec_vec_size()
Get the size of vector containing fields to be stored externally.
Definition: lob0lob.h:1157
const big_rec_t * get_big_rec_vec()
Get the vector containing fields to be stored externally.
Definition: lob0lob.h:1153
const big_rec_t * m_big_rec_vec
The B-tree Context.
Definition: lob0lob.h:1163
InsertContext(const BtrContext &btr_ctx, const big_rec_t *big_rec_vec)
Constructor.
Definition: lob0lob.h:1148
The context information for reading a single BLOB.
Definition: lob0lob.h:1252
bool is_valid_blob() const
Check if the BLOB reference is valid.
Definition: lob0lob.h:1290
const byte * m_data
The 'internally' stored part of the field containing also the reference to the external part; must be...
Definition: lob0lob.h:1300
bool assert_read_uncommitted() const
Assert that current trx is using isolation level read uncommitted.
Definition: lob0lob.cc:58
dict_index_t * index()
Definition: lob0lob.h:1292
const ref_t m_blobref
The blob reference of the blob that is being read.
Definition: lob0lob.h:1307
ulint m_lob_version
Definition: lob0lob.h:1326
const bool m_is_sdi
Is it a tablespace dictionary index (SDI)?
Definition: lob0lob.h:1334
ulint m_local_len
Length (in bytes) of BLOB prefix stored inline in clustered index record.
Definition: lob0lob.h:1304
ulint m_offset
The offset information obtained from the blob reference.
Definition: lob0lob.h:1322
const page_size_t & m_page_size
The page size information.
Definition: lob0lob.h:1295
byte * m_buf
Buffer into which data is read.
Definition: lob0lob.h:1310
page_no_t m_page_no
The page number obtained from the blob reference.
Definition: lob0lob.h:1319
dict_index_t * m_index
Definition: lob0lob.h:1324
ulint m_len
Length of the buffer m_buf.
Definition: lob0lob.h:1313
space_id_t m_space_id
The identifier of the space in which blob is available.
Definition: lob0lob.h:1316
bool is_sdi() const
Is it a space dictionary index (SDI)?
Definition: lob0lob.h:1331
trx_t * m_trx
The transaction that is reading.
Definition: lob0lob.h:1342
void read_blobref()
Read the space_id, page_no and offset information from the BLOB reference object and update the membe...
Definition: lob0lob.h:1280
ReadContext(const page_size_t &page_size, const byte *data, ulint prefix_len, byte *buf, ulint len, bool is_sdi)
Constructor.
Definition: lob0lob.h:1265
Fetch uncompressed BLOB.
Definition: lob0lob.h:1399
ulint m_copied_len
Total bytes of LOB data that has been copied from multiple LOB pages.
Definition: lob0lob.h:1419
void fetch_page()
Fetch one BLOB page.
Definition: lob0lob.cc:744
ReadContext m_rctx
Definition: lob0lob.h:1411
buf_block_t * m_cur_block
Buffer block of the current BLOB page.
Definition: lob0lob.h:1414
ulint fetch()
Fetch the complete or prefix of the uncompressed LOB data.
Definition: lob0lob.cc:780
Reader(const ReadContext &ctx)
Constructor.
Definition: lob0lob.h:1401
The in-memory blob directory.
Definition: lob0lob.h:1219
std::vector< blob_page_info_t >::const_iterator const_iterator
Definition: lob0lob.h:1220
std::vector< blob_page_info_t > m_pages
A vector of blob pages along with its metadata.
Definition: lob0lob.h:1239
std::ostream & print(std::ostream &out) const
Print this blob directory into the given output stream.
Definition: lob0lob.cc:146
dberr_t add(const blob_page_info_t &page)
Append the given blob page information.
Definition: lob0lob.h:1233
void clear()
Clear the contents of this blob directory.
Definition: lob0lob.h:1228
Information about data stored in one BLOB page.
Definition: lob0lob.h:1167
page_no_t m_page_no
The BLOB page number.
Definition: lob0lob.h:1203
blob_page_info_t(page_no_t page_no, uint bytes, uint zbytes)
Constructor.
Definition: lob0lob.h:1174
uint m_zbytes
Amount of compressed data (in bytes) in the BLOB page.
Definition: lob0lob.h:1209
std::ostream & print(std::ostream &out) const
Print this blob_page_into_t object into the given output stream.
Definition: lob0lob.cc:158
void set_uncompressed_size(uint bytes)
Set the uncompressed data size in bytes.
Definition: lob0lob.h:1195
void set_page_no(page_no_t page_no)
Set the page number.
Definition: lob0lob.h:1199
uint m_bytes
Amount of uncompressed data (in bytes) in the BLOB page.
Definition: lob0lob.h:1206
void set_compressed_size(uint bytes)
Set the compressed data size in bytes.
Definition: lob0lob.h:1191
void reset()
Re-initialize the current object.
Definition: lob0lob.h:1178
In memory representation of the LOB reference.
Definition: lob0lob.h:154
bool m_partial
Whether the LOB is partially updated.
Definition: lob0lob.h:178
page_no_t m_page_no
Page number of first LOB page.
Definition: lob0lob.h:159
ulint m_offset
Offset within m_page_no where LOB begins.
Definition: lob0lob.h:162
bool m_inherit
Whether the clustered index record inherited this LOB from another clustered index record.
Definition: lob0lob.h:175
bool m_owner
Whether the clustered index record owns this LOB.
Definition: lob0lob.h:171
ulint m_length
Length of LOB.
Definition: lob0lob.h:165
bool m_null
Whether the LOB is null.
Definition: lob0lob.h:168
bool m_being_modified
Whether the blob is being modified.
Definition: lob0lob.h:181
space_id_t m_space_id
Space Identifier of the clustered index.
Definition: lob0lob.h:156
bool is_purged() const
Check if the LOB has already been purged.
Definition: lob0lob.h:185
The struct 'lob::ref_t' represents an external field reference.
Definition: lob0lob.h:198
static bool use_single_z_stream(ulint len)
For compressed LOB, if the length is less than or equal to Z_CHUNK_SIZE then use the older single z s...
Definition: lob0lob.h:222
void set_page_no(const ulint page_no, mtr_t *mtr)
Set the page number in the external field reference.
Definition: lob0lob.h:467
void set_space_id(const space_id_t space_id, mtr_t *mtr)
Set the space_id in the external field reference.
Definition: lob0lob.h:454
void update(space_id_t space_id, ulint page_no, ulint offset, mtr_t *mtr)
Update the information stored in the external field reference.
Definition: lob0lob.h:445
void set_owner(bool owner)
Set the ownership flag in the blob reference.
Definition: lob0lob.h:322
void set_inherited(bool inherited, mtr_t *mtr)
Set the inherited flag in the field reference.
Definition: lob0lob.h:373
void set_version(const ulint version)
Set the version information in the external field reference.
Definition: lob0lob.h:486
void parse(ref_mem_t &obj) const
Parse the LOB reference object and copy data into the given ref_mem_t object.
Definition: lob0lob.h:245
void set_length(const ulint len)
Set the length of blob in the external field reference.
Definition: lob0lob.h:500
static bool is_null(const byte *ref)
Check if the LOB reference is null (all zeroes).
Definition: lob0lob.h:297
static const ulint LOB_BIG_THRESHOLD_SIZE
If the LOB size is equal to or above this limit (in physical page size terms), then the LOB is big en...
Definition: lob0lob.h:203
static const ulint LOB_SMALL_CHANGE_THRESHOLD
If the total number of bytes modified in an LOB, in an update operation, is less than or equal to thi...
Definition: lob0lob.h:210
static bool is_being_modified(const byte *field_ref)
Check if the current blob is being modified.
Definition: lob0lob.h:361
static const uint SIZE
The size of an LOB reference object (in bytes)
Definition: lob0lob.h:566
bool check_space_id(dict_index_t *index) const
Check if the space_id in the LOB reference is equal to the space_id of the index to which it belongs.
Definition: lob0lob.cc:1245
void set_length(const ulint len, mtr_t *mtr)
Set the length of blob in the external field reference.
Definition: lob0lob.h:493
void set_owner(bool owner, mtr_t *mtr)
Set the ownership flag in the blob reference.
Definition: lob0lob.h:306
bool is_null() const
Check if the field reference is made of zeroes.
Definition: lob0lob.h:279
void set_space_id(const space_id_t space_id)
Set the space_id in the external field reference.
Definition: lob0lob.h:460
ulint length() const
Read the length from the blob reference.
Definition: lob0lob.h:436
ref_t(byte *ptr)
Constructor.
Definition: lob0lob.h:214
bool is_being_modified() const
Check if the current blob is being modified.
Definition: lob0lob.h:368
bool use_single_z_stream() const
For compressed LOB, if the length is less than or equal to Z_CHUNK_SIZE then use the older single z s...
Definition: lob0lob.h:218
bool is_lob_partially_updatable(const dict_index_t *index) const
Check if the LOB can be partially updated.
Definition: lob0lob.cc:1216
static space_id_t space_id(const byte *ref)
Read the space id from the given blob reference.
Definition: lob0lob.h:403
std::ostream & print(std::ostream &out) const
Print this LOB reference into the given output stream.
Definition: lob0lob.cc:1236
static void set_being_modified(byte *ref, bool modifying, mtr_t *mtr)
Set the being_modified flag in the field reference.
Definition: lob0lob.h:339
static bool is_big(const page_size_t &page_size, const ulint lob_length)
Check if this LOB is big enough to do partial update.
Definition: lob0lob.h:228
ulint offset() const
Read the offset of blob header from the blob reference.
Definition: lob0lob.h:426
bool is_inherited() const
Check if the current row inherited the blob from parent row.
Definition: lob0lob.h:394
void copy(byte *field_ref) const
Copy the LOB reference into the given memory location.
Definition: lob0lob.h:259
byte * m_ref
Pointing to a memory of size BTR_EXTERN_FIELD_REF_SIZE.
Definition: lob0lob.h:570
ulint get_lob_page_info(const dict_index_t *index, const page_size_t &page_size, bool &is_partially_updatable) const
Load the first page of LOB and read its page type.
Definition: lob0lob.cc:1135
page_no_t page_no() const
Read the page number from the blob reference.
Definition: lob0lob.h:420
void init()
Initialize the reference object with zeroes.
Definition: lob0lob.h:282
bool is_big(const page_size_t &page_size) const
Check if this LOB is big enough to do partial update.
Definition: lob0lob.h:237
void set_being_modified(bool modifying, mtr_t *mtr)
Set the being_modified flag in the field reference.
Definition: lob0lob.h:354
page_t * page_align() const
Get the start of a page containing this blob reference.
Definition: lob0lob.h:507
static bool is_null_relaxed(const byte *ref)
Check if the LOB reference is null (all zeroes) except the "is being modified" bit.
Definition: lob0lob.h:290
space_id_t space_id() const
Read the space id from the blob reference.
Definition: lob0lob.h:416
void set_page_no(const ulint page_no)
Set the page number in the external field reference.
Definition: lob0lob.h:473
bool is_null_relaxed() const
Check if the field reference is made of zeroes except the being_modified bit.
Definition: lob0lob.h:273
bool validate(mtr_t *mtr)
Check if the given mtr has necessary latches to update this LOB reference.
Definition: lob0lob.h:515
bool is_equal(const byte *ptr) const
Check whether the stored external field reference is equal to the given field reference.
Definition: lob0lob.h:264
void mark_not_partially_updatable(trx_t *trx, mtr_t *mtr, dict_index_t *index, const page_size_t &page_size)
Load the first page of the LOB and mark it as not partially updatable anymore.
Definition: lob0lob.cc:1177
bool is_owner() const
Check if the current row is the owner of the blob.
Definition: lob0lob.h:387
void set_ref(byte *ptr)
Set the external field reference to the given memory location.
Definition: lob0lob.h:268
void set_offset(const ulint offset, mtr_t *mtr)
Set the offset information in the external field reference.
Definition: lob0lob.h:480
uint32_t version() const
Read the LOB version from the blob reference.
Definition: lob0lob.h:430
static page_no_t page_no(const byte *ref)
Read the page no from the blob reference.
Definition: lob0lob.h:409
Fetch compressed BLOB.
Definition: lob0lob.h:1346
ulint length() const
Get the length of data that has been read.
Definition: lob0lob.h:1360
int setup_zstream()
Do setup of the zlib stream.
Definition: lob0lob.cc:166
dberr_t fetch()
Fetch the BLOB.
Definition: lob0lob.cc:185
zReader(const ReadContext &ctx)
Constructor.
Definition: lob0lob.h:1348
ulint m_page_type_ex
The expected page type.
Definition: lob0lob.h:1394
buf_page_t * m_bpage
Definition: lob0lob.h:1390
dberr_t fetch_page()
Fetch one BLOB page.
Definition: lob0lob.cc:262
mem_heap_t * m_heap
The memory heap that will be used by zlib allocator.
Definition: lob0lob.h:1384
z_stream m_stream
The zlib stream used to uncompress while fetching blob.
Definition: lob0lob.h:1381
ReadContext m_rctx
Definition: lob0lob.h:1375
bool assert_empty_local_prefix()
Assert that the local prefix is empty.
Definition: lob0lob.cc:256
ulint m_remaining
Bytes yet to be read.
Definition: lob0lob.h:1378
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:302
Mini-transaction handle and buffer.
Definition: mtr0mtr.h:177
Flush_observer * get_flush_observer() const
Get flush observer.
Definition: mtr0mtr.h:516
mtr_log_t set_log_mode(mtr_log_t mode)
Change the logging mode.
Definition: mtr0mtr.cc:468
void commit()
Commit the mini-transaction.
Definition: mtr0mtr.cc:662
mtr_log_t get_log_mode() const
Get the logging mode.
Definition: mtr0mtr.ic:153
void start(bool sync=true)
Start a mini-transaction.
Definition: mtr0mtr.cc:565
buf_block_t * memo_contains_page_flagged(const byte *ptr, ulint flags) const
Check if memo contains the given page.
Definition: mtr0mtr.cc:1076
Index page cursor.
Definition: page0cur.h:311
buf_block_t * block
Pointer to the current block containing rec.
Definition: page0cur.h:322
rec_t * rec
pointer to a record on page
Definition: page0cur.h:316
Compressed page descriptor.
Definition: page0types.h:201
Definition: row0purge.h:93
Definition: result.h:30
Definition: trx0trx.h:684
Definition: row0upd.h:467
Definition: row0upd.h:565
@ RW_X_LATCH
Definition: sync0rw.h:99
ib_id_t undo_no_t
Undo number.
Definition: trx0types.h:142
ib_id_t trx_id_t
Transaction identifier (DB_TRX_ID, DATA_TRX_ID)
Definition: trx0types.h:138
Version control for database, common definitions, and include files.
#define IF_DEBUG(...)
Definition: univ.i:674
unsigned long int ulint
Definition: univ.i:406
constexpr ulint ULINT_UNDEFINED
The 'undefined' value for a ulint.
Definition: univ.i:420
#define UT_LOCATION_HERE
Definition: ut0core.h:73
#define ut_error
Abort execution.
Definition: ut0dbg.h:101
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:105
#define ut_o(EXPR)
Opposite of ut_d().
Definition: ut0dbg.h:109
#define ut_d(EXPR)
Debug statement.
Definition: ut0dbg.h:107
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:93
int n
Definition: xcom_base.cc:509