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