MySQL 8.0.30
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, 2022, 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
34class Alter_info;
35class Alter_table_ctx;
36class Create_field;
37class Field;
38class Item;
39class KEY;
40class String;
41class THD;
42class partition_info;
43struct CHARSET_INFO;
44struct HA_CREATE_INFO;
45struct MEM_ROOT;
46struct MY_BITMAP;
47struct TABLE;
48struct handlerton;
49
51template <class T>
52class 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
87typedef struct {
91
92int 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);
96int get_part_for_delete(const uchar *buf, const uchar *rec0,
97 partition_info *part_info, uint32 *part_id);
98void prune_partition_set(const TABLE *table, part_id_range *part_spec);
99void set_linear_hash_mask(partition_info *part_info, uint num_parts);
100bool fix_partition_func(THD *thd, TABLE *table, bool create_table_ind);
101bool partition_key_modified(TABLE *table, const MY_BITMAP *fields);
102void 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);
110void 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);
113bool 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);
119bool check_part_func_fields(Field **ptr, bool ok_with_charsets);
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*/
129void append_row_to_str(String &str, const uchar *row, TABLE *table);
130void mem_alloc_error(size_t size);
131void truncate_partition_filename(MEM_ROOT *root, const char **path);
132
133bool set_part_state(Alter_info *alter_info, partition_info *tab_part_info,
134 enum partition_state part_state,
135 bool include_subpartitions);
136void set_all_part_state(partition_info *tab_part_info,
137 enum partition_state part_state);
138uint 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);
142int 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);
145char *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);
149bool verify_data_with_partition(TABLE *table, TABLE *part_table,
150 uint32 part_id);
151bool compare_partition_options(HA_CREATE_INFO *table_create_info,
152 partition_element *part_elem);
153
164
165extern 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:203
Runtime context for ALTER TABLE.
Definition: sql_alter.h:507
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:573
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:433
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:166
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:922
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:133
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1055
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:5276
uint get_partition_field_store_length(Field *field)
Definition: sql_partition.cc:6117
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.
Definition: sql_partition.cc:4205
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:2288
bool field_is_partition_charset(Field *field)
Definition: sql_partition.cc:1390
void set_linear_hash_mask(partition_info *part_info, uint num_parts)
Definition: sql_partition.cc:1338
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:3533
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:4145
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:2018
void append_row_to_str(String &str, const uchar *row, TABLE *table)
Append all fields in read_set to string.
Definition: sql_partition.cc:5207
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:4267
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:3497
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
bool partition_key_modified(TABLE *table, const MY_BITMAP *fields)
Definition: sql_partition.cc:2469
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:4260
void mem_alloc_error(size_t size)
Definition: sql_partition.cc:5257
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:3667
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:1790
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:4114
void prune_partition_set(const TABLE *table, part_id_range *part_spec)
Definition: sql_partition.cc:3614
Item * convert_charset_partition_constant(Item *item, const CHARSET_INFO *cs)
Definition: sql_partition.cc:210
key_range key_range
Definition: sql_partition.h:48
bool check_part_func_fields(Field **ptr, bool ok_with_charsets)
Definition: sql_partition.cc:1422
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:1469
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:3868
Definition: m_ctype.h:354
Definition: handler.h:2923
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:82
Definition: mysql_lex_string.h:39
Definition: my_bitmap.h:42
Definition: table.h:1394
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2542
Definition: my_base.h:1123
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