MySQL 26.7.0
Source Code Documentation
ddl0impl.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2005, 2026, 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. */
85 }
86
87 /** Destructor. */
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. */
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. It makes m_ptr point to data
133 found in m_rec, m_add_cols, ctx.m_add_v, handling ctx.m_fts.m_doc_id and
134 ctx.m_add_autoinc, too.
135 @param[in,out] ctx DDL context.
136 @param[in,out] heap Heap to use for allocation.
137 @return DB_SUCCESS or error code. */
138 [[nodiscard]] dberr_t build(ddl::Context &ctx, mem_heap_t *heap) noexcept;
139
140 /** Makes the row indpendent from the original buffers, i.e. the m_ptr
141 will point to fresh copies allocated from heap, instead of data inside m_rec,
142 or m_add_cols. The caller should first call build(..).
143 @param[in] heap Heap to use for allocation.
144 */
145 void deep_copy(mem_heap_t *heap) noexcept;
146
147 /** Externally stored fields. */
149
150 /** Column offsets. */
152
153 /** Row data. */
154 const rec_t *m_rec{};
155
156 /** DTuple data, mapped over m_rec. */
157 const dtuple_t *m_ptr{};
158
159 /** Add column data values. */
161};
162
163/** Create a merge file int the given location.
164@param[out] file Temporary generated during DDL.
165@param[in] path Location for creating temporary file
166@return true if file is created successfully */
167[[nodiscard]] bool file_create(file_t *file, const char *path) noexcept;
168
169/** Write a merge block to the file system.
170@param[in] fd File descriptor
171@param[in] ptr Buffer to write.
172@param[in] size Number of bytes to write.
173@param[in] offset Byte offset where to write.
174@return DB_SUCCESS or error code */
175dberr_t pwrite(os_fd_t fd, byte *ptr, size_t size, os_offset_t offset) noexcept;
176
177/** Read a merge block from the file system.
178@param[in] fd file descriptor.
179@param[out] ptr Buffer to read into.
180@param[in] len Number of bytes to read.
181@param[in] offset Byte offset to start reading from.
182@return DB_SUCCESS or error code */
183[[nodiscard]] dberr_t pread(os_fd_t fd, byte *ptr, size_t len,
184 os_offset_t offset) noexcept;
185
186} // namespace ddl
187
188#endif /* ddl0impl_h */
Captures ownership and manages lifetime of an already opened OS file descriptor.
Definition: ddl0ddl.h:200
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:105
uint64_t doc_id_t
Document id type.
Definition: fts0fts.h:76
static char * path
Definition: mysqldump.cc:151
The general architecture is that the work is done in two phases, roughly the read and write phase.
Definition: btr0load.cc:43
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
dberr_t pwrite(os_fd_t fd, byte *ptr, size_t len, os_offset_t offset) noexcept
Write a merge block to the file system.
Definition: ddl0ddl.cc:115
bool file_create(ddl::file_t *file, const char *path) noexcept
Create a merge file int the given location.
Definition: ddl0ddl.cc:176
dberr_t pread(os_fd_t fd, byte *ptr, size_t len, os_offset_t offset) noexcept
Read a merge block from the file system.
Definition: ddl0ddl.cc:98
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
bool index(const std::string &value, const String &search_for, uint32_t *idx)
Definition: contains.h:76
noexcept
The return type for any call_and_catch(f, args...) call where f(args...) returns Type.
Definition: call_and_catch.h:76
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
For loading indexes.
Definition: ddl0impl-builder.h:48
Document ID sequence.
Definition: ddl0ddl.h:364
doc_id_t m_doc_id
Current document ID.
Definition: ddl0ddl.h:391
DDL context/configuration.
Definition: ddl0ddl.h:360
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.
void deep_copy(mem_heap_t *heap) noexcept
Makes the row indpendent from the original buffers, i.e.
Definition: ddl0ddl.cc:535
dberr_t build(ddl::Context &ctx, mem_heap_t *heap) noexcept
Build a row from a raw record.
Definition: ddl0ddl.cc:503
row_ext_t * m_ext
Externally stored fields.
Definition: ddl0impl.h:148
dtuple_t * m_add_cols
Add column data values.
Definition: ddl0impl.h:160
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:157
ulint * m_offsets
Column offsets.
Definition: ddl0impl.h:151
const rec_t * m_rec
Row data.
Definition: ddl0impl.h:154
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:1069
unsigned type
index type (DICT_CLUSTERED, DICT_UNIQUE, DICT_IBUF, DICT_CORRUPT)
Definition: dict0mem.h:1096
Structure for an SQL data tuple of fields (logical record)
Definition: data0data.h:706
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:295
Prefixes of externally stored columns.
Definition: row0ext.h:95
unsigned long int ulint
Definition: univ.i:403
Utilities related to class lifecycle.
#define ut_error
Abort execution.
Definition: ut0dbg.h:105
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:97