1 #ifndef PARTITION_ELEMENT_INCLUDED
2 #define PARTITION_ELEMENT_INCLUDED
3 
4 /* Copyright (c) 2005, 2021, Oracle and/or its affiliates.
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, version 2.0,
8    as published by the Free Software Foundation.
9 
10    This program is also distributed 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 included with MySQL.
16 
17    This program is distributed in the hope that it will be useful,
18    but WITHOUT ANY WARRANTY; without even the implied warranty of
19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20    GNU General Public License, version 2.0, for more details.
21 
22    You should have received a copy of the GNU General Public License
23    along with this program; if not, write to the Free Software
24    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
25 
26 #include "my_base.h"                            /* ha_rows */
27 #include "handler.h"                            /* UNDEF_NODEGROUP */
28 
29 /**
30  * An enum and a struct to handle partitioning and subpartitioning.
31  */
32 enum partition_type {
33   NOT_A_PARTITION= 0,
34   RANGE_PARTITION,
35   HASH_PARTITION,
36   LIST_PARTITION
37 };
38 
39 enum partition_state {
40   PART_NORMAL= 0,
41   PART_IS_DROPPED= 1,
42   PART_TO_BE_DROPPED= 2,
43   PART_TO_BE_ADDED= 3,
44   PART_TO_BE_REORGED= 4,
45   PART_REORGED_DROPPED= 5,
46   PART_CHANGED= 6,
47   PART_IS_CHANGED= 7,
48   PART_IS_ADDED= 8,
49   PART_ADMIN= 9
50 };
51 
52 /*
53   This struct is used to keep track of column expressions as part
54   of the COLUMNS concept in conjunction with RANGE and LIST partitioning.
55   The value can be either of MINVALUE, MAXVALUE and an expression that
56   must be constant and evaluate to the same type as the column it
57   represents.
58 
59   The data in this fixed in two steps. The parser will only fill in whether
60   it is a max_value or provide an expression. Filling in
61   column_value, part_info, partition_id, null_value is done by the
62   function fix_column_value_function. However the item tree needs
63   fixed also before writing it into the frm file (in add_column_list_values).
64   To distinguish between those two variants, fixed= 1 after the
65   fixing in add_column_list_values and fixed= 2 otherwise. This is
66   since the fixing in add_column_list_values isn't a complete fixing.
67 */
68 
69 typedef struct p_column_list_val
70 {
71   void* column_value;
72   Item* item_expression;
73   partition_info *part_info;
74   uint partition_id;
75   bool max_value;
76   bool null_value;
77   char fixed;
78 } part_column_list_val;
79 
80 
81 /*
82   This struct is used to contain the value of an element
83   in the VALUES IN struct. It needs to keep knowledge of
84   whether it is a signed/unsigned value and whether it is
85   NULL or not.
86 */
87 
88 typedef struct p_elem_val
89 {
90   longlong value;
91   uint added_items;
92   bool null_value;
93   bool unsigned_flag;
94   part_column_list_val *col_val_array;
95 } part_elem_value;
96 
97 struct st_ddl_log_memory_entry;
98 
99 class partition_element :public Sql_alloc {
100 public:
101   List<partition_element> subpartitions;
102   List<part_elem_value> list_val_list;  // list of LIST values/column arrays
103   ha_rows part_max_rows;
104   ha_rows part_min_rows;
105   longlong range_value;
106   const char *partition_name;
107   const char *tablespace_name;
108   struct st_ddl_log_memory_entry *log_entry;
109   char* part_comment;
110   const char* data_file_name;
111   const char* index_file_name;
112   handlerton *engine_type;
113   enum partition_state part_state;
114   uint16 nodegroup_id;
115   bool has_null_value;
116   bool signed_flag;                          // Range value signed
117   bool max_value;                            // MAXVALUE range
118 
partition_element()119   partition_element()
120   : part_max_rows(0), part_min_rows(0), range_value(0),
121     partition_name(NULL), tablespace_name(NULL),
122     log_entry(NULL), part_comment(NULL),
123     data_file_name(NULL), index_file_name(NULL),
124     engine_type(NULL), part_state(PART_NORMAL),
125     nodegroup_id(UNDEF_NODEGROUP), has_null_value(FALSE),
126     signed_flag(FALSE), max_value(FALSE)
127   {
128   }
partition_element(partition_element * part_elem)129   partition_element(partition_element *part_elem)
130   : part_max_rows(part_elem->part_max_rows),
131     part_min_rows(part_elem->part_min_rows),
132     range_value(0), partition_name(NULL),
133     tablespace_name(part_elem->tablespace_name),
134     part_comment(part_elem->part_comment),
135     data_file_name(part_elem->data_file_name),
136     index_file_name(part_elem->index_file_name),
137     engine_type(part_elem->engine_type),
138     part_state(part_elem->part_state),
139     nodegroup_id(part_elem->nodegroup_id),
140     has_null_value(FALSE)
141   {
142   }
set_from_info(const HA_CREATE_INFO * info)143   inline void set_from_info(const HA_CREATE_INFO* info)
144   {
145     data_file_name= info->data_file_name;
146     index_file_name= info->index_file_name;
147     tablespace_name= info->tablespace;
148     part_max_rows= info->max_rows;
149     part_min_rows= info->min_rows;
150   }
put_to_info(HA_CREATE_INFO * info)151   inline void put_to_info(HA_CREATE_INFO* info) const
152   {
153     info->data_file_name= data_file_name;
154     info->index_file_name= index_file_name;
155     info->tablespace= tablespace_name;
156     info->max_rows= part_max_rows;
157     info->min_rows= part_min_rows;
158   }
~partition_element()159   ~partition_element() {}
160 };
161 
162 #endif /* PARTITION_ELEMENT_INCLUDED */
163