My Project
sql_partition.h
00001 #ifndef SQL_PARTITION_INCLUDED
00002 #define SQL_PARTITION_INCLUDED
00003 
00004 /* Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; version 2 of the License.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014 
00015    You should have received a copy of the GNU General Public License
00016    along with this program; if not, write to the Free Software
00017    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
00018 
00019 #include "sql_list.h"                           /* List */
00020 #include "table.h"                              /* TABLE_LIST */
00021 
00022 class Alter_info;
00023 class Alter_table_ctx;
00024 class Field;
00025 class String;
00026 class handler;
00027 class partition_info;
00028 struct TABLE;
00029 struct TABLE_LIST;
00030 typedef struct st_bitmap MY_BITMAP;
00031 typedef struct st_ha_create_information HA_CREATE_INFO;
00032 typedef struct st_key KEY;
00033 typedef struct st_key_range key_range;
00034 
00035 /* Flags for partition handlers */
00036 #define HA_CAN_PARTITION       (1 << 0) /* Partition support */
00037 #define HA_CAN_UPDATE_PARTITION_KEY (1 << 1)
00038 #define HA_CAN_PARTITION_UNIQUE (1 << 2)
00039 /* If the engine will use auto partitioning even when not defined. */
00040 #define HA_USE_AUTO_PARTITION (1 << 3)
00041 
00042 #define NORMAL_PART_NAME 0
00043 #define TEMP_PART_NAME 1
00044 #define RENAMED_PART_NAME 2
00045 
00046 typedef struct st_lock_param_type
00047 {
00048   TABLE_LIST *table_list;
00049   ulonglong copied;
00050   ulonglong deleted;
00051   THD *thd;
00052   HA_CREATE_INFO *create_info;
00053   Alter_info *alter_info;
00054   TABLE *table;
00055   KEY *key_info_buffer;
00056   const char *db;
00057   const char *table_name;
00058   uchar *pack_frm_data;
00059   uint key_count;
00060   uint db_options;
00061   size_t pack_frm_len;
00062   partition_info *part_info;
00063 } ALTER_PARTITION_PARAM_TYPE;
00064 
00065 typedef struct {
00066   longlong list_value;
00067   uint32 partition_id;
00068 } LIST_PART_ENTRY;
00069 
00070 typedef struct {
00071   uint32 start_part;
00072   uint32 end_part;
00073 } part_id_range;
00074 
00075 struct st_partition_iter;
00076 #define NOT_A_PARTITION_ID UINT_MAX32
00077 
00078 bool is_partition_in_list(char *part_name, List<char> list_part_names);
00079 char *are_partitions_in_table(partition_info *new_part_info,
00080                               partition_info *old_part_info);
00081 handler *get_ha_partition(partition_info *part_info);
00082 int get_parts_for_update(const uchar *old_data, uchar *new_data,
00083                          const uchar *rec0, partition_info *part_info,
00084                          uint32 *old_part_id, uint32 *new_part_id,
00085                          longlong *func_value);
00086 int get_part_for_delete(const uchar *buf, const uchar *rec0,
00087                         partition_info *part_info, uint32 *part_id);
00088 void prune_partition_set(const TABLE *table, part_id_range *part_spec);
00089 bool check_partition_info(partition_info *part_info,handlerton **eng_type,
00090                           TABLE *table, handler *file, HA_CREATE_INFO *info);
00091 void set_linear_hash_mask(partition_info *part_info, uint num_parts);
00092 bool fix_partition_func(THD *thd, TABLE *table, bool create_table_ind);
00093 bool partition_key_modified(TABLE *table, const MY_BITMAP *fields);
00094 void get_partition_set(const TABLE *table, uchar *buf, const uint index,
00095                        const key_range *key_spec,
00096                        part_id_range *part_spec);
00097 uint get_partition_field_store_length(Field *field);
00098 int get_cs_converted_part_value_from_string(THD *thd,
00099                                             Item *item,
00100                                             String *input_str,
00101                                             String *output_str,
00102                                             const CHARSET_INFO *cs,
00103                                             bool use_hex);
00104 void get_full_part_id_from_key(const TABLE *table, uchar *buf,
00105                                KEY *key_info,
00106                                const key_range *key_spec,
00107                                part_id_range *part_spec);
00108 bool mysql_unpack_partition(THD *thd, char *part_buf,
00109                             uint part_info_len,
00110                             TABLE *table, bool is_create_table_ind,
00111                             handlerton *default_db_type,
00112                             bool *work_part_info_used);
00113 bool make_used_partitions_str(partition_info *part_info,
00114                               List<const char> *parts);
00115 uint32 get_list_array_idx_for_endpoint(partition_info *part_info,
00116                                        bool left_endpoint,
00117                                        bool include_endpoint);
00118 uint32 get_partition_id_range_for_endpoint(partition_info *part_info,
00119                                            bool left_endpoint,
00120                                            bool include_endpoint);
00121 bool check_part_func_fields(Field **ptr, bool ok_with_charsets);
00122 bool field_is_partition_charset(Field *field);
00123 Item* convert_charset_partition_constant(Item *item, const CHARSET_INFO *cs);
00124 void mem_alloc_error(size_t size);
00125 void truncate_partition_filename(char *path);
00126 
00127 /*
00128   A "Get next" function for partition iterator.
00129 
00130   SYNOPSIS
00131     partition_iter_func()
00132       part_iter  Partition iterator, you call only "iter.get_next(&iter)"
00133 
00134   DESCRIPTION
00135     Depending on whether partitions or sub-partitions are iterated, the
00136     function returns next subpartition id/partition number. The sequence of
00137     returned numbers is not ordered and may contain duplicates.
00138 
00139     When the end of sequence is reached, NOT_A_PARTITION_ID is returned, and 
00140     the iterator resets itself (so next get_next() call will start to 
00141     enumerate the set all over again).
00142 
00143   RETURN 
00144     NOT_A_PARTITION_ID if there are no more partitions.
00145     [sub]partition_id  of the next partition
00146 */
00147 
00148 typedef uint32 (*partition_iter_func)(st_partition_iter* part_iter);
00149 
00150 
00151 /*
00152   Partition set iterator. Used to enumerate a set of [sub]partitions
00153   obtained in partition interval analysis (see get_partitions_in_range_iter).
00154 
00155   For the user, the only meaningful field is get_next, which may be used as
00156   follows:
00157              part_iterator.get_next(&part_iterator);
00158   
00159   Initialization is done by any of the following calls:
00160     - get_partitions_in_range_iter-type function call
00161     - init_single_partition_iterator()
00162     - init_all_partitions_iterator()
00163   Cleanup is not needed.
00164 */
00165 
00166 typedef struct st_partition_iter
00167 {
00168   partition_iter_func get_next;
00169   /* 
00170     Valid for "Interval mapping" in LIST partitioning: if true, let the
00171     iterator also produce id of the partition that contains NULL value.
00172   */
00173   bool ret_null_part, ret_null_part_orig;
00174   struct st_part_num_range
00175   {
00176     uint32 start;
00177     uint32 cur;
00178     uint32 end;
00179   };
00180 
00181   struct st_field_value_range
00182   {
00183     longlong start;
00184     longlong cur;
00185     longlong end;
00186   };
00187 
00188   union
00189   {
00190     struct st_part_num_range     part_nums;
00191     struct st_field_value_range  field_vals;
00192   };
00193   partition_info *part_info;
00194 } PARTITION_ITERATOR;
00195 
00196 
00197 /*
00198   Get an iterator for set of partitions that match given field-space interval
00199 
00200   SYNOPSIS
00201     get_partitions_in_range_iter()
00202       part_info            Partitioning info
00203       is_subpart
00204       store_length_array   Length of fields packed in opt_range_key format
00205       min_val              Left edge,  field value in opt_range_key format
00206       max_val              Right edge, field value in opt_range_key format
00207       min_len              Length of minimum value
00208       max_len              Length of maximum value
00209       flags                Some combination of NEAR_MIN, NEAR_MAX, NO_MIN_RANGE,
00210                            NO_MAX_RANGE
00211       part_iter            Iterator structure to be initialized
00212 
00213   DESCRIPTION
00214     Functions with this signature are used to perform "Partitioning Interval
00215     Analysis". This analysis is applicable for any type of [sub]partitioning 
00216     by some function of a single fieldX. The idea is as follows:
00217     Given an interval "const1 <=? fieldX <=? const2", find a set of partitions
00218     that may contain records with value of fieldX within the given interval.
00219 
00220     The min_val, max_val and flags parameters specify the interval.
00221     The set of partitions is returned by initializing an iterator in *part_iter
00222 
00223   NOTES
00224     There are currently three functions of this type:
00225      - get_part_iter_for_interval_via_walking
00226      - get_part_iter_for_interval_cols_via_map
00227      - get_part_iter_for_interval_via_mapping
00228 
00229   RETURN 
00230     0 - No matching partitions, iterator not initialized
00231     1 - Some partitions would match, iterator intialized for traversing them
00232    -1 - All partitions would match, iterator not initialized
00233 */
00234 
00235 typedef int (*get_partitions_in_range_iter)(partition_info *part_info,
00236                                             bool is_subpart,
00237                                             uint32 *store_length_array,
00238                                             uchar *min_val, uchar *max_val,
00239                                             uint min_len, uint max_len,
00240                                             uint flags,
00241                                             PARTITION_ITERATOR *part_iter);
00242 
00243 #include "partition_info.h"
00244 
00245 #ifdef WITH_PARTITION_STORAGE_ENGINE
00246 uint fast_alter_partition_table(THD *thd, TABLE *table,
00247                                 Alter_info *alter_info,
00248                                 HA_CREATE_INFO *create_info,
00249                                 TABLE_LIST *table_list,
00250                                 char *db,
00251                                 const char *table_name,
00252                                 partition_info *new_part_info);
00253 void set_all_part_state(partition_info *tab_part_info,
00254                         enum partition_state part_state);
00255 bool set_part_state(Alter_info *alter_info, partition_info *tab_part_info,
00256                     enum partition_state part_state);
00257 uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
00258                            HA_CREATE_INFO *create_info,
00259                            Alter_table_ctx *alter_ctx,
00260                            bool *partition_changed,
00261                            partition_info **new_part_info);
00262 char *generate_partition_syntax(partition_info *part_info,
00263                                 uint *buf_length, bool use_sql_alloc,
00264                                 bool show_partition_options,
00265                                 HA_CREATE_INFO *create_info,
00266                                 Alter_info *alter_info,
00267                                 const char *current_comment_start);
00268 bool verify_data_with_partition(TABLE *table, TABLE *part_table,
00269                                 uint32 part_id);
00270 bool compare_partition_options(HA_CREATE_INFO *table_create_info,
00271                                partition_element *part_elem);
00272 #endif
00273 
00274 void create_partition_name(char *out, const char *in1,
00275                            const char *in2, uint name_variant,
00276                            bool translate);
00277 void create_subpartition_name(char *out, const char *in1,
00278                               const char *in2, const char *in3,
00279                               uint name_variant);
00280 
00281 void set_field_ptr(Field **ptr, const uchar *new_buf, const uchar *old_buf);
00282 void set_key_field_ptr(KEY *key_info, const uchar *new_buf,
00283                        const uchar *old_buf);
00284 
00285 extern const LEX_STRING partition_keywords[];
00286 
00287 #endif /* SQL_PARTITION_INCLUDED */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines