1 #ifndef HA_PARTITION_INCLUDED
2 #define HA_PARTITION_INCLUDED
20 #include "sql_partition.h"
23 enum partition_keywords
25 PKW_HASH= 0, PKW_RANGE, PKW_LIST, PKW_KEY, PKW_MAXVALUE, PKW_LINEAR,
26 PKW_COLUMNS, PKW_ALGORITHM
30 #define PARTITION_BYTES_IN_POS 2
36 uchar *partition_name;
62 bool init(uint arg_num_parts)
65 num_parts= arg_num_parts;
85 bool auto_inc_initialized;
93 HASH partition_name_hash;
99 DBUG_ENTER(
"Partition_share::~Partition_share");
102 my_hash_free(&partition_name_hash);
107 bool init(uint num_parts);
112 void unlock_auto_inc()
122 enum partition_index_scan_type
124 partition_index_read= 0,
125 partition_index_first= 1,
126 partition_index_first_unordered= 2,
127 partition_index_last= 3,
128 partition_index_read_last= 4,
129 partition_read_range = 5,
130 partition_no_index_scan= 6
134 uint m_open_test_lock;
136 char *m_name_buffer_ptr;
139 uint m_file_tot_parts;
144 Field **m_part_field_array;
145 uchar *m_ordered_rec_buffer;
153 KEY *m_curr_key_info[3];
155 const uchar *m_err_rec;
164 ulong m_low_byte_first;
165 enum enum_handler_status
167 handler_not_initialized= 0,
172 enum_handler_status m_handler_status;
174 uint m_reorged_parts;
184 enum partition_index_scan_type m_index_scan_type;
191 bool m_pkey_is_clustered;
192 bool m_create_handler;
193 bool m_is_sub_partitioned;
194 bool m_ordered_scan_ongoing;
224 uint m_extra_cache_size;
226 bool m_extra_prepare_for_update;
228 uint m_extra_cache_part_id;
230 void init_handler_variables();
236 bool auto_increment_lock;
241 bool auto_increment_safe_stmt_log_lock;
244 ha_rows m_bulk_inserted_rows;
246 enum_monotonicity_info m_part_func_monotonicity_info;
254 uint32 *m_part_ids_sorted_by_num_of_records;
263 bool m_key_not_found;
269 m_part_info= part_info;
270 m_is_sub_partitioned= part_info->is_sub_partitioned();
296 bool initialize_partition(
MEM_ROOT *mem_root);
316 virtual int create(
const char *name,
TABLE *
form,
318 virtual int create_handler_files(
const char *name,
319 const char *old_name,
int action_flag,
322 virtual char *update_table_comment(
const char *comment);
325 ulonglong *
const copied,
326 ulonglong *
const deleted,
327 const uchar *pack_frm_data,
328 size_t pack_frm_len);
329 virtual int drop_partitions(
const char *path);
330 virtual int rename_partitions(
const char *path);
333 DBUG_ENTER(
"ha_partition::get_no_parts");
334 *num_parts= m_tot_parts;
341 int copy_partitions(ulonglong *
const copied, ulonglong *
const deleted);
342 void cleanup_new_partition(uint part_count);
350 int del_ren_table(
const char *from,
const char *to);
356 bool create_handler_file(
const char *name);
357 bool setup_engine_array(
MEM_ROOT *mem_root);
358 bool read_par_file(
const char *name);
359 bool get_from_handler_file(
const char *name,
MEM_ROOT *mem_root,
361 bool new_handlers_from_part_info(
MEM_ROOT *mem_root);
362 bool create_handlers(
MEM_ROOT *mem_root);
363 void clear_handler_file();
364 int set_up_table_before_create(
TABLE *table_arg,
365 const char *partition_name_with_path,
369 bool insert_partition_name_in_hash(
const char *name, uint part_id,
371 bool populate_partition_name_hash();
374 void fix_data_dir(
char* path);
375 bool init_partition_bitmaps();
376 void free_partition_bitmaps();
393 virtual int open(
const char *name,
int mode, uint test_if_locked);
394 virtual int close(
void);
411 enum thr_lock_type lock_type);
412 virtual int external_lock(THD * thd,
int lock_type);
417 virtual int start_stmt(THD * thd, thr_lock_type lock_type);
425 virtual void unlock_row();
440 #ifdef HAVE_M_PSI_PER_PARTITION
444 virtual void unbind_psi();
445 virtual void rebind_psi();
467 virtual int write_row(uchar *
buf);
468 virtual int update_row(
const uchar * old_data, uchar * new_data);
469 virtual int delete_row(
const uchar *
buf);
472 virtual void start_bulk_insert(ha_rows rows);
473 virtual int end_bulk_insert();
475 ha_rows guess_bulk_insert_rows();
476 void start_part_bulk_insert(THD *thd, uint part_id);
477 long estimate_read_buffer_size(
long original_size);
487 int truncate_partition(
Alter_info *,
bool *binlog_stmt);
492 error == HA_ERR_NO_PARTITION_FOUND ||
493 error == HA_ERR_NOT_IN_LOCK_PARTITIONS)
525 virtual int rnd_end();
527 virtual int rnd_pos(uchar *
buf, uchar * pos);
529 virtual void position(
const uchar *
record);
564 key_part_map keypart_map,
565 enum ha_rkey_function find_flag);
566 virtual int index_init(uint idx,
bool sorted);
567 virtual int index_end();
576 key_part_map keypart_map,
577 enum ha_rkey_function find_flag);
588 key_part_map keypart_map);
609 bool eq_range,
bool sorted);
613 bool init_record_priority_queue();
614 void destroy_record_priority_queue();
615 int common_index_read(uchar *
buf,
bool have_start_key);
616 int common_first_last(uchar *
buf);
617 int partition_scan_set_up(uchar *
buf,
bool idx_read_flag);
618 int handle_unordered_next(uchar *
buf,
bool next_same);
619 int handle_unordered_scan_next_partition(uchar *
buf);
620 int handle_ordered_index_scan(uchar *
buf,
bool reverse_order);
621 int handle_ordered_index_scan_key_not_found();
622 int handle_ordered_next(uchar *
buf,
bool next_same);
623 int handle_ordered_prev(uchar *
buf);
624 void return_top_record(uchar *
buf);
635 virtual int info(uint);
638 virtual int extra(
enum ha_extra_function operation);
639 virtual int extra_opt(
enum ha_extra_function operation, ulong cachesize);
640 virtual int reset(
void);
649 ulonglong *engine_data)
651 *engine_callback= NULL;
657 static const uint NO_CURRENT_PART_ID;
658 int loop_extra(
enum ha_extra_function operation);
659 int loop_extra_alter(
enum ha_extra_function operations);
660 void late_extra_cache(uint partition_id);
661 void late_extra_no_cache(uint partition_id);
662 void prepare_extra_cache(uint cachesize);
686 ha_rows min_rows_for_estimate();
687 uint get_biggest_used_partition(uint *part_index);
697 virtual const key_map *keys_to_use_for_scanning();
702 virtual double scan_time();
712 virtual ha_rows records_in_range(uint inx,
key_range * min_key,
729 uint32 calculate_key_hash_value(
Field **field_array);
744 virtual const char *index_type(uint inx);
898 virtual Table_flags table_flags()
const;
956 virtual ulong index_flags(uint inx, uint part,
bool all_parts)
const
961 return m_file[0]->index_flags(inx, part, all_parts) &
962 ~HA_DO_INDEX_COND_PUSHDOWN;
973 virtual const char **
bas_ext()
const;
980 uint min_of_the_max_uint(uint (
handler::*operator_func)(
void)
const)
const;
981 virtual uint max_supported_record_length()
const;
982 virtual uint max_supported_keys()
const;
983 virtual uint max_supported_key_parts()
const;
984 virtual uint max_supported_key_length()
const;
985 virtual uint max_supported_key_part_length()
const;
990 virtual bool low_byte_first()
const
991 {
return m_low_byte_first; }
997 virtual uint extra_rec_buf_length()
const;
998 virtual uint min_record_length(uint options)
const;
1004 virtual bool primary_key_is_clustered()
1005 {
return m_pkey_is_clustered; }
1023 virtual int cmp_ref(
const uchar * ref1,
const uchar * ref2);
1038 ulonglong nb_desired_values,
1039 ulonglong *first_value,
1040 ulonglong *nb_reserved_values);
1041 virtual void release_auto_increment();
1043 virtual int reset_auto_increment(ulonglong value);
1044 virtual void lock_auto_increment()
1047 if (auto_increment_safe_stmt_log_lock)
1049 DBUG_ASSERT(!auto_increment_lock);
1050 if(table_share->tmp_table == NO_TMP_TABLE)
1052 auto_increment_lock= TRUE;
1053 part_share->lock_auto_inc();
1056 virtual void unlock_auto_increment()
1063 if(auto_increment_lock && !auto_increment_safe_stmt_log_lock)
1065 part_share->unlock_auto_inc();
1066 auto_increment_lock= FALSE;
1069 virtual void set_auto_increment_if_higher(
Field *field)
1071 ulonglong nr= (((
Field_num*) field)->unsigned_flag ||
1072 field->val_int() > 0) ? field->val_int() : 0;
1073 lock_auto_increment();
1074 DBUG_ASSERT(part_share->auto_inc_initialized);
1078 unlock_auto_increment();
1090 virtual void init_table_handle_for_HANDLER();
1149 virtual enum_alter_inplace_result
1183 virtual int optimize(THD* thd,
HA_CHECK_OPT *check_opt);
1184 virtual int analyze(THD* thd,
HA_CHECK_OPT *check_opt);
1187 virtual bool check_and_repair(THD *thd);
1188 virtual bool auto_repair()
const;
1189 virtual bool is_crashed()
const;
1194 int handle_opt_part(THD *thd,
HA_CHECK_OPT *check_opt, uint part_id,
1200 int check_misplaced_rows(uint read_part_id,
bool repair);
1201 void append_row_to_str(
String &str);
1214 virtual uint checksum()
const;
1216 virtual int assign_to_keycache(THD* thd,
HA_CHECK_OPT *check_opt);
1217 virtual int preload_keys(THD* thd,
HA_CHECK_OPT* check_opt);
1226 virtual int disable_indexes(uint
mode);
1227 virtual int enable_indexes(uint
mode);
1228 virtual int indexes_are_disabled(
void);