MySQL 9.1.0
Source Code Documentation
Partition_helper Class Referenceabstract

Partition_helper is a helper class that implements most generic partitioning functionality such as: table scan, index scan (both ordered and non-ordered), insert (write_row()), delete and update. More...

#include <partition_handler.h>

Inheritance diagram for Partition_helper:
[legend]

Public Member Functions

 Partition_helper (handler *main_handler)
 
virtual ~Partition_helper ()
 
virtual void set_part_info_low (partition_info *part_info, bool early)
 Set partition info. More...
 
bool init_partitioning (MEM_ROOT *mem_root)
 Initialize variables used before the table is opened. More...
 
void ph_release_auto_increment ()
 Release unused auto increment values. More...
 
int ph_write_row (uchar *buf)
 INSERT/UPDATE/DELETE functions. More...
 
int ph_update_row (const uchar *old_data, uchar *new_data)
 Update an existing row in the partitioned table. More...
 
int ph_delete_row (const uchar *buf)
 Delete an existing row in the partitioned table. More...
 
int ph_rnd_init (bool scan)
 MODULE full table scan. More...
 
int ph_rnd_end ()
 End of a table scan. More...
 
int ph_rnd_next (uchar *buf)
 Read next row during full table scan (scan in random row order). More...
 
void ph_position (const uchar *record)
 Save position of current row. More...
 
int ph_index_init_setup (uint key_nr, bool sorted)
 MODULE index scan. More...
 
int ph_index_first (uchar *buf)
 Start an index scan from leftmost record and return first record. More...
 
int ph_index_last (uchar *buf)
 Start an index scan from rightmost record and return first record. More...
 
int ph_index_next (uchar *buf)
 Read next record in a forward index scan. More...
 
int ph_index_next_same (uchar *buf, uint keylen)
 Read next same record. More...
 
int ph_index_prev (uchar *buf)
 Read next record when performing index scan backwards. More...
 
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. More...
 
int ph_index_read_last_map (uchar *buf, const uchar *key, key_part_map keypart_map)
 Read last using key. More...
 
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. More...
 
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. More...
 
int ph_read_range_next ()
 Read next record in read of a range with start and end key. More...
 
virtual void get_dynamic_partition_info_low (ha_statistics *stat_info, ha_checksum *check_sum, uint part_id)
 Functions matching Partition_handler API. More...
 
void prepare_change_partitions ()
 Prepare for reorganizing partitions by setting up partition_info::read_partitions according to the partition_info mark-up. More...
 

Static Public Member Functions

static uint32 ph_calculate_key_hash_value (Field **field_array)
 Calculate key hash value from an null terminated array of fields. More...
 

Protected Member Functions

bool open_partitioning (Partition_share *part_share)
 Set m_part_share, Allocate internal bitmaps etc. More...
 
void close_partitioning ()
 Close partitioning for a table. More...
 
void lock_auto_increment ()
 Lock auto increment value if needed. More...
 
void unlock_auto_increment ()
 unlock auto increment. More...
 
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. More...
 
int init_record_priority_queue ()
 Initialize the record priority queue used for sorted index scans. More...
 
void destroy_record_priority_queue ()
 Destroy the record priority queue used for sorted index scans. More...
 
bool print_partition_error (int error)
 Print partitioning specific error. More...
 
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. More...
 
int check_misplaced_rows (uint read_part_id, bool repair)
 Check/fix misplaced rows. More...
 
bool set_altered_partitions ()
 Set used partitions bitmap from Alter_info. More...
 
virtual int copy_partitions (ulonglong *const deleted)
 Copy partitions as part of ALTER TABLE of partitions. More...
 

Protected Attributes

