1 /* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
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__PARTITION_INDEX_IMPL_INCLUDED
24 #define DD__PARTITION_INDEX_IMPL_INCLUDED
25 
26 #include <stddef.h>
27 #include <sys/types.h>
28 #include <memory>
29 #include <new>
30 
31 #include "sql/dd/impl/properties_impl.h"
32 #include "sql/dd/impl/types/weak_object_impl.h"  // dd::Weak_object_impl
33 #include "sql/dd/object_id.h"
34 #include "sql/dd/sdi_fwd.h"
35 #include "sql/dd/string_type.h"
36 #include "sql/dd/types/index.h"
37 #include "sql/dd/types/partition_index.h"  // dd::Partition_index
38 
39 namespace dd {
40 
41 ///////////////////////////////////////////////////////////////////////////
42 
43 class Index;
44 class Object_key;
45 class Object_table;
46 class Open_dictionary_tables_ctx;
47 class Partition;
48 class Partition_impl;
49 class Raw_record;
50 class Sdi_rcontext;
51 class Sdi_wcontext;
52 class Weak_object;
53 
54 ///////////////////////////////////////////////////////////////////////////
55 
56 class Partition_index_impl : public Weak_object_impl, public Partition_index {
57  public:
58   Partition_index_impl();
59 
60   Partition_index_impl(Partition_impl *partition, Index *index);
61 
62   Partition_index_impl(const Partition_index_impl &src, Partition_impl *parent,
63                        Index *index);
64 
~Partition_index_impl()65   virtual ~Partition_index_impl() {}
66 
67  public:
68   virtual const Object_table &object_table() const;
69 
70   virtual bool validate() const;
71 
72   virtual bool restore_attributes(const Raw_record &r);
73 
74   virtual bool store_attributes(Raw_record *r);
75 
76   void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const;
77 
78   bool deserialize(Sdi_rcontext *rctx, const RJ_Value &val);
79 
80   void debug_print(String_type &outb) const;
81 
set_ordinal_position(uint)82   void set_ordinal_position(uint) {}
83 
ordinal_position()84   virtual uint ordinal_position() const { return -1; }
85 
86  public:
87   static void register_tables(Open_dictionary_tables_ctx *otx);
88 
89   /////////////////////////////////////////////////////////////////////////
90   // Partition.
91   /////////////////////////////////////////////////////////////////////////
92 
93   virtual const Partition &partition() const;
94 
95   virtual Partition &partition();
96 
partition_impl()97   Partition_impl &partition_impl() { return *m_partition; }
98 
99   /////////////////////////////////////////////////////////////////////////
100   // Index.
101   /////////////////////////////////////////////////////////////////////////
102 
103   virtual const Index &index() const;
104 
105   virtual Index &index();
106 
107   /////////////////////////////////////////////////////////////////////////
108   // Options.
109   /////////////////////////////////////////////////////////////////////////
110 
options()111   virtual const Properties &options() const { return m_options; }
112 
options()113   virtual Properties &options() { return m_options; }
114 
set_options(const Properties & options)115   virtual bool set_options(const Properties &options) {
116     return m_options.insert_values(options);
117   }
118 
set_options(const String_type & options_raw)119   virtual bool set_options(const String_type &options_raw) {
120     return m_options.insert_values(options_raw);
121   }
122 
123   /////////////////////////////////////////////////////////////////////////
124   // se_private_data.
125   /////////////////////////////////////////////////////////////////////////
126 
se_private_data()127   virtual const Properties &se_private_data() const {
128     return m_se_private_data;
129   }
130 
se_private_data()131   virtual Properties &se_private_data() { return m_se_private_data; }
132 
set_se_private_data(const String_type & se_private_data_raw)133   virtual bool set_se_private_data(const String_type &se_private_data_raw) {
134     return m_se_private_data.insert_values(se_private_data_raw);
135   }
136 
set_se_private_data(const Properties & se_private_data)137   virtual bool set_se_private_data(const Properties &se_private_data) {
138     return m_se_private_data.insert_values(se_private_data);
139   }
140 
141   /////////////////////////////////////////////////////////////////////////
142   // Tablespace.
143   /////////////////////////////////////////////////////////////////////////
144 
tablespace_id()145   virtual Object_id tablespace_id() const { return m_tablespace_id; }
146 
set_tablespace_id(Object_id tablespace_id)147   virtual void set_tablespace_id(Object_id tablespace_id) {
148     m_tablespace_id = tablespace_id;
149   }
150 
151  public:
restore_item(Partition_impl * partition)152   static Partition_index_impl *restore_item(Partition_impl *partition) {
153     return new (std::nothrow) Partition_index_impl(partition, nullptr);
154   }
155 
156   static Partition_index_impl *clone(const Partition_index_impl &other,
157                                      Partition_impl *partition);
158 
159  public:
160   virtual Object_key *create_primary_key() const;
161   virtual bool has_new_primary_key() const;
162 
163  private:
164   // Fields.
165 
166   Properties_impl m_options;
167   Properties_impl m_se_private_data;
168 
169   // References to tightly-coupled objects.
170 
171   Partition_impl *m_partition;
172   Index *m_index;
173 
174   // References to loosely-coupled objects.
175 
176   Object_id m_tablespace_id;
177 };
178 
179 ///////////////////////////////////////////////////////////////////////////
180 
181 /**
182   Used to sort Partition_index objects for the same partition in
183   the same order as Index objects for the table.
184 */
185 
186 struct Partition_index_order_comparator {
operatorPartition_index_order_comparator187   bool operator()(const dd::Partition_index *pi1,
188                   const dd::Partition_index *pi2) const {
189     return pi1->index().ordinal_position() < pi2->index().ordinal_position();
190   }
191 };
192 
193 ///////////////////////////////////////////////////////////////////////////
194 
195 }  // namespace dd
196 
197 #endif  // DD__PARTITION_INDEX_IMPL_INCLUDED
198