MySQL 8.0.39
Source Code Documentation
|
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>
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 | |
TABLE * | m_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_less > | Prio_queue |
Private Member Functions | |
virtual THD * | get_thd () const =0 |
virtual TABLE * | get_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 | |
handler * | m_handler |
handler to use (ha_innopart etc.) More... | |
Partition_share * | m_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_info * | m_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 uchar * | m_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 |
uchar * | m_ordered_rec_buffer |
Row and key buffer for ordered index scan. More... | |
Prio_queue * | m_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... | |
KEY * | m_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... | |
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:
|
private |
|
protected |
|
private |
Partition_helper::Partition_helper | ( | handler * | main_handler | ) |
|
virtual |
|
protected |
Check/fix misplaced rows.
read_part_id | Partition to check/fix. |
repair | If true, move misplaced rows to correct partition. |
0 | Success |
!= | 0 Error |
|
inlineprivatevirtual |
Checksum for a partition.
part_id | Partition to checksum. |
|
protected |
Close partitioning for a table.
Frees memory and release other resources.
|
private |
Common routine for index_first/index_last.
[out] | buf | Read row in MySQL Row Format. |
0 | Success |
!= | 0 Error code |
|
private |
Common routine for a number of index_read variants.
[out] | buf | Buffer where the record should be returned. |
[in] | have_start_key | true <=> 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). |
0 | OK |
HA_ERR_END_OF_FILE | Whole index scanned, without finding the record. |
HA_ERR_KEY_NOT_FOUND | Record not found, but index cursor positioned. |
other | Error code. |
Start scanning the range (when invoked from read_range_first()) or doing an index lookup (when invoked from index_read_XXX):
|
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.
[out] | to_rec | Buffer to copy to. |
[in] | from_rec | Buffer to copy from. |
Reimplemented in ha_innopart.
|
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.
[out] | deleted | Number of records deleted. |
0 | Success |
>0 | Error code |
|
privatepure virtual |
Delete an existing row in the specified partition.
part_id | Partition to delete from. |
buf | Buffer containing row to delete. |
0 | Success. |
!= | 0 Error code. |
Implemented in ha_innopart.
|
protected |
Destroy the record priority queue used for sorted index scans.
Destroy the ordered record buffer and the priority queue.
|
inlineprivatevirtual |
Destroy and release engine specific resources used by the record priority queue.
Reimplemented in ha_innopart.
|
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.
[in] | increment | Increment value. |
[in] | nb_desired_values | Number of desired values. |
[out] | first_value | First auto inc value reserved or MAX if failure. |
[out] | nb_reserved_values | Number of values reserved. |
|
virtual |
Functions matching Partition_handler API.
Get statistics from a specific partition.
[out] | stat_info | Area to report values into. |
[out] | check_sum | Check sum of partition. |
[in] | part_id | Partition to report from. |
|
privatepure virtual |
Implemented in ha_innopart.
|
privatepure virtual |
Implemented in ha_innopart.
|
privatepure virtual |
Implemented in ha_innopart.
|
private |
Common routine to start index scan with ordered results.
[out] | buf | Read row in MySQL Row Format |
HA_ERR_END_OF_FILE | End of scan |
HA_ERR_KEY_NOT_FOUND | End of scan |
0 | Success |
other | Error 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.
|
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.
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.
|
private |
Common routine to handle index_next with ordered results.
[out] | buf | Read row in MySQL Row Format. |
[in] | is_next_same | Called from index_next_same. |
HA_ERR_END_OF_FILE | End of scan |
0 | Success |
other | Error code |
|
private |
Common routine to handle index_prev with ordered results.
[out] | buf | Read row in MySQL Row Format. |
HA_ERR_END_OF_FILE | End of scan |
0 | Success |
other | Error code |
|
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.
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.
[out] | buf | Read row in MySQL Row Format. |
[in] | is_next_same | Called from index_next_same. |
HA_ERR_END_OF_FILE | End of scan |
0 | Success |
other | Error code |
|
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.
[out] | buf | Read row in MySQL Row Format |
HA_ERR_END_OF_FILE | End of scan |
0 | Success |
other | Error code |
Implemented in ha_innopart.
Implemented in ha_innopart.
Implemented in ha_innopart.
|
privatepure virtual |
Implemented in ha_innopart.
Implemented in ha_innopart.
|
privatepure virtual |
Implemented in ha_innopart.
|
privatepure virtual |
Implemented in ha_innopart.
|
privatepure virtual |
Implemented in ha_innopart.
|
inline |
Initialize variables used before the table is opened.
mem_root | Memory root to allocate things from (not yet used). |
false | success. |
true | failure. |
|
protected |
Initialize the record priority queue used for sorted index scans.
Setup the ordered record buffer and the priority queue.
0 | Success. |
!= | 0 Error code. |
Call destroy_record_priority_queue() to deallocate or clean-up from failure.
|
inlineprivatevirtual |
Initialize engine specific resources for the record priority queue used duing ordered index reads for multiple partitions.
used_parts | Number of partitions used in query (number of set bits in m_part_info->read_partitions). |
0 | Success. |
!= | 0 Error code. |
Reimplemented in ha_innopart.
|
privatepure virtual |
Initialize the shared auto increment value.
no_lock | If HA_STATUS_NO_LOCK should be used in info(HA_STATUS_AUTO). |
Also sets stats.auto_increment_value.
Implemented in ha_innopart.
|
protected |
Lock auto increment value if needed.
|
protected |
Set m_part_share, Allocate internal bitmaps etc.
Initialize the partitioning helper for use after the table is opened.
used by open tables.
part_share | Partitioning share (used for auto increment). |
false | for success otherwise true. |
|
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.
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.
buf | Buffer to later return record in (this function needs it to calculate partitioning function values) |
idx_read_flag | true <=> 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. |
0 | Success |
!=0 | Error code |
Calculate key hash value from an null terminated array of fields.
Support function for KEY partitioning.
field_array | An array of the fields in KEY partitioning |
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]
buf | The record in MySQL Row Format. |
0 | Success |
!= | 0 Error code |
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.
[out] | buf | Read row in MySQL Row Format. |
0 | Success |
!= | 0 Error code |
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
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.
inx | Index to be used. |
sorted | True if the rows must be returned in index order. |
0 | Success |
!= | 0 Error code |
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.
[out] | buf | Read row in MySQL Row Format. |
0 | Success |
!= | 0 Error code |
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).
[out] | buf | Read row in MySQL Row Format. |
0 | Success |
!= | 0 Error code |
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.
[out] | buf | Read row in MySQL Row Format. |
[in] | keylen | Length of key. |
0 | Success |
!= | 0 Error code |
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).
[out] | buf | Read row in MySQL Row Format. |
0 | Success |
!= | 0 Error code |
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.
[out] | buf | Read row in MySQL Row Format |
[in] | index | Index to read from |
[in] | key | Key |
[in] | keypart_map | Which part of key is used |
[in] | find_flag | Direction/how to search. |
0 | Success |
!= | 0 Error code |
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.
[out] | buf | Read row in MySQL Row Format |
[in] | key | Key |
[in] | keypart_map | Which part of key is used |
0 | Success |
!= | 0 Error code |
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.
[out] | buf | Read row in MySQL Row Format |
[in] | key | Key parts in consecutive order |
[in] | keypart_map | Which part of key is used |
[in] | find_flag | What type of key condition is used |
0 | Success |
!= | 0 Error code |
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.
record | Current record in MySQL Row Format. |
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.
start_key | Specification of start key. |
end_key | Specification of end key. |
eq_range_arg | Is it equal range. |
sorted | Should records be returned in sorted order. |
0 | Success |
!= | 0 Error code |
int Partition_helper::ph_read_range_next | ( | ) |
Read next record in read of a range with start and end key.
0 | Success |
!= | 0 Error code |
void Partition_helper::ph_release_auto_increment | ( | ) |
Release unused auto increment values.
int Partition_helper::ph_rnd_end | ( | ) |
End of a table scan.
0 | Success |
!= | 0 Error code |
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.
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.
scan | false for initialize for random reads through rnd_pos() true for initialize for random scan through rnd_next(). |
0 | Success |
!= | 0 Error code |
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.
[out] | buf | buffer that should be filled with data. |
0 | Success |
!= | 0 Error code |
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.
part_id | Partition to read from. | |
[in,out] | buf | buffer that should be filled with data. |
0 | Success |
!= | 0 Error code |
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]
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]
old_data | The old record in MySQL Row Format. |
new_data | The new record in MySQL Row Format. |
0 | Success |
!= | 0 Error code |
int Partition_helper::ph_write_row | ( | uchar * | buf | ) |
INSERT/UPDATE/DELETE functions.
Insert a row to the partitioned table.
buf | The row in MySQL Row Format. |
0 | Success |
!= | 0 Error code |
|
privatepure virtual |
Implemented in ha_innopart.
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.
|
protected |
Print a message row formatted for ANALYZE/CHECK/OPTIMIZE/REPAIR TABLE.
Modeled after mi_check_print_msg.
thd | Thread context. |
len | Needed length for message buffer. |
msg_type | Message type. |
db_name | Database name. |
table_name | Table name. |
op_name | Operation name. |
fmt | Message (in printf format with additional arguments). |
false | for success else true. |
|
protected |
Print partitioning specific error.
error | Error code. |
|
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.
|
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.
|
inlineprivatevirtual |
Release auto_increment in all underlying partitions.
|
private |
Return the top record in sort order.
[out] | buf | Row returned in MySQL Row Format. |
|
privatepure virtual |
Implemented in ha_innopart.
|
privatepure virtual |
Per partition equivalent of rnd_* and index_* functions.
Implemented in ha_innopart.
Implemented in ha_innopart.
|
inlineprivatevirtual |
Save or persist the current max auto increment.
Reimplemented in ha_innopart.
|
protected |
Set used partitions bitmap from Alter_info.
|
inlineprivate |
Update auto increment value if current row contains a higher value.
|
privatepure virtual |
Implemented in ha_innopart.
|
virtual |
Set partition info.
To be called from Partition_handler.
part_info | Partition info to use. |
early | True if called when part_info only created and parsed, but not setup, checked or fixed. |
|
inlineprivate |
Set table->read_set taking partitioning expressions into account.
|
privatepure virtual |
Implemented in ha_innopart.
|
inlineprotected |
unlock auto increment.
|
privatepure virtual |
Update a row in the specified partition.
part_id | Partition to update in. |
old_data | Buffer containing old row. |
new_data | Buffer containing new row. |
0 | Success. |
!= | 0 Error code. |
Implemented in ha_innopart.
|
privatepure virtual |
write row to new partition.
new_part | New partition to write to. |
0 | Success. |
!= | 0 Error code. |
Implemented in ha_innopart.
Write a row in the specified partition.
part_id | Partition to write to. |
buf | Buffer with data to write. |
0 | Success. |
!= | 0 Error code. |
Implemented in ha_innopart.
|
protected |
|
protected |
|
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.
|
protected |
|
private |
handler to use (ha_innopart etc.)
|
protected |
|
protected |
Cached value of m_part_info->is_sub_partitioned().
|
protected |
Set if previous index_* call returned HA_ERR_KEY_NOT_FOUND.
|
protected |
Partitions that returned HA_ERR_KEY_NOT_FOUND.
|
protected |
|
protected |
|
protected |
Row and key buffer for ordered index scan.
|
protected |
|
protected |
All internal partitioning data!
Tables partitioning info (same as table->part_info)
|
private |
Partition share for auto_inc handling.
|
protected |
|
protected |
Is primary key clustered.
|
protected |
Prio queue used by sorted read.
|
protected |
|
protected |
Offset in m_ordered_rec_buffer from part buffer to its record buffer.
|
protected |
How handler::ref is used in the priority queue.
|
protected |
|
protected |
|
protected |
|
protected |
Convenience pointer to table from m_handler (i.e.
m_handler->table).
|
protected |
Which partition is to deliver next result.
|
protected |
Total number of partitions.