TABLEm_table
 Convenience pointer to table from m_handler (i.e. More...
 

Private Types

enum  partition_index_scan_type {
  PARTITION_INDEX_READ = 1 , PARTITION_INDEX_FIRST , PARTITION_INDEX_FIRST_UNORDERED , PARTITION_INDEX_LAST ,
  PARTITION_INDEX_READ_LAST , PARTITION_READ_RANGE , PARTITION_NO_INDEX_SCAN
}
 
typedef Priority_queue< uchar *, std::vector< uchar * >, Key_rec_lessPrio_queue
 

Private Member Functions

virtual THDget_thd () const =0
 
virtual TABLEget_table () const =0
 
virtual bool get_eq_range () const =0
 
virtual void set_eq_range (bool eq_range)=0
 
virtual void set_range_key_part (KEY_PART_INFO *key_part)=0
 
virtual int write_row_in_part (uint part_id, uchar *buf)=0
 Write a row in the specified partition. More...
 
virtual int update_row_in_part (uint part_id, const uchar *old_data, uchar *new_data)=0
 Update a row in the specified partition. More...
 
virtual int delete_row_in_part (uint part_id, const uchar *buf)=0
 Delete an existing row in the specified partition. More...
 
virtual int initialize_auto_increment (bool no_lock)=0
 Initialize the shared auto increment value. More...
 
virtual void release_auto_increment_all_parts ()
 Release auto_increment in all underlying partitions. More...
 
virtual void save_auto_increment (ulonglong nr)
 Save or persist the current max auto increment. More...
 
virtual int rnd_init_in_part (uint part_id, bool table_scan)=0
 Per partition equivalent of rnd_* and index_* functions. More...
 
int ph_rnd_next_in_part (uint part_id, uchar *buf)
 Read next row during full partition scan (scan in random row order). More...
 
virtual int rnd_next_in_part (uint part_id, uchar *buf)=0
 
virtual int rnd_end_in_part (uint part_id, bool scan)=0
 
virtual void position_in_last_part (uchar *ref, const uchar *row)=0
 
virtual int index_first_in_part (uint part, uchar *buf)=0
 
virtual int index_last_in_part (uint part, uchar *buf)=0
 
virtual int index_prev_in_part (uint part, uchar *buf)=0
 
virtual int index_next_in_part (uint part, uchar *buf)=0
 
virtual int index_next_same_in_part (uint part, uchar *buf, const uchar *key, uint length)=0
 
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
 
virtual int index_read_last_map_in_part (uint part, uchar *buf, const uchar *key, key_part_map keypart_map)=0
 
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. More...
 
virtual int read_range_next_in_part (uint part, uchar *buf)=0
 Do read_range_next in the specified partition. More...
 
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
 
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 multiple partitions. More...
 
virtual void destroy_record_priority_queue_for_parts ()
 Destroy and release engine specific resources used by the record priority queue. More...
 
virtual ha_checksum checksum_in_part (uint part_id) const
 Checksum for a partition. More...
 
virtual void copy_cached_row (uchar *to_rec, const uchar *from_rec)
 Copy a cached row. More...
 
virtual int write_row_in_new_part (uint new_part)=0
 write row to new partition. More...
 
void set_auto_increment_if_higher ()
 Update auto increment value if current row contains a higher value. More...
 
int partition_scan_set_up (uchar *buf, bool idx_read_flag)
 Common routine to set up index scans. More...
 
int handle_unordered_next (uchar *buf, bool is_next_same)
 Common routine to handle index_next with unordered results. More...
 
int handle_unordered_scan_next_partition (uchar *buf)
 Handle index_next when changing to new partition. More...
 
int handle_ordered_index_scan (uchar *buf)
 Common routine to start index scan with ordered results. More...
 
int handle_ordered_index_scan_key_not_found ()
 Add index_next/prev results from partitions without exact match. More...
 
int handle_ordered_prev (uchar *buf)
 Common routine to handle index_prev with ordered results. More...
 
int handle_ordered_next (uchar *buf, bool is_next_same)
 Common routine to handle index_next with ordered results. More...
 
int common_index_read (uchar *buf, bool have_start_key)
 Common routine for a number of index_read variants. More...
 
int common_first_last (uchar *buf)
 Common routine for index_first/index_last. More...
 
void return_top_record (uchar *buf)
 Return the top record in sort order. More...
 
void set_partition_read_set ()
 Set table->read_set taking partitioning expressions into account. More...
 

Private Attributes

handlerm_handler
 handler to use (ha_innopart etc.) More...
 
Partition_sharem_part_share
 Partition share for auto_inc handling. More...
 
enum  enum_using_ref { REF_NOT_USED = 0 , REF_STORED_IN_PQ , REF_USED_FOR_SORT }
 
partition_infom_part_info
 All internal partitioning data! More...
 
bool m_pkey_is_clustered
 Is primary key clustered. More...
 
bool m_is_sub_partitioned
 Cached value of m_part_info->is_sub_partitioned(). More...
 
uint m_tot_parts
 Total number of partitions. More...
 
uint m_last_part
 
const ucharm_err_rec
 
bool m_auto_increment_safe_stmt_log_lock
 
bool m_auto_increment_lock
 
part_id_range m_part_spec
 
uint m_scan_value
 
key_range m_start_key
 
enum partition_index_scan_type m_index_scan_type
 
uint m_rec_length
 
bool m_ordered
 
bool m_ordered_scan_ongoing
 
bool m_reverse_order
 
ucharm_ordered_rec_buffer
 Row and key buffer for ordered index scan. More...
 
Prio_queuem_queue
 Prio queue used by sorted read. More...
 
uint m_top_entry
 Which partition is to deliver next result. More...
 
uint m_rec_offset
 Offset in m_ordered_rec_buffer from part buffer to its record buffer. More...
 
KEYm_curr_key_info [3]
 Current index used for sorting. More...
 
enum_using_ref m_ref_usage
 How handler::ref is used in the priority queue. More...
 
bool m_key_not_found
 Set if previous index_* call returned HA_ERR_KEY_NOT_FOUND. More...
 
MY_BITMAP m_key_not_found_partitions
 Partitions that returned HA_ERR_KEY_NOT_FOUND. More...
 

Detailed Description

Partition_helper is a helper class that implements most generic partitioning functionality such as: table scan, index scan (both ordered and non-ordered), insert (write_row()), delete and update.

And includes ALTER TABLE ... ADD/COALESCE/DROP/REORGANIZE/... PARTITION support. It also implements a cache for the auto increment value and check/repair for rows in wrong partition.

How to use it: Inherit it and implement:

  • *_in_part() functions for row operations.
  • write_row_in_new_part() for handling 'fast' alter partition.

Member Typedef Documentation

◆ Prio_queue

Member Enumeration Documentation

◆ enum_using_ref

Enumerator
REF_NOT_USED 

handler::ref is not copied to the PQ.

REF_STORED_IN_PQ 

handler::ref is copied to the PQ but does not need to be used in sorting.

REF_USED_FOR_SORT 

handler::ref is copied to the PQ and must be used during sorting.

◆ partition_index_scan_type

Enumerator
PARTITION_INDEX_READ 
PARTITION_INDEX_FIRST 
PARTITION_INDEX_FIRST_UNORDERED 
PARTITION_INDEX_LAST 
PARTITION_INDEX_READ_LAST 
PARTITION_READ_RANGE 
PARTITION_NO_INDEX_SCAN 

Constructor & Destructor Documentation

◆ Partition_helper()

Partition_helper::Partition_helper ( handler main_handler)

◆ ~Partition_helper()

Partition_helper::~Partition_helper ( )
virtual

Member Function Documentation

◆ check_misplaced_rows()

int Partition_helper::check_misplaced_rows ( uint  read_part_id,
bool  repair 
)
protected

Check/fix misplaced rows.

Parameters
read_part_idPartition to check/fix.
repairIf true, move misplaced rows to correct partition.
Returns
Operation status.
Return values
0Success
!=0 Error

◆ checksum_in_part()

virtual ha_checksum Partition_helper::checksum_in_part ( uint  part_id) const
inlineprivatevirtual

Checksum for a partition.

Parameters
part_idPartition to checksum.

◆ close_partitioning()

void Partition_helper::close_partitioning ( )
protected

Close partitioning for a table.

Frees memory and release other resources.

◆ common_first_last()

int Partition_helper::common_first_last ( uchar buf)
private

Common routine for index_first/index_last.

Parameters
[out]bufRead row in MySQL Row Format.
Returns
Operation status.
Return values
0Success
!=0 Error code

◆ common_index_read()

int Partition_helper::common_index_read ( uchar buf,
bool  have_start_key 
)
private

Common routine for a number of index_read variants.

Parameters
[out]bufBuffer where the record should be returned.
[in]have_start_keytrue <=> the left endpoint is available, i.e. we're in index_read call or in read_range_first call and the range has left endpoint. false <=> there is no left endpoint (we're in read_range_first() call and the range has no left endpoint).
Returns
Operation status
Return values
0OK
HA_ERR_END_OF_FILEWhole index scanned, without finding the record.
HA_ERR_KEY_NOT_FOUNDRecord not found, but index cursor positioned.
otherError code.

