MySQL  8.0.27
Source Code Documentation
sql_partition.cc File Reference
#include "sql/sql_partition.h"
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstring>
#include "field_types.h"
#include "m_ctype.h"
#include "m_string.h"
#include "my_alloc.h"
#include "my_bitmap.h"
#include "my_byteorder.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_io.h"
#include "my_sqlcommand.h"
#include "my_sys.h"
#include "mysql/components/services/my_io_bits.h"
#include "mysql/components/services/psi_statement_bits.h"
#include "mysql/plugin.h"
#include "mysql/psi/mysql_file.h"
#include "mysql/service_mysql_alloc.h"
#include "mysql/udf_registration_types.h"
#include "mysql_com.h"
#include "mysql_time.h"
#include "mysqld_error.h"
#include "sql/create_field.h"
#include "sql/current_thd.h"
#include "sql/debug_sync.h"
#include "sql/derror.h"
#include "sql/enum_query_type.h"
#include "sql/field.h"
#include "sql/handler.h"
#include "sql/item.h"
#include "sql/item_func.h"
#include "sql/key.h"
#include "sql/mdl.h"
#include "sql/mysqld.h"
#include "sql/parse_tree_node_base.h"
#include "sql/partition_info.h"
#include "sql/partitioning/partition_handler.h"
#include "sql/psi_memory_key.h"
#include "sql/query_options.h"
#include "sql/range_optimizer/range_optimizer.h"
#include "sql/sql_alter.h"
#include "sql/sql_base.h"
#include "sql/sql_class.h"
#include "sql/sql_const.h"
#include "sql/sql_digest_stream.h"
#include "sql/sql_error.h"
#include "sql/sql_lex.h"
#include "sql/sql_list.h"
#include "sql/sql_parse.h"
#include "sql/sql_show.h"
#include "sql/sql_table.h"
#include "sql/system_variables.h"
#include "sql/table.h"
#include "sql/thd_raii.h"
#include "sql/thr_malloc.h"
#include "sql_string.h"

Macros

#define MAX_COMPARE_PARTITION_OPTION_ERRORS   5
 
#define MAX_RANGE_TO_WALK   32
 

Typedefs

typedef uint32(* get_endpoint_func) (partition_info *, bool left_endpoint, bool include_endpoint)
 
typedef uint32(* get_col_endpoint_func) (partition_info *, bool left_endpoint, bool include_endpoint, uint32 num_parts)
 

Functions

static int get_partition_id_list_col (partition_info *part_info, uint32 *part_id, longlong *func_value)
 
static int get_partition_id_list (partition_info *part_info, uint32 *part_id, longlong *func_value)
 
static int get_partition_id_range_col (partition_info *part_info, uint32 *part_id, longlong *func_value)
 
static int get_partition_id_range (partition_info *part_info, uint32 *part_id, longlong *func_value)
 
static int get_part_id_charset_func_part (partition_info *part_info, uint32 *part_id, longlong *func_value)
 
static int get_part_id_charset_func_subpart (partition_info *part_info, uint32 *part_id)
 
static int get_partition_id_hash_nosub (partition_info *part_info, uint32 *part_id, longlong *func_value)
 
static int get_partition_id_key_nosub (partition_info *part_info, uint32 *part_id, longlong *func_value)
 
static int get_partition_id_linear_hash_nosub (partition_info *part_info, uint32 *part_id, longlong *func_value)
 
static int get_partition_id_linear_key_nosub (partition_info *part_info, uint32 *part_id, longlong *func_value)
 
static int get_partition_id_with_sub (partition_info *part_info, uint32 *part_id, longlong *func_value)
 
static int get_partition_id_hash_sub (partition_info *part_info, uint32 *part_id)
 
static int get_partition_id_key_sub (partition_info *part_info, uint32 *part_id)
 
static int get_partition_id_linear_hash_sub (partition_info *part_info, uint32 *part_id)
 
static int get_partition_id_linear_key_sub (partition_info *part_info, uint32 *part_id)
 
static uint32 get_next_partition_via_walking (PARTITION_ITERATOR *)
 
static void set_up_range_analysis_info (partition_info *part_info)
 
static uint32 get_next_subpartition_via_walking (PARTITION_ITERATOR *)
 
static uint32 get_partition_id_range_for_endpoint (partition_info *part_info, bool left_endpoint, bool include_endpoint)
 
static uint32 get_next_partition_id_list (PARTITION_ITERATOR *part_iter)
 
static int get_part_iter_for_interval_via_mapping (partition_info *part_info, bool is_subpart, uint32 *store_length_array, uchar *min_value, uchar *max_value, uint min_len, uint max_len, uint flags, PARTITION_ITERATOR *part_iter)
 
