~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to sql/sql_partition.h

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2006 MySQL AB
 
2
 
 
3
  This program is free software; you can redistribute it and/or modify
 
4
  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
  This program is distributed in the hope that it will be useful,
 
8
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
  GNU General Public License for more details.
 
11
 
 
12
  You should have received a copy of the GNU General Public License
 
13
  along with this program; if not, write to the Free Software
 
14
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#ifdef __GNUC__
 
17
#pragma interface                               /* gcc class implementation */
 
18
#endif
 
19
 
 
20
/* Flags for partition handlers */
 
21
#define HA_CAN_PARTITION       (1 << 0) /* Partition support */
 
22
#define HA_CAN_UPDATE_PARTITION_KEY (1 << 1)
 
23
#define HA_CAN_PARTITION_UNIQUE (1 << 2)
 
24
#define HA_USE_AUTO_PARTITION (1 << 3)
 
25
 
 
26
/*typedef struct {
 
27
  ulonglong data_file_length;
 
28
  ulonglong max_data_file_length;
 
29
  ulonglong index_file_length;
 
30
  ulonglong delete_length;
 
31
  ha_rows records;
 
32
  ulong mean_rec_length;
 
33
  time_t create_time;
 
34
  time_t check_time;
 
35
  time_t update_time;
 
36
  ulonglong check_sum;
 
37
} PARTITION_INFO;
 
38
*/
 
39
typedef struct {
 
40
  longlong list_value;
 
41
  uint32 partition_id;
 
42
} LIST_PART_ENTRY;
 
43
 
 
44
typedef struct {
 
45
  uint32 start_part;
 
46
  uint32 end_part;
 
47
} part_id_range;
 
48
 
 
49
struct st_partition_iter;
 
50
#define NOT_A_PARTITION_ID ((uint32)-1)
 
51
 
 
52
bool is_partition_in_list(char *part_name, List<char> list_part_names);
 
53
char *are_partitions_in_table(partition_info *new_part_info,
 
54
                              partition_info *old_part_info);
 
55
bool check_reorganise_list(partition_info *new_part_info,
 
56
                           partition_info *old_part_info,
 
57
                           List<char> list_part_names);
 
58
handler *get_ha_partition(partition_info *part_info);
 
59
int get_parts_for_update(const uchar *old_data, uchar *new_data,
 
60
                         const uchar *rec0, partition_info *part_info,
 
61
                         uint32 *old_part_id, uint32 *new_part_id,
 
62
                         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 no_parts);
 
69
bool fix_partition_func(THD *thd, TABLE *table, bool create_table_ind);
 
70
char *generate_partition_syntax(partition_info *part_info,
 
71
                                uint *buf_length, bool use_sql_alloc,
 
72
                                bool show_partition_options);
 
73
bool partition_key_modified(TABLE *table, const MY_BITMAP *fields);
 
74
void get_partition_set(const TABLE *table, uchar *buf, const uint index,
 
75
                       const key_range *key_spec,
 
76
                       part_id_range *part_spec);
 
77
void get_full_part_id_from_key(const TABLE *table, uchar *buf,
 
78
                               KEY *key_info,
 
79
                               const key_range *key_spec,
 
80
                               part_id_range *part_spec);
 
81
bool mysql_unpack_partition(THD *thd, const char *part_buf,
 
82
                            uint part_info_len,
 
83
                            const char *part_state, uint part_state_len,
 
84
                            TABLE *table, bool is_create_table_ind,
 
85
                            handlerton *default_db_type,
 
86
                            bool *work_part_info_used);
 
87
void make_used_partitions_str(partition_info *part_info, String *parts_str);
 
88
uint32 get_list_array_idx_for_endpoint(partition_info *part_info,
 
89
                                       bool left_endpoint,
 
90
                                       bool include_endpoint);
 
91
uint32 get_partition_id_range_for_endpoint(partition_info *part_info,
 
92
                                           bool left_endpoint,
 
93
                                           bool include_endpoint);
 
94
bool check_part_func_fields(Field **ptr, bool ok_with_charsets);
 
95
bool field_is_partition_charset(Field *field);
 