Start scanning the range (when invoked from read_range_first()) or doing an index lookup (when invoked from index_read_XXX):

  • If possible, perform partition selection
  • Find the set of partitions we're going to use
  • Depending on whether we need ordering: NO: Get the first record from first used partition (see handle_unordered_scan_next_partition) YES: Fill the priority queue and get the record that is the first in the ordering

◆ copy_cached_row()

virtual void Partition_helper::copy_cached_row ( uchar to_rec,
const uchar from_rec 
)
inlineprivatevirtual

Copy a cached row.

Used when copying a row from the record priority queue to the return buffer. For some engines, like InnoDB, only marked columns must be copied, to preserve non-read columns.

Parameters
[out]to_recBuffer to copy to.
[in]from_recBuffer to copy from.

Reimplemented in ha_innopart.

◆ copy_partitions()

int Partition_helper::copy_partitions ( ulonglong *const  deleted)
protectedvirtual

Copy partitions as part of ALTER TABLE of partitions.

SE and prepare_change_partitions has done all the preparations, now it is time to actually copy the data from the reorganized partitions to the new partitions.

Parameters
[out]deletedNumber of records deleted.
Returns
Operation status
Return values
0Success
>0Error code

◆ delete_row_in_part()

virtual int Partition_helper::delete_row_in_part ( uint  part_id,
const uchar buf 
)
privatepure virtual

Delete an existing row in the specified partition.

See also
handler::delete_row().
Parameters
part_idPartition to delete from.
bufBuffer containing row to delete.
Returns
Operation status.
Return values
0Success.
!=0 Error code.

Implemented in ha_innopart.

◆ destroy_record_priority_queue()

void Partition_helper::destroy_record_priority_queue ( )
protected

Destroy the record priority queue used for sorted index scans.

Destroy the ordered record buffer and the priority queue.

◆ destroy_record_priority_queue_for_parts()

virtual void Partition_helper::destroy_record_priority_queue_for_parts ( )
inlineprivatevirtual

Destroy and release engine specific resources used by the record priority queue.

Reimplemented in ha_innopart.

◆ get_auto_increment_first_field()

void Partition_helper::get_auto_increment_first_field ( ulonglong  increment,
ulonglong  nb_desired_values,
ulonglong first_value,
ulonglong nb_reserved_values 
)
protected

Get a range of auto increment values.

Can only be used if the auto increment field is the first field in an index.

This method is called by update_auto_increment which in turn is called by the individual handlers as part of write_row. We use the part_share->next_auto_inc_val, or search all partitions for the highest auto_increment_value if not initialized or if auto_increment field is a secondary part of a key, we must search every partition when holding a mutex to be sure of correctness.

Parameters
[in]incrementIncrement value.
[in]nb_desired_valuesNumber of desired values.
[out]first_valueFirst auto inc value reserved or MAX if failure.
[out]nb_reserved_valuesNumber of values reserved.

◆ get_dynamic_partition_info_low()

void Partition_helper::get_dynamic_partition_info_low ( ha_statistics stat_info,
ha_checksum check_sum,
uint  part_id 
)
virtual

Functions matching Partition_handler API.

Get statistics from a specific partition.

Parameters
[out]stat_infoArea to report values into.
[out]check_sumCheck sum of partition.
[in]part_idPartition to report from.

◆ get_eq_range()

virtual bool Partition_helper::get_eq_range ( ) const
privatepure virtual

Implemented in ha_innopart.

◆ get_table()

virtual TABLE * Partition_helper::get_table ( ) const
privatepure virtual

Implemented in ha_innopart.

◆ get_thd()

virtual THD * Partition_helper::get_thd ( ) const
privatepure virtual

Implemented in ha_innopart.

◆ handle_ordered_index_scan()

