MySQL 9.0.0
Source Code Documentation
ddl0impl-cursor.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-cursor.h
29 DDL scan cursor interface.
30 Created 2020-11-01 by Sunny Bains. */
31
32#ifndef ddl0impl_cursor_h
33#define ddl0impl_cursor_h
34
35#include "ddl0fts.h"
36#include "ddl0impl.h"
37
38namespace ddl {
39
40/** Cursor for reading the data. */
41struct Cursor {
42 using Post_row = std::function<dberr_t()>;
43
44 /** Constructor.
45 @param[in,out] ctx DDL context. */
46 explicit Cursor(ddl::Context &ctx) noexcept : m_ctx(ctx) {}
47
48 /** Destructor. */
49 virtual ~Cursor() noexcept {
50 if (m_prev_fields != nullptr) {
52 m_prev_fields = nullptr;
53 }
54 }
55
56 /** Open the cursor. */
57 virtual void open() noexcept = 0;
58
59 /** Do any post processing.
60 @param[in] err Error code.
61 @return DB_SUCCESS or error code. */
62 virtual dberr_t finish(dberr_t err) noexcept;
63
64 /** @return the index to iterate over. */
65 [[nodiscard]] virtual dict_index_t *index() noexcept = 0;
66
67 /** Copy the row data, by default only the pointers are copied.
68 @param[in] thread_id Scan thread ID.
69 @param[in,out] row Row to copy.
70 @return DB_SUCCESS or error code. */
71 [[nodiscard]] virtual dberr_t copy_row(size_t thread_id,
72 Row &row) noexcept = 0;
73
74 /** Setup the primary key sort data structures.
75 @param[in] n_uniq Number of columns to make they unique key.
76 @return DB_SUCCESS or error code. */
77 [[nodiscard]] dberr_t setup_pk_sort(size_t n_uniq) noexcept {
78 auto p =
80
81 if (p == nullptr) {
82 return DB_OUT_OF_MEMORY;
83 }
84
85 m_prev_fields = static_cast<dfield_t *>(p);
86
88
89 return m_tuple_heap.get() == nullptr ? DB_OUT_OF_MEMORY : DB_SUCCESS;
90 }
91
92 /** Reads clustered index of the table and create temporary file(s)
93 containing the index entries for the indexes to be built.
94 @param[in,out] builders Merge buffers to use for reading.
95 @return DB_SUCCESS or error code. */
96 [[nodiscard]] virtual dberr_t scan(Builders &builders) noexcept = 0;
97
98 /** @return true if EOF reached. */
99 [[nodiscard]] virtual bool eof() const noexcept = 0;
100
101 /** Create a cluster index scan cursor.
102 @param[in,out] ctx DDL context.
103 @return a cursor instance or nullptr (if OOM). */
104 static Cursor *create_cursor(ddl::Context &ctx) noexcept;
105
106 public:
107 /** DDL context. */
109
110 /** Scoped heap to use for rows. */
112
113 /** Scoped heap to use for tuple instances. */
115
116 /** Previous fields. */
118};
119
120} // namespace ddl
121
122#endif /* !ddl0impl-cursor_h */
const char * p
Definition: ctype-mb.cc:1225
dberr_t
Definition: db0err.h:39
@ DB_OUT_OF_MEMORY
Definition: db0err.h:49
@ DB_SUCCESS
Definition: db0err.h:43
Create Full Text Index with (parallel) merge sort.
DDL implementation include file.
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
byte[UNIV_PAGE_SIZE_MAX] mrec_buf_t
Secondary buffer for I/O operations of merge records.
Definition: ddl0ddl.h:72
static Value err()
Create a Value object that represents an error condition.
Definition: json_binary.cc:927
void * malloc_withkey(PSI_memory_key_t key, std::size_t size) noexcept
Dynamically allocates storage of given size.
Definition: ut0new.h:597
void free(void *ptr) noexcept
Releases storage which has been dynamically allocated through any of the ut::malloc*(),...
Definition: ut0new.h:718
Heap wrapper that destroys the heap instance when it goes out of scope.
Definition: mem0mem.h:439
void create(size_t n, ut::Location location) noexcept
Create the heap, it must not already be created.
Definition: mem0mem.h:457
Type * get() noexcept
Definition: mem0mem.h:468
DDL context/configuration.
Definition: ddl0ddl.h:321
Cursor for reading the data.
Definition: ddl0impl-cursor.h:41
static Cursor * create_cursor(ddl::Context &ctx) noexcept
Create a cluster index scan cursor.
Definition: ddl0par-scan.cc:407
std::function< dberr_t()> Post_row
Definition: ddl0impl-cursor.h:42
virtual bool eof() const noexcept=0
virtual ~Cursor() noexcept
Destructor.
Definition: ddl0impl-cursor.h:49
Cursor(ddl::Context &ctx) noexcept
Constructor.
Definition: ddl0impl-cursor.h:46
Scoped_heap m_row_heap
Scoped heap to use for rows.
Definition: ddl0impl-cursor.h:111
ddl::Context & m_ctx
DDL context.
Definition: ddl0impl-cursor.h:108
dberr_t setup_pk_sort(size_t n_uniq) noexcept
Setup the primary key sort data structures.
Definition: ddl0impl-cursor.h:77
virtual dberr_t finish(dberr_t err) noexcept
Do any post processing.
Definition: ddl0ddl.cc:528
virtual void open() noexcept=0
Open the cursor.
virtual dict_index_t * index() noexcept=0
dfield_t * m_prev_fields
Previous fields.
Definition: ddl0impl-cursor.h:117
Scoped_heap m_tuple_heap
Scoped heap to use for tuple instances.
Definition: ddl0impl-cursor.h:114
virtual dberr_t copy_row(size_t thread_id, Row &row) noexcept=0
Copy the row data, by default only the pointers are copied.
virtual dberr_t scan(Builders &builders) noexcept=0
Reads clustered index of the table and create temporary file(s) containing the index entries for the ...
Physical row context.
Definition: ddl0impl.h:121
Structure for an SQL data field.
Definition: data0data.h:605
Data structure for an index.
Definition: dict0mem.h:1046
#define UT_LOCATION_HERE
Definition: ut0core.h:73
#define UT_NEW_THIS_FILE_PSI_KEY
Definition: ut0new.h:565