sql_partition.h 8.23 KB
Newer Older
1
/* Copyright 2005-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
2 3 4

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
5
  the Free Software Foundation; version 2 of the License.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

#ifdef __GNUC__
#pragma interface				/* gcc class implementation */
#endif

/* Flags for partition handlers */
#define HA_CAN_PARTITION       (1 << 0) /* Partition support */
#define HA_CAN_UPDATE_PARTITION_KEY (1 << 1)
#define HA_CAN_PARTITION_UNIQUE (1 << 2)
#define HA_USE_AUTO_PARTITION (1 << 3)

/*typedef struct {
  ulonglong data_file_length;
  ulonglong max_data_file_length;
  ulonglong index_file_length;
  ulonglong delete_length;
  ha_rows records;
  ulong mean_rec_length;
  time_t create_time;
  time_t check_time;
  time_t update_time;
  ulonglong check_sum;
} PARTITION_INFO;
*/
typedef struct {
  longlong list_value;
  uint32 partition_id;
} LIST_PART_ENTRY;

typedef struct {
  uint32 start_part;
  uint32 end_part;
} part_id_range;

struct st_partition_iter;
#define NOT_A_PARTITION_ID ((uint32)-1)

bool is_partition_in_list(char *part_name, List<char> list_part_names);
char *are_partitions_in_table(partition_info *new_part_info,
                              partition_info *old_part_info);
bool check_reorganise_list(partition_info *new_part_info,
                           partition_info *old_part_info,
                           List<char> list_part_names);
handler *get_ha_partition(partition_info *part_info);
59 60
int get_parts_for_update(const uchar *old_data, uchar *new_data,
                         const uchar *rec0, partition_info *part_info,
61 62
                         uint32 *old_part_id, uint32 *new_part_id,
                         longlong *func_value);
63
int get_part_for_delete(const uchar *buf, const uchar *rec0,
64
                        partition_info *part_info, uint32 *part_id);
65
void prune_partition_set(const TABLE *table, part_id_range *part_spec);
66
bool check_partition_info(partition_info *part_info,handlerton **eng_type,
67
                          TABLE *table, handler *file, HA_CREATE_INFO *info);
68
void set_linear_hash_mask(partition_info *part_info, uint num_parts);
69
bool fix_partition_func(THD *thd, TABLE *table, bool create_table_ind);
70
bool partition_key_modified(TABLE *table, const MY_BITMAP *fields);
71
void get_partition_set(const TABLE *table, uchar *buf, const uint index,
72 73
                       const key_range *key_spec,
                       part_id_range *part_spec);
74
uint get_partition_field_store_length(Field *field);
75
void get_full_part_id_from_key(const TABLE *table, uchar *buf,
76 77 78
                               KEY *key_info,
                               const key_range *key_spec,
                               part_id_range *part_spec);
79
bool mysql_unpack_partition(THD *thd, const char *part_buf,
80
                            uint part_info_len,
81
                            const char *part_state, uint part_state_len,
82
                            TABLE *table, bool is_create_table_ind,
83 84
                            handlerton *default_db_type,
                            bool *work_part_info_used);
85 86 87 88 89 90 91
void make_used_partitions_str(partition_info *part_info, String *parts_str);
uint32 get_list_array_idx_for_endpoint(partition_info *part_info,
                                       bool left_endpoint,
                                       bool include_endpoint);
uint32 get_partition_id_range_for_endpoint(partition_info *part_info,
                                           bool left_endpoint,
                                           bool include_endpoint);
92 93
bool fix_fields_part_func(THD *thd, Item* func_expr, TABLE *table,
                          bool is_sub_part, bool is_field_to_be_setup);
94

95 96
bool check_part_func_fields(Field **ptr, bool ok_with_charsets);
bool field_is_partition_charset(Field *field);
97
Item* convert_charset_partition_constant(Item *item, CHARSET_INFO *cs);
98