int Partition_helper::handle_ordered_index_scan ( uchar buf)
private

Common routine to start index scan with ordered results.

Returns
Operation status
HA_ERR_END_OF_FILE End of scan
HA_ERR_KEY_NOT_FOUND End of scan
0 Success
other Error code
Parameters
[out]bufRead row in MySQL Row Format
Returns
Operation status
Return values
HA_ERR_END_OF_FILEEnd of scan
HA_ERR_KEY_NOT_FOUNDEnd of scan
0Success
otherError code

This part contains the logic to handle index scans that require ordered output. This includes all except those started by read_range_first with the flag ordered set to false. Thus most direct index_read and all index_first and index_last.

We implement ordering by keeping one record plus a key buffer for each partition. Every time a new entry is requested we will fetch a new entry from the partition that is currently not filled with an entry. Then the entry is put into its proper sort position.

Returning a record is done by getting the top record, copying the record to the request buffer and setting the partition as empty on entries.

◆ handle_ordered_index_scan_key_not_found()

int Partition_helper::handle_ordered_index_scan_key_not_found ( )
private

Add index_next/prev results from partitions without exact match.

If there where any partitions that returned HA_ERR_KEY_NOT_FOUND when ha_index_read_map was done, those partitions must be included in the following index_next/prev call.

Returns
Operation status
HA_ERR_END_OF_FILE End of scan
0 Success
other Error code

If there where any partitions that returned HA_ERR_KEY_NOT_FOUND when ha_index_read_map was done, those partitions must be included in the following index_next/prev call.

◆ handle_ordered_next()

int Partition_helper::handle_ordered_next ( uchar buf,
bool  is_next_same 
)
private

Common routine to handle index_next with ordered results.

Parameters
[out]bufRead row in MySQL Row Format.
[in]is_next_sameCalled from index_next_same.
Returns
Operation status.
Return values
HA_ERR_END_OF_FILEEnd of scan
0Success
otherError code

◆ handle_ordered_prev()

int Partition_helper::handle_ordered_prev ( uchar buf)
private

Common routine to handle index_prev with ordered results.

Parameters
[out]bufRead row in MySQL Row Format.
Returns
Operation status.
Return values
HA_ERR_END_OF_FILEEnd of scan
0Success
otherError code

◆ handle_unordered_next()

int Partition_helper::handle_unordered_next ( uchar buf,
bool  is_next_same 
)
private

Common routine to handle index_next with unordered results.

These routines are used to scan partitions without considering order. This is performed in two situations. 1) In read_multi_range this is the normal case 2) When performing any type of index_read, index_first, index_last where all fields in the partition function is bound. In this case the index scan is performed on only one partition and thus it isn't necessary to perform any sort.

Returns
Operation status.
HA_ERR_END_OF_FILE End of scan
0 Success
other Error code

These routines are used to scan partitions without considering order. This is performed in two situations. 1) In read_multi_range this is the normal case 2) When performing any type of index_read, index_first, index_last where all fields in the partition function is bound. In this case the index scan is performed on only one partition and thus it isn't necessary to perform any sort.

Parameters
[out]bufRead row in MySQL Row Format.
[in]is_next_sameCalled from index_next_same.
Returns
Operation status.
Return values
HA_ERR_END_OF_FILEEnd of scan
0Success
otherError code

◆ handle_unordered_scan_next_partition()

int Partition_helper::handle_unordered_scan_next_partition ( uchar buf)
private

Handle index_next when changing to new partition.

This routine is used to start the index scan on the next partition. Both initial start and after completing scan on one partition.

Parameters
[out]bufRead row in MySQL Row Format
Returns
Operation status.
Return values
HA_ERR_END_OF_FILEEnd of scan
0Success
otherError code

◆ index_first_in_part()

virtual int Partition_helper::index_first_in_part ( uint  part,
uchar buf 
)
privatepure virtual

Implemented in ha_innopart.

◆ index_last_in_part()

virtual int Partition_helper::index_last_in_part ( uint  part,
uchar buf 
)
privatepure virtual

Implemented in ha_innopart.

◆ index_next_in_part()

virtual int Partition_helper::index_next_in_part ( uint  part,
uchar buf 
)
privatepure virtual

Implemented in ha_innopart.

◆ index_next_same_in_part()

virtual int Partition_helper::index_next_same_in_part ( uint  part,
uchar buf,
const uchar key,
uint  length 
)
privatepure virtual

Implemented in ha_innopart.

◆ index_prev_in_part()

virtual int Partition_helper::index_prev_in_part ( uint  part,
uchar buf 
)
privatepure virtual

Implemented in ha_innopart.

◆ index_read_idx_map_in_part()

virtual int Partition_helper::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 
)
privatepure virtual

Implemented in ha_innopart.

◆ index_read_last_map_in_part()

virtual int Partition_helper::index_read_last_map_in_part ( uint  part,
uchar buf,
const uchar key,
key_part_map  keypart_map 
)
privatepure virtual

Implemented in ha_innopart.

◆ index_read_map_in_part()

virtual int Partition_helper::index_read_map_in_part ( uint  part,
uchar buf,
const uchar key,
key_part_map  keypart_map,
enum ha_rkey_function  find_flag 
)
privatepure virtual

Implemented in ha_innopart.

◆ init_partitioning()

bool Partition_helper::init_partitioning ( MEM_ROOT mem_root)
inline

Initialize variables used before the table is opened.

Parameters
mem_rootMemory root to allocate things from (not yet used).
Returns
Operation status.
Return values
falsesuccess.
truefailure.

