| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 2005, 2026, Oracle and/or its affiliates. |
| 4 |
|
| 5 |
This program is free software; you can redistribute it and/or modify it under |
| 6 |
the terms of the GNU General Public License, version 2.0, as published by the |
| 7 |
Free Software Foundation. |
| 8 |
|
| 9 |
This program is designed to work with certain software (including |
| 10 |
but not limited to OpenSSL) that is licensed under separate terms, |
| 11 |
as designated in a particular file or component or in included license |
| 12 |
documentation. The authors of MySQL hereby grant you an additional |
| 13 |
permission to link the program and your derivative works with the |
| 14 |
separately licensed software that they have either included with |
| 15 |
the program or referenced in the documentation. |
| 16 |
|
| 17 |
This program is distributed in the hope that it will be useful, but WITHOUT |
| 18 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 19 |
FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, |
| 20 |
for more details. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License along with |
| 23 |
this program; if not, write to the Free Software Foundation, Inc., |
| 24 |
51 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 |
|
| 40 |
namespace ddl { |
| 41 |
|
| 42 |
/** Cluster index ID (always the first index). */ |
| 43 |
static constexpr size_t SERVER_CLUSTER_INDEX_ID = 0; |
| 44 |
|
| 45 |
/** @brief Block size for DDL I/O operations. The minimum is UNIV_PAGE_SIZE, |
| 46 |
or page_get_free_space_of_empty() rounded to a power of 2. */ |
| 47 |
using IO_buffer = std::pair<byte *, os_offset_t>; |
| 48 |
|
| 49 |
/** Called when a log free check is required. */ |
| 50 |
using 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. |
| 58 |
struct Cursor; |
| 59 |
struct Builder; |
| 60 |
|
| 61 |
using Builders = std::vector<Builder *, ut::allocator<Builder *>>; |
| 62 |
|
| 63 |
/** Start offsets in the file, from where to merge records. */ |
| 64 |
using Merge_offsets = std::deque<os_offset_t, ut::allocator<os_offset_t>>; |
| 65 |
|
| 66 |
/** Information about temporary files used in merge sort */ |
| 67 |
struct file_t { |
| 68 |
/** File. */ |
| 69 |
Unique_os_file_descriptor m_file; |
| 70 |
|
| 71 |
/** Size of the file in bytes. */ |
| 72 |
os_offset_t m_size; |
| 73 |
|
| 74 |
/** Number of records in the file */ |
| 75 |
uint64_t m_n_recs{}; |
| 76 |
}; |
| 77 |
|
| 78 |
/** Fetch the document ID from the table. */ |
| 79 |
struct Fetch_sequence : public Context::FTS::Sequence { |
| 80 |
/** Constructor. |
| 81 |
@param[in] index Document ID index. */ |
| 82 |
explicit Fetch_sequence(dict_index_t *index) noexcept : m_index(index) { |
| 83 |
ut_a(m_index->type & DICT_FTS); |
| 84 |
m_max_doc_id = m_doc_id = 0; |
| 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. */ |
| 114 |
dict_index_t *m_index{}; |
| 115 |
|
| 116 |
/** Maximum document ID seen so far. */ |
| 117 |
doc_id_t m_max_doc_id{}; |
| 118 |
}; |
| 119 |
|
| 120 |
/** Physical row context. */ |
| 121 |
struct 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. */ |
| 142 |
row_ext_t *m_ext{}; |
| 143 |
|
| 144 |
/** Column offsets. */ |
| 145 |
ulint *m_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. */ |
| 154 |
dtuple_t *m_add_cols{}; |
| 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 */ |
| 169 |
dberr_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 */ |