MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sql_partition.h
1 #ifndef SQL_PARTITION_INCLUDED
2 #define SQL_PARTITION_INCLUDED
3 
4 /* Copyright (c) 2006, 2013, 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 "sql_list.h" /* List */
20 #include "table.h" /* TABLE_LIST */
21 
22 class Alter_info;
23 class Alter_table_ctx;
24 class Field;
25 class String;
26 class handler;
27 class partition_info;
28 struct TABLE;
29 struct TABLE_LIST;
30 typedef struct st_bitmap MY_BITMAP;
32 typedef struct st_key KEY;
33 typedef struct st_key_range key_range;
34 
35 /* Flags for partition handlers */
36 #define HA_CAN_PARTITION (1 << 0) /* Partition support */
37 #define HA_CAN_UPDATE_PARTITION_KEY (1 << 1)
38 #define HA_CAN_PARTITION_UNIQUE (1 << 2)
39 /* If the engine will use auto partitioning even when not defined. */
40 #define HA_USE_AUTO_PARTITION (1 << 3)
41 
42 #define NORMAL_PART_NAME 0
43 #define TEMP_PART_NAME 1
44 #define RENAMED_PART_NAME 2
45 
46 typedef struct st_lock_param_type
47 {
48  TABLE_LIST *table_list;
49  ulonglong copied;
50  ulonglong deleted;
51  THD *thd;
52  HA_CREATE_INFO *create_info;
53  Alter_info *alter_info;
54  TABLE *table;
55  KEY *key_info_buffer;
56  const char *db;
57  const char *table_name;
58  uchar *pack_frm_data;
59  uint key_count;
60  uint db_options;
61  size_t pack_frm_len;
62  partition_info *part_info;
64 
65 typedef struct {
66  longlong list_value;
67  uint32 partition_id;
69 
70 typedef struct {
71  uint32 start_part;
72  uint32 end_part;
74 
75 struct st_partition_iter;
76 #define NOT_A_PARTITION_ID UINT_MAX32
77 
78 bool is_partition_in_list(char *part_name, List<char> list_part_names);
79 char *are_partitions_in_table(partition_info *new_part_info,
80  partition_info *old_part_info);
81 handler *get_ha_partition(partition_info *part_info);
82 int get_parts_for_update(const uchar *old_data, uchar *new_data,
83  const uchar *rec0, partition_info *part_info,
84  uint32 *old_part_id, uint32 *new_part_id,
85  longlong *func_value);
86 int get_part_for_delete(const uchar *buf, const uchar *rec0,
87  partition_info *part_info, uint32 *part_id);
88 void prune_partition_set(const TABLE *table, part_id_range *part_spec);
89 bool check_partition_info(partition_info *part_info,handlerton **eng_type,
91 void set_linear_hash_mask(partition_info *part_info, uint num_parts);
92 bool fix_partition_func(THD *thd, TABLE *table, bool create_table_ind);
93 bool partition_key_modified(TABLE *table, const MY_BITMAP *fields);
94 void get_partition_set(const TABLE *table, uchar *buf, const uint index,
95  const key_range *key_spec,
96  part_id_range *part_spec);
97 uint get_partition_field_store_length(Field *field);
98 int get_cs_converted_part_value_from_string(THD *thd,
99  Item *item,
100  String *input_str,
101  String *output_str,
102  const CHARSET_INFO *cs,
103  bool use_hex);
104 void get_full_part_id_from_key(const TABLE *table, uchar *buf,
105  KEY *key_info,
106  const key_range *key_spec,
107  part_id_range *part_spec);
108 bool mysql_unpack_partition(THD *thd, char *part_buf,
109  uint part_info_len,
110  TABLE *table, bool is_create_table_ind,
111  handlerton *default_db_type,
112  bool *work_part_info_used);
113 bool make_used_partitions_str(partition_info *part_info,
114  List<const char> *parts);
115 uint32 get_list_array_idx_for_endpoint(partition_info *part_info,
116  bool left_endpoint,
117  bool include_endpoint);
118 uint32 get_partition_id_range_for_endpoint(partition_info *part_info,
119  bool left_endpoint,
120  bool include_endpoint);
121 bool check_part_func_fields(Field **ptr, bool ok_with_charsets);
122 bool field_is_partition_charset(Field *field);
123 Item* convert_charset_partition_constant(Item *item, const CHARSET_INFO *cs);
124 void mem_alloc_error(size_t size);
125 void truncate_partition_filename(char *path);
126 
127 /*
128  A "Get next" function for partition iterator.
129 
130  SYNOPSIS
131  partition_iter_func()
132  part_iter Partition iterator, you call only "iter.get_next(&iter)"
133 
134  DESCRIPTION
135  Depending on whether partitions or sub-partitions are iterated, the
136  function returns next subpartition id/partition number. The sequence of
137  returned numbers is not ordered and may contain duplicates.
138 
139  When the end of sequence is reached, NOT_A_PARTITION_ID is returned, and
140  the iterator resets itself (so next get_next() call will start to
141  enumerate the set all over again).
142 
143  RETURN
144  NOT_A_PARTITION_ID if there are no more partitions.
145  [sub]partition_id of the next partition
146 */
147 
148 typedef uint32 (*partition_iter_func)(st_partition_iter* part_iter);
149 
150 
151 /*
152  Partition set iterator. Used to enumerate a set of [sub]partitions
153  obtained in partition interval analysis (see get_partitions_in_range_iter).
154 
155  For the user, the only meaningful field is get_next, which may be used as
156  follows:
157  part_iterator.get_next(&part_iterator);
158 
159  Initialization is done by any of the following calls:
160  - get_partitions_in_range_iter-type function call
161  - init_single_partition_iterator()
162  - init_all_partitions_iterator()
163  Cleanup is not needed.
164 */
165 
166 typedef struct st_partition_iter
167 {
168  partition_iter_func get_next;
169  /*
170  Valid for "Interval mapping" in LIST partitioning: if true, let the
171  iterator also produce id of the partition that contains NULL value.
172  */
173  bool ret_null_part, ret_null_part_orig;
175  {
176  uint32 start;
177  uint32 cur;
178  uint32 end;
179  };
180 
182  {
183  longlong start;
184  longlong cur;
185  longlong end;
186  };
187 
188  union
189  {
190  struct st_part_num_range part_nums;
191  struct st_field_value_range field_vals;
192  };
193  partition_info *part_info;
195 
196 
197 /*
198  Get an iterator for set of partitions that match given field-space interval
199 
200  SYNOPSIS
201  get_partitions_in_range_iter()
202  part_info Partitioning info
203  is_subpart
204  store_length_array Length of fields packed in opt_range_key format
205  min_val Left edge, field value in opt_range_key format
206  max_val Right edge, field value in opt_range_key format
207  min_len Length of minimum value
208  max_len Length of maximum value
209  flags Some combination of NEAR_MIN, NEAR_MAX, NO_MIN_RANGE,
210  NO_MAX_RANGE
211  part_iter Iterator structure to be initialized
212 
213  DESCRIPTION
214  Functions with this signature are used to perform "Partitioning Interval
215  Analysis". This analysis is applicable for any type of [sub]partitioning
216  by some function of a single fieldX. The idea is as follows:
217  Given an interval "const1 <=? fieldX <=? const2", find a set of partitions
218  that may contain records with value of fieldX within the given interval.
219 
220  The min_val, max_val and flags parameters specify the interval.
221  The set of partitions is returned by initializing an iterator in *part_iter
222 
223  NOTES
224  There are currently three functions of this type:
225  - get_part_iter_for_interval_via_walking
226  - get_part_iter_for_interval_cols_via_map
227  - get_part_iter_for_interval_via_mapping
228 
229  RETURN
230  0 - No matching partitions, iterator not initialized
231  1 - Some partitions would match, iterator intialized for traversing them
232  -1 - All partitions would match, iterator not initialized
233 */
234 
235 typedef int (*get_partitions_in_range_iter)(partition_info *part_info,
236  bool is_subpart,
237  uint32 *store_length_array,
238  uchar *min_val, uchar *max_val,
239  uint min_len, uint max_len,
240  uint flags,
241  PARTITION_ITERATOR *part_iter);
242 
243 #include "partition_info.h"
244 
245 #ifdef WITH_PARTITION_STORAGE_ENGINE
246 uint fast_alter_partition_table(THD *thd, TABLE *table,
247  Alter_info *alter_info,
248  HA_CREATE_INFO *create_info,
249  TABLE_LIST *table_list,
250  char *db,
251  const char *table_name);
252 bool set_part_state(Alter_info *alter_info, partition_info *tab_part_info,
253  enum partition_state part_state);
254 uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
255  HA_CREATE_INFO *create_info,
256  Alter_table_ctx *alter_ctx,
257  bool *partition_changed,
258  bool *fast_alter_table);
259 char *generate_partition_syntax(partition_info *part_info,
260  uint *buf_length, bool use_sql_alloc,
261  bool show_partition_options,
262  HA_CREATE_INFO *create_info,
263  Alter_info *alter_info,
264  const char *current_comment_start);
265 bool verify_data_with_partition(TABLE *table, TABLE *part_table,
266  uint32 part_id);
267 bool compare_partition_options(HA_CREATE_INFO *table_create_info,
268  partition_element *part_elem);
269 #endif
270 
271 void create_partition_name(char *out, const char *in1,
272  const char *in2, uint name_variant,
273  bool translate);
274 void create_subpartition_name(char *out, const char *in1,
275  const char *in2, const char *in3,
276  uint name_variant);
277 
278 void set_field_ptr(Field **ptr, const uchar *new_buf, const uchar *old_buf);
279 void set_key_field_ptr(KEY *key_info, const uchar *new_buf,
280  const uchar *old_buf);
281 
282 extern const LEX_STRING partition_keywords[];
283 
284 #endif /* SQL_PARTITION_INCLUDED */