static int get_part_iter_for_interval_cols_via_map (partition_info *part_info, bool is_subpart, uint32 *store_length_array, uchar *min_value, uchar *max_value, uint min_len, uint max_len, uint flags, PARTITION_ITERATOR *part_iter)
 
static int get_part_iter_for_interval_via_walking (partition_info *part_info, bool is_subpart, uint32 *store_length_array, uchar *min_value, uchar *max_value, uint min_len, uint max_len, uint flags, PARTITION_ITERATOR *part_iter)
 
static int cmp_rec_and_tuple (part_column_list_val *val, uint32 nvals_in_rec)
 RANGE(columns) partitioning: compare partition value bound and probe tuple. More...
 
static int cmp_rec_and_tuple_prune (part_column_list_val *val, uint32 n_vals_in_rec, bool is_left_endpoint, bool include_endpoint)
 Compare record and columns partition tuple including endpoint handling. More...
 
static void set_field_ptr (Field **ptr, const uchar *new_buf, const uchar *old_buf)
 
static uint32 get_list_array_idx_for_endpoint (partition_info *part_info, bool left_endpoint, bool include_endpoint)
 
Itemconvert_charset_partition_constant (Item *item, const CHARSET_INFO *cs)
 
static bool is_name_in_list (const char *name, List< String > list_names)
 A support function to check if a name is in a list of strings. More...
 
static bool partition_default_handling (TABLE *table, partition_info *part_info, bool is_create_table_ind, const char *normalized_path)
 
int get_parts_for_update (const uchar *old_data, const uchar *new_data[[maybe_unused]], const uchar *rec0, partition_info *part_info, uint32 *old_part_id, uint32 *new_part_id, longlong *new_func_value)
 
int get_part_for_delete (const uchar *buf, const uchar *rec0, partition_info *part_info, uint32 *part_id)
 
static bool set_up_field_array (TABLE *table, bool is_sub_part)
 
static bool create_full_part_field_array (THD *thd, TABLE *table, partition_info *part_info)
 
static void clear_indicator_in_key_fields (KEY *key_info)
 
static void set_indicator_in_key_fields (KEY *key_info)
 
static void check_fields_in_PF (Field **ptr, bool *all_fields, bool *some_fields)
 
static void clear_field_flag (TABLE *table)
 
static bool handle_list_of_fields (List_iterator< char > it, TABLE *table, partition_info *part_info, bool is_sub_part)
 
static int check_signed_flag (partition_info *part_info)
 
static bool init_lex_with_single_table (THD *thd, TABLE *table, LEX *lex)
 Initialize lex object for use in fix_fields and parsing. More...
 
static void end_lex_with_single_table (THD *thd, TABLE *table, LEX *old_lex)
 End use of local lex with single table. More...
 
static bool fix_fields_part_func (THD *thd, Item *func_expr, TABLE *table, bool is_sub_part, bool is_create_table_ind)
 
static bool check_primary_key (TABLE *table)
 
static bool check_unique_keys (TABLE *table)
 
static void check_range_capable_PF (TABLE *)
 
static bool set_up_partition_bitmaps (partition_info *part_info)
 Set up partition bitmaps. More...
 
static void set_up_partition_key_maps (TABLE *table, partition_info *part_info)
 
static void set_up_partition_func_pointers (partition_info *part_info)
 
void set_linear_hash_mask (partition_info *part_info, uint num_parts)
 
static uint32 get_part_id_from_linear_hash (longlong hash_value, uint mask, uint num_parts)
 
bool field_is_partition_charset (Field *field)
 
bool check_part_func_fields (Field **ptr, bool ok_with_charsets)
 
bool fix_partition_func (THD *thd, TABLE *table, bool is_create_table_ind)
 
static int add_write (File fptr, const char *buf, size_t len)
 
static int add_string_object (File fptr, String *string)
 
static int add_string (File fptr, const char *string)
 
static int add_string_len (File fptr, const char *string, size_t len)
 
static int add_space (File fptr)
 
static int add_comma (File fptr)
 
static int add_equal (File fptr)
 
static int add_end_parenthesis (File fptr)
 
static int add_begin_parenthesis (File fptr)
 
static int add_part_key_word (File fptr, const char *key_string)
 
static int add_partition (File fptr)
 
static int add_subpartition (File fptr)
 
static int add_partition_by (File fptr)
 
static int add_subpartition_by (File fptr)
 
static bool append_field_list (THD *thd, String *str, List< char > field_list)
 Append field list to string. More...
 
static int add_part_field_list (File fptr, List< char > field_list)
 
static int add_ident_string (File fptr, const char *name)
 
static int add_name_string (File fptr, const char *name)
 
static int add_int (File fptr, longlong number)
 