◆ init_record_priority_queue()

int Partition_helper::init_record_priority_queue ( )
protected

Initialize the record priority queue used for sorted index scans.

Setup the ordered record buffer and the priority queue.

Returns
Operation status.
Return values
0Success.
!=0 Error code.

Call destroy_record_priority_queue() to deallocate or clean-up from failure.

Returns
false on success, else true.

◆ init_record_priority_queue_for_parts()

virtual int Partition_helper::init_record_priority_queue_for_parts ( uint  used_parts)
inlineprivatevirtual

Initialize engine specific resources for the record priority queue used duing ordered index reads for multiple partitions.

Parameters
used_partsNumber of partitions used in query (number of set bits in m_part_info->read_partitions).
Returns
Operation status.
Return values
0Success.
!=0 Error code.

Reimplemented in ha_innopart.

◆ initialize_auto_increment()

virtual int Partition_helper::initialize_auto_increment ( bool  no_lock)
privatepure virtual

Initialize the shared auto increment value.

Parameters
no_lockIf HA_STATUS_NO_LOCK should be used in info(HA_STATUS_AUTO).

Also sets stats.auto_increment_value.

Implemented in ha_innopart.

◆ lock_auto_increment()

void Partition_helper::lock_auto_increment ( )
protected

Lock auto increment value if needed.

◆ open_partitioning()

bool Partition_helper::open_partitioning ( Partition_share part_share)
protected

Set m_part_share, Allocate internal bitmaps etc.

Initialize the partitioning helper for use after the table is opened.

used by open tables.

Returns
Operation status.
false success.
true failure.
Parameters
part_sharePartitioning share (used for auto increment).
Returns
Operation status.
Return values
falsefor success otherwise true.

◆ partition_scan_set_up()

int Partition_helper::partition_scan_set_up ( uchar buf,
bool  idx_read_flag 
)
private

Common routine to set up index scans.

Find out which partitions we'll need to read when scanning the specified range.

If we need to scan only one partition, set m_ordered_scan_ongoing=false as we will not need to do merge ordering.

Returns
Operation status.
0 Success
!=0 Error code

Find out which partitions we'll need to read when scanning the specified range.

If we need to scan only one partition, set m_ordered_scan_ongoing=false as we will not need to do merge ordering.

Parameters
bufBuffer to later return record in (this function needs it to calculate partitioning function values)
idx_read_flagtrue <=> m_start_key has range start endpoint which probably can be used to determine the set of partitions to scan. false <=> there is no start endpoint.
Returns
Operation status.
Return values
0Success
!=0Error code

◆ ph_calculate_key_hash_value()

uint32 Partition_helper::ph_calculate_key_hash_value ( Field **  field_array)
static

Calculate key hash value from an null terminated array of fields.

Support function for KEY partitioning.

Parameters
field_arrayAn array of the fields in KEY partitioning
Returns
hash_value calculated
Note
Uses the hash function on the character set of the field. Integer and floating point fields use the binary character set by default.

◆ ph_delete_row()

int Partition_helper::ph_delete_row ( const uchar buf)

Delete an existing row in the partitioned table.

This will delete a row. buf will contain a copy of the row to be deleted. The server will call this right after the current row has been read (from either a previous rnd_xxx() or index_xxx() call). If you keep a pointer to the last row or can access a primary key it will make doing the deletion quite a bit easier. Keep in mind that the server does no guarantee consecutive deletions. ORDER BY clauses can be used.

buf is either record[0] or record[1]

Parameters
bufThe record in MySQL Row Format.
Returns
Operation status.
Return values
0Success
!=0 Error code

◆ ph_index_first()

int Partition_helper::ph_index_first ( uchar buf)

Start an index scan from leftmost record and return first record.

index_first() asks for the first key in the index. This is similar to index_read except that there is no start key since the scan starts from the leftmost entry and proceeds forward with index_next.

Parameters
[out]bufRead row in MySQL Row Format.
Returns
Operation status.
Return values
0Success
!=0 Error code

◆ ph_index_init_setup()

int Partition_helper::ph_index_init_setup ( uint  inx,
bool  sorted 
)

MODULE index scan.

Common setup for index_init.

This part of the handler interface is used to perform access through indexes. The interface is defined as a scan interface but the handler can also use key lookup if the index is a unique index or a primary key index. Index scans are mostly useful for SELECT queries but are an important part also of UPDATE, DELETE, REPLACE and CREATE TABLE table AS SELECT and so forth. Naturally an index is needed for an index scan and indexes can either be ordered, hash based. Some ordered indexes can return data in order but not necessarily all of them. There are many flags that define the behavior of indexes in the

various handlers. These methods are found in the optimizer module.

index_read is called to start a scan of an index. The find_flag defines the semantics of the scan. These flags are defined in include/my_base.h index_read_idx is the same but also initializes index before calling doing the same thing as index_read. Thus it is similar to index_init followed by index_read. This is also how we implement it.

index_read/index_read_idx does also return the first row. Thus for key lookups, the index_read will be the only call to the handler in the index scan.

index_init initializes an index before using it and index_end does any end processing needed.

Set up variables and initialize the record priority queue.

Parameters
inxIndex to be used.
sortedTrue if the rows must be returned in index order.
Returns
Operation status.
Return values
0Success
!=0 Error code

◆ ph_index_last()

int Partition_helper::ph_index_last ( uchar buf)

Start an index scan from rightmost record and return first record.

index_last() asks for the last key in the index. This is similar to index_read except that there is no start key since the scan starts from the rightmost entry and proceeds forward with index_prev.

