MySQL 8.4.2
Source Code Documentation
ddl0impl-loader.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2020, 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-loader.h
29 DDL index loader interface.
30 Created 2020-11-01 by Sunny Bains. */
31
32#ifndef ddl0impl_loader_h
33#define ddl0impl_loader_h
34
35#include "ddl0fts.h"
36#include "ddl0impl-buffer.h"
37#include "ut0mpmcbq.h"
38
39namespace ddl {
40
41/** Build indexes on a table by reading a clustered index, creating a temporary
42file containing index entries, merge sorting these index entries and inserting
43sorted index entries to indexes. */
44class Loader {
45 public:
46 /** Builder task. */
47 struct Task {
48 /** Constructor. */
49 Task() = default;
50
51 /** Constructor.
52 @param[in,out] builder Builder that performs the operation. */
53 explicit Task(Builder *builder) : m_builder(builder) {}
54
55 /** Constructor.
56 @param[in,out] builder Builder that performs the operation.
57 @param[in] thread_id Index value of the thread_state to work on. */
58 explicit Task(Builder *builder, size_t thread_id)
59 : m_builder(builder), m_thread_id(thread_id) {}
60
61 /** Do the operation.
62 @return DB_SUCCESS or error code. */
63 [[nodiscard]] dberr_t operator()() noexcept;
64
65 private:
66 /** Builder instance. */
68
69 /** Thread state index. */
70 size_t m_thread_id{std::numeric_limits<size_t>::max()};
71
72 friend class Loader;
73 };
74
75 // Forward declaration
76 class Task_queue;
77
78 /** Constructor.
79 @param[in,out] ctx DDL context. */
80 explicit Loader(ddl::Context &ctx) noexcept;
81
82 /** Destructor. */
83 ~Loader() noexcept;
84
85 /** Build the read instance.
86 @return DB_SUCCESS or error code. */
87 [[nodiscard]] dberr_t build_all() noexcept;
88
89 /** Add a task to the task queue.
90 @param[in] task Task to add. */
91 void add_task(Task task) noexcept;
92
93 /** Validate the indexes (except FTS).
94 @return true on success. */
95 [[nodiscard]] bool validate_indexes() const noexcept;
96
97 private:
98 /** Prepare to build and load the indexes.
99 @return DB_SUCCESS or error code. */
100 [[nodiscard]] dberr_t prepare() noexcept;
101
102 /** Load the indexes.
103 @return DB_SUCCESS or error code. */
104 [[nodiscard]] dberr_t load() noexcept;
105
106 /** Scan and build the indexes.
107 @return DB_SUCCESS or error code. */
108 [[nodiscard]] dberr_t scan_and_build_indexes() noexcept;
109
110 private:
111 /** DDL context, shared by the loader threads. */
113
114 /** If true then use parallel scan and index build. */
116
117 /** Sort buffer size. */
119
120 /** IO buffer size. */
122
123 /** Index builders. */
125
126 /** Task queue. */
128};
129
130} // namespace ddl
131
132#endif /* !ddl0impl_loader_h */
Unbounded task queue.
Definition: ddl0loader.cc:46
Build indexes on a table by reading a clustered index, creating a temporary file containing index ent...
Definition: ddl0impl-loader.h:44
dberr_t load() noexcept
Load the indexes.
Definition: ddl0loader.cc:289
bool validate_indexes() const noexcept
Validate the indexes (except FTS).
Definition: ddl0loader.cc:509
Builders m_builders
Index builders.
Definition: ddl0impl-loader.h:124
void add_task(Task task) noexcept
Add a task to the task queue.
Definition: ddl0loader.cc:287
size_t m_io_buffer_size
IO buffer size.
Definition: ddl0impl-loader.h:121
size_t m_sort_buffer_size
Sort buffer size.
Definition: ddl0impl-loader.h:118
Task_queue * m_taskq
Task queue.
Definition: ddl0impl-loader.h:127
~Loader() noexcept
Destructor.
Definition: ddl0loader.cc:267
dberr_t build_all() noexcept
Build the read instance.
Definition: ddl0loader.cc:477
Loader(ddl::Context &ctx) noexcept
Constructor.
Definition: ddl0loader.cc:265
dberr_t prepare() noexcept
Prepare to build and load the indexes.
Definition: ddl0loader.cc:366
dberr_t scan_and_build_indexes() noexcept
Scan and build the indexes.
Definition: ddl0loader.cc:398
ddl::Context & m_ctx
DDL context, shared by the loader threads.
Definition: ddl0impl-loader.h:112
bool m_parallel
If true then use parallel scan and index build.
Definition: ddl0impl-loader.h:115
dberr_t
Definition: db0err.h:39
Create Full Text Index with (parallel) merge sort.
DDL buffer infrastructure.
static my_thread_id thread_id
Definition: my_thr_init.cc:63
The general architecture is that the work is done in two phases, roughly the read and write phase.
Definition: btr0load.cc:42
std::vector< Builder *, ut::allocator< Builder * > > Builders
Definition: ddl0impl.h:61
For loading indexes.
Definition: ddl0impl-builder.h:48
DDL context/configuration.
Definition: ddl0ddl.h:321
Builder task.
Definition: ddl0impl-loader.h:47
size_t m_thread_id
Thread state index.
Definition: ddl0impl-loader.h:70
Task()=default
Constructor.
Builder * m_builder
Builder instance.
Definition: ddl0impl-loader.h:67
Task(Builder *builder)
Constructor.
Definition: ddl0impl-loader.h:53
dberr_t operator()() noexcept
Do the operation.
Definition: ddl0builder.cc:2132
Task(Builder *builder, size_t thread_id)
Constructor.
Definition: ddl0impl-loader.h:58