static int add_uint (File fptr, ulonglong number)
 
static int add_quoted_string (File fptr, const char *quotestr)
 
void truncate_partition_filename (MEM_ROOT *root, const char **path)
 Truncate the partition file name from a path if it exists. More...
 
static int add_keyword_path (File fptr, const char *keyword, const char *path)
 Output a filepath. More...
 
static int add_keyword_string (File fptr, const char *keyword, bool should_use_quotes, const char *keystr)
 
static int add_keyword_int (File fptr, const char *keyword, longlong num)
 
static int add_engine (File fptr, handlerton *engine_type)
 
static int add_partition_options (File fptr, partition_element *p_elem)
 
static int check_part_field (enum_field_types sql_type, const char *field_name, Item_result *result_type, bool *need_cs_check)
 
static Create_fieldget_sql_field (const char *field_name, List< Create_field > *create_fields)
 
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)
 
static int add_column_list_values (File fptr, partition_info *part_info, part_elem_value *list_value)
 
static int add_partition_values (File fptr, partition_info *part_info, partition_element *p_elem)
 
static int add_key_with_algorithm (File fptr, partition_info *part_info, const char *current_comment_start)
 Add 'KEY' word, with optional 'ALGORTIHM = N'. More...
 
static char * get_file_content (File fptr, uint *buf_length, bool use_sql_alloc)
 
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 partition_key_modified (TABLE *table, const MY_BITMAP *fields)
 
static int part_val_int (Item *item_expr, longlong *result)
 
static uint32 get_part_id_for_sub (uint32 loc_part_id, uint32 sub_part_id, uint num_subparts)
 
static int get_part_id_hash (uint num_parts, Item *part_expr, uint32 *part_id, longlong *func_value)
 
static int get_part_id_linear_hash (partition_info *part_info, uint num_parts, Item *part_expr, uint32 *part_id, longlong *func_value)
 
static uint32 get_part_id_key (handler *file, Field **field_array, uint num_parts, longlong *func_value)
 Calculate part_id for (SUB)PARTITION BY KEY. More...
 
static uint32 get_part_id_linear_key (partition_info *part_info, Field **field_array, uint num_parts, longlong *func_value)
 
static void copy_to_part_field_buffers (Field **ptr, uchar **field_bufs, uchar **restore_ptr)
 
static void restore_part_field_pointers (Field **ptr, uchar **restore_ptr)
 
static uint32 get_partition_id_cols_list_for_endpoint (partition_info *part_info, bool left_endpoint, bool include_endpoint, uint32 nparts)
 
static uint32 get_list_array_idx_for_endpoint_charset (partition_info *part_info, bool left_endpoint, bool include_endpoint)
 Find the sub-array part_info->list_array that corresponds to given interval. More...
 
static uint32 get_partition_id_range_for_endpoint_charset (partition_info *part_info, bool left_endpoint, bool include_endpoint)
 
static bool set_PF_fields_in_key (KEY *key_info, uint key_length)
 
static bool check_part_func_bound (Field **ptr)
 
static int get_sub_part_id_from_key (const TABLE *table, uchar *buf, KEY *key_info, const key_range *key_spec, uint32 *part_id)
 
static bool get_part_id_from_key (const TABLE *table, uchar *buf, KEY *key_info, const key_range *key_spec, uint32 *part_id)
 
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 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...
 
void prune_partition_set (const TABLE *table, part_id_range *part_spec)
 
void get_partition_set (const TABLE *table, uchar *buf, const uint index, 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)
 
static void set_engine_all_partitions (partition_info *part_info, handlerton *engine_type)
 
static bool check_native_partitioned (HA_CREATE_INFO *create_info, bool *ret_val, partition_info *part_info, THD *thd)
 
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...
 
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...
 
bool compare_partition_options (HA_CREATE_INFO *table_create_info, partition_element *part_elem)
 Check if partition is exchangable with table by checking table options. More...
 
uint prep_alter_part_table (THD *thd, TABLE *table, Alter_info *alter_info, HA_CREATE_INFO *create_info, Alter_table_ctx *alter_ctx[[maybe_unused]], bool *partition_changed, partition_info **new_part_info)
 
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)
 
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...
 
static uint32 store_tuple_to_record (Field **pfield, uint32 *store_length_array, uchar *value, uchar *value_end)
 
static uint32 get_partition_id_cols_range_for_endpoint (partition_info *part_info, bool is_left_endpoint, bool include_endpoint, uint32 nparts)
 Get partition for RANGE COLUMNS endpoint. More...
 
static int get_part_iter_for_interval_via_mapping (partition_info *part_info, bool is_subpart[[maybe_unused]], uint32 *store_length_array, uchar *min_value, uchar *max_value, uint min_len, uint max_len, uint flags, PARTITION_ITERATOR *part_iter)
 Partitioning Interval Analysis: Initialize the iterator for "mapping" case. More...
 
