1#ifndef PARTITION_HANDLER_INCLUDED
2#define PARTITION_HANDLER_INCLUDED
52template <
class Key,
class Value>
61#define PARTITION_BYTES_IN_POS 2
76#define HA_PARTITION_FUNCTION_SUPPORTED (1L << 0)
77#define HA_INPLACE_CHANGE_PARTITION (1L << 1)
338 dd::Table *part_table_def [[maybe_unused]],
578 bool eq_range_arg,
bool sorted);
713 const char *op_name,
const char *fmt, ...)
714 MY_ATTRIBUTE((format(printf, 8, 9)));
app_data_ptr new_data(u_int n, char *val, cons_type consensus)
Base class to be used by handlers different shares.
Definition: handler.h:4115
Class for partitioning specific operations.
Definition: partition_handler.h:194
int exchange_partition(uint part_id, dd::Table *part_table_def, dd::Table *swap_table_def)
Exchange partition.
Definition: partition_handler.cc:329
int truncate_partition(dd::Table *table_def)
Truncate partitions.
Definition: partition_handler.cc:318
virtual bool get_num_parts(const char *name, uint *num_parts)
Get number of partitions for table in SE.
Definition: partition_handler.h:244
virtual int truncate_partition_low(dd::Table *)
Truncate partition.
Definition: partition_handler.h:326
virtual int get_default_num_partitions(HA_CREATE_INFO *info)
Get default number of partitions.
Definition: partition_handler.h:220
virtual ~Partition_handler()=default
virtual uint alter_flags(uint flags) const
Alter flags.
Definition: partition_handler.h:306
virtual enum row_type get_partition_row_type(const dd::Table *table, uint part_id)=0
Get partition row type from SE.
virtual int exchange_partition_low(uint part_id, dd::Table *part_table_def, dd::Table *swap_table_def)
Exchange partition.
Definition: partition_handler.h:337
virtual void set_part_info(partition_info *part_info, bool early)=0
Set the partition info object to be used by the handler.
virtual void get_dynamic_partition_info(ha_statistics *stat_info, ha_checksum *check_sum, uint part_id)=0
Get dynamic table information from partition.
virtual void set_auto_partitions(partition_info *part_info)
Setup auto partitioning.
Definition: partition_handler.h:232
Partition_handler()=default
virtual handler * get_handler()
Return the table handler.
Definition: partition_handler.h:353
Partition_helper is a helper class that implements most generic partitioning functionality such as: t...
Definition: partition_handler.h:390
int ph_index_first(uchar *buf)
Start an index scan from leftmost record and return first record.
Definition: partition_handler.cc:1908
bool set_altered_partitions()
Set used partitions bitmap from Alter_info.
Definition: partition_handler.cc:1278
Prio_queue * m_queue
Prio queue used by sorted read.
Definition: partition_handler.h:1107
void return_top_record(uchar *buf)
Return the top record in sort order.
Definition: partition_handler.cc:2567
void close_partitioning()
Close partitioning for a table.
Definition: partition_handler.cc:424
part_id_range m_part_spec
Definition: partition_handler.h:1093
int ph_index_read_map(uchar *buf, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag)
Read one record in an index scan and start an index scan.
Definition: partition_handler.cc:1833
virtual void destroy_record_priority_queue_for_parts()
Destroy and release engine specific resources used by the record priority queue.
Definition: partition_handler.h:888
uint m_rec_length
Definition: partition_handler.h:1099
virtual void save_auto_increment(ulonglong nr)
Save or persist the current max auto increment.
Definition: partition_handler.h:829
Partition_helper(handler *main_handler)
Definition: partition_handler.cc:345
int common_first_last(uchar *buf)
Common routine for index_first/index_last.
Definition: partition_handler.cc:1955
void get_auto_increment_first_field(ulonglong increment, ulonglong nb_desired_values, ulonglong *first_value, ulonglong *nb_reserved_values)
Get a range of auto increment values.
Definition: partition_handler.cc:693
virtual int index_read_map_in_part(uint part, uchar *buf, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag)=0
uint m_top_entry
Which partition is to deliver next result.
Definition: partition_handler.h:1109
virtual int write_row_in_new_part(uint new_part)=0
write row to new partition.
Priority_queue< uchar *, std::vector< uchar * >, Key_rec_less > Prio_queue
Definition: partition_handler.h:392
int ph_index_prev(uchar *buf)
Read next record when performing index scan backwards.
Definition: partition_handler.cc:2129
int ph_update_row(const uchar *old_data, uchar *new_data)
Update an existing row in the partitioned table.
Definition: partition_handler.cc:559
bool m_ordered
Definition: partition_handler.h:1101
virtual int delete_row_in_part(uint part_id, const uchar *buf)=0
Delete an existing row in the specified partition.
enum_using_ref
Definition: partition_handler.h:1122
@ REF_USED_FOR_SORT
handler::ref is copied to the PQ and must be used during sorting.
Definition: partition_handler.h:1130
@ REF_STORED_IN_PQ
handler::ref is copied to the PQ but does not need to be used in sorting.
Definition: partition_handler.h:1128
@ REF_NOT_USED
handler::ref is not copied to the PQ.
Definition: partition_handler.h:1124
const uchar * m_err_rec
Definition: partition_handler.h:1090
bool m_auto_increment_lock
Definition: partition_handler.h:1092
int handle_ordered_next(uchar *buf, bool is_next_same)
Common routine to handle index_next with ordered results.
Definition: partition_handler.cc:2664
virtual void copy_cached_row(uchar *to_rec, const uchar *from_rec)
Copy a cached row.
Definition: partition_handler.h:908
virtual int rnd_end_in_part(uint part_id, bool scan)=0
int ph_write_row(uchar *buf)
INSERT/UPDATE/DELETE functions.
Definition: partition_handler.cc:454
void unlock_auto_increment()
unlock auto increment.
Definition: partition_handler.h:640
partition_info * m_part_info
All internal partitioning data!
Definition: partition_handler.h:1082
int ph_rnd_init(bool scan)
MODULE full table scan.
Definition: partition_handler.cc:1431
int handle_unordered_scan_next_partition(uchar *buf)
Handle index_next when changing to new partition.
Definition: partition_handler.cc:2340
bool m_reverse_order
Definition: partition_handler.h:1103
virtual void set_eq_range(bool eq_range)=0
handler * m_handler
handler to use (ha_innopart etc.)
Definition: partition_handler.h:761
int handle_ordered_index_scan_key_not_found()
Add index_next/prev results from partitions without exact match.
Definition: partition_handler.cc:2588
int ph_index_next_same(uchar *buf, uint keylen)
Read next same record.
Definition: partition_handler.cc:2107
uint m_tot_parts
Total number of partitions.
Definition: partition_handler.h:1088
uint m_scan_value
Definition: partition_handler.h:1094
bool print_admin_msg(THD *thd, uint len, const char *msg_type, const char *db_name, const char *table_name, const char *op_name, const char *fmt,...)
Print a message row formatted for ANALYZE/CHECK/OPTIMIZE/REPAIR TABLE.
Definition: partition_handler.cc:1311
MY_BITMAP m_key_not_found_partitions
Partitions that returned HA_ERR_KEY_NOT_FOUND.
Definition: partition_handler.h:1137
bool print_partition_error(int error)
Print partitioning specific error.
Definition: partition_handler.cc:908
int handle_unordered_next(uchar *buf, bool is_next_same)
Common routine to handle index_next with unordered results.
Definition: partition_handler.cc:2292
bool m_is_sub_partitioned
Cached value of m_part_info->is_sub_partitioned().
Definition: partition_handler.h:1086
virtual ~Partition_helper()
Definition: partition_handler.cc:356
virtual int index_next_in_part(uint part, uchar *buf)=0
int ph_index_last(uchar *buf)
Start an index scan from rightmost record and return first record.
Definition: partition_handler.cc:1931
int ph_rnd_next(uchar *buf)
Read next row during full table scan (scan in random row order).
Definition: partition_handler.cc:1539
int ph_read_range_next()
Read next record in read of a range with start and end key.
Definition: partition_handler.cc:2192
int check_misplaced_rows(uint read_part_id, bool repair)
Check/fix misplaced rows.
Definition: partition_handler.cc:1096
virtual int index_read_idx_map_in_part(uint part, uchar *buf, uint index, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag)=0
int handle_ordered_prev(uchar *buf)
Common routine to handle index_prev with ordered results.
Definition: partition_handler.cc:2778
int common_index_read(uchar *buf, bool have_start_key)
Common routine for a number of index_read variants.
Definition: partition_handler.cc:1844
virtual void position_in_last_part(uchar *ref, const uchar *row)=0
bool open_partitioning(Partition_share *part_share)
Set m_part_share, Allocate internal bitmaps etc.
Definition: partition_handler.cc:394
Partition_share * m_part_share
Partition share for auto_inc handling.
Definition: partition_handler.h:1142
virtual void set_part_info_low(partition_info *part_info, bool early)
Set partition info.
Definition: partition_handler.cc:370
static uint32 ph_calculate_key_hash_value(Field **field_array)
Calculate key hash value from an null terminated array of fields.
Definition: partition_handler.cc:804
void set_auto_increment_if_higher()
Update auto increment value if current row contains a higher value.
Definition: partition_handler.cc:752
bool m_pkey_is_clustered
Is primary key clustered.
Definition: partition_handler.h:1084
void ph_position(const uchar *record)
Save position of current row.
Definition: partition_handler.cc:1607
bool m_auto_increment_safe_stmt_log_lock
Definition: partition_handler.h:1091
virtual THD * get_thd() const =0
bool m_ordered_scan_ongoing
Definition: partition_handler.h:1102
void destroy_record_priority_queue()
Destroy the record priority queue used for sorted index scans.
Definition: partition_handler.cc:1746
int ph_rnd_end()
End of a table scan.
Definition: partition_handler.cc:1492
virtual void release_auto_increment_all_parts()
Release auto_increment in all underlying partitions.
Definition: partition_handler.h:827
int ph_index_read_idx_map(uchar *buf, uint index, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag)
Read index by key and keymap.
Definition: partition_handler.cc:2015
virtual int write_row_in_part(uint part_id, uchar *buf)=0
Write a row in the specified partition.
void prepare_change_partitions()
Prepare for reorganizing partitions by setting up partition_info::read_partitions according to the pa...
Definition: partition_handler.cc:975
virtual int init_record_priority_queue_for_parts(uint used_parts)
Initialize engine specific resources for the record priority queue used duing ordered index reads for...
Definition: partition_handler.h:880
TABLE * m_table
Convenience pointer to table from m_handler (i.e.
Definition: partition_handler.h:1078
int ph_index_read_last_map(uchar *buf, const uchar *key, key_part_map keypart_map)
Read last using key.
Definition: partition_handler.cc:1983
virtual TABLE * get_table() const =0
virtual int index_first_in_part(uint part, uchar *buf)=0
partition_index_scan_type
Definition: partition_handler.h:750
@ PARTITION_INDEX_FIRST_UNORDERED
Definition: partition_handler.h:753
@ PARTITION_INDEX_READ
Definition: partition_handler.h:751
@ PARTITION_INDEX_FIRST
Definition: partition_handler.h:752
@ PARTITION_INDEX_LAST
Definition: partition_handler.h:754
@ PARTITION_READ_RANGE
Definition: partition_handler.h:756
@ PARTITION_NO_INDEX_SCAN
Definition: partition_handler.h:757
@ PARTITION_INDEX_READ_LAST
Definition: partition_handler.h:755
uint m_last_part
Definition: partition_handler.h:1089
enum partition_index_scan_type m_index_scan_type
Definition: partition_handler.h:1097
void ph_release_auto_increment()
Release unused auto increment values.
Definition: partition_handler.cc:768
int handle_ordered_index_scan(uchar *buf)
Common routine to start index scan with ordered results.
Definition: partition_handler.cc:2435
uint m_rec_offset
Offset in m_ordered_rec_buffer from part buffer to its record buffer.
Definition: partition_handler.h:1111
uchar * m_ordered_rec_buffer
Row and key buffer for ordered index scan.
Definition: partition_handler.h:1105
virtual int index_prev_in_part(uint part, uchar *buf)=0
key_range m_start_key
Definition: partition_handler.h:1096
virtual int read_range_next_in_part(uint part, uchar *buf)=0
Do read_range_next in the specified partition.
virtual int index_read_last_map_in_part(uint part, uchar *buf, const uchar *key, key_part_map keypart_map)=0
void lock_auto_increment()
Lock auto increment value if needed.
Definition: partition_handler.cc:430
int ph_index_next(uchar *buf)
Read next record in a forward index scan.
Definition: partition_handler.cc:2076
bool init_partitioning(MEM_ROOT *mem_root)
Initialize variables used before the table is opened.
Definition: partition_handler.h:417
bool m_key_not_found
Set if previous index_* call returned HA_ERR_KEY_NOT_FOUND.
Definition: partition_handler.h:1135
virtual int index_next_same_in_part(uint part, uchar *buf, const uchar *key, uint length)=0
virtual int copy_partitions(ulonglong *const deleted)
Copy partitions as part of ALTER TABLE of partitions.
Definition: partition_handler.cc:1034
void set_partition_read_set()
Set table->read_set taking partitioning expressions into account.
Definition: partition_handler.cc:1367
int ph_rnd_next_in_part(uint part_id, uchar *buf)
Read next row during full partition scan (scan in random row order).
Definition: partition_handler.cc:1264
virtual int update_row_in_part(uint part_id, const uchar *old_data, uchar *new_data)=0
Update a row in the specified partition.
int ph_read_range_first(const key_range *start_key, const key_range *end_key, bool eq_range_arg, bool sorted)
Start a read of one range with start and end key.
Definition: partition_handler.cc:2156
virtual int initialize_auto_increment(bool no_lock)=0
Initialize the shared auto increment value.
int ph_index_init_setup(uint key_nr, bool sorted)
MODULE index scan.
Definition: partition_handler.cc:1775
enum_using_ref m_ref_usage
How handler::ref is used in the priority queue.
Definition: partition_handler.h:1133
virtual int index_last_in_part(uint part, uchar *buf)=0
int ph_delete_row(const uchar *buf)
Delete an existing row in the partitioned table.
Definition: partition_handler.cc:645
virtual int rnd_init_in_part(uint part_id, bool table_scan)=0
Per partition equivalent of rnd_* and index_* functions.
virtual int rnd_next_in_part(uint part_id, uchar *buf)=0
virtual void get_dynamic_partition_info_low(ha_statistics *stat_info, ha_checksum *check_sum, uint part_id)
Functions matching Partition_handler API.
Definition: partition_handler.cc:2862
virtual void set_range_key_part(KEY_PART_INFO *key_part)=0
int init_record_priority_queue()
Initialize the record priority queue used for sorted index scans.
Definition: partition_handler.cc:1660
int partition_scan_set_up(uchar *buf, bool idx_read_flag)
Common routine to set up index scans.
Definition: partition_handler.cc:2223
virtual int read_range_first_in_part(uint part, uchar *buf, const key_range *start_key, const key_range *end_key, bool sorted)=0
Do read_range_first in the specified partition.
KEY * m_curr_key_info[3]
Current index used for sorting.
Definition: partition_handler.h:1121
virtual ha_checksum checksum_in_part(uint part_id) const
Checksum for a partition.
Definition: partition_handler.h:894
virtual bool get_eq_range() const =0
Partition specific Handler_share.
Definition: partition_handler.h:104
bool init_auto_inc_mutex(TABLE_SHARE *table_share)
Initializes and sets auto_inc_mutex.
Definition: partition_handler.cc:150
void release_auto_inc_if_possible(THD *thd, TABLE_SHARE *table_share, const ulonglong next_insert_id, const ulonglong max_reserved)
Release reserved auto increment values not used.
Definition: partition_handler.cc:176
~Partition_share() override
Definition: partition_handler.cc:132
ulonglong next_auto_inc_val
First non reserved auto increment value.
Definition: partition_handler.h:117
bool insert_partition_name_in_hash(const char *name, uint part_id, bool is_subpart)
Insert [sub]partition name into partition_name_hash.
Definition: partition_handler.cc:278
mysql_mutex_t * auto_inc_mutex
Mutex protecting next_auto_inc_val.
Definition: partition_handler.h:115
const uchar ** partition_names
Definition: partition_handler.h:174
bool auto_inc_initialized
Set if auto increment is used an initialized.
Definition: partition_handler.h:110
void unlock_auto_inc()
unlock mutex protecting auto increment value next_auto_inc_val.
Definition: partition_handler.h:150
const char * get_partition_name(size_t part_id) const
Get partition name.
Definition: partition_handler.cc:311
std::unique_ptr< collation_unordered_map< std::string, unique_ptr_my_free< PART_NAME_DEF > > > partition_name_hash
Hash of partition names.
Definition: partition_handler.h:125
void lock_auto_inc()
lock mutex protecting auto increment value next_auto_inc_val.
Definition: partition_handler.h:145
Partition_share()
Definition: partition_handler.cc:126
bool populate_partition_name_hash(partition_info *part_info)
Populate partition_name_hash with partition and subpartition names from part_info.
Definition: partition_handler.cc:205
Implements a priority queue using a vector-based max-heap.
Definition: priority_queue.h:104
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
std::unordered_map, but with my_malloc and collation-aware comparison.
Definition: map_helpers.h:219
Definition: handler.h:4036
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4573
Definition: partition_info.h:209
A table definition from the master.
Definition: rpl_utility.h:249
static MEM_ROOT mem_root
Definition: client_plugin.cc:114
#define mysql_mutex_lock(M)
Definition: mysql_mutex.h:50
#define mysql_mutex_unlock(M)
Definition: mysql_mutex.h:57
static int flags[50]
Definition: hp_test1.cc:40
static uint keys
Definition: hp_test2.cc:49
int key_rec_cmp(KEY **key, uchar *first_rec, uchar *second_rec)
Compare two records in index order.
Definition: key.cc:589
This file includes constants used by all storage engines.
ha_rkey_function
Definition: my_base.h:78
ulong key_part_map
Definition: my_base.h:1008
#define HA_ERR_WRONG_COMMAND
Command not supported.
Definition: my_base.h:841
std::uint32_t ha_checksum
Definition: my_checksum.h:106
Header for compiler-dependent features.
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
unsigned char uchar
Definition: my_inttypes.h:52
uint32_t uint32
Definition: my_inttypes.h:67
#define UINT_MAX32
Definition: my_inttypes.h:79
Common header for many mysys elements.
static int record
Definition: mysqltest.cc:195
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
Definition: buf0block_hint.cc:30
PT & ref(PT *tp)
Definition: tablespace_impl.cc:359
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:43
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
const char * table_name
Definition: rules_table_service.cc:56
const char * db_name
Definition: rules_table_service.cc:55
std::conditional_t< !std::is_array< T >::value, std::unique_ptr< T, detail::Deleter< T > >, std::conditional_t< detail::is_unbounded_array_v< T >, std::unique_ptr< T, detail::Array_deleter< std::remove_extent_t< T > > >, void > > unique_ptr
The following is a common type that is returned by all the ut::make_unique (non-aligned) specializati...
Definition: ut0new.h:2439
enum_part_operation
Definition: partition_handler.h:79
@ REPAIR_PARTS
Definition: partition_handler.h:83
@ PRELOAD_KEYS_PARTS
Definition: partition_handler.h:85
@ CHECK_PARTS
Definition: partition_handler.h:82
@ ASSIGN_KEYCACHE_PARTS
Definition: partition_handler.h:84
@ ANALYZE_PARTS
Definition: partition_handler.h:81
@ OPTIMIZE_PARTS
Definition: partition_handler.h:80
void partitioning_init()
Initialize partitioning (currently only PSI keys).
Definition: partition_handler.cc:112
static const uint NO_CURRENT_PART_ID
Definition: partition_handler.h:65
Instrumentation helpers for mutexes.
required string key
Definition: replication_asynchronous_connection_failover.proto:60
row_type
Definition: handler.h:684
case opt name
Definition: sslopt-case.h:29
Struct to hold information about the table that should be created.
Definition: handler.h:3202
Maps compare function to strict weak ordering required by Priority_queue.
Definition: partition_handler.h:357
KEY ** m_keys
Definition: partition_handler.h:369
Key_rec_less(KEY **keys)
Definition: partition_handler.h:360
bool m_max_at_top
Definition: partition_handler.h:372
key_compare_fun m_fun
Definition: partition_handler.h:370
int(* key_compare_fun)(KEY **, uchar *, uchar *)
Definition: partition_handler.h:358
bool operator()(uchar *first, uchar *second)
Definition: partition_handler.h:363
uint m_rec_offset
Definition: partition_handler.h:371
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
Definition: my_bitmap.h:43
my_bitmap_map * bitmap
Definition: my_bitmap.h:44
Struct used for partition_name_hash.
Definition: partition_handler.h:89
uint length
Definition: partition_handler.h:91
bool is_subpart
Definition: partition_handler.h:93
uchar * partition_name
Definition: partition_handler.h:90
uint32 part_id
Definition: partition_handler.h:92
This structure is shared between different table objects.
Definition: table.h:701
Definition: my_base.h:1125
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
Definition: sql_partition.h:88