MySQL 8.0.39
Source Code Documentation
sql_partition.h File Reference
#include <stddef.h>
#include <sys/types.h>
#include "lex_string.h"
#include "my_base.h"
#include "my_inttypes.h"
#include "sql/partition_element.h"

Go to the source code of this file.

Classes

struct  part_id_range
 

Macros

#define HA_CAN_UPDATE_PARTITION_KEY   (1 << 1)
 
#define HA_CAN_PARTITION_UNIQUE   (1 << 2)
 
#define HA_USE_AUTO_PARTITION   (1 << 3)
 
#define HA_CAN_EXCHANGE_PARTITION   (1 << 4)
 The handler can exchange a partition with a non-partitioned table of the same handlerton/engine. More...
 
#define HA_CANNOT_PARTITION_FK   (1 << 5)
 The handler can not use FOREIGN KEYS with partitioning. More...
 
#define HA_TRUNCATE_PARTITION_PRECLOSE   (1 << 6)
 Engine requires closing all open table instances before TRUNCATE PARTITION operation. More...
 

Typedefs

typedef key_range key_range
 

Enumerations

enum  enum_partition_keywords {
  PKW_HASH = 0 , PKW_RANGE , PKW_LIST , PKW_KEY ,
  PKW_MAXVALUE , PKW_LINEAR , PKW_COLUMNS , PKW_ALGORITHM
}
 

Functions

int get_parts_for_update (const uchar *old_data, const uchar *new_data, const uchar *rec0, partition_info *part_info, uint32 *old_part_id, uint32 *new_part_id, longlong *func_value)
 
int get_part_for_delete (const uchar *buf, const uchar *rec0, partition_info *part_info, uint32 *part_id)
 
void prune_partition_set (const TABLE *table, part_id_range *part_spec)
 
void set_linear_hash_mask (partition_info *part_info, uint num_parts)
 
bool fix_partition_func (THD *thd, TABLE *table, bool create_table_ind)
 
bool partition_key_modified (TABLE *table, const MY_BITMAP *fields)
 
void get_partition_set (const TABLE *table, uchar *buf, const uint index, const key_range *key_spec, part_id_range *part_spec)
 
uint get_partition_field_store_length (Field *field)
 
bool get_cs_converted_part_value_from_string (THD *thd, Item *item, String *input_str, String *output_str, const CHARSET_INFO *cs, bool use_hex)
 
void get_full_part_id_from_key (const TABLE *table, uchar *buf, KEY *key_info, const key_range *key_spec, part_id_range *part_spec)
 
bool mysql_unpack_partition (THD *thd, char *part_buf, uint part_info_len, TABLE *table, bool is_create_table_ind, handlerton *default_db_type, bool *work_part_info_used)
 
bool make_used_partitions_str (partition_info *part_info, List< const char > *parts)
 Return comma-separated list of used partitions in the provided given string. More...
 
bool check_part_func_fields (Field **ptr, bool ok_with_charsets)
 
bool field_is_partition_charset (Field *field)
 
Itemconvert_charset_partition_constant (Item *item, const CHARSET_INFO *cs)
 
void append_row_to_str (String &str, const uchar *row, TABLE *table)
 Append all fields in read_set to string. More...
 
void mem_alloc_error (size_t size)
 
void truncate_partition_filename (MEM_ROOT *root, const char **path)
 Truncate the partition file name from a path if it exists. More...
 
bool set_part_state (Alter_info *alter_info, partition_info *tab_part_info, enum partition_state part_state, bool include_subpartitions)
 Sets which partitions to be used in the command. More...
 
void set_all_part_state (partition_info *tab_part_info, enum partition_state part_state)
 Set part_state for all partitions to given state. More...
 
uint prep_alter_part_table (THD *thd, TABLE *table, Alter_info *alter_info, HA_CREATE_INFO *create_info, Alter_table_ctx *alter_ctx, bool *partition_changed, partition_info **new_part_info)
 
int expr_to_string (String *val_conv, Item *item_expr, Field *field, const char *field_name, const HA_CREATE_INFO *create_info, List< Create_field > *create_fields)
 
char * generate_partition_syntax (partition_info *part_info, uint *buf_length, bool use_sql_alloc, bool show_partition_options, bool print_expr, const char *current_comment_start)
 Generate the partition syntax from the partition data structure. More...
 
bool verify_data_with_partition (TABLE *table, TABLE *part_table, uint32 part_id)
 Verify that all rows in a table is in the given partition. More...
 
