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