uint32 get_next_partition_id_range (PARTITION_ITERATOR *part_iter)
 
uint get_partition_field_store_length (Field *field)
 

Variables

const LEX_CSTRING partition_keywords []
 
static const char * part_str = "PARTITION"
 
static const char * sub_str = "SUB"
 
static const char * by_str = "BY"
 
static const char * space_str = " "
 
static const char * equal_str = "="
 
static const char * end_paren_str = ")"
 
static const char * begin_paren_str = "("
 
static const char * comma_str = ","
 

Macro Definition Documentation

◆ MAX_COMPARE_PARTITION_OPTION_ERRORS

#define MAX_COMPARE_PARTITION_OPTION_ERRORS   5

◆ MAX_RANGE_TO_WALK

#define MAX_RANGE_TO_WALK   32

Typedef Documentation

◆ get_col_endpoint_func

typedef uint32(* get_col_endpoint_func) (partition_info *, bool left_endpoint, bool include_endpoint, uint32 num_parts)

◆ get_endpoint_func

typedef uint32(* get_endpoint_func) (partition_info *, bool left_endpoint, bool include_endpoint)

Function Documentation

◆ add_begin_parenthesis()

static int add_begin_parenthesis ( File  fptr)
static

◆ add_column_list_values()

static int add_column_list_values ( File  fptr,
partition_info part_info,
part_elem_value list_value 
)
static

◆ add_comma()

static int add_comma ( File  fptr)
static

◆ add_end_parenthesis()

static int add_end_parenthesis ( File  fptr)
static

◆ add_engine()

static int add_engine ( File  fptr,
handlerton engine_type 
)
static

◆ add_equal()

static int add_equal ( File  fptr)
static

◆ add_ident_string()

static int add_ident_string ( File  fptr,
const char *  name 
)
static

◆ add_int()

static int add_int ( File  fptr,
longlong  number 
)
static

◆ add_key_with_algorithm()

static int add_key_with_algorithm ( File  fptr,
partition_info part_info,
const char *  current_comment_start 
)
static

Add 'KEY' word, with optional 'ALGORTIHM = N'.

Parameters
fptrFile to write to.
part_infopartition_info holding the used key_algorithm
current_comment_startNULL, or comment string encapsulating the PARTITION BY clause.
Returns
Operation status.
Return values
0Success
!=0 Failure

◆ add_keyword_int()

static int add_keyword_int ( File  fptr,
const char *  keyword,
longlong  num 
)
static

◆ add_keyword_path()

static int add_keyword_path ( File  fptr,
const char *  keyword,
const char *  path 
)
static

Output a filepath.

Similar to add_keyword_string except it also converts \ to / on Windows and skips the partition file name at the end if found.

Note
When Mysql sends a DATA DIRECTORY from SQL for partitions it does not use a file name, but it does for DATA DIRECTORY on a non-partitioned table. So when the storage engine is asked for the DATA DIRECTORY string after a restart through Handler::update_create_options(), the storage engine may include the filename.

◆ add_keyword_string()

static int add_keyword_string ( File  fptr,
const char *  keyword,
bool  should_use_quotes,
const char *  keystr 
)
static

◆ add_name_string()

static int add_name_string ( File  fptr,
const char *  name 
)
static

◆ add_part_field_list()

static int add_part_field_list ( File  fptr,
List< char >  field_list 
)
static

◆ add_part_key_word()

static int add_part_key_word ( File  fptr,
const char *  key_string 
)
static

◆ add_partition()

static int add_partition ( File  fptr)
static

◆ add_partition_by()

static int add_partition_by ( File  fptr)
static

◆ add_partition_options()

static int add_partition_options ( File  fptr,
partition_element p_elem 
)
static

◆ add_partition_values()

static int add_partition_values ( File  fptr,
partition_info part_info,
partition_element p_elem 
)
static

◆ add_quoted_string()

static int add_quoted_string ( File  fptr,
const char *  quotestr 
)
static

◆ add_space()

static int add_space ( File  fptr)
static

◆ add_string()

static int add_string ( File  fptr,
const char *  string 
)
static

◆ add_string_len()

static int add_string_len ( File  fptr,
const char *  string,
size_t  len 
)
static

◆ add_string_object()

static int add_string_object ( File  fptr,
String string 
)
static

◆ add_subpartition()

static int add_subpartition ( File  fptr)
static

◆ add_subpartition_by()

static int add_subpartition_by ( File  fptr)
static

◆ add_uint()

static int add_uint ( File  fptr,
ulonglong  number 
)
static