bool compare_partition_options (HA_CREATE_INFO *table_create_info, partition_element *part_elem)
 Check if partition is exchangeable with table by checking table options. More...
 

Variables

const LEX_CSTRING partition_keywords []
 

Macro Definition Documentation

◆ HA_CAN_EXCHANGE_PARTITION

#define HA_CAN_EXCHANGE_PARTITION   (1 << 4)

The handler can exchange a partition with a non-partitioned table of the same handlerton/engine.

◆ HA_CAN_PARTITION_UNIQUE

#define HA_CAN_PARTITION_UNIQUE   (1 << 2)

◆ HA_CAN_UPDATE_PARTITION_KEY

#define HA_CAN_UPDATE_PARTITION_KEY   (1 << 1)

◆ HA_CANNOT_PARTITION_FK

#define HA_CANNOT_PARTITION_FK   (1 << 5)

The handler can not use FOREIGN KEYS with partitioning.

◆ HA_TRUNCATE_PARTITION_PRECLOSE

#define HA_TRUNCATE_PARTITION_PRECLOSE   (1 << 6)

Engine requires closing all open table instances before TRUNCATE PARTITION operation.

◆ HA_USE_AUTO_PARTITION

#define HA_USE_AUTO_PARTITION   (1 << 3)

Typedef Documentation

◆ key_range

Enumeration Type Documentation

◆ enum_partition_keywords

Enumerator
PKW_HASH 
PKW_RANGE 
PKW_LIST 
PKW_KEY 
PKW_MAXVALUE 
PKW_LINEAR 
PKW_COLUMNS 
PKW_ALGORITHM 

Function Documentation

◆ append_row_to_str()

void append_row_to_str ( String str,
const uchar row,
TABLE table 
)

Append all fields in read_set to string.

Parameters
[in,out]strString to append to.
[in]rowRow to append.
[in]tableTable containing read_set and fields for the row.

◆ check_part_func_fields()

bool check_part_func_fields ( Field **  ptr,
bool  ok_with_charsets 
)

◆ compare_partition_options()

bool compare_partition_options ( HA_CREATE_INFO table_create_info,
partition_element part_elem 
)

Check if partition is exchangeable with table by checking table options.

Parameters
table_create_infoTable options from table.
part_elemAll the info of the partition.
Return values
falseif they are equal, otherwise true.
Note
Any difference that would cause a change in the frm file is prohibited. Such options as data_file_name, index_file_name, min_rows, max_rows etc. are not allowed to differ. But comment is allowed to differ.

◆ convert_charset_partition_constant()

Item * convert_charset_partition_constant ( Item item,
const CHARSET_INFO cs 
)

◆ expr_to_string()

int expr_to_string ( String val_conv,
Item item_expr,
Field field,
const char *  field_name,
const HA_CREATE_INFO create_info,
List< Create_field > *  create_fields 
)

◆ field_is_partition_charset()

bool field_is_partition_charset ( Field field)

◆ fix_partition_func()

bool fix_partition_func ( THD thd,
TABLE table,
bool  create_table_ind 
)

◆ generate_partition_syntax()

char * generate_partition_syntax ( partition_info part_info,
uint buf_length,
bool  use_sql_alloc,
bool  show_partition_options,
bool  print_expr,
const char *  current_comment_start 
)

Generate the partition syntax from the partition data structure.

Useful for support of generating defaults, SHOW CREATE TABLES and easy partition management.

Parameters
part_infoThe partitioning data structure
buf_lengthA pointer to the returned buffer length
use_sql_allocAllocate buffer from sql_alloc if true otherwise use my_malloc
show_partition_optionsShould we display partition options
print_exprIndicates whether partitioning expressions should be re-printed to get quoting according to current sql_mode.
current_comment_startNULL, or comment string encapsulating the PARTITION BY clause.
Return values
NULL- error
Note
Here we will generate the full syntax for the given command where all defaults have been expanded. By so doing the it is also possible to make lots of checks of correctness while at it. This could will also be reused for SHOW CREATE TABLES and also for all type ALTER TABLE commands focusing on changing the PARTITION structure in any fashion.

The implementation writes the syntax to a temporary file (essentially an abstraction of a dynamic array) and if all writes goes well it allocates a buffer and writes the syntax into this one and returns it.

As a security precaution the file is deleted before writing into it. This means that no other processes on the machine can open and read the file while this processing is ongoing.

