MySQL  8.0.23
Source Code Documentation
sql_partition.h
Go to the documentation of this file.
1 #ifndef SQL_PARTITION_INCLUDED
2 #define SQL_PARTITION_INCLUDED
3 
4 /* Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License, version 2.0,
8  as published by the Free Software Foundation.
9 
10  This program is also distributed with certain software (including
11  but not limited to OpenSSL) that is licensed under separate terms,
12  as designated in a particular file or component or in included license
13  documentation. The authors of MySQL hereby grant you an additional
14  permission to link the program and your derivative works with the
15  separately licensed software that they have included with MySQL.
16 
17  This program is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License, version 2.0, for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with this program; if not, write to the Free Software
24  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
25 
26 #include <stddef.h>
27 #include <sys/types.h>
28 
29 #include "lex_string.h"
30 #include "my_base.h"
31 #include "my_inttypes.h"
32 #include "sql/partition_element.h" // partition_state
33 
34 class Alter_info;
35 class Alter_table_ctx;
36 class Create_field;
37 class Field;
38 class Item;
39 class KEY;
40 class String;
41 class THD;
42 class partition_info;
43 struct CHARSET_INFO;
44 struct HA_CREATE_INFO;
45 struct MEM_ROOT;
46 struct MY_BITMAP;
47 struct TABLE;
48 struct handlerton;
49 
51 template <class T>
52 class List;
53 
54 /* Flags for partition handlers */
55 /*
56  Removed HA_CAN_PARTITION (1 << 0) since if handlerton::partition_flags
57  is set, then it implies that it have partitioning support.
58 */
59 /*
60  Set if the handler can update fields that are part of the partition
61  function.
62 */
63 #define HA_CAN_UPDATE_PARTITION_KEY (1 << 1)
64 /*
65  Set if the handler can handle unique indexes where the fields of the
66  unique key are not part of the fields of the partition function. Thus
67  a unique key can be set on all fields.
68 */
69 #define HA_CAN_PARTITION_UNIQUE (1 << 2)
70 /* If the engine will use auto partitioning even when not defined. */
71 #define HA_USE_AUTO_PARTITION (1 << 3)
72 /**
73  The handler can exchange a partition with a non-partitioned table
74  of the same handlerton/engine.
75 */
76 #define HA_CAN_EXCHANGE_PARTITION (1 << 4)
77 /**
78  The handler can not use FOREIGN KEYS with partitioning
79 */
80 #define HA_CANNOT_PARTITION_FK (1 << 5)
81 /**
82  Engine requires closing all open table instances before TRUNCATE
83  PARTITION operation.
84 */
85 #define HA_TRUNCATE_PARTITION_PRECLOSE (1 << 6)
86 
87 typedef struct {
91 
92 int get_parts_for_update(const uchar *old_data, const uchar *new_data,
93  const uchar *rec0, partition_info *part_info,
94  uint32 *old_part_id, uint32 *new_part_id,
95  longlong *func_value);
96 int get_part_for_delete(const uchar *buf, const uchar *rec0,
97  partition_info *part_info, uint32 *part_id);
98 void prune_partition_set(const TABLE *table, part_id_range *part_spec);
99 void set_linear_hash_mask(partition_info *part_info, uint num_parts);
100 bool fix_partition_func(THD *thd, TABLE *table, bool create_table_ind);
101 bool partition_key_modified(TABLE *table, const MY_BITMAP *fields);
102 void get_partition_set(const TABLE *table, uchar *buf, const uint index,
103  const key_range *key_spec, part_id_range *part_spec);
106  String *input_str,
107  String *output_str,
108  const CHARSET_INFO *cs,
109  bool use_hex);
110 void get_full_part_id_from_key(const TABLE *table, uchar *buf, KEY *key_info,
111  const key_range *key_spec,
112  part_id_range *part_spec);
113 bool mysql_unpack_partition(THD *thd, char *part_buf, uint part_info_len,
114  TABLE *table, bool is_create_table_ind,
115  handlerton *default_db_type,
116  bool *work_part_info_used);
118  List<const char> *parts);
119 bool check_part_func_fields(Field **ptr, bool ok_with_charsets);
120 bool field_is_partition_charset(Field *field);
122 /**
123  Append all fields in read_set to string
124 
125  @param[in,out] str String to append to.
126  @param[in] row Row to append.
127  @param[in] table Table containing read_set and fields for the row.
128 */
129 void append_row_to_str(String &str, const uchar *row, TABLE *table);
130 void mem_alloc_error(size_t size);
131 void truncate_partition_filename(MEM_ROOT *root, const char **path);
132 
133 bool set_part_state(Alter_info *alter_info, partition_info *tab_part_info,
134  enum partition_state part_state,
135  bool include_subpartitions);
136 void set_all_part_state(partition_info *tab_part_info,
137  enum partition_state part_state);
138 uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
139  HA_CREATE_INFO *create_info,
140  Alter_table_ctx *alter_ctx, bool *partition_changed,
141  partition_info **new_part_info);
142 int expr_to_string(String *val_conv, Item *item_expr, Field *field,
143  const char *field_name, const HA_CREATE_INFO *create_info,
144  List<Create_field> *create_fields);
145 char *generate_partition_syntax(partition_info *part_info, uint *buf_length,
146  bool use_sql_alloc, bool show_partition_options,
147  bool print_expr,
148  const char *current_comment_start);
149 bool verify_data_with_partition(TABLE *table, TABLE *part_table,
150  uint32 part_id);
151 bool compare_partition_options(HA_CREATE_INFO *table_create_info,
152  partition_element *part_elem);
153 
155  PKW_HASH = 0,
163 };
164 
165 extern const LEX_CSTRING partition_keywords[];
166 
167 #endif /* SQL_PARTITION_INCLUDED */
MYSQL_LEX_CSTRING
Definition: mysql_lex_string.h:39
Item
Definition: item.h:775
THD
Definition: sql_class.h:807
get_partition_field_store_length
uint get_partition_field_store_length(Field *field)
Definition: sql_partition.cc:6123
my_base.h
Alter_info
Data describing the table being created by CREATE TABLE or altered by ALTER TABLE.
Definition: sql_alter.h:206
Alter_table_ctx
Runtime context for ALTER TABLE.
Definition: sql_alter.h:510
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)
Definition: sql_partition.cc:314
truncate_partition_filename
void truncate_partition_filename(MEM_ROOT *root, const char **path)
Truncate the partition file name from a path if it exists.
Definition: sql_partition.cc:1793
PKW_ALGORITHM
@ PKW_ALGORITHM
Definition: sql_partition.h:162
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)
Definition: sql_partition.cc:3676
CHARSET_INFO
Definition: m_ctype.h:354
PKW_MAXVALUE
@ PKW_MAXVALUE
Definition: sql_partition.h:159
handlerton
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2310
key_range
key_range key_range
Definition: sql_partition.h:48
Create_field
Create_field is a description a field/column that may or may not exists in a table.
Definition: create_field.h:49
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.
Definition: sql_partition.cc:5282
new_data
app_data_ptr new_data(u_int n, char *val, cons_type consensus)
Definition: app_data.cc:363
String
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:164
TABLE
Definition: table.h:1364
longlong
long long int longlong
Definition: my_inttypes.h:54
PKW_HASH
@ PKW_HASH
Definition: sql_partition.h:155
partition_key_modified
bool partition_key_modified(TABLE *table, const MY_BITMAP *fields)
Definition: sql_partition.cc:2472
part_id_range::start_part
uint32 start_part
Definition: sql_partition.h:88
PKW_LIST
@ PKW_LIST
Definition: sql_partition.h:157
field_is_partition_charset
bool field_is_partition_charset(Field *field)
Definition: sql_partition.cc:1391
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)
Definition: sql_partition.cc:2021
my_inttypes.h
set_linear_hash_mask
void set_linear_hash_mask(partition_info *part_info, uint num_parts)
Definition: sql_partition.cc:1339
enum_partition_keywords
enum_partition_keywords
Definition: sql_partition.h:154
MEM_ROOT
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:77
lex_string.h
partition_keywords
const LEX_CSTRING partition_keywords[]
Definition: sql_partition.cc:113
cs
Definition: commit_order_queue.h:33
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.
Definition: sql_partition.cc:2291
PKW_LINEAR
@ PKW_LINEAR
Definition: sql_partition.h:160
append_row_to_str
void append_row_to_str(String &str, const uchar *row, TABLE *table)
Append all fields in read_set to string.
Definition: sql_partition.cc:5213
uint
unsigned int uint
Definition: uca-dump.cc:29
part_id_range::end_part
uint32 end_part
Definition: sql_partition.h:89
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)
Definition: sql_partition.cc:3875
uchar
unsigned char uchar
Definition: my_inttypes.h:51
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)
Definition: sql_show.cc:4127
uint32
uint32_t uint32
Definition: my_inttypes.h:66
PKW_RANGE
@ PKW_RANGE
Definition: sql_partition.h:156
mem_alloc_error
void mem_alloc_error(size_t size)
Definition: sql_partition.cc:5263
buf
Definition: buf0block_hint.cc:29
get_part_for_delete
int get_part_for_delete(const uchar *buf, const uchar *rec0, partition_info *part_info, uint32 *part_id)
Definition: sql_partition.cc:361
path
static char * path
Definition: mysqldump.cc:132
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.
Definition: sql_partition.cc:4152
partition_element
Definition: partition_element.h:107
check_part_func_fields
bool check_part_func_fields(Field **ptr, bool ok_with_charsets)
Definition: sql_partition.cc:1423
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.
Definition: sql_partition.cc:4212
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)
Definition: sql_partition.cc:4267
KEY
Definition: key.h:111
partition_element.h
prune_partition_set
void prune_partition_set(const TABLE *table, part_id_range *part_spec)
Definition: sql_partition.cc:3623
partition_state
partition_state
Definition: partition_element.h:34
part_id_range
Definition: sql_partition.h:87
PKW_KEY
@ PKW_KEY
Definition: sql_partition.h:158
fix_partition_func
bool fix_partition_func(THD *thd, TABLE *table, bool create_table_ind)
Definition: sql_partition.cc:1470
PKW_COLUMNS
@ PKW_COLUMNS
Definition: sql_partition.h:161
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)
Definition: sql_partition.cc:3505
List
Definition: auth_common.h:57
convert_charset_partition_constant
Item * convert_charset_partition_constant(Item *item, const CHARSET_INFO *cs)
Definition: sql_partition.cc:210
Field
Definition: field.h:568
partition_info
Definition: partition_info.h:208
key_range
Definition: my_base.h:1120
MY_BITMAP
Definition: my_bitmap.h:41
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.
Definition: sql_partition.cc:4121
HA_CREATE_INFO
Definition: handler.h:2670
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.
Definition: sql_partition.cc:3541