◆ add_write()

static int add_write ( File  fptr,
const char *  buf,
size_t  len 
)
static

◆ append_field_list()

static bool append_field_list ( THD thd,
String str,
List< char >  field_list 
)
static

Append field list to string.

Used by KEY and COLUMNS partitioning.

Parameters
[in]thdThread handle.
[in,out]strString to append.
[in]field_listList of field names to append.
Returns
false if success, else true.

◆ 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_fields_in_PF()

static void check_fields_in_PF ( Field **  ptr,
bool *  all_fields,
bool *  some_fields 
)
static

◆ check_native_partitioned()

static bool check_native_partitioned ( HA_CREATE_INFO create_info,
bool *  ret_val,
partition_info part_info,
THD thd 
)
static

◆ check_part_field()

static int check_part_field ( enum_field_types  sql_type,
const char *  field_name,
Item_result result_type,
bool *  need_cs_check 
)
static

◆ check_part_func_bound()

static bool check_part_func_bound ( Field **  ptr)
static

◆ check_part_func_fields()

bool check_part_func_fields ( Field **  ptr,
bool  ok_with_charsets 
)

◆ check_primary_key()

static bool check_primary_key ( TABLE table)
static

◆ check_range_capable_PF()

static void check_range_capable_PF ( TABLE )
static

◆ check_signed_flag()

static int check_signed_flag ( partition_info part_info)
static

◆ check_unique_keys()

static bool check_unique_keys ( TABLE table)
static

◆ clear_field_flag()

static void clear_field_flag ( TABLE table)
static

◆ clear_indicator_in_key_fields()

static void clear_indicator_in_key_fields ( KEY key_info)
static

◆ cmp_rec_and_tuple()

static int cmp_rec_and_tuple ( part_column_list_val val,
uint32  nvals_in_rec 
)
static

RANGE(columns) partitioning: compare partition value bound and probe tuple.

Parameters
valPartition column values.
nvals_in_recNumber of (prefix) fields to compare.
Returns
Less than/Equal to/Greater than 0 if the record is L/E/G than val.
Note
The partition value bound is always a full tuple (but may include the MAXVALUE special value). The probe tuple may be a prefix of partitioning tuple.

◆ cmp_rec_and_tuple_prune()

static int cmp_rec_and_tuple_prune ( part_column_list_val val,
uint32  n_vals_in_rec,
bool  is_left_endpoint,
bool  include_endpoint 
)
static

Compare record and columns partition tuple including endpoint handling.

Parameters
valColumns partition tuple
n_vals_in_recNumber of columns to compare
is_left_endpointTrue if left endpoint (part_tuple < rec or part_tuple <= rec)
include_endpointIf endpoint is included (part_tuple <= rec or rec <= part_tuple)
Returns
Less than/Equal to/Greater than 0 if the record is L/E/G than the partition tuple.
See also
get_list_array_idx_for_endpoint() and get_partition_id_range_for_endpoint().

◆ compare_partition_options()

bool compare_partition_options ( HA_CREATE_INFO table_create_info,
partition_element part_elem 
)

Check if partition is exchangable 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 differens 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 
)

◆ copy_to_part_field_buffers()

static void copy_to_part_field_buffers ( Field **  ptr,
uchar **  field_bufs,
uchar **  restore_ptr 
)
static

◆ create_full_part_field_array()

static bool create_full_part_field_array ( THD thd,
TABLE table,
partition_info part_info 
)
static

◆ end_lex_with_single_table()

static void end_lex_with_single_table ( THD thd,
TABLE table,
LEX old_lex 
)
static

End use of local lex with single table.

SYNOPSIS end_lex_with_single_table()

Parameters
thdThe thread object
tableThe table object
old_lexThe real lex object connected to THD

DESCRIPTION This function restores the real lex object after calling init_lex_with_single_table and also restores some table variables temporarily set.

◆ 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_fields_part_func()

static bool fix_fields_part_func ( THD thd,
Item func_expr,
TABLE table,
bool  is_sub_part,
bool  is_create_table_ind 
)
static

◆ fix_partition_func()

