diff options
Diffstat (limited to 'sql/ha_partition.h')
-rw-r--r-- | sql/ha_partition.h | 104 |
1 files changed, 47 insertions, 57 deletions
diff --git a/sql/ha_partition.h b/sql/ha_partition.h index a7e072a3b77..2142fd27a7f 100644 --- a/sql/ha_partition.h +++ b/sql/ha_partition.h @@ -1,3 +1,6 @@ +#ifndef HA_PARTITION_INCLUDED +#define HA_PARTITION_INCLUDED + /* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. @@ -12,43 +15,21 @@ 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifdef __GNUC__ #pragma interface /* gcc class implementation */ #endif +#include "sql_partition.h" /* part_id_range, partition_element */ +#include "queues.h" /* QUEUE */ + enum partition_keywords { - PKW_HASH= 0, PKW_RANGE, PKW_LIST, PKW_KEY, PKW_MAXVALUE, PKW_LINEAR + PKW_HASH= 0, PKW_RANGE, PKW_LIST, PKW_KEY, PKW_MAXVALUE, PKW_LINEAR, + PKW_COLUMNS }; -/* - PARTITION_SHARE is a structure that will be shared amoung all open handlers - The partition implements the minimum of what you will probably need. -*/ - -#ifdef NOT_USED -typedef struct st_partition_share -{ - char *table_name; - uint table_name_length, use_count; - pthread_mutex_t mutex; - THR_LOCK lock; -} PARTITION_SHARE; -#endif - -/** - Partition specific ha_data struct. - @todo: move all partition specific data from TABLE_SHARE here. -*/ -typedef struct st_ha_data_partition -{ - ulonglong next_auto_inc_val; /**< first non reserved value */ - pthread_mutex_t LOCK_auto_inc; - bool auto_inc_initialized; -} HA_DATA_PARTITION; #define PARTITION_BYTES_IN_POS 2 #define PARTITION_ENABLED_TABLE_FLAGS (HA_FILE_BASED | HA_REC_NOT_IN_SEQ) @@ -123,7 +104,7 @@ private: uint m_reorged_parts; // Number of reorganised parts uint m_tot_parts; // Total number of partitions; - uint m_no_locks; // For engines like ha_blackhole, which needs no locks + uint m_num_locks; // For engines like ha_blackhole, which needs no locks uint m_last_part; // Last file that we update,write,read int m_lock_type; // Remembers type of last // external_lock @@ -184,9 +165,6 @@ private: Variables for lock structures. */ THR_LOCK_DATA lock; /* MySQL lock */ -#ifdef NOT_USED - PARTITION_SHARE *share; /* Shared lock info */ -#endif bool auto_increment_lock; /**< lock reading/updating auto_inc */ /** @@ -199,6 +177,12 @@ private: ha_rows m_bulk_inserted_rows; /** used for prediction of start_bulk_insert rows */ enum_monotonicity_info m_part_func_monotonicity_info; + /** Sorted array of partition ids in descending order of number of rows. */ + uint32 *m_part_ids_sorted_by_num_of_records; + /* Compare function for my_qsort2, for reversed order. */ + static int compare_number_of_records(ha_partition *me, + const uint32 *a, + const uint32 *b); public: handler *clone(const char *name, MEM_ROOT *mem_root); virtual void set_part_info(partition_info *part_info) @@ -265,10 +249,10 @@ public: size_t pack_frm_len); virtual int drop_partitions(const char *path); virtual int rename_partitions(const char *path); - bool get_no_parts(const char *name, uint *no_parts) + bool get_no_parts(const char *name, uint *num_parts) { DBUG_ENTER("ha_partition::get_no_parts"); - *no_parts= m_tot_parts; + *num_parts= m_tot_parts; DBUG_RETURN(0); } virtual void change_table_ptr(TABLE *table_arg, TABLE_SHARE *share); @@ -388,6 +372,7 @@ public: virtual int update_row(const uchar * old_data, uchar * new_data); virtual int delete_row(const uchar * buf); virtual int delete_all_rows(void); + virtual int truncate(); virtual void start_bulk_insert(ha_rows rows); virtual int end_bulk_insert(); private: @@ -396,6 +381,15 @@ private: long estimate_read_buffer_size(long original_size); public: + /* + Method for truncating a specific partition. + (i.e. ALTER TABLE t1 TRUNCATE PARTITION p). + + @remark This method is a partitioning-specific hook + and thus not a member of the general SE API. + */ + int truncate_partition(Alter_info *, bool *binlog_stmt); + virtual bool is_fatal_error(int error, uint flags) { if (!handler::is_fatal_error(error, flags) || @@ -557,7 +551,7 @@ public: ------------------------------------------------------------------------- */ virtual int info(uint); - void get_dynamic_partition_info(PARTITION_INFO *stat_info, + void get_dynamic_partition_info(PARTITION_STATS *stat_info, uint part_id); virtual int extra(enum ha_extra_function operation); virtual int extra_opt(enum ha_extra_function operation, ulong cachesize); @@ -605,15 +599,9 @@ public: */ private: - /* - Helper function to get the minimum number of partitions to use for - the optimizer hints/cost calls. - */ - void partitions_optimizer_call_preparations(uint *num_used_parts, - uint *check_min_num, - uint *first); - ha_rows estimate_rows(bool is_records_in_range, uint inx, - key_range *min_key, key_range *max_key); + /* Helper functions for optimizer hints. */ + ha_rows min_rows_for_estimate(); + uint get_biggest_used_partition(uint *part_index); public: /* @@ -990,17 +978,16 @@ private: /* lock already taken */ if (auto_increment_safe_stmt_log_lock) return; - DBUG_ASSERT(table_share->ha_data && !auto_increment_lock); + DBUG_ASSERT(table_share->ha_part_data && !auto_increment_lock); if(table_share->tmp_table == NO_TMP_TABLE) { - HA_DATA_PARTITION *ha_data= (HA_DATA_PARTITION*) table_share->ha_data; auto_increment_lock= TRUE; - pthread_mutex_lock(&ha_data->LOCK_auto_inc); + mysql_mutex_lock(&table_share->ha_part_data->LOCK_auto_inc); } } virtual void unlock_auto_increment() { - DBUG_ASSERT(table_share->ha_data); + DBUG_ASSERT(table_share->ha_part_data); /* If auto_increment_safe_stmt_log_lock is true, we have to keep the lock. It will be set to false and thus unlocked at the end of the statement by @@ -1008,21 +995,19 @@ private: */ if(auto_increment_lock && !auto_increment_safe_stmt_log_lock) { - HA_DATA_PARTITION *ha_data= (HA_DATA_PARTITION*) table_share->ha_data; - pthread_mutex_unlock(&ha_data->LOCK_auto_inc); + mysql_mutex_unlock(&table_share->ha_part_data->LOCK_auto_inc); auto_increment_lock= FALSE; } } virtual void set_auto_increment_if_higher(Field *field) { - HA_DATA_PARTITION *ha_data= (HA_DATA_PARTITION*) table_share->ha_data; ulonglong nr= (((Field_num*) field)->unsigned_flag || field->val_int() > 0) ? field->val_int() : 0; lock_auto_increment(); - DBUG_ASSERT(ha_data->auto_inc_initialized == TRUE); + DBUG_ASSERT(table_share->ha_part_data->auto_inc_initialized == TRUE); /* must check when the mutex is taken */ - if (nr >= ha_data->next_auto_inc_val) - ha_data->next_auto_inc_val= nr + 1; + if (nr >= table_share->ha_part_data->next_auto_inc_val) + table_share->ha_part_data->next_auto_inc_val= nr + 1; unlock_auto_increment(); } @@ -1094,7 +1079,9 @@ public: They are used for on-line/fast alter table add/drop index: ------------------------------------------------------------------------- */ - virtual int add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys); + virtual int add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys, + handler_add_index **add); + virtual int final_add_index(handler_add_index *add, bool commit); virtual int prepare_drop_index(TABLE *table_arg, uint *key_num, uint num_of_keys); virtual int final_drop_index(TABLE *table_arg); @@ -1140,12 +1127,13 @@ public: virtual int backup(TD* thd, HA_CHECK_OPT *check_opt); virtual int restore(THD* thd, HA_CHECK_OPT *check_opt); - virtual int assign_to_keycache(THD* thd, HA_CHECK_OPT *check_opt); - virtual int preload_keys(THD *thd, HA_CHECK_OPT *check_opt); virtual int dump(THD* thd, int fd = -1); virtual int net_read_dump(NET* net); virtual uint checksum() const; */ + /* Enabled keycache for performance reasons, WL#4571 */ + virtual int assign_to_keycache(THD* thd, HA_CHECK_OPT *check_opt); + virtual int preload_keys(THD* thd, HA_CHECK_OPT* check_opt); /* ------------------------------------------------------------------------- @@ -1169,3 +1157,5 @@ public: virtual void append_create_info(String *packet) */ }; + +#endif /* HA_PARTITION_INCLUDED */ |