| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 2020, 2026, Oracle and/or its affiliates. |
| 4 |
|
| 5 |
This program is free software; you can redistribute it and/or modify it under |
| 6 |
the terms of the GNU General Public License, version 2.0, as published by the |
| 7 |
Free Software Foundation. |
| 8 |
|
| 9 |
This program is designed to work with certain software (including |
| 10 |
but not limited to OpenSSL) that is licensed under separate terms, |
| 11 |
as designated in a particular file or component or in included license |
| 12 |
documentation. The authors of MySQL hereby grant you an additional |
| 13 |
permission to link the program and your derivative works with the |
| 14 |
separately licensed software that they have either included with |
| 15 |
the program or referenced in the documentation. |
| 16 |
|
| 17 |
This program is distributed in the hope that it will be useful, but WITHOUT |
| 18 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 19 |
FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, |
| 20 |
for more details. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License along with |
| 23 |
this program; if not, write to the Free Software Foundation, Inc., |
| 24 |
51 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 |
|
| 38 |
namespace ddl { |
| 39 |
|
| 40 |
/** Cursor for reading the data. */ |
| 41 |
struct 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) { |
| 51 |
ut::free(m_prev_fields); |
| 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 = |
| 79 |
ut::malloc_withkey(UT_NEW_THIS_FILE_PSI_KEY, n_uniq * sizeof(dfield_t)); |
| 80 |
|
| 81 |
if (p == nullptr) { |
| 82 |
return DB_OUT_OF_MEMORY; |
| 83 |
} |
| 84 |
|
| 85 |
m_prev_fields = static_cast<dfield_t *>(p); |
| 86 |
|
| 87 |
m_tuple_heap.create(sizeof(mrec_buf_t), UT_LOCATION_HERE); |
| 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. */ |
| 108 |
ddl::Context &m_ctx; |
| 109 |
|
| 110 |
/** Scoped heap to use for rows. */ |
| 111 |
Scoped_heap m_row_heap{}; |
| 112 |
|
| 113 |
/** Scoped heap to use for tuple instances. */ |
| 114 |
Scoped_heap m_tuple_heap{}; |
| 115 |
|
| 116 |
/** Previous fields. */ |
| 117 |
dfield_t *m_prev_fields{}; |
| 118 |
}; |
| 119 |
|
| 120 |
} // namespace ddl |
| 121 |
|
| 122 |
#endif /* !ddl0impl-cursor_h */ |