MySQL 8.4.2
Source Code Documentation
ddl0impl.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2005, 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
28/** @file include/ddl0impl.h
29 DDL implementation include file.
30 Created 2020-11-01 by Sunny Bains. */
31
32#ifndef ddl0impl_h
33#define ddl0impl_h
34
35#include "ddl0ddl.h"
36#include "dict0mem.h"
37#include "ut0class_life_cycle.h"
38#include "ut0mpmcbq.h"
39
40namespace ddl {
41
42/** Cluster index ID (always the first index). */
43static constexpr size_t SERVER_CLUSTER_INDEX_ID = 0;
44
45/** @brief Block size for DDL I/O operations. The minimum is UNIV_PAGE_SIZE,
46or page_get_free_space_of_empty() rounded to a power of 2. */
47using IO_buffer = std::pair<byte *, os_offset_t>;
48
49/** Called when a log free check is required. */
50using Latch_release = std::function<dberr_t()>;
51
52/* Ignore posix_fadvise() on those platforms where it does not exist */
53#if defined _WIN32
54#define posix_fadvise(fd, offset, len, advice) /* nothing */
55#endif /* _WIN32 */
56
57// Forward declaration.
58struct Cursor;
59struct Builder;
60
61using Builders = std::vector<Builder *, ut::allocator<Builder *>>;
62
63/** Start offsets in the file, from where to merge records. */
64using Merge_offsets = std::deque<os_offset_t, ut::allocator<os_offset_t>>;
65
66/** Information about temporary files used in merge sort */
67struct file_t {
68 /** File. */
70
71 /** Size of the file in bytes. */
73
74 /** Number of records in the file */
75 uint64_t m_n_recs{};
76};
77
78/** Fetch the document ID from the table. */
80 /** Constructor.
81 @param[in] index Document ID index. */
82 explicit Fetch_sequence(dict_index_t *index) noexcept : m_index(index) {
85 }
86
87 /** Destructor. */
88 ~Fetch_sequence() noexcept override {}
89
90 /** Not supported.
91 @return the current document ID. */
92 [[nodiscard]] doc_id_t current() noexcept override { ut_error; }
93
94 /** Not supported. */
95 void increment() noexcept override { ut_error; }
96
97 /** Get the next document ID.
98 @param[in] dtuple Row from which to fetch ID.
99 @return the document ID from the row. */
100 [[nodiscard]] doc_id_t fetch(const dtuple_t *dtuple) noexcept override;
101
102 /** @return the number of document IDs generated. */
103 doc_id_t generated_count() const noexcept override { ut_error; }
104
105 /** @return the maximum document ID seen so far. */
106 [[nodiscard]] doc_id_t max_doc_id() const noexcept override {
107 return m_max_doc_id;
108 }
109
110 /** @return false, because we never generate the document ID. */
111 [[nodiscard]] bool is_generated() const noexcept override { return false; }
112
113 /** The document ID index. */
115
116 /** Maximum document ID seen so far. */
118};
119
120/** Physical row context. */
121struct Row {
122 /** Constructor. */
123 Row() = default;
124
125 Row(const Row &) = default;
126
127 /** Destructor. */
128 ~Row() = default;
129
130 Row &operator=(const Row &) = default;
131
132 /** Build a row from a raw record.
133 @param[in,out] ctx DDL context.
134 @param[in,out] index Index the record belongs to.
135 @param[in,out] heap Heap to use for allocation.
136 @param[in] type Copy pointers or copy data.
137 @return DB_SUCCESS or error code. */
138 [[nodiscard]] dberr_t build(ddl::Context &ctx, dict_index_t *index,
139 mem_heap_t *heap, size_t type) noexcept;
140
141 /** Externally stored fields. */
143
144 /** Column offsets. */
146
147 /** Row data. */
148 const rec_t *m_rec{};
149
150 /** DTuple data, mapped over m_rec. */
151 const dtuple_t *m_ptr{};
152
153 /** Add column data values. */
155};
156
157/** Create a merge file int the given location.
158@param[out] file Temporary generated during DDL.
159@param[in] path Location for creating temporary file
160@return true if file is created successfully */
161[[nodiscard]] bool file_create(file_t *file, const char *path) noexcept;
162
163/** Write a merge block to the file system.
164@param[in] fd File descriptor
165@param[in] ptr Buffer to write.
166@param[in] size Number of bytes to write.
167@param[in] offset Byte offset where to write.
168@return DB_SUCCESS or error code */
169dberr_t pwrite(os_fd_t fd, void *ptr, size_t size, os_offset_t offset) noexcept;
170
171/** Read a merge block from the file system.
172@param[in] fd file descriptor.
173@param[out] ptr Buffer to read into.
174@param[in] len Number of bytes to read.
175@param[in] offset Byte offset to start reading from.
176@return DB_SUCCESS or error code */
177[[nodiscard]] dberr_t pread(os_fd_t fd, void *ptr, size_t len,
178 os_offset_t offset) noexcept;
179
180} // namespace ddl
181
182#endif /* ddl0impl_h */
Captures ownership and manages lifetime of an already opened OS file descriptor.
Definition: ddl0ddl.h:161
dberr_t
Definition: db0err.h:39
DDL context.
Data dictionary memory object creation.
constexpr uint32_t DICT_FTS
FTS index; can't be combined with the other flags.
Definition: dict0mem.h:104
uint64_t doc_id_t
Document id type.
Definition: fts0fts.h:79
static char * path
Definition: mysqldump.cc:149
The general architecture is that the work is done in two phases, roughly the read and write phase.
Definition: btr0load.cc:42
std::deque< os_offset_t, ut::allocator< os_offset_t > > Merge_offsets
Start offsets in the file, from where to merge records.
Definition: ddl0impl.h:64
bool file_create(ddl::file_t *file, const char *path) noexcept
Create a merge file int the given location.
Definition: ddl0ddl.cc:169
dberr_t pwrite(os_fd_t fd, void *ptr, size_t len, os_offset_t offset) noexcept
Write a merge block to the file system.
Definition: ddl0ddl.cc:111
dberr_t pread(os_fd_t fd, void *ptr, size_t len, os_offset_t offset) noexcept
Read a merge block from the file system.
Definition: ddl0ddl.cc:92
std::function< dberr_t()> Latch_release
Called when a log free check is required.
Definition: ddl0impl.h:50
static constexpr size_t SERVER_CLUSTER_INDEX_ID
Cluster index ID (always the first index).
Definition: ddl0impl.h:43
std::pair< byte *, os_offset_t > IO_buffer
Block size for DDL I/O operations.
Definition: ddl0impl.h:47
std::vector< Builder *, ut::allocator< Builder * > > Builders
Definition: ddl0impl.h:61
Definition: os0file.h:89
size_t size(const char *const c)
Definition: base64.h:46
int os_fd_t
Raw file handle.
Definition: os0file.h:115
uint64_t os_offset_t
File offset in bytes.
Definition: os0file.h:87
byte rec_t
Definition: rem0types.h:41
required string type
Definition: replication_group_member_actions.proto:34
For loading indexes.
Definition: ddl0impl-builder.h:48
Document ID sequence.
Definition: ddl0ddl.h:325
doc_id_t m_doc_id
Current document ID.
Definition: ddl0ddl.h:352
DDL context/configuration.
Definition: ddl0ddl.h:321
Cursor for reading the data.
Definition: ddl0impl-cursor.h:41
Fetch the document ID from the table.
Definition: ddl0impl.h:79
doc_id_t m_max_doc_id
Maximum document ID seen so far.
Definition: ddl0impl.h:117
void increment() noexcept override
Not supported.
Definition: ddl0impl.h:95
doc_id_t current() noexcept override
Not supported.
Definition: ddl0impl.h:92
doc_id_t max_doc_id() const noexcept override
Definition: ddl0impl.h:106
doc_id_t generated_count() const noexcept override
Definition: ddl0impl.h:103
bool is_generated() const noexcept override
Definition: ddl0impl.h:111
doc_id_t fetch(const dtuple_t *dtuple) noexcept override
Get the next document ID.
Definition: ddl0ddl.cc:55
dict_index_t * m_index
The document ID index.
Definition: ddl0impl.h:114
Fetch_sequence(dict_index_t *index) noexcept
Constructor.
Definition: ddl0impl.h:82
~Fetch_sequence() noexcept override
Destructor.
Definition: ddl0impl.h:88
Physical row context.
Definition: ddl0impl.h:121
Row()=default
Constructor.
row_ext_t * m_ext
Externally stored fields.
Definition: ddl0impl.h:142
dtuple_t * m_add_cols
Add column data values.
Definition: ddl0impl.h:154
Row(const Row &)=default
~Row()=default
Destructor.
Row & operator=(const Row &)=default
const dtuple_t * m_ptr
DTuple data, mapped over m_rec.
Definition: ddl0impl.h:151
ulint * m_offsets
Column offsets.
Definition: ddl0impl.h:145
dberr_t build(ddl::Context &ctx, dict_index_t *index, mem_heap_t *heap, size_t type) noexcept
Build a row from a raw record.
Definition: ddl0ddl.cc:496
const rec_t * m_rec
Row data.
Definition: ddl0impl.h:148
Information about temporary files used in merge sort.
Definition: ddl0impl.h:67
uint64_t m_n_recs
Number of records in the file.
Definition: ddl0impl.h:75
Unique_os_file_descriptor m_file
File.
Definition: ddl0impl.h:69
os_offset_t m_size
Size of the file in bytes.
Definition: ddl0impl.h:72
Data structure for an index.
Definition: dict0mem.h:1046
unsigned type
index type (DICT_CLUSTERED, DICT_UNIQUE, DICT_IBUF, DICT_CORRUPT)
Definition: dict0mem.h:1073
Structure for an SQL data tuple of fields (logical record)
Definition: data0data.h:682
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:302
Prefixes of externally stored columns.
Definition: row0ext.h:95
unsigned long int ulint
Definition: univ.i:406
Utilities related to class lifecycle.
#define ut_error
Abort execution.
Definition: ut0dbg.h:101
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:93