bool fix_partition_func ( THD thd,
TABLE table,
bool  is_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_file_content()

static char* get_file_content ( File  fptr,
uint buf_length,
bool  use_sql_alloc 
)
static

◆ 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_list_array_idx_for_endpoint()

static uint32 get_list_array_idx_for_endpoint ( partition_info part_info,
bool  left_endpoint,
bool  include_endpoint 
)
static

◆ get_list_array_idx_for_endpoint_charset()

static uint32 get_list_array_idx_for_endpoint_charset ( partition_info part_info,
bool  left_endpoint,
bool  include_endpoint 
)
static

Find the sub-array part_info->list_array that corresponds to given interval.

Parameters
part_infoPartitioning info (partitioning type must be LIST)
left_endpointtrue - the interval is [a; +inf) or (a; +inf) false - the interval is (-inf; a] or (-inf; a)
include_endpointtrue iff the interval includes the endpoint

This function finds the sub-array of part_info->list_array where values of list_array[idx].list_value are contained within the specifed interval. list_array is ordered by list_value, so

  1. For [a; +inf) or (a; +inf)-type intervals (left_endpoint==true), the sought sub-array starts at some index idx and continues till array end. The function returns first number idx, such that list_array[idx].list_value is contained within the passed interval.
  2. For (-inf; a] or (-inf; a)-type intervals (left_endpoint==false), the sought sub-array starts at array start and continues till some last index idx. The function returns first number idx, such that list_array[idx].list_value is NOT contained within the passed interval. If all array elements are contained, part_info->num_list_values is returned.
Note
The caller will call this function and then will run along the sub-array of list_array to collect partition ids. If the number of list values is significantly higher then number of partitions, this could be slow and we could invent some other approach. The "run over list array" part is already wrapped in a get_next()-like function.
Returns
The index of corresponding sub-array of part_info->list_array.

◆ get_next_partition_id_list()

static uint32 get_next_partition_id_list ( PARTITION_ITERATOR part_iter)
static

◆ get_next_partition_id_range()

uint32 get_next_partition_id_range ( PARTITION_ITERATOR part_iter)

◆ get_next_partition_via_walking()

static uint32 get_next_partition_via_walking ( PARTITION_ITERATOR part_iter)
static

◆ get_next_subpartition_via_walking()

static uint32 get_next_subpartition_via_walking ( PARTITION_ITERATOR part_iter)
static

◆ get_part_for_delete()

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

◆ get_part_id_charset_func_part()

static int get_part_id_charset_func_part ( partition_info part_info,
uint32 part_id,
longlong func_value 
)
static

◆ get_part_id_charset_func_subpart()

static int get_part_id_charset_func_subpart ( partition_info part_info,
uint32 part_id 
)
static

◆ get_part_id_for_sub()

static uint32 get_part_id_for_sub ( uint32  loc_part_id,
uint32  sub_part_id,
uint  num_subparts 
)
inlinestatic

◆ get_part_id_from_key()

static bool get_part_id_from_key ( const TABLE table,
uchar buf,
KEY key_info,
const key_range key_spec,
uint32 part_id 
)
static

◆ get_part_id_from_linear_hash()

static uint32 get_part_id_from_linear_hash ( longlong  hash_value,
uint  mask,
uint  num_parts 
)
static

◆ get_part_id_hash()

static int get_part_id_hash ( uint  num_parts,
Item part_expr,
uint32 part_id,
longlong func_value 
)
static

◆ get_part_id_key()

static uint32 get_part_id_key ( handler file,
Field **  field_array,
uint  num_parts,
longlong func_value 
)
inlinestatic

Calculate part_id for (SUB)PARTITION BY KEY.

Parameters
fileHandler to storage engine
field_arrayArray of fields for PARTTION KEY
num_partsNumber of KEY partitions
[out]func_valueReturns calculated hash value
Returns
Calculated partition id

◆ get_part_id_linear_hash()

static int get_part_id_linear_hash ( partition_info part_info,
uint  num_parts,
Item part_expr,
uint32 part_id,
longlong func_value 
)
static

◆ get_part_id_linear_key()

static uint32 get_part_id_linear_key ( partition_info part_info,
Field **  field_array,
uint  num_parts,
longlong func_value 
)
inlinestatic

◆ get_part_iter_for_interval_cols_via_map()

static int get_part_iter_for_interval_cols_via_map ( partition_info part_info,
bool  is_subpart,
uint32 store_length_array,
uchar min_value,
uchar max_value,
uint  min_len,
uint  max_len,
uint  flags,
PARTITION_ITERATOR part_iter 
)
static

◆ get_part_iter_for_interval_via_mapping() [1/2]

static int get_part_iter_for_interval_via_mapping ( partition_info part_info,
bool  is_subpart,
uint32 store_length_array,
uchar min_value,
uchar max_value,
uint  min_len,
uint  max_len,
uint  flags,
PARTITION_ITERATOR part_iter 
)
static

◆ get_part_iter_for_interval_via_mapping() [2/2]

static int get_part_iter_for_interval_via_mapping ( partition_info part_info,
bool is_subpart]  [[maybe_unused],
uint32 store_length_array,
uchar min_value,
uchar max_value,
uint  min_len,
uint  max_len,
uint  flags,
PARTITION_ITERATOR part_iter 
)
static

Partitioning Interval Analysis: Initialize the iterator for "mapping" case.

Parameters
part_infoPartition info
is_subparttrue - act for subpartitioning false - act for partitioning
store_length_arrayIgnored.
min_valueminimum field value, in opt_range key format.
max_valueminimum field value, in opt_range key format.
min_lenIgnored.
max_lenIgnored.
flagsSome combination of NEAR_MIN, NEAR_MAX, NO_MIN_RANGE, NO_MAX_RANGE.
part_iterIterator structure to be initialized

Initialize partition set iterator to walk over the interval in ordered-array-of-partitions (for RANGE partitioning) or ordered-array-of-list-constants (for LIST partitioning) space.

This function is used when partitioning is done by <RANGE|LIST>(ascending_func(t.field)), and we can map an interval in t.field space into a sub-array of partition_info::range_int_array or partition_info::list_array (see get_partition_id_range_for_endpoint, get_list_array_idx_for_endpoint for details).

The function performs this interval mapping, and sets the iterator to traverse the sub-array and return appropriate partitions.

Returns
Status of iterator
Return values
0No matching partitions (iterator not initialized)
1Ok, iterator intialized for traversal of matching partitions.
-1All partitions would match (iterator not initialized)

◆ get_part_iter_for_interval_via_walking()

static int get_part_iter_for_interval_via_walking ( partition_info part_info,
bool  is_subpart,
uint32 store_length_array,
uchar min_value,
uchar max_value,
uint  min_len,
uint  max_len,
uint  flags,
PARTITION_ITERATOR part_iter 
)
static

◆ get_partition_field_store_length()

uint get_partition_field_store_length ( Field field)

◆ get_partition_id_cols_list_for_endpoint()

static uint32 get_partition_id_cols_list_for_endpoint ( partition_info part_info,
bool  left_endpoint,
bool  include_endpoint,
uint32  nparts 
)
static

◆ get_partition_id_cols_range_for_endpoint()

static uint32 get_partition_id_cols_range_for_endpoint ( partition_info part_info,
bool  is_left_endpoint,
bool  include_endpoint,
uint32  nparts 
)
static

Get partition for RANGE COLUMNS endpoint.

Parameters
part_infoPartitioning metadata.
is_left_endpointTrue if left endpoint (const <=/< cols)
include_endpointTrue if range includes the endpoint (<=/>=)
npartsTotal number of partitions
Returns
Partition id of matching partition.
See also
get_partition_id_cols_list_for_endpoint and get_partition_id_range_for_endpoint.

◆ get_partition_id_hash_nosub()

static int get_partition_id_hash_nosub ( partition_info part_info,
uint32 part_id,
longlong func_value 
)
static

◆ get_partition_id_hash_sub()

static int get_partition_id_hash_sub ( partition_info part_info,
uint32 part_id 
)
static

◆ get_partition_id_key_nosub()

static int get_partition_id_key_nosub ( partition_info part_info,
uint32 part_id,
longlong func_value 
)
static

◆ get_partition_id_key_sub()

static int get_partition_id_key_sub ( partition_info part_info,
uint32 part_id 
)
static

◆ get_partition_id_linear_hash_nosub()

static int get_partition_id_linear_hash_nosub ( partition_info part_info,
uint32 part_id,
longlong func_value 
)
static

◆ get_partition_id_linear_hash_sub()

static int get_partition_id_linear_hash_sub ( partition_info part_info,
uint32 part_id 
)
static

◆ get_partition_id_linear_key_nosub()

static int get_partition_id_linear_key_nosub ( partition_info part_info,
uint32 part_id,
longlong func_value 
)
static

◆ get_partition_id_linear_key_sub()

static int get_partition_id_linear_key_sub ( partition_info part_info,
uint32 part_id 
)
static

◆ get_partition_id_list()

static int get_partition_id_list ( partition_info part_info,
uint32 part_id,
longlong func_value 
)
static

◆ get_partition_id_list_col()

static int get_partition_id_list_col ( partition_info part_info,
uint32 part_id,
longlong func_value 
)
static

◆ get_partition_id_range()

int get_partition_id_range ( partition_info part_info,
uint32 part_id,
longlong func_value 
)
static

◆ get_partition_id_range_col()

static int get_partition_id_range_col ( partition_info part_info,
uint32 part_id,
longlong func_value 
)
static

◆ get_partition_id_range_for_endpoint()

static uint32 get_partition_id_range_for_endpoint ( partition_info part_info,
bool  left_endpoint,
bool  include_endpoint 
)
static

◆ get_partition_id_range_for_endpoint_charset()

static uint32 get_partition_id_range_for_endpoint_charset ( partition_info part_info,
bool  left_endpoint,
bool  include_endpoint 
)
static

◆ get_partition_id_with_sub()

static int get_partition_id_with_sub ( partition_info part_info,
uint32 part_id,
longlong func_value 
)
static

◆ 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 [[maybe_unused],
const uchar rec0,
partition_info part_info,
uint32 old_part_id,
uint32 new_part_id,
longlong new_func_value 
)

◆ get_sql_field()

static Create_field* get_sql_field ( const char *  field_name,
List< Create_field > *  create_fields 
)
static

◆ get_sub_part_id_from_key()

static int get_sub_part_id_from_key ( const TABLE table,
uchar buf,
KEY key_info,
const key_range key_spec,
uint32 part_id 
)
static

◆ handle_list_of_fields()

static bool handle_list_of_fields ( List_iterator< char >  it,
TABLE table,
partition_info part_info,
bool  is_sub_part 
)
static

◆ init_lex_with_single_table()

static bool init_lex_with_single_table ( THD thd,
TABLE table,
LEX lex 
)
static

Initialize lex object for use in fix_fields and parsing.

Parameters
thdThe thread object
tableThe table object
lexThe LEX object, must be initialized and contain query_block.
Returns
false if success, true if error

This function is used to set up a lex object on the stack for resolving of fields from a single table.

◆ is_name_in_list()

static bool is_name_in_list ( const char *  name,
List< String list_names 
)
static

A support function to check if a name is in a list of strings.

Parameters
nameString searched for
list_namesA list of names searched in
Returns
True if if the name is in the list.
Return values
trueString found
falseString not found

◆ 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 
)

