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