1#ifndef PARTITION_ELEMENT_INCLUDED
2#define PARTITION_ELEMENT_INCLUDED
3
4/* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; version 2 of the License.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
18
19#include "my_base.h" /* ha_rows */
20#include "handler.h" /* UNDEF_NODEGROUP */
21
22/**
23 * An enum and a struct to handle partitioning and subpartitioning.
24 */
25enum partition_type {
26 NOT_A_PARTITION= 0,
27 RANGE_PARTITION,
28 HASH_PARTITION,
29 LIST_PARTITION,
30 VERSIONING_PARTITION
31};
32
33enum partition_state {
34 PART_NORMAL= 0,
35 PART_IS_DROPPED= 1,
36 PART_TO_BE_DROPPED= 2,
37 PART_TO_BE_ADDED= 3,
38 PART_TO_BE_REORGED= 4,
39 PART_REORGED_DROPPED= 5,
40 PART_CHANGED= 6,
41 PART_IS_CHANGED= 7,
42 PART_IS_ADDED= 8,
43 PART_ADMIN= 9
44};
45
46/*
47 This struct is used to keep track of column expressions as part
48 of the COLUMNS concept in conjunction with RANGE and LIST partitioning.
49 The value can be either of MINVALUE, MAXVALUE and an expression that
50 must be constant and evaluate to the same type as the column it
51 represents.
52
53 The data in this fixed in two steps. The parser will only fill in whether
54 it is a max_value or provide an expression. Filling in
55 column_value, part_info, partition_id, null_value is done by the
56 function fix_column_value_function. However the item tree needs
57 fixed also before writing it into the frm file (in add_column_list_values).
58 To distinguish between those two variants, fixed= 1 after the
59 fixing in add_column_list_values and fixed= 2 otherwise. This is
60 since the fixing in add_column_list_values isn't a complete fixing.
61*/
62
63typedef struct p_column_list_val
64{
65 void* column_value;
66 Item* item_expression;
67 partition_info *part_info;
68 uint partition_id;
69 bool max_value; // MAXVALUE for RANGE type or DEFAULT value for LIST type
70 bool null_value;
71 char fixed;
72} part_column_list_val;
73
74
75/*
76 This struct is used to contain the value of an element
77 in the VALUES IN struct. It needs to keep knowledge of
78 whether it is a signed/unsigned value and whether it is
79 NULL or not.
80*/
81
82typedef struct p_elem_val
83{
84 longlong value;
85 uint added_items;
86 bool null_value;
87 bool unsigned_flag;
88 part_column_list_val *col_val_array;
89} part_elem_value;
90
91struct st_ddl_log_memory_entry;
92
93enum stat_trx_field
94{
95 STAT_TRX_END= 0
96};
97
98class partition_element :public Sql_alloc
99{
100public:
101 enum elem_type
102 {
103 CONVENTIONAL= 0,
104 CURRENT,
105 HISTORY
106 };
107
108 List<partition_element> subpartitions;
109 List<part_elem_value> list_val_list;
110 ha_rows part_max_rows;
111 ha_rows part_min_rows;
112 longlong range_value;
113 const char *partition_name;
114 const char *tablespace_name;
115 struct st_ddl_log_memory_entry *log_entry;
116 const char* part_comment;
117 const char* data_file_name;
118 const char* index_file_name;
119 handlerton *engine_type;
120 LEX_CSTRING connect_string;
121 enum partition_state part_state;
122 uint16 nodegroup_id;
123 bool has_null_value;
124 bool signed_flag; // Range value signed
125 bool max_value; // MAXVALUE range
126 uint32 id;
127 bool empty;
128
129 // TODO: subclass partition_element by partitioning type to avoid such semantic
130 // mixup
131 elem_type type()
132 {
133 return (elem_type)(int(signed_flag) << 1 | int(max_value));
134 }
135
136 void type(elem_type val)
137 {
138 max_value= (bool)(val & 1);
139 signed_flag= (bool)(val & 2);
140 }
141
142 partition_element()
143 : part_max_rows(0), part_min_rows(0), range_value(0),
144 partition_name(NULL), tablespace_name(NULL),
145 log_entry(NULL), part_comment(NULL),
146 data_file_name(NULL), index_file_name(NULL),
147 engine_type(NULL), connect_string(null_clex_str), part_state(PART_NORMAL),
148 nodegroup_id(UNDEF_NODEGROUP), has_null_value(FALSE),
149 signed_flag(FALSE), max_value(FALSE),
150 id(UINT_MAX32),
151 empty(true)
152 {}
153 partition_element(partition_element *part_elem)
154 : part_max_rows(part_elem->part_max_rows),
155 part_min_rows(part_elem->part_min_rows),
156 range_value(0), partition_name(NULL),
157 tablespace_name(part_elem->tablespace_name),
158 part_comment(part_elem->part_comment),
159 data_file_name(part_elem->data_file_name),
160 index_file_name(part_elem->index_file_name),
161 engine_type(part_elem->engine_type),
162 connect_string(null_clex_str),
163 part_state(part_elem->part_state),
164 nodegroup_id(part_elem->nodegroup_id),
165 has_null_value(FALSE),
166 id(part_elem->id),
167 empty(part_elem->empty)
168 {}
169 ~partition_element() {}
170
171 part_column_list_val& get_col_val(uint idx)
172 {
173 DBUG_ASSERT(type() == CONVENTIONAL || list_val_list.elements == 1);
174 part_elem_value *ev= list_val_list.head();
175 DBUG_ASSERT(ev);
176 DBUG_ASSERT(ev->col_val_array);
177 return ev->col_val_array[idx];
178 }
179
180 bool find_engine_flag(uint32 flag)
181 {
182 if (ha_check_storage_engine_flag(engine_type, flag))
183 return true;
184
185 List_iterator_fast<partition_element> it(subpartitions);
186 while (partition_element *element= it++)
187 {
188 if (element->find_engine_flag(flag))
189 return true;
190 }
191
192 return false;
193 }
194};
195
196#endif /* PARTITION_ELEMENT_INCLUDED */
197