96
 
 
97
/*
 
98
  A "Get next" function for partition iterator.
 
99
 
 
100
  SYNOPSIS
 
101
    partition_iter_func()
 
102
      part_iter  Partition iterator, you call only "iter.get_next(&iter)"
 
103
 
 
104
  DESCRIPTION
 
105
    Depending on whether partitions or sub-partitions are iterated, the
 
106
    function returns next subpartition id/partition number. The sequence of
 
107
    returned numbers is not ordered and may contain duplicates.
 
108
 
 
109
    When the end of sequence is reached, NOT_A_PARTITION_ID is returned, and 
 
110
    the iterator resets itself (so next get_next() call will start to 
 
111
    enumerate the set all over again).
 
112
 
 
113
  RETURN 
 
114
    NOT_A_PARTITION_ID if there are no more partitions.
 
115
    [sub]partition_id  of the next partition
 
116
*/
 
117
 
 
118
typedef uint32 (*partition_iter_func)(st_partition_iter* part_iter);
 
119
 
 
120
 
 
121
/*
 
122
  Partition set iterator. Used to enumerate a set of [sub]partitions
 
123
  obtained in partition interval analysis (see get_partitions_in_range_iter).
 
124
 
 
125
  For the user, the only meaningful field is get_next, which may be used as
 
126
  follows:
 
127
             part_iterator.get_next(&part_iterator);
 
128
  
 
129
  Initialization is done by any of the following calls:
 
130
    - get_partitions_in_range_iter-type function call
 
131
    - init_single_partition_iterator()
 
132
    - init_all_partitions_iterator()
 
133
  Cleanup is not needed.
 
134
*/
 
135
 
 
136
typedef struct st_partition_iter
 
137
{
 
138
  partition_iter_func get_next;
 
139
  /* 
 
140
    Valid for "Interval mapping" in LIST partitioning: if true, let the
 
141
    iterator also produce id of the partition that contains NULL value.
 
142
  */
 
143
  bool ret_null_part, ret_null_part_orig;
 
144
  struct st_part_num_range
 
145
  {
 
146
    uint32 start;
 
147
    uint32 cur;
 
148
    uint32 end;
 
149
  };
 
150
 
 
151
  struct st_field_value_range
 
152
  {
 
153
    longlong start;
 
154
    longlong cur;
 
155
    longlong end;
 
156
  };
 
157
 
 
158
  union
 
159
  {
 
160
    struct st_part_num_range     part_nums;
 
161
    struct st_field_value_range  field_vals;
 
162
  };
 
163
  partition_info *part_info;
 
164
} PARTITION_ITERATOR;
 
165
 
 
166
 
 
167
/*
 
168
  Get an iterator for set of partitions that match given field-space interval
 
169
 
 
170
  SYNOPSIS
 
171
    get_partitions_in_range_iter()
 
172
      part_info   Partitioning info
 
173
      is_subpart  
 
174
      min_val     Left edge,  field value in opt_range_key format.
 
175
      max_val     Right edge, field value in opt_range_key format. 
 
176
      flags       Some combination of NEAR_MIN, NEAR_MAX, NO_MIN_RANGE,
 
177
                  NO_MAX_RANGE.
 
178
      part_iter   Iterator structure to be initialized
 
179
 
 
180
  DESCRIPTION
 
181
    Functions with this signature are used to perform "Partitioning Interval
 
182
    Analysis". This analysis is applicable for any type of [sub]partitioning 
 
183
    by some function of a single fieldX. The idea is as follows:
 
184
    Given an interval "const1 <=? fieldX <=? const2", find a set of partitions
 
185
    that may contain records with value of fieldX within the given interval.
 
186
 
 
187
    The min_val, max_val and flags parameters specify the interval.
 
188
    The set of partitions is returned by initializing an iterator in *part_iter
 
189
 
 
190
  NOTES
 
191
    There are currently two functions of this type:
 
192
     - get_part_iter_for_interval_via_walking
 
193
     - get_part_iter_for_interval_via_mapping
 
194
 
 
195
  RETURN 
 
196
    0 - No matching partitions, iterator not initialized
 
197
    1 - Some partitions would match, iterator intialized for traversing them
 
198
   -1 - All partitions would match, iterator not initialized
 
199
*/
 
200
 
 
201
typedef int (*get_partitions_in_range_iter)(partition_info *part_info,
 
202
                                            bool is_subpart,
 
203
                                            uchar *min_val, uchar *max_val,
 
204
                                            uint flags,
 
205
                                            PARTITION_ITERATOR *part_iter);
 
206
 
 
207
#include "partition_info.h"
 
208