MySQL 8.0.40
Source Code Documentation
lob0ins.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2016, 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 lob0ins_h
28#define lob0ins_h
29
30#include "lob0lob.h"
31
32namespace lob {
33
34/** This struct can hold BLOB routines/functions, and state variables,
35that are common for compressed and uncompressed BLOB. */
37 /** Constructor.
38 @param[in] ctx blob operation context. */
40 : m_ctx(ctx),
42 m_prev_page_no(ctx->get_page_no()),
45
46 /** Start the BLOB mtr.
47 @return pointer to the BLOB mtr. */
52 return (&m_blob_mtr);
53 }
54
55 /** Allocate one BLOB page.
56 @return the allocated block of the BLOB page. */
58
59 /** Get the previous BLOB page frame. This will return a BLOB page.
60 It should not be called for the first BLOB page, because it will not
61 have a previous BLOB page.
62 @return the previous BLOB page frame. */
64
65 /** Get the previous BLOB page block. This will return a BLOB block.
66 It should not be called for the first BLOB page, because it will not
67 have a previous BLOB page.
68 @return the previous BLOB block. */
70
71 /** Check if the index is SDI index
72 @return true if index is SDI index else false */
73 bool is_index_sdi() { return (dict_index_is_sdi(m_ctx->index())); }
74
75 /** Get the current BLOB page frame.
76 @return the current BLOB page frame. */
78
79 protected:
80 /** The BLOB operation context */
82
83 /** Success or failure status of the operation so far. */
85
86 /** The mini trx used to write into blob pages */
88
89 /** The previous BLOB page number. This is needed to maintain
90 the linked list of BLOB pages. */
92
93 /** The current BLOB buf_block_t object. */
95
96 /** The current BLOB page number. */
98};
99
100/** Insert or write an uncompressed BLOB */
101class Inserter : private BaseInserter {
102 public:
103 /** Constructor.
104 @param[in] ctx blob operation context. */
106
107 /** Destructor. */
108 ~Inserter() = default;
109
110 /** Write all the BLOBs of the clustered index record.
111 @return DB_SUCCESS on success, error code on failure. */
112 dberr_t write();
113
114 /** Write one blob field data.
115 @param[in] blob_j the blob field number
116 @return DB_SUCCESS on success, error code on failure. */
117 dberr_t write_one_blob(size_t blob_j);
118
119 /** Write one blob field data.
120 @param[in] blob_j the blob field number
121 @return DB_SUCCESS on success, error code on failure. */
122 dberr_t write_one_small_blob(size_t blob_j);
123
124 /** Write one blob page. This function will be repeatedly called
125 with an increasing nth_blob_page to completely write a BLOB.
126 @param[in] field the big record field.
127 @param[in] nth_blob_page count of the BLOB page (starting from 1).
128 @return DB_SUCCESS or DB_FAIL. */
130
131 /** Check if the BLOB operation has reported any errors.
132 @return true if BLOB operation is successful, false otherwise. */
133 bool is_ok() const { return (m_err == DB_SUCCESS); }
134
135 /** Make the current page as next page of previous page. In other
136 words, make the page m_cur_blob_page_no as the next page of page
137 m_prev_page_no. */
138 void set_page_next();
139
140 /** Write the page type of the current BLOB page and also generate the
141 redo log record. */
143 page_type_t page_type;
144 page_t *blob_page = cur_page();
145
146 if (is_index_sdi()) {
147 page_type = FIL_PAGE_SDI_BLOB;
148 } else {
149 page_type = FIL_PAGE_TYPE_BLOB;
150 }
151
152 mlog_write_ulint(blob_page + FIL_PAGE_TYPE, page_type, MLOG_2BYTES,
153 &m_blob_mtr);
154 }
155
156 /** Calculate the payload size of the BLOB page.
157 @return payload size in bytes. */
158 ulint payload() const {
159 const page_size_t page_size = m_ctx->page_size();
160 const ulint payload_size =
162 return (payload_size);
163 }
164
165 /** Write contents into a single BLOB page.
166 @param[in] field the big record field. */
168
169 /** Write first blob page.
170 @param[in] field the big record field.
171 @return DB_SUCCESS on success. */
173
174 private:
175 /** The BLOB directory information. */
177
178 /** Data remaining to be written. */
180};
181
182} // namespace lob
183
184#endif /* lob0ins_h */
uint32_t page_no_t
Page number.
Definition: api0api.h:50
static buf_frame_t * buf_block_get_frame(const buf_block_t *block)
Gets a pointer to the memory frame of a block.
mtr_log_t get_log_mode()
Get the log mode of the btr mtr.
Definition: lob0lob.h:1017
Flush_observer * get_flush_observer() const
Get flush observer.
Definition: lob0lob.h:1021
dict_index_t * index() const
Get the index object.
Definition: lob0lob.h:973
const page_size_t page_size() const
Obtain the page size of the underlying table.
Definition: lob0lob.h:993
Insert or write an uncompressed BLOB.
Definition: lob0ins.h:101
ulint m_remaining
Data remaining to be written.
Definition: lob0ins.h:179
void write_into_single_page(big_rec_field_t &field)
Write contents into a single BLOB page.
Definition: lob0ins.cc:237
dberr_t write_one_blob(size_t blob_j)
Write one blob field data.
Definition: lob0ins.cc:143
dberr_t write_first_page(big_rec_field_t &field)
Write first blob page.
Definition: lob0ins.cc:178
void set_page_next()
Make the current page as next page of previous page.
Definition: lob0ins.cc:171
ulint payload() const
Calculate the payload size of the BLOB page.
Definition: lob0ins.h:158
~Inserter()=default
Destructor.
dberr_t write_one_small_blob(size_t blob_j)
Write one blob field data.
Definition: lob0ins.cc:123
bool is_ok() const
Check if the BLOB operation has reported any errors.
Definition: lob0ins.h:133
blob_dir_t m_dir
The BLOB directory information.
Definition: lob0ins.h:176
void log_page_type()
Write the page type of the current BLOB page and also generate the redo log record.
Definition: lob0ins.h:142
dberr_t write_single_blob_page(big_rec_field_t &field, ulint nth_blob_page)
Write one blob page.
Definition: lob0ins.cc:211
Inserter(InsertContext *ctx)
Constructor.
Definition: lob0ins.h:105
dberr_t write()
Write all the BLOBs of the clustered index record.
Definition: lob0ins.cc:105
Page size descriptor.
Definition: page0size.h:50
size_t physical() const
Retrieve the physical page size (on-disk).
Definition: page0size.h:121
dberr_t
Definition: db0err.h:39
@ DB_SUCCESS
Definition: db0err.h:43
static bool dict_index_is_sdi(const dict_index_t *index)
Check if the index is SDI index.
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:222
uint16_t page_type_t
Definition: fil0fil.h:1193
constexpr page_no_t FIL_NULL
'null' (undefined) page offset in the context of file spaces
Definition: fil0fil.h:1131
constexpr page_type_t FIL_PAGE_SDI_BLOB
Uncompressed SDI BLOB page.
Definition: fil0fil.h:1262
constexpr page_type_t FIL_PAGE_TYPE_BLOB
Uncompressed BLOB page.
Definition: fil0fil.h:1237
constexpr uint32_t FIL_PAGE_TYPE
file page type: FIL_PAGE_INDEX,..., 2 bytes.
Definition: fil0types.h:76
constexpr uint32_t FIL_PAGE_DATA
start of the data on the page
Definition: fil0types.h:111
constexpr uint32_t FIL_PAGE_DATA_END
size of the page trailer
Definition: fil0types.h:119
Implements the large objects (LOB) module.
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:256
#define mtr_start(m)
Start a mini-transaction.
Definition: mtr0mtr.h:50
@ MLOG_2BYTES
2 bytes ...
Definition: mtr0types.h:73
Provides the large objects (LOB) module.
Definition: lob0del.h:32
const ulint LOB_HDR_SIZE
Size of an uncompressed LOB page header, in bytes.
Definition: lob0lob.h:148
byte page_t
Type of the index page.
Definition: page0types.h:152
A slot for a field in a big rec vector.
Definition: data0data.h:799
The buffer control block structure.
Definition: buf0buf.h:1690
This struct can hold BLOB routines/functions, and state variables, that are common for compressed and...
Definition: lob0ins.h:36
buf_block_t * alloc_blob_page()
Allocate one BLOB page.
Definition: lob0ins.cc:35
page_t * cur_page() const
Get the current BLOB page frame.
Definition: lob0ins.h:77
buf_block_t * get_previous_blob_block()
Get the previous BLOB page block.
Definition: lob0ins.cc:76
BaseInserter(InsertContext *ctx)
Constructor.
Definition: lob0ins.h:39
page_t * get_previous_blob_page()
Get the previous BLOB page frame.
Definition: lob0ins.cc:98
buf_block_t * m_cur_blob_block
The current BLOB buf_block_t object.
Definition: lob0ins.h:94
mtr_t m_blob_mtr
The mini trx used to write into blob pages.
Definition: lob0ins.h:87
bool is_index_sdi()
Check if the index is SDI index.
Definition: lob0ins.h:73
mtr_t * start_blob_mtr()
Start the BLOB mtr.
Definition: lob0ins.h:48
page_no_t m_prev_page_no
The previous BLOB page number.
Definition: lob0ins.h:91
page_no_t m_cur_blob_page_no
The current BLOB page number.
Definition: lob0ins.h:97
InsertContext * m_ctx
The BLOB operation context.
Definition: lob0ins.h:81
dberr_t m_err
Success or failure status of the operation so far.
Definition: lob0ins.h:84
The context for a LOB operation.
Definition: lob0lob.h:1099
The in-memory blob directory.
Definition: lob0lob.h:1174
Mini-transaction handle and buffer.
Definition: mtr0mtr.h:177
mtr_log_t set_log_mode(mtr_log_t mode)
Change the logging mode.
Definition: mtr0mtr.cc:471
void set_flush_observer(Flush_observer *observer)
Set flush observer.
Definition: mtr0mtr.h:522
unsigned long int ulint
Definition: univ.i:406