Parameters
[out]bufRead row in MySQL Row Format.
Returns
Operation status.
Return values
0Success
!=0 Error code

◆ ph_index_next()

int Partition_helper::ph_index_next ( uchar buf)

Read next record in a forward index scan.

Used to read forward through the index (left to right, low to high).

Parameters
[out]bufRead row in MySQL Row Format.
Returns
Operation status.
Return values
0Success
!=0 Error code

◆ ph_index_next_same()

int Partition_helper::ph_index_next_same ( uchar buf,
uint  keylen 
)

Read next same record.

This routine is used to read the next but only if the key is the same as supplied in the call.

Parameters
[out]bufRead row in MySQL Row Format.
[in]keylenLength of key.
Returns
Operation status.
Return values
0Success
!=0 Error code

◆ ph_index_prev()

int Partition_helper::ph_index_prev ( uchar buf)

Read next record when performing index scan backwards.

Used to read backwards through the index (right to left, high to low).

Parameters
[out]bufRead row in MySQL Row Format.
Returns
Operation status.
Return values
0Success
!=0 Error code

◆ ph_index_read_idx_map()

int Partition_helper::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.

Positions an index cursor to the index specified. Fetches the row if available. If the key value is null, begin at first key of the index.

Optimization of the default implementation to take advantage of dynamic partition pruning.

Parameters
[out]bufRead row in MySQL Row Format
[in]indexIndex to read from
[in]keyKey
[in]keypart_mapWhich part of key is used
[in]find_flagDirection/how to search.
Returns
Operation status.
Return values
0Success
!=0 Error code

◆ ph_index_read_last_map()

int Partition_helper::ph_index_read_last_map ( uchar buf,
const uchar key,
key_part_map  keypart_map 
)

Read last using key.

This is used in join_read_last_key to optimize away an ORDER BY. Can only be used on indexes supporting HA_READ_ORDER.

Parameters
[out]bufRead row in MySQL Row Format
[in]keyKey
[in]keypart_mapWhich part of key is used
Returns
Operation status.
Return values
0Success
!=0 Error code

◆ ph_index_read_map()

int Partition_helper::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.

index_read_map starts a new index scan using a start key. The MySQL Server will check the end key on its own. Thus to function properly the partitioned handler need to ensure that it delivers records in the sort order of the MySQL Server. index_read_map can be restarted without calling index_end on the previous index scan and without calling index_init. In this case the index_read_map is on the same index as the previous index_scan. This is particularly used in conjunction with multi read ranges.

Parameters
[out]bufRead row in MySQL Row Format
[in]keyKey parts in consecutive order
[in]keypart_mapWhich part of key is used
[in]find_flagWhat type of key condition is used
Returns
Operation status.
Return values
0Success
!=0 Error code

◆ ph_position()

void Partition_helper::ph_position ( const uchar record)

Save position of current row.

position() is called after each call to rnd_next() if the data needs to be ordered or accessed later.

The server uses ref to store data. ref_length in the above case is the size needed to store current_position. ref is just a byte array that the server will maintain. If you are using offsets to mark rows, then current_position should be the offset. If it is a primary key like in InnoDB, then it needs to be a primary key.

Parameters
recordCurrent record in MySQL Row Format.

◆ ph_read_range_first()

int Partition_helper::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.

We re-implement read_range_first since we don't want the compare_key check at the end. This is already performed in the partition handler. read_range_next is very much different due to that we need to scan all underlying handlers.

Parameters
start_keySpecification of start key.
end_keySpecification of end key.
eq_range_argIs it equal range.
sortedShould records be returned in sorted order.
Returns
Operation status.
Return values
0Success
!=0 Error code

◆ ph_read_range_next()

int Partition_helper::ph_read_range_next ( )

Read next record in read of a range with start and end key.

Returns
Operation status.
Return values
0Success
!=0 Error code

◆ ph_release_auto_increment()

void Partition_helper::ph_release_auto_increment ( )

Release unused auto increment values.

◆ ph_rnd_end()

int Partition_helper::ph_rnd_end ( )

End of a table scan.

Returns
Operation status.
Return values
0Success
!=0 Error code

◆ ph_rnd_init()

int Partition_helper::ph_rnd_init ( bool  scan)

MODULE full table scan.

Initialize engine for random reads.

This module is used for the most basic access method for any table handler. This is to fetch all data through a full table scan. No indexes are needed to implement this part. It contains one method to start the scan (rnd_init) that can also be called multiple times (typical in a nested loop join). Then proceeding to the next record (rnd_next) and closing the scan (rnd_end). To remember a record for later access there is a method (position) and there is a method used to retrieve the record based on the stored position. The position can be a file position, a primary key, a ROWID dependent on the handler below.

