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