◆ part_val_int()

static int part_val_int ( Item item_expr,
longlong result 
)
inlinestatic

◆ partition_default_handling()

static bool partition_default_handling ( TABLE table,
partition_info part_info,
bool  is_create_table_ind,
const char *  normalized_path 
)
static

◆ 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]  [[maybe_unused],
bool *  partition_changed,
partition_info **  new_part_info 
)

◆ prune_partition_set()

void prune_partition_set ( const TABLE table,
part_id_range part_spec 
)

◆ restore_part_field_pointers()

static void restore_part_field_pointers ( Field **  ptr,
uchar **  restore_ptr 
)
static

◆ 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_engine_all_partitions()

static void set_engine_all_partitions ( partition_info part_info,
handlerton engine_type 
)
static

◆ set_field_ptr()

static void set_field_ptr ( Field **  ptr,
const uchar new_buf,
const uchar old_buf 
)
static

◆ set_indicator_in_key_fields()

static void set_indicator_in_key_fields ( KEY key_info)
static

◆ 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

◆ set_PF_fields_in_key()

static bool set_PF_fields_in_key ( KEY key_info,
uint  key_length 
)
static

◆ set_up_field_array()

static bool set_up_field_array ( TABLE table,
bool  is_sub_part 
)
static

◆ set_up_partition_bitmaps()

