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