unlike index_init(), rnd_init() can be called two times without rnd_end() in between (it only makes sense if scan=1). then the second call should prepare for the new table scan (e.g if rnd_init allocates the cursor, second call should position it to the start of the table, no need to deallocate and allocate it again.

See also
handler.h

rnd_init() is called when the server wants the storage engine to do a table scan or when the server wants to access data through rnd_pos.

When scan is used we will scan one handler partition at a time. When preparing for rnd_pos we will initialize all handler partitions. No extra cache handling is needed when scanning is not performed.

Before initializing we will call rnd_end to ensure that we clean up from any previous incarnation of a table scan.

Parameters
scanfalse for initialize for random reads through rnd_pos() true for initialize for random scan through rnd_next().
Returns
Operation status.
Return values
0Success
!=0 Error code

◆ ph_rnd_next()

int Partition_helper::ph_rnd_next ( uchar buf)

Read next row during full table scan (scan in random row order).

This is called for each row of the table scan. When you run out of records you should return HA_ERR_END_OF_FILE. The Field structure for the table is the key to getting data into buf in a manner that will allow the server to understand it.

Parameters
[out]bufbuffer that should be filled with data.
Returns
Operation status.
Return values
0Success
!=0 Error code

◆ ph_rnd_next_in_part()

int Partition_helper::ph_rnd_next_in_part ( uint  part_id,
uchar buf 
)
private

Read next row during full partition scan (scan in random row order).

This function can evaluate the virtual generated columns. If virtual generated columns are involved, you should not call rnd_next_in_part directly but this one.

Parameters
part_idPartition to read from.
[in,out]bufbuffer that should be filled with data.
Returns
Operation status.
Return values
0Success
!=0 Error code

◆ ph_update_row()

int Partition_helper::ph_update_row ( const uchar old_data,
uchar new_data 
)

Update an existing row in the partitioned table.

Yes, update_row() does what you expect, it updates a row. old_data will have the previous row record in it, while new_data will have the newest data in it. Keep in mind that the server can do updates based on ordering if an ORDER BY clause was used. Consecutive ordering is not guaranteed.

If the new record belongs to a different partition than the old record then it will be inserted into the new partition and deleted from the old.

new_data is always record[0] old_data is always record[1]

Returns
Operation status.
0 Success
!= 0 Error code

Yes, update_row() does what you expect, it updates a row. old_data will have the previous row record in it, while new_data will have the newest data in it. Keep in mind that the server can do updates based on ordering if an ORDER BY clause was used. Consecutive ordering is not guaranteed.

If the new record belongs to a different partition than the old record then it will be inserted into the new partition and deleted from the old.

new_data is always record[0] old_data is always record[1]

Parameters
old_dataThe old record in MySQL Row Format.
new_dataThe new record in MySQL Row Format.
Returns
Operation status.
Return values
0Success
!=0 Error code

◆ ph_write_row()

int Partition_helper::ph_write_row ( uchar buf)

INSERT/UPDATE/DELETE functions.

Insert a row to the partitioned table.

See also
handler.h Insert a row to the partitioned table.
Returns
Operation status.
0 Success
!= 0 Error code
Parameters
bufThe row in MySQL Row Format.
Returns
Operation status.
Return values
0Success
!=0 Error code

◆ position_in_last_part()

virtual void Partition_helper::position_in_last_part ( uchar ref,
const uchar row 
)
privatepure virtual

Implemented in ha_innopart.

◆ prepare_change_partitions()

void Partition_helper::prepare_change_partitions ( )

Prepare for reorganizing partitions by setting up partition_info::read_partitions according to the partition_info mark-up.

This is helper method which can also be used by SEs implementing support for reorganizing partitions through ALTER TABLE INPLACE SE API.

◆ print_admin_msg()

bool Partition_helper::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,
  ... 
)
protected

Print a message row formatted for ANALYZE/CHECK/OPTIMIZE/REPAIR TABLE.

Modeled after mi_check_print_msg.

Parameters
thdThread context.
lenNeeded length for message buffer.
msg_typeMessage type.
db_nameDatabase name.
table_nameTable name.
op_nameOperation name.
fmtMessage (in printf format with additional arguments).
Returns
Operation status.
Return values
falsefor success else true.

◆ print_partition_error()

bool Partition_helper::print_partition_error ( int  error)
protected

Print partitioning specific error.

Parameters
errorError code.
Returns
false if error is printed else true.

◆ read_range_first_in_part()

virtual int Partition_helper::read_range_first_in_part ( uint  part,
uchar buf,
const key_range start_key,
const key_range end_key,
bool  sorted 
)
privatepure virtual

Do read_range_first in the specified partition.

If buf is set, then copy the result there instead of table->record[0].

Implemented in ha_innopart.

◆ read_range_next_in_part()

virtual int Partition_helper::read_range_next_in_part ( uint  part,
uchar buf 
)
privatepure virtual

Do read_range_next in the specified partition.

If buf is set, then copy the result there instead of table->record[0].

Implemented in ha_innopart.

◆ release_auto_increment_all_parts()

virtual void Partition_helper::release_auto_increment_all_parts ( )
inlineprivatevirtual

Release auto_increment in all underlying partitions.

◆ return_top_record()

void Partition_helper::return_top_record ( uchar buf)
private

Return the top record in sort order.

Parameters
[out]bufRow returned in MySQL Row Format.

◆ rnd_end_in_part()

virtual int Partition_helper::rnd_end_in_part ( uint  part_id,
bool  scan 
)
privatepure virtual

Implemented in ha_innopart.

◆ rnd_init_in_part()

virtual int Partition_helper::rnd_init_in_part ( uint  part_id,
bool  table_scan 
)
privatepure virtual

Per partition equivalent of rnd_* and index_* functions.

See also
class handler.

Implemented in ha_innopart.

◆ rnd_next_in_part()

virtual int Partition_helper::rnd_next_in_part ( uint  part_id,
uchar buf 
)
privatepure virtual

Implemented in ha_innopart.

◆ save_auto_increment()

virtual void Partition_helper::save_auto_increment ( ulonglong  nr)
inlineprivatevirtual

Save or persist the current max auto increment.

Reimplemented in ha_innopart.

◆ set_altered_partitions()

bool Partition_helper::set_altered_partitions ( )
protected

Set used partitions bitmap from Alter_info.

Returns
false if success else true.