99 100
/*
  A "Get next" function for partition iterator.
101

102 103 104 105
  SYNOPSIS
    partition_iter_func()
      part_iter  Partition iterator, you call only "iter.get_next(&iter)"

106 107 108 109 110 111 112 113 114
  DESCRIPTION
    Depending on whether partitions or sub-partitions are iterated, the
    function returns next subpartition id/partition number. The sequence of
    returned numbers is not ordered and may contain duplicates.

    When the end of sequence is reached, NOT_A_PARTITION_ID is returned, and 
    the iterator resets itself (so next get_next() call will start to 
    enumerate the set all over again).

115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
  RETURN 
    NOT_A_PARTITION_ID if there are no more partitions.
    [sub]partition_id  of the next partition
*/

typedef uint32 (*partition_iter_func)(st_partition_iter* part_iter);


/*
  Partition set iterator. Used to enumerate a set of [sub]partitions
  obtained in partition interval analysis (see get_partitions_in_range_iter).

  For the user, the only meaningful field is get_next, which may be used as
  follows:
             part_iterator.get_next(&part_iterator);
  
  Initialization is done by any of the following calls:
    - get_partitions_in_range_iter-type function call
    - init_single_partition_iterator()
    - init_all_partitions_iterator()
  Cleanup is not needed.
*/

typedef struct st_partition_iter
{
  partition_iter_func get_next;
141 142 143 144 145
  /* 
    Valid for "Interval mapping" in LIST partitioning: if true, let the
    iterator also produce id of the partition that contains NULL value.
  */
  bool ret_null_part, ret_null_part_orig;
146 147 148
  struct st_part_num_range
  {
    uint32 start;
149
    uint32 cur;
150 151 152 153 154 155
    uint32 end;
  };

  struct st_field_value_range
  {
    longlong start;
156
    longlong cur;
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
    longlong end;
  };

  union
  {
    struct st_part_num_range     part_nums;
    struct st_field_value_range  field_vals;
  };
  partition_info *part_info;
} PARTITION_ITERATOR;


/*
  Get an iterator for set of partitions that match given field-space interval

  SYNOPSIS
    get_partitions_in_range_iter()
174
      part_info            Partitioning info
175
      is_subpart
176 177 178 179 180 181 182 183
      store_length_array   Length of fields packed in opt_range_key format
      min_val              Left edge,  field value in opt_range_key format
      max_val              Right edge, field value in opt_range_key format
      min_len              Length of minimum value
      max_len              Length of maximum value
      flags                Some combination of NEAR_MIN, NEAR_MAX, NO_MIN_RANGE,
                           NO_MAX_RANGE
      part_iter            Iterator structure to be initialized
184 185 186 187 188 189 190 191 192 193 194 195

  DESCRIPTION
    Functions with this signature are used to perform "Partitioning Interval
    Analysis". This analysis is applicable for any type of [sub]partitioning 
    by some function of a single fieldX. The idea is as follows:
    Given an interval "const1 <=? fieldX <=? const2", find a set of partitions
    that may contain records with value of fieldX within the given interval.

    The min_val, max_val and flags parameters specify the interval.
    The set of partitions is returned by initializing an iterator in *part_iter

  NOTES
196
    There are currently three functions of this type:
197
     - get_part_iter_for_interval_via_walking
198
     - get_part_iter_for_interval_cols_via_map
199 200 201 202 203 204 205 206 207 208
     - get_part_iter_for_interval_via_mapping

  RETURN 
    0 - No matching partitions, iterator not initialized
    1 - Some partitions would match, iterator intialized for traversing them
   -1 - All partitions would match, iterator not initialized
*/

typedef int (*get_partitions_in_range_iter)(partition_info *part_info,
                                            bool is_subpart,
209
                                            uint32 *store_length_array,
210
                                            uchar *min_val, uchar *max_val,
211
                                            uint min_len, uint max_len,
212 213 214 215 216
                                            uint flags,
                                            PARTITION_ITERATOR *part_iter);

#include "partition_info.h"