MySQL 9.0.0
Source Code Documentation
ddl0impl-file-reader.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-file-reader.h
29 For scanning the temporary file.
30 Created 2020-11-01 by Sunny Bains. */
31
32#ifndef ddl0impl_file_reader_h
33#define ddl0impl_file_reader_h
34
35#include "ddl0impl-buffer.h"
36
37namespace ddl {
38
39// Forward declaration
40struct File_cursor;
41
42/** Read rows from the temporary file. */
43struct File_reader : private ut::Non_copyable {
44 /** Constructor.
45 @param[in] file Opened file.
46 @param[in,out] index Index that the rows belong to.
47 @param[in] buffer_size Size of file buffer for reading.
48 @param[in] size File size in bytes. */
50 size_t buffer_size, os_offset_t size) noexcept
52 ut_a(size > 0);
54 ut_a(m_index != nullptr);
56 }
57
58 /** Destructor. */
59 ~File_reader() noexcept {
60 if (m_aux_buf != nullptr) {
62 }
63 }
64
65 /** Prepare the file for reading.
66 @return DB_SUCCESS or error code. */
67 [[nodiscard]] dberr_t prepare() noexcept;
68
69 /** The current row as a tuple. Note: the tuple only does a shallow copy.
70 @param[in,out] builder Index builder instance.
71 @param[in,out] heap Heap to use for allocation.
72 @param[out] dtuple Row converted to a tuple.
73 @return DB_SUCCESS or error code. */
74 [[nodiscard]] dberr_t get_tuple(Builder *builder, mem_heap_t *heap,
75 dtuple_t *&dtuple) noexcept;
76
77 /** Seek to the offset and read the page in.
78 @param[in] offset Offset to read in.
79 @return DB_SUCCESS or error code. */
80 dberr_t read(os_offset_t offset) noexcept;
81
82 /** Set the range or rows to traverse.
83 @param[in] offset New offset to read from. */
84 void set_offset(os_offset_t offset) noexcept { m_offset = offset; }
85
86 /** @return true if the range first == second. */
87 [[nodiscard]] bool eof() const noexcept { return m_offset == m_size; }
88
89 /** @return the number of rows read from the file. */
90 [[nodiscard]] uint64_t get_n_rows_read() const noexcept {
91 return m_n_rows_read;
92 }
93
94 private:
95 /** Seek to the start of the range and load load the page.
96 @param[in] offset Offset to read in.
97 @return DB_SUCCESS or error code. */
98 [[nodiscard]] dberr_t seek(os_offset_t offset) noexcept;
99
100 /** Advance page number to the next and read in.
101 @return DB_SUCCESS or error code. */
102 [[nodiscard]] dberr_t read_next() noexcept;
103
104 /** Advance the "cursor".
105 @return DB_SUCCESS or error code. */
106 [[nodiscard]] dberr_t next() noexcept;
107
108 public:
109 using Offsets = std::vector<ulint, ut::allocator<ulint>>;
110
111 /** Index that the records belong to. */
113
114 /** Pointer to current row. */
115 const mrec_t *m_mrec{};
116
117 /** Columns offsets. */
119
120 /** File handle to read from. */
122
123 private:
124 using Bounds = std::pair<const byte *, const byte *>;
125
126 /** Size of the file in bytes. */
128
129 /** Offset to read. */
131
132 /** Pointer current offset within file buffer. */
133 const byte *m_ptr{};
134
135 /** File buffer bounds. */
137
138 /** Auxiliary buffer for records that span across pages. */
139 byte *m_aux_buf{};
140
141 /** IO buffer size in bytes. */
143
144 /** Aligned IO buffer. */
146
147 /** File buffer for reading. */
149
150 /** Number of rows read from the file. */
151 uint64_t m_n_rows_read{};
152
154};
155
156} // namespace ddl
157
158#endif /* ddl0impl_file_reader_h */
Captures ownership and manages lifetime of an already opened OS file descriptor.
Definition: ddl0ddl.h:161
bool is_open() const
Definition: ddl0ddl.h:179
A utility class which, if inherited from, prevents the descendant class from being copied,...
Definition: ut0class_life_cycle.h:41
dberr_t
Definition: db0err.h:39
DDL buffer infrastructure.
The general architecture is that the work is done in two phases, roughly the read and write phase.
Definition: btr0load.cc:42
byte mrec_t
Merge record in Aligned_buffer.
Definition: ddl0ddl.h:78
std::pair< byte *, os_offset_t > IO_buffer
Block size for DDL I/O operations.
Definition: ddl0impl.h:47
Definition: os0file.h:89
size_t size(const char *const c)
Definition: base64.h:46
size_t buffer_size(const ConstBufferSequence &buffers) noexcept
Definition: buffer.h:313
Definition: gcs_xcom_synode.h:64
This file contains a set of libraries providing overloads for regular dynamic allocation routines whi...
Definition: aligned_alloc.h:48
std::vector< T, ut::allocator< T > > vector
Specialization of vector which uses allocator.
Definition: ut0new.h:2875
void delete_arr(T *ptr) noexcept
Releases storage which has been dynamically allocated through any of the ut::new_arr*() variants.
Definition: ut0new.h:1110
std::conditional_t< !std::is_array< T >::value, std::unique_ptr< T, detail::Aligned_deleter< T > >, std::conditional_t< detail::is_unbounded_array_v< T >, std::unique_ptr< T, detail::Aligned_array_deleter< std::remove_extent_t< T > > >, void > > unique_ptr_aligned
The following is a common type that is returned by all the ut::make_unique_aligned (non-aligned) spec...
Definition: ut0new.h:2573
uint64_t os_offset_t
File offset in bytes.
Definition: os0file.h:87
For loading indexes.
Definition: ddl0impl-builder.h:48
Read rows from the temporary file.
Definition: ddl0impl-file-reader.h:43
std::vector< ulint, ut::allocator< ulint > > Offsets
Definition: ddl0impl-file-reader.h:109
uint64_t m_n_rows_read
Number of rows read from the file.
Definition: ddl0impl-file-reader.h:151
void set_offset(os_offset_t offset) noexcept
Set the range or rows to traverse.
Definition: ddl0impl-file-reader.h:84
Bounds m_bounds
File buffer bounds.
Definition: ddl0impl-file-reader.h:136
size_t m_buffer_size
IO buffer size in bytes.
Definition: ddl0impl-file-reader.h:142
os_offset_t m_offset
Offset to read.
Definition: ddl0impl-file-reader.h:130
uint64_t get_n_rows_read() const noexcept
Definition: ddl0impl-file-reader.h:90
dberr_t read(os_offset_t offset) noexcept
Seek to the offset and read the page in.
Definition: ddl0file-reader.cc:110
const byte * m_ptr
Pointer current offset within file buffer.
Definition: ddl0impl-file-reader.h:133
const Unique_os_file_descriptor & m_file
File handle to read from.
Definition: ddl0impl-file-reader.h:121
dberr_t seek(os_offset_t offset) noexcept
Seek to the start of the range and load load the page.
Definition: ddl0file-reader.cc:97
byte * m_aux_buf
Auxiliary buffer for records that span across pages.
Definition: ddl0impl-file-reader.h:139
dict_index_t * m_index
Index that the records belong to.
Definition: ddl0impl-file-reader.h:112
bool eof() const noexcept
Definition: ddl0impl-file-reader.h:87
friend File_cursor
Definition: ddl0impl-file-reader.h:153
const mrec_t * m_mrec
Pointer to current row.
Definition: ddl0impl-file-reader.h:115
dberr_t next() noexcept
Advance the "cursor".
Definition: ddl0file-reader.cc:126
dberr_t get_tuple(Builder *builder, mem_heap_t *heap, dtuple_t *&dtuple) noexcept
The current row as a tuple.
Definition: ddl0builder.cc:235
IO_buffer m_io_buffer
File buffer for reading.
Definition: ddl0impl-file-reader.h:148
~File_reader() noexcept
Destructor.
Definition: ddl0impl-file-reader.h:59
dberr_t read_next() noexcept
Advance page number to the next and read in.
Definition: ddl0file-reader.cc:121
os_offset_t m_size
Size of the file in bytes.
Definition: ddl0impl-file-reader.h:127
Offsets m_offsets
Columns offsets.
Definition: ddl0impl-file-reader.h:118
File_reader(const Unique_os_file_descriptor &file, dict_index_t *index, size_t buffer_size, os_offset_t size) noexcept
Constructor.
Definition: ddl0impl-file-reader.h:49
ut::unique_ptr_aligned< byte[]> m_aligned_buffer
Aligned IO buffer.
Definition: ddl0impl-file-reader.h:145
std::pair< const byte *, const byte * > Bounds
Definition: ddl0impl-file-reader.h:124
dberr_t prepare() noexcept
Prepare the file for reading.
Definition: ddl0file-reader.cc:39
Data structure for an index.
Definition: dict0mem.h:1046
Structure for an SQL data tuple of fields (logical record)
Definition: data0data.h:684
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:302
unsigned long int ulint
Definition: univ.i:406
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:93