MySQL 8.0.39
Source Code Documentation
tablespace_id_owner_visitor.h
Go to the documentation of this file.
1/* Copyright (c) 2019, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef DD__TABLESPACE_ID_OWNER_VISITOR_INCLUDED
25#define DD__TABLESPACE_ID_OWNER_VISITOR_INCLUDED
26
27#include "sql/dd/types/index.h" // dd::Index
28#include "sql/dd/types/partition.h" // dd::Partition
29#include "sql/dd/types/partition_index.h" // dd::Partition_index
30#include "sql/dd/types/table.h" // dd::Table
31
32namespace dd {
33/**
34 Visitor function which invokes its visitor argument on any subobject
35 which holds a tablespace, that is, the partition itself, its
36 Partition_indexes, its sub-partitions, and Partition_indexes of those.
37 Visitation is terminated when the vistor closure returns true.
38
39 @param p partition to visit.
40
41 @param visitor generic closure which can be applied to all
42 tablespace holding objects.
43
44 @return value of last visitor invocation.
45*/
46template <class VISITOR_TYPE>
47bool visit_tablespace_id_owners(const Partition &p, VISITOR_TYPE &&visitor) {
48 if (visitor(p)) {
49 return true;
50 }
51
52 // Visit indexes for top-level partition
53 for (const Partition_index *pi : p.indexes()) {
54 if (visitor(*pi)) {
55 return true;
56 }
57 }
58
59 // Visit subpartitions, if any
60 for (const Partition *sp : p.subpartitions()) {
61 if (visitor(*sp)) {
62 return true;
63 }
64 // Visit indexes for subpartition
65 for (const Partition_index *spi : sp->indexes()) {
66 if (visitor(*spi)) {
67 return true;
68 }
69 }
70 }
71 return false;
72}
73
74/**
75 Visitor function which invokes its visitor argument on any subobject
76 which holds a tablespace, that is, the table itself, its m_indexes,
77 its m_partitions, and m_indexes (Partition_index) of each
78 partition and sub-partition. Visitation is terminated when the vistor closure
79 returns true.
80
81 @param t table to visit.
82
83 @param visitor generic closure which can be applied to all
84 tablespace holding objects.
85
86 @return value of last visitor invocation.
87*/
88template <class VISITOR_TYPE>
89bool visit_tablespace_id_owners(const Table &t, VISITOR_TYPE &&visitor) {
90 if (visitor(t)) {
91 return true;
92 }
93 for (const Index *i : t.indexes()) {
94 if (visitor(*i)) {
95 return true;
96 }
97 }
98 for (const Partition *p : t.partitions()) {
99 if (visit_tablespace_id_owners(*p, std::forward<VISITOR_TYPE>(visitor))) {
100 return true;
101 }
102 }
103 return false;
104}
105} // namespace dd
106
107#endif
Definition: index.h:51
Definition: partition_index.h:47
Definition: partition.h:51
Definition: table.h:47
virtual const Index_collection & indexes() const =0
virtual const Partition_collection & partitions() const =0
const char * p
Definition: ctype-mb.cc:1237
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:43
bool visit_tablespace_id_owners(const Partition &p, VISITOR_TYPE &&visitor)
Visitor function which invokes its visitor argument on any subobject which holds a tablespace,...
Definition: tablespace_id_owner_visitor.h:47