MySQL 8.3.0
Source Code Documentation
Go to the documentation of this file.
3Copyright (c) 2014, 2023, Oracle and/or its affiliates.
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.
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.
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.
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
27/** @file include/btr0load.h
28 The B-tree bulk load
30 Created 03/11/2014 Shaohua Wang
31 *************************************************************************/
33#ifndef btr0load_h
34#define btr0load_h
36#include <stddef.h>
37#include <vector>
39#include "dict0dict.h"
40#include "page0cur.h"
41#include "ut0class_life_cycle.h"
42#include "ut0new.h"
44// Forward declaration.
45class Page_load;
47/** @note We should call commit(false) for a Page_load object, which is not in
48m_page_loaders after page_commit, and we will commit or abort Page_load
49objects in function "finish". */
51 public:
52 /** Interface to consume from. */
53 struct Cursor {
54 /** Constructor. */
55 Cursor() = default;
57 /** Destructor. */
58 virtual ~Cursor() = default;
60 /** Fetch the current row as a tuple.
61 @param[out] dtuple Row represented as a tuple.
62 @return DB_SUCCESS, DB_END_OF_INDEX or error code. */
63 [[nodiscard]] virtual dberr_t fetch(dtuple_t *&dtuple) noexcept = 0;
65 /** @return true if duplicates detected. */
66 virtual bool duplicates_detected() const noexcept = 0;
68 /** Move to the next record.
69 @return DB_SUCCESS, DB_END_OF_INDEX or error code. */
70 [[nodiscard]] virtual dberr_t next() noexcept = 0;
71 };
73 public:
74 using Page_loaders = std::vector<Page_load *, ut::allocator<Page_load *>>;
76 /** Constructor
77 @param[in] index B-tree index.
78 @param[in] trx_id Transaction id.
79 @param[in] observer Flush observer */
80 Btree_load(dict_index_t *index, trx_id_t trx_id,
81 Flush_observer *observer) noexcept;
83 /** Destructor */
84 ~Btree_load() noexcept;
86 /** Load the btree from the cursor.
87 @param[in,out] cursor Cursor to read tuples from.
88 @return DB_SUCCESS or error code. */
89 [[nodiscard]] dberr_t build(Cursor &cursor) noexcept;
91 /** Btree bulk load finish. We commit the last page in each level
92 and copy the last page in top level to the root page of the index
93 if no error occurs.
94 @param[in] err Whether bulk load was successful until now
95 @return error code */
96 [[nodiscard]] dberr_t finish(dberr_t err) noexcept;
98 /** Release latch on the rightmost leaf page in the index tree. */
99 void release() noexcept;
101 /** Re-latch latch on the rightmost leaf page in the index tree. */
102 void latch() noexcept;
104 /** Insert a tuple to a page in a level
105 @param[in] dtuple Tuple to insert
106 @param[in] level B-tree level
107 @return error code */
108 [[nodiscard]] dberr_t insert(dtuple_t *dtuple, size_t level) noexcept;
110 private:
111 /** Set the root page on completion.
112 @param[in] last_page_no Last page number (the new root).
113 @return DB_SUCCESS or error code. */
114 dberr_t load_root_page(page_no_t last_page_no) noexcept;
116 /** Split a page
117 @param[in] page_load Page to split
118 @param[in] next_page_load Next page
119 @return error code */
120 [[nodiscard]] dberr_t page_split(Page_load *page_load,
121 Page_load *next_page_load) noexcept;
123 /** Commit(finish) a page. We set next/prev page no, compress a page of
124 compressed table and split the page if compression fails, insert a node
125 pointer to father page if needed, and commit mini-transaction.
126 @param[in] page_load Page to commit
127 @param[in] next_page_load Next page
128 @param[in] insert_father Flag whether need to insert node ptr
129 @return error code */
130 [[nodiscard]] dberr_t page_commit(Page_load *page_load,
131 Page_load *next_page_load,
132 bool insert_father) noexcept;
134 /** Prepare space to insert a tuple.
135 @param[in,out] page_load Page bulk that will be used to store the record.
136 It may be replaced if there is not enough space
137 to hold the record.
138 @param[in] level B-tree level
139 @param[in] rec_size Record size
140 @return error code */
141 [[nodiscard]] dberr_t prepare_space(Page_load *&page_load, size_t level,
142 size_t rec_size) noexcept;
144 /** Insert a tuple to a page.
145 @param[in] page_load Page bulk object
146 @param[in] tuple Tuple to insert
147 @param[in] big_rec Big record vector, maybe NULL if there is no
148 Data to be stored externally.
149 @param[in] rec_size Record size
150 @return error code */
151 [[nodiscard]] dberr_t insert(Page_load *page_load, dtuple_t *tuple,
152 big_rec_t *big_rec, size_t rec_size) noexcept;
154 /** Log free check */
155 void log_free_check() noexcept;
157 /** Btree page bulk load finish. Commits the last page in each level
158 if no error occurs. Also releases all page bulks.
159 @param[in] err Whether bulk load was successful until now
160 @param[out] last_page_no Last page number
161 @return error code */
163 page_no_t &last_page_no) noexcept;
165 private:
166 /** Number of records inserted. */
167 uint64_t m_n_recs{};
169 /** B-tree index */
172 /** Transaction id */
175 /** Root page level */
176 size_t m_root_level{};
178 /** Flush observer */
181 /** Page cursor vector for all level */
184 /** State of the index. Used for asserting at the end of a
185 bulk load operation to ensure that the online status of the
186 index does not change */
190#endif /* btr0load_h */
uint32_t page_no_t
Page number.
Definition: api0api.h:44
Definition: btr0load.h:50
dberr_t load_root_page(page_no_t last_page_no) noexcept
Set the root page on completion.
dict_index_t * m_index
B-tree index.
Definition: btr0load.h:170
dberr_t insert(dtuple_t *dtuple, size_t level) noexcept
Insert a tuple to a page in a level.
dberr_t page_split(Page_load *page_load, Page_load *next_page_load) noexcept
Split a page.
Page_loaders m_page_loaders
Page cursor vector for all level.
Definition: btr0load.h:182
unsigned m_index_online
State of the index.
Definition: btr0load.h:187
dberr_t build(Cursor &cursor) noexcept
Load the btree from the cursor.
void log_free_check() noexcept
Log free check.
dberr_t prepare_space(Page_load *&page_load, size_t level, size_t rec_size) noexcept
Prepare space to insert a tuple.
dberr_t finalize_page_loads(dberr_t err, page_no_t &last_page_no) noexcept
Btree page bulk load finish.
void latch() noexcept
Re-latch latch on the rightmost leaf page in the index tree.
dberr_t page_commit(Page_load *page_load, Page_load *next_page_load, bool insert_father) noexcept
Commit(finish) a page.
void release() noexcept
Release latch on the rightmost leaf page in the index tree.
std::vector< Page_load *, ut::allocator< Page_load * > > Page_loaders
Definition: btr0load.h:74
dberr_t finish(dberr_t err) noexcept
Btree bulk load finish.
trx_id_t m_trx_id
Transaction id.
Definition: btr0load.h:173
Flush_observer * m_flush_observer
Flush observer.
Definition: btr0load.h:179
uint64_t m_n_recs
Number of records inserted.
Definition: btr0load.h:167
size_t m_root_level
Root page level.
Definition: btr0load.h:176
We use Flush_observer to track flushing of non-redo logged pages in bulk create index(btr0load....
Definition: buf0flu.h:269
The proper function call sequence of Page_load is as below: – Page_load::init – Page_load::insert – P...
A utility class which, if inherited from, prevents the descendant class from being copied,...
Definition: ut0class_life_cycle.h:40
Definition: db0err.h:38
Data dictionary system.
static Value err()
Create a Value object that represents an error condition.
Definition: varlen_sort.h:174
This file contains a set of libraries providing overloads for regular dynamic allocation routines whi...
Definition: aligned_alloc.h:47
std::vector< T, ut::allocator< T > > vector
Specialization of vector which uses allocator.
Definition: ut0new.h:2873
The page cursor.
Interface to consume from.
Definition: btr0load.h:53
virtual dberr_t fetch(dtuple_t *&dtuple) noexcept=0
Fetch the current row as a tuple.
virtual ~Cursor()=default
virtual dberr_t next() noexcept=0
Move to the next record.
virtual bool duplicates_detected() const noexcept=0
Storage format for overflow data in a big record, that is, a clustered index record which needs exter...
Definition: data0data.h:837
Data structure for an index.
Definition: dict0mem.h:1045
Structure for an SQL data tuple of fields (logical record)
Definition: data0data.h:681
ib_id_t trx_id_t
Transaction identifier (DB_TRX_ID, DATA_TRX_ID)
Definition: trx0types.h:137
#define IF_DEBUG(...)
Definition: univ.i:673
Utilities related to class lifecycle.
Dynamic memory allocation routines and custom allocators specifically crafted to support memory instr...