static bool set_up_partition_bitmaps ( partition_info part_info)
static

Set up partition bitmaps.

Parameters
part_infoReference to partitioning data structure
Returns
Operation status
Return values
trueMemory allocation failure
falseSuccess

Allocate memory for bitmaps of the partitioned table and initialise it.

◆ set_up_partition_func_pointers()

static void set_up_partition_func_pointers ( partition_info part_info)
static

◆ set_up_partition_key_maps()

static void set_up_partition_key_maps ( TABLE table,
partition_info part_info 
)
static

◆ set_up_range_analysis_info()

static void set_up_range_analysis_info ( partition_info part_info)
static

◆ store_tuple_to_record()

static uint32 store_tuple_to_record ( Field **  pfield,
uint32 store_length_array,
uchar value,
uchar value_end 
)
static

◆ 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

◆ begin_paren_str

const char* begin_paren_str = "("
static

◆ by_str

const char* by_str = "BY"
static

◆ comma_str

const char* comma_str = ","
static

◆ end_paren_str

const char* end_paren_str = ")"
static

◆ equal_str

const char* equal_str = "="
static

◆ part_str

const char* part_str = "PARTITION"
static

◆ partition_keywords

const LEX_CSTRING partition_keywords[]
Initial value:
= {{STRING_WITH_LEN("HASH")},
{STRING_WITH_LEN("RANGE")},
{STRING_WITH_LEN("LIST")},
{STRING_WITH_LEN("KEY")},
{STRING_WITH_LEN("MAXVALUE")},
{STRING_WITH_LEN("LINEAR ")},
{STRING_WITH_LEN(" COLUMNS")},
{STRING_WITH_LEN("ALGORITHM")}
}
#define STRING_WITH_LEN(X)
Definition: m_string.h:321

◆ space_str

const char* space_str = " "
static

◆ sub_str

const char* sub_str = "SUB"
static