Debian Codegraph @

storage/innobase/include/ddl0impl-rtree.h

raw
1
2 /*****************************************************************************
3
4 Copyright (c) 2020, 2026, Oracle and/or its affiliates.
5
6 This program is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License, version 2.0, as published by the
8 Free Software Foundation.
9
10 This program is designed to work with certain software (including
11 but not limited to OpenSSL) that is licensed under separate terms,
12 as designated in a particular file or component or in included license
13 documentation. The authors of MySQL hereby grant you an additional
14 permission to link the program and your derivative works with the
15 separately licensed software that they have either included with
16 the program or referenced in the documentation.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
21 for more details.
22
23 You should have received a copy of the GNU General Public License along with
24 this program; if not, write to the Free Software Foundation, Inc.,
25 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
27 *****************************************************************************/
28
29 /** @file include/ddl0impl-rtree.h
30 DDL RTree insert interface.
31 Created 2020-11-01 by Sunny Bains. */
32
33 #ifndef ddl0impl_rtree_h
34 #define ddl0impl_rtree_h
35
36 #include "ddl0fts.h"
37 #include "ddl0impl.h"
38 #include "row0pread.h"
39
40 namespace ddl {
41
42 /** Class that caches RTree index tuples made from a single cluster
43 index page scan, and then insert into corresponding index tree. */
44 class RTree_inserter {
45 public:
46 /** Constructor.
47 @param[in,out] ctx DDL context.
48 @param[in] index Index to be created */
49 RTree_inserter(Context &ctx, dict_index_t *index) noexcept;
50
51 /** Destructor */
52 ~RTree_inserter() noexcept;
53
54 /** @return true if initialization succeeded . */
55 [[nodiscard]] bool is_initialized() noexcept {
56 return m_dtuple_heap != nullptr && m_dml_heap != nullptr;
57 }
58
59 /** Get the index instance.
60 @return the index instance. */
61 [[nodiscard]] dict_index_t *get_index() noexcept { return m_index; }
62
63 /** Caches an index row into index tuple vector
64 @param[in] row Table row
65 @param[in] ext Externally stored column
66 prefixes, or nullptr */
67 void add_to_batch(const dtuple_t *row, const row_ext_t *ext) noexcept;
68
69 /** Insert the rows cached in the batch (m_dtuples).
70 @param[in] trx_id Transaction id.
71 @param[in,out] latch_release Called when a log free check is required.
72 @return DB_SUCCESS if successful, else error number */
73 [[nodiscard]] dberr_t batch_insert(trx_id_t trx_id,
74 Latch_release &&latch_release) noexcept;
75
76 /** Deep copy the fields pointing to the clustered index record. */
77 void deep_copy_tuples() noexcept { deep_copy_tuples(m_dtuples->begin()); }
78
79 private:
80 /** Cache index rows made from a cluster index scan. Usually
81 for rows on single cluster index page */
82 using Tuples = std::vector<dtuple_t *, ut::allocator<dtuple_t *>>;
83
84 /** Deep copy the fields pointing to the clustered index record.
85 @param[in] it Deep copy from this tuple onwards. */
86 void deep_copy_tuples(Tuples::iterator it) noexcept;
87
88 private:
89 /** vector used to cache index rows made from cluster index scan */
90 Tuples *m_dtuples{};
91
92 /** Memory heap for creating index tuples */
93 mem_heap_t *m_dtuple_heap{};
94
95 /** Memory heap for inserting the tuples */
96 mem_heap_t *m_dml_heap{};
97
98 /** the index being built */
99 dict_index_t *m_index{};
100
101 /** Iterator to process m_dtuples */
102 Tuples::iterator m_iter{};
103
104 /** DDL context. */
105 Context &m_ctx;
106 };
107
108 } // namespace ddl
109
110 #endif /* !ddl0impl-rtree_h */