MySQL 8.0.31
Source Code Documentation
ddl0impl-merge.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2020, 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-merge.h
28 DDL cluster merge sort data structures.
29 Created 2020-11-01 by Sunny Bains. */
30
31#ifndef ddl0impl_merge_h
32#define ddl0impl_merge_h
33
35
36namespace ddl {
37
38// Forward declaration.
39struct Builder;
40
41/** Merge the blocks in the file. */
43 // Forward declarations.
44 struct Cursor;
45 struct Output_file;
46
47 /** The design is generalized as an N way merge, however we stick
48 with 2 for now. */
49 static constexpr size_t N_WAY_MERGE = 2;
50
51 /** Context to use for merging the files/runs. */
52 struct Context {
53 /** File to sort. */
55
56 /** For reporting duplicates, it has the index instance too. */
58
59 /** Number of scan threads used, for memory buffer calculation. */
60 size_t m_n_threads{};
61
62 /** PFS progress monitoring. */
64 };
65
66 /** Start of the record lists to merge. */
67 using Range = std::pair<os_offset_t, os_offset_t>;
68
69 /** Constructor.
70 @param[in,out] merge_ctx Data blocks merge meta data. */
71 explicit Merge_file_sort(Context *merge_ctx) noexcept
72 : m_merge_ctx(merge_ctx) {}
73
74 /** Merge the the blocks.
75 @param[in,out] builder Builder instance used for building index.
76 @param[in,out] offsets Offsets from where to start the merge.
77 @return DB_SUCCESS or error code. */
78 [[nodiscard]] dberr_t sort(Builder *builder, Merge_offsets &offsets) noexcept;
79
80 /** @return the number of rows in the sorted file. */
81 [[nodiscard]] uint64_t get_n_rows() const noexcept { return m_n_rows; }
82
83 private:
84 /** Merge the rows.
85 @param[in,out] cursor To iterate over the rows to merge.
86 @param[in,out] output_file Output file to write the merged rows.
87 @return DB_SUCCESS or error code. */
88 [[nodiscard]] dberr_t merge_rows(Cursor &cursor,
89 Output_file &output_file) noexcept;
90
91 /** Merge the blocks in the ranges.
92 @param[in,out] cursor To iterate over the rows to merge.
93 @param[in,out] offsets Starting offsets of record lists to merge.
94 @param[in,out] output_file Output file to write the merged rows.
95 @param[in] buffer_size IO buffer size for reads.
96 @return DB_SUCCESS or error code. */
97 [[nodiscard]] dberr_t merge_ranges(Cursor &cursor, Merge_offsets &offsets,
98 Output_file &output_file,
99 size_t buffer_size) noexcept;
100
101 /** Move to the next range of pages to merge.
102 @param[in,out] offsets Current offsets to start the merge from.
103 @return the next range to merge. */
104 Range next_range(Merge_offsets &offsets) noexcept;
105
106 private:
107 /** To check and report duplicates. */
109
110 /** Meta data for merging blocks. */
112
113 /** Page numbers to merge for the next pass. */
115
116 /** Number of rows in the sorted file. */
117 uint64_t m_n_rows{};
118};
119
120} // namespace ddl
121
122#endif /* !ddl0impl_merge_h */
Class used to report ALTER TABLE progress via performance_schema.
Definition: ut0stage.h:80
dberr_t
Definition: db0err.h:38
For scanning the temporary file.
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
size_t buffer_size(const ConstBufferSequence &buffers) noexcept
Definition: buffer.h:313
For loading indexes.
Definition: ddl0impl-builder.h:47
Cursor for reading the data.
Definition: ddl0impl-cursor.h:40
Structure for reporting duplicate records.
Definition: ddl0ddl.h:131
Context to use for merging the files/runs.
Definition: ddl0impl-merge.h:52
Alter_stage * m_stage
PFS progress monitoring.
Definition: ddl0impl-merge.h:63
size_t m_n_threads
Number of scan threads used, for memory buffer calculation.
Definition: ddl0impl-merge.h:60
Dup * m_dup
For reporting duplicates, it has the index instance too.
Definition: ddl0impl-merge.h:57
ddl::file_t * m_file
File to sort.
Definition: ddl0impl-merge.h:54
Cursor for merging blocks from the same file.
Definition: ddl0merge.cc:52
For writing out the merged rows.
Definition: ddl0merge.cc:107
Merge the blocks in the file.
Definition: ddl0impl-merge.h:42
uint64_t m_n_rows
Number of rows in the sorted file.
Definition: ddl0impl-merge.h:117
dberr_t merge_rows(Cursor &cursor, Output_file &output_file) noexcept
Merge the rows.
Definition: ddl0merge.cc:403
std::pair< os_offset_t, os_offset_t > Range
Start of the record lists to merge.
Definition: ddl0impl-merge.h:67
Dup * m_dup
To check and report duplicates.
Definition: ddl0impl-merge.h:108
Merge_file_sort(Context *merge_ctx) noexcept
Constructor.
Definition: ddl0impl-merge.h:71
Range next_range(Merge_offsets &offsets) noexcept
Move to the next range of pages to merge.
Definition: ddl0merge.cc:385
Context * m_merge_ctx
Meta data for merging blocks.
Definition: ddl0impl-merge.h:111
Merge_offsets m_next_offsets
Page numbers to merge for the next pass.
Definition: ddl0impl-merge.h:114
static constexpr size_t N_WAY_MERGE
The design is generalized as an N way merge, however we stick with 2 for now.
Definition: ddl0impl-merge.h:49
dberr_t merge_ranges(Cursor &cursor, Merge_offsets &offsets, Output_file &output_file, size_t buffer_size) noexcept
Merge the blocks in the ranges.
Definition: ddl0merge.cc:430
dberr_t sort(Builder *builder, Merge_offsets &offsets) noexcept
Merge the the blocks.
Definition: ddl0merge.cc:469
uint64_t get_n_rows() const noexcept
Definition: ddl0impl-merge.h:81
Information about temporary files used in merge sort.
Definition: ddl0impl.h:66