You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

207 lines
7.7 KiB

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