◆ set_auto_increment_if_higher()

void Partition_helper::set_auto_increment_if_higher ( )
inlineprivate

Update auto increment value if current row contains a higher value.

◆ set_eq_range()

virtual void Partition_helper::set_eq_range ( bool  eq_range)
privatepure virtual

Implemented in ha_innopart.

◆ set_part_info_low()

void Partition_helper::set_part_info_low ( partition_info part_info,
bool  early 
)
virtual

Set partition info.

To be called from Partition_handler.

Parameters
part_infoPartition info to use.
earlyTrue if called when part_info only created and parsed, but not setup, checked or fixed.

◆ set_partition_read_set()

void Partition_helper::set_partition_read_set ( )
inlineprivate

Set table->read_set taking partitioning expressions into account.

◆ set_range_key_part()

virtual void Partition_helper::set_range_key_part ( KEY_PART_INFO key_part)
privatepure virtual

Implemented in ha_innopart.

◆ unlock_auto_increment()

void Partition_helper::unlock_auto_increment ( )
inlineprotected

unlock auto increment.

◆ update_row_in_part()

virtual int Partition_helper::update_row_in_part ( uint  part_id,
const uchar old_data,
uchar new_data 
)
privatepure virtual

Update a row in the specified partition.

See also
handler::update_row().
Parameters
part_idPartition to update in.
old_dataBuffer containing old row.
new_dataBuffer containing new row.
Returns
Operation status.
Return values
0Success.
!=0 Error code.

Implemented in ha_innopart.

◆ write_row_in_new_part()

virtual int Partition_helper::write_row_in_new_part ( uint  new_part)
privatepure virtual

write row to new partition.

Parameters
new_partNew partition to write to.
Returns
Operation status.
Return values
0Success.
!=0 Error code.

Implemented in ha_innopart.

◆ write_row_in_part()

virtual int Partition_helper::write_row_in_part ( uint  part_id,
uchar buf 
)
privatepure virtual

Write a row in the specified partition.

See also
handler::write_row().
Parameters
part_idPartition to write to.
bufBuffer with data to write.
Returns
Operation status.
Return values
0Success.
!=0 Error code.

Implemented in ha_innopart.

Member Data Documentation

◆ m_auto_increment_lock

bool Partition_helper::m_auto_increment_lock
protected

◆ m_auto_increment_safe_stmt_log_lock

bool Partition_helper::m_auto_increment_safe_stmt_log_lock
protected

◆ m_curr_key_info

KEY* Partition_helper::m_curr_key_info[3]
protected

Current index used for sorting.

If clustered PK exists, then it will be used as secondary index to sort on if the first is equal in key_rec_cmp. So if clustered pk: m_curr_key_info[0]= current index and m_curr_key_info[1]= pk and [2]= NULL. Otherwise [0]= current index, [1]= NULL, and we will sort by rowid as secondary sort key if equal first key.

◆ m_err_rec

const uchar* Partition_helper::m_err_rec
protected

◆ m_handler

handler* Partition_helper::m_handler
private

handler to use (ha_innopart etc.)

◆ m_index_scan_type

enum partition_index_scan_type Partition_helper::m_index_scan_type
protected

◆ m_is_sub_partitioned

bool Partition_helper::m_is_sub_partitioned
protected

Cached value of m_part_info->is_sub_partitioned().

◆ m_key_not_found

bool Partition_helper::m_key_not_found
protected

Set if previous index_* call returned HA_ERR_KEY_NOT_FOUND.

◆ m_key_not_found_partitions

MY_BITMAP Partition_helper::m_key_not_found_partitions
protected

Partitions that returned HA_ERR_KEY_NOT_FOUND.

◆ m_last_part

uint Partition_helper::m_last_part
protected

◆ m_ordered

bool Partition_helper::m_ordered
protected

◆ m_ordered_rec_buffer

uchar* Partition_helper::m_ordered_rec_buffer
protected

Row and key buffer for ordered index scan.

◆ m_ordered_scan_ongoing

bool Partition_helper::m_ordered_scan_ongoing
protected

◆ m_part_info

partition_info* Partition_helper::m_part_info
protected

All internal partitioning data!

Tables partitioning info (same as table->part_info)

◆ m_part_share

Partition_share* Partition_helper::m_part_share
private

Partition share for auto_inc handling.

◆ m_part_spec

part_id_range Partition_helper::m_part_spec
protected

◆ m_pkey_is_clustered

bool Partition_helper::m_pkey_is_clustered
protected

Is primary key clustered.

◆ m_queue

Prio_queue* Partition_helper::m_queue
protected

Prio queue used by sorted read.

◆ m_rec_length

uint Partition_helper::m_rec_length
protected

◆ m_rec_offset

uint Partition_helper::m_rec_offset
protected

Offset in m_ordered_rec_buffer from part buffer to its record buffer.

◆ m_ref_usage

enum_using_ref Partition_helper::m_ref_usage
protected

How handler::ref is used in the priority queue.

◆ m_reverse_order

bool Partition_helper::m_reverse_order
protected

◆ m_scan_value

uint Partition_helper::m_scan_value
protected

◆ m_start_key

key_range Partition_helper::m_start_key
protected

◆ m_table

TABLE* Partition_helper::m_table
protected

Convenience pointer to table from m_handler (i.e.

m_handler->table).

◆ m_top_entry

uint Partition_helper::m_top_entry
protected

Which partition is to deliver next result.

◆ m_tot_parts

uint Partition_helper::m_tot_parts
protected

Total number of partitions.


The documentation for this class was generated from the following files: