MySQL 8.1.0
Source Code Documentation
lob0ins.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2016, 2023, 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 also distributed with certain software (including but not
10limited to OpenSSL) that is licensed under separate terms, as designated in a
11particular file or component or in included license documentation. The authors
12of MySQL hereby grant you an additional permission to link the program and
13your derivative works with the separately licensed software that they have
14included with MySQL.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
25*****************************************************************************/
26#ifndef lob0ins_h
27#define lob0ins_h
28
29#include "lob0lob.h"
30
31namespace lob {
32
33/** This struct can hold BLOB routines/functions, and state variables,
34that are common for compressed and uncompressed BLOB. */
36 /** Constructor.
37 @param[in] ctx blob operation context. */
39 : m_ctx(ctx),
41 m_prev_page_no(ctx->get_page_no()),
44
45 /** Start the BLOB mtr.
46 @return pointer to the BLOB mtr. */
51 return (&m_blob_mtr);
52 }
53
54 /** Allocate one BLOB page.
55 @return the allocated block of the BLOB page. */
57
58 /** Get the previous BLOB page frame. This will return a BLOB page.
59 It should not be called for the first BLOB page, because it will not
60 have a previous BLOB page.
61 @return the previous BLOB page frame. */
63
64 /** Get the previous BLOB page block. This will return a BLOB block.
65 It should not be called for the first BLOB page, because it will not
66 have a previous BLOB page.
67 @return the previous BLOB block. */
69
70 /** Check if the index is SDI index
71 @return true if index is SDI index else false */
72 bool is_index_sdi() { return (dict_index_is_sdi(m_ctx->index())); }
73
74 /** Get the current BLOB page frame.
75 @return the current BLOB page frame. */
77
78 protected:
79 /** The BLOB operation context */
81
82 /** Success or failure status of the operation so far. */
84
85 /** The mini trx used to write into blob pages */
87
88 /** The previous BLOB page number. This is needed to maintain
89 the linked list of BLOB pages. */
91
92 /** The current BLOB buf_block_t object. */
94
95 /** The current BLOB page number. */
97};
98
99/** Insert or write an uncompressed BLOB */
100class Inserter : private BaseInserter {
101 public:
102 /** Constructor.
103 @param[in] ctx blob operation context. */
105
106 /** Destructor. */
107 ~Inserter() = default;
108
109 /** Write all the BLOBs of the clustered index record.
110 @return DB_SUCCESS on success, error code on failure. */
111 dberr_t write();
112
113 /** Write one blob field data.
114 @param[in] blob_j the blob field number
115 @return DB_SUCCESS on success, error code on failure. */
116 dberr_t write_one_blob(size_t blob_j);
117
118 /** Write one blob field data.
119 @param[in] blob_j the blob field number
120 @return DB_SUCCESS on success, error code on failure. */
121 dberr_t write_one_small_blob(size_t blob_j);
122
123 /** Write one blob page. This function will be repeatedly called
124 with an increasing nth_blob_page to completely write a BLOB.
125 @param[in] field the big record field.
126 @param[in] nth_blob_page count of the BLOB page (starting from 1).
127 @return DB_SUCCESS or DB_FAIL. */
129
130 /** Check if the BLOB operation has reported any errors.
131 @return true if BLOB operation is successful, false otherwise. */
132 bool is_ok() const { return (m_err == DB_SUCCESS); }
133
134 /** Make the current page as next page of previous page. In other
135 words, make the page m_cur_blob_page_no as the next page of page
136 m_prev_page_no. */
137 void set_page_next();
138
139 /** Write the page type of the current BLOB page and also generate the
140 redo log record. */
142 page_type_t page_type;
143 page_t *blob_page = cur_page();
144
145 if (is_index_sdi()) {
146 page_type = FIL_PAGE_SDI_BLOB;
147 } else {
148 page_type = FIL_PAGE_TYPE_BLOB;
149 }
150
151 mlog_write_ulint(blob_page + FIL_PAGE_TYPE, page_type, MLOG_2BYTES,
152 &m_blob_mtr);
153 }
154
155 /** Calculate the payload size of the BLOB page.
156 @return payload size in bytes. */
157 ulint payload() const {
158 const page_size_t page_size = m_ctx->page_size();
159 const ulint payload_size =
161 return (payload_size);
162 }
163
164 /** Write contents into a single BLOB page.
165 @param[in] field the big record field. */
167
168 /** Write first blob page.
169 @param[in] field the big record field.
170 @return DB_SUCCESS on success. */
172
173 private:
174 /** The BLOB directory information. */
176
177 /** Data remaining to be written. */
179};
180
181} // namespace lob
182
183#endif /* lob0ins_h */
uint32_t page_no_t
Page number.
Definition: api0api.h:48
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:100
ulint m_remaining
Data remaining to be written.
Definition: lob0ins.h:178
void write_into_single_page(big_rec_field_t &field)
Write contents into a single BLOB page.
Definition: lob0ins.cc:236
dberr_t write_one_blob(size_t blob_j)
Write one blob field data.
Definition: lob0ins.cc:142
dberr_t write_first_page(big_rec_field_t &field)
Write first blob page.
Definition: lob0ins.cc:177
void set_page_next()
Make the current page as next page of previous page.
Definition: lob0ins.cc:170
ulint payload() const
Calculate the payload size of the BLOB page.
Definition: lob0ins.h:157
~Inserter()=default
Destructor.
dberr_t write_one_small_blob(size_t blob_j)
Write one blob field data.
Definition: lob0ins.cc:122
bool is_ok() const
Check if the BLOB operation has reported any errors.
Definition: lob0ins.h:132
blob_dir_t m_dir
The BLOB directory information.
Definition: lob0ins.h:175
void log_page_type()
Write the page type of the current BLOB page and also generate the redo log record.
Definition: lob0ins.h:141
dberr_t write_single_blob_page(big_rec_field_t &field, ulint nth_blob_page)
Write one blob page.
Definition: lob0ins.cc:210
Inserter(InsertContext *ctx)
Constructor.
Definition: lob0ins.h:104
dberr_t write()
Write all the BLOBs of the clustered index record.
Definition: lob0ins.cc:104
Page size descriptor.
Definition: page0size.h:49
size_t physical() const
Retrieve the physical page size (on-disk).
Definition: page0size.h:120
dberr_t
Definition: db0err.h:38
@ DB_SUCCESS
Definition: db0err.h:42
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:221
uint16_t page_type_t
Definition: fil0fil.h:1180
constexpr page_no_t FIL_NULL
'null' (undefined) page offset in the context of file spaces
Definition: fil0fil.h:1118
constexpr page_type_t FIL_PAGE_SDI_BLOB
Uncompressed SDI BLOB page.
Definition: fil0fil.h:1249
constexpr page_type_t FIL_PAGE_TYPE_BLOB
Uncompressed BLOB page.
Definition: fil0fil.h:1224
constexpr uint32_t FIL_PAGE_TYPE
file page type: FIL_PAGE_INDEX,..., 2 bytes.
Definition: fil0types.h:75
constexpr uint32_t FIL_PAGE_DATA
start of the data on the page
Definition: fil0types.h:110
constexpr uint32_t FIL_PAGE_DATA_END
size of the page trailer
Definition: fil0types.h:118
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:255
#define mtr_start(m)
Start a mini-transaction.
Definition: mtr0mtr.h:49
@ MLOG_2BYTES
2 bytes ...
Definition: mtr0types.h:72
Provides the large objects (LOB) module.
Definition: lob0del.h:31
const ulint LOB_HDR_SIZE
Size of an uncompressed LOB page header, in bytes.
Definition: lob0lob.h:147
byte page_t
Type of the index page.
Definition: page0types.h:151
A slot for a field in a big rec vector.
Definition: data0data.h:786
The buffer control block structure.
Definition: buf0buf.h:1689
This struct can hold BLOB routines/functions, and state variables, that are common for compressed and...
Definition: lob0ins.h:35
buf_block_t * alloc_blob_page()
Allocate one BLOB page.
Definition: lob0ins.cc:34
page_t * cur_page() const
Get the current BLOB page frame.
Definition: lob0ins.h:76
buf_block_t * get_previous_blob_block()
Get the previous BLOB page block.
Definition: lob0ins.cc:75
BaseInserter(InsertContext *ctx)
Constructor.
Definition: lob0ins.h:38
page_t * get_previous_blob_page()
Get the previous BLOB page frame.
Definition: lob0ins.cc:97
buf_block_t * m_cur_blob_block
The current BLOB buf_block_t object.
Definition: lob0ins.h:93
mtr_t m_blob_mtr
The mini trx used to write into blob pages.
Definition: lob0ins.h:86
bool is_index_sdi()
Check if the index is SDI index.
Definition: lob0ins.h:72
mtr_t * start_blob_mtr()
Start the BLOB mtr.
Definition: lob0ins.h:47
page_no_t m_prev_page_no
The previous BLOB page number.
Definition: lob0ins.h:90
page_no_t m_cur_blob_page_no
The current BLOB page number.
Definition: lob0ins.h:96
InsertContext * m_ctx
The BLOB operation context.
Definition: lob0ins.h:80
dberr_t m_err
Success or failure status of the operation so far.
Definition: lob0ins.h:83
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:176
mtr_log_t set_log_mode(mtr_log_t mode)
Change the logging mode.
Definition: mtr0mtr.cc:470
void set_flush_observer(Flush_observer *observer)
Set flush observer.
Definition: mtr0mtr.h:521
unsigned long int ulint
Definition: univ.i:405