MySQL  8.0.27
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, 2021, Oracle and/or its affiliates.
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 */
app_data_ptr new_data(u_int n, char *val, cons_type consensus)
Data describing the table being created by CREATE TABLE or altered by ALTER TABLE.
Definition: sql_alter.h:204
Runtime context for ALTER TABLE.
Definition: sql_alter.h:508
Create_field is a description a field/column that may or may not exists in a table.
Definition: create_field.h:50
Definition: field.h:590
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:802
Definition: key.h:112
Definition: sql_list.h:431
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:165
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:821
Definition: partition_element.h:107
Definition: partition_info.h:208
This file includes constants used by all storage engines.
Some integer typedefs for easier portability.
unsigned char uchar
Definition: my_inttypes.h:51
long long int longlong
Definition: my_inttypes.h:54
uint32_t uint32
Definition: my_inttypes.h:66
static char * path
Definition: mysqldump.cc:130
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1056
Definition: buf0block_hint.cc:29
Definition: commit_order_queue.h:33
partition_state
Definition: partition_element.h:34
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:5281
uint get_partition_field_store_length(Field *field)
Definition: sql_partition.cc:6122
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:4211
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
bool field_is_partition_charset(Field *field)
Definition: sql_partition.cc:1391
void set_linear_hash_mask(partition_info *part_info, uint num_parts)
Definition: sql_partition.cc:1339
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:3540
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:4151
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
void append_row_to_str(String &str, const uchar *row, TABLE *table)
Append all fields in read_set to string.
Definition: sql_partition.cc:5212
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:4153
const LEX_CSTRING partition_keywords[]
Definition: sql_partition.cc:113
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:3504
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)
bool partition_key_modified(TABLE *table, const MY_BITMAP *fields)
Definition: sql_partition.cc:2472
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)
void mem_alloc_error(size_t size)
Definition: sql_partition.cc:5262
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:3675
Item * convert_charset_partition_constant(Item *item, const CHARSET_INFO *cs)
Definition: sql_partition.cc:210
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
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:4120
void prune_partition_set(const TABLE *table, part_id_range *part_spec)
Definition: sql_partition.cc:3622
key_range key_range
Definition: sql_partition.h:48
bool check_part_func_fields(Field **ptr, bool ok_with_charsets)
Definition: sql_partition.cc:1423
int get_part_for_delete(const uchar *buf, const uchar *rec0, partition_info *part_info, uint32 *part_id)
Definition: sql_partition.cc:361
bool fix_partition_func(THD *thd, TABLE *table, bool create_table_ind)
Definition: sql_partition.cc:1470
enum_partition_keywords
Definition: sql_partition.h:154
@ PKW_COLUMNS
Definition: sql_partition.h:161
@ PKW_KEY
Definition: sql_partition.h:158
@ PKW_LINEAR
Definition: sql_partition.h:160
@ PKW_LIST
Definition: sql_partition.h:157
@ PKW_RANGE
Definition: sql_partition.h:156
@ PKW_ALGORITHM
Definition: sql_partition.h:162
@ PKW_MAXVALUE
Definition: sql_partition.h:159
@ PKW_HASH
Definition: sql_partition.h:155
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:3874
Definition: m_ctype.h:354
Definition: handler.h:2764
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:78
Definition: mysql_lex_string.h:39
Definition: my_bitmap.h:41
Definition: table.h:1394
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2391
Definition: my_base.h:1122
Definition: sql_partition.h:87
uint32 start_part
Definition: sql_partition.h:88
uint32 end_part
Definition: sql_partition.h:89
unsigned int uint
Definition: uca-dump.cc:29