The code is optimised for minimal code size since it is not used in any common queries.

◆ get_cs_converted_part_value_from_string()

bool get_cs_converted_part_value_from_string ( THD thd,
Item item,
String input_str,
String output_str,
const CHARSET_INFO cs,
bool  use_hex 
)

◆ get_full_part_id_from_key()

void get_full_part_id_from_key ( const TABLE table,
uchar buf,
KEY key_info,
const key_range key_spec,
part_id_range part_spec 
)

◆ get_part_for_delete()

int get_part_for_delete ( const uchar buf,
const uchar rec0,
partition_info part_info,
uint32 part_id 
)

◆ get_partition_field_store_length()

uint get_partition_field_store_length ( Field field)

◆ get_partition_set()

void get_partition_set ( const TABLE table,
uchar buf,
const uint  index,
const key_range key_spec,
part_id_range part_spec 
)

◆ get_parts_for_update()

int get_parts_for_update ( const uchar old_data,
const uchar new_data,
const uchar rec0,
partition_info part_info,
uint32 old_part_id,
uint32 new_part_id,
longlong func_value 
)

◆ make_used_partitions_str()

bool make_used_partitions_str ( partition_info part_info,
List< const char > *  parts 
)

Return comma-separated list of used partitions in the provided given string.

Parameters
part_infoPartitioning info
[out]partsThe resulting list of string to fill

Generate a list of used partitions (from bits in part_info->read_partitions bitmap), and store it into the provided String object.

Note
The produced string must not be longer then MAX_PARTITIONS * (1 + FN_LEN). In case of UPDATE, only the partitions read is given, not the partitions that was written or locked.

◆ mem_alloc_error()

void mem_alloc_error ( size_t  size)

◆ mysql_unpack_partition()

bool mysql_unpack_partition ( THD thd,
char *  part_buf,
uint  part_info_len,
TABLE table,
bool  is_create_table_ind,
handlerton default_db_type,
bool *  work_part_info_used 
)

◆ partition_key_modified()

bool partition_key_modified ( TABLE table,
const MY_BITMAP fields 
)

◆ prep_alter_part_table()

uint prep_alter_part_table ( THD thd,
TABLE table,
Alter_info alter_info,
HA_CREATE_INFO create_info,
Alter_table_ctx alter_ctx,
bool *  partition_changed,
partition_info **  new_part_info 
)

◆ prune_partition_set()

void prune_partition_set ( const TABLE table,
part_id_range part_spec 
)

◆ set_all_part_state()

void set_all_part_state ( partition_info tab_part_info,
enum partition_state  part_state 
)

Set part_state for all partitions to given state.

Parameters
tab_part_infopartition_info holding all partitions.
part_stateWhich state to set for the named partitions.

◆ set_linear_hash_mask()

void set_linear_hash_mask ( partition_info part_info,
uint  num_parts 
)

◆ set_part_state()

bool set_part_state ( Alter_info alter_info,
partition_info tab_part_info,
enum partition_state  part_state,
bool  include_subpartitions 
)

Sets which partitions to be used in the command.

Parameters
alter_infoAlter_info pointer holding partition names and flags.
tab_part_infopartition_info holding all partitions.
part_stateWhich state to set for the named partitions.
include_subpartitionsAlso include subpartitions in the search.
Returns
Operation status
Return values
falseSuccess
trueFailure

◆ truncate_partition_filename()

void truncate_partition_filename ( MEM_ROOT root,
const char **  path 
)

Truncate the partition file name from a path if it exists.

A partition file name will contain one or more '#' characters. One of the occurrences of '#' will be either "#P#" or "#p#" depending on whether the storage engine has converted the filename to lower case. If we need to truncate the name, we will allocate a new string and replace with, in case the original string was owned by something else.

Parameters
[in]rootMEM_ROOT to allocate from. If NULL alter the string directly.
[in,out]pathPointer to string to check and truncate.

◆ verify_data_with_partition()

bool verify_data_with_partition ( TABLE table,
TABLE part_table,
uint32  part_id 
)

Verify that all rows in a table is in the given partition.

Parameters
tableTable which contains the data that will be checked if it is matching the partition definition.
part_tablePartitioned table containing the partition to check.
part_idWhich partition to match with.
Returns
Operation status
Return values
trueNot all rows match the given partition
falseOK

Variable Documentation

◆ partition_keywords

const LEX_CSTRING partition_keywords[]
extern