MySQL 8.0.40
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, 2024, 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 designed to work 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 either included with
16 the program or referenced in the documentation.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License, version 2.0, for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
26
27#include <stddef.h>
28#include <sys/types.h>
29
30#include "lex_string.h"
31#include "my_base.h"
32#include "my_inttypes.h"
33#include "sql/partition_element.h" // partition_state
34
35class Alter_info;
36class Alter_table_ctx;
37class Create_field;
38class Field;
39class Item;
40class KEY;
41class String;
42class THD;
43class partition_info;
44struct CHARSET_INFO;
45struct HA_CREATE_INFO;
46struct MEM_ROOT;
47struct MY_BITMAP;
48struct TABLE;
49struct handlerton;
50
52template <class T>
53class List;
54
55/* Flags for partition handlers */
56/*
57 Removed HA_CAN_PARTITION (1 << 0) since if handlerton::partition_flags
58 is set, then it implies that it have partitioning support.
59*/
60/*
61 Set if the handler can update fields that are part of the partition
62 function.
63*/
64#define HA_CAN_UPDATE_PARTITION_KEY (1 << 1)
65/*
66 Set if the handler can handle unique indexes where the fields of the
67 unique key are not part of the fields of the partition function. Thus
68 a unique key can be set on all fields.
69*/
70#define HA_CAN_PARTITION_UNIQUE (1 << 2)
71/* If the engine will use auto partitioning even when not defined. */
72#define HA_USE_AUTO_PARTITION (1 << 3)
73/**
74 The handler can exchange a partition with a non-partitioned table
75 of the same handlerton/engine.
76*/
77#define HA_CAN_EXCHANGE_PARTITION (1 << 4)
78/**
79 The handler can not use FOREIGN KEYS with partitioning
80*/
81#define HA_CANNOT_PARTITION_FK (1 << 5)
82/**
83 Engine requires closing all open table instances before TRUNCATE
84 PARTITION operation.
85*/
86#define HA_TRUNCATE_PARTITION_PRECLOSE (1 << 6)
87
88typedef struct {
92
93int get_parts_for_update(const uchar *old_data, const uchar *new_data,
94 const uchar *rec0, partition_info *part_info,
95 uint32 *old_part_id, uint32 *new_part_id,
96 longlong *func_value);
97int get_part_for_delete(const uchar *buf, const uchar *rec0,
98 partition_info *part_info, uint32 *part_id);
99void prune_partition_set(const TABLE *table, part_id_range *part_spec);
100void set_linear_hash_mask(partition_info *part_info, uint num_parts);
101bool fix_partition_func(THD *thd, TABLE *table, bool create_table_ind);
102bool partition_key_modified(TABLE *table, const MY_BITMAP *fields);
103void get_partition_set(const TABLE *table, uchar *buf, const uint index,
104 const key_range *key_spec, part_id_range *part_spec);
107 String *input_str,
108 String *output_str,
109 const CHARSET_INFO *cs,
110 bool use_hex);
111void get_full_part_id_from_key(const TABLE *table, uchar *buf, KEY *key_info,
112 const key_range *key_spec,
113 part_id_range *part_spec);
114bool mysql_unpack_partition(THD *thd, char *part_buf, uint part_info_len,
115 TABLE *table, bool is_create_table_ind,
116 handlerton *default_db_type,
117 bool *work_part_info_used);
119 List<const char> *parts);
120bool check_part_func_fields(Field **ptr, bool ok_with_charsets);
123/**
124 Append all fields in read_set to string
125
126 @param[in,out] str String to append to.
127 @param[in] row Row to append.
128 @param[in] table Table containing read_set and fields for the row.
129*/
130void append_row_to_str(String &str, const uchar *row, TABLE *table);
131void mem_alloc_error(size_t size);
132void truncate_partition_filename(MEM_ROOT *root, const char **path);
133
134bool set_part_state(Alter_info *alter_info, partition_info *tab_part_info,
135 enum partition_state part_state,
136 bool include_subpartitions);
137void set_all_part_state(partition_info *tab_part_info,
138 enum partition_state part_state);
139uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
140 HA_CREATE_INFO *create_info,
141 Alter_table_ctx *alter_ctx, bool *partition_changed,
142 partition_info **new_part_info);
143int expr_to_string(String *val_conv, Item *item_expr, Field *field,
144 const char *field_name, const HA_CREATE_INFO *create_info,
145 List<Create_field> *create_fields);
146char *generate_partition_syntax(partition_info *part_info, uint *buf_length,
147 bool use_sql_alloc, bool show_partition_options,
148 bool print_expr,
149 const char *current_comment_start);
150bool verify_data_with_partition(TABLE *table, TABLE *part_table,
151 uint32 part_id);
152bool compare_partition_options(HA_CREATE_INFO *table_create_info,
153 partition_element *part_elem);
154
165
166extern const LEX_CSTRING partition_keywords[];
167
168#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:51
Definition: field.h:575
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:853
Definition: key.h:113
Definition: sql_list.h:434
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:168
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
Definition: partition_element.h:108
Definition: partition_info.h:209
This file includes constants used by all storage engines.
Some integer typedefs for easier portability.
unsigned char uchar
Definition: my_inttypes.h:52
long long int longlong
Definition: my_inttypes.h:55
uint32_t uint32
Definition: my_inttypes.h:67
static char * path
Definition: mysqldump.cc:137
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1052
Definition: buf0block_hint.cc:30
Definition: commit_order_queue.h:34
partition_state
Definition: partition_element.h:35
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:5277
uint get_partition_field_store_length(Field *field)
Definition: sql_partition.cc:6118
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:4206
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:2289
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:3534
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:4146
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:2019
void append_row_to_str(String &str, const uchar *row, TABLE *table)
Append all fields in read_set to string.
Definition: sql_partition.cc:5208
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:4435
const LEX_CSTRING partition_keywords[]
Definition: sql_partition.cc:114
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:3498
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:315
bool partition_key_modified(TABLE *table, const MY_BITMAP *fields)
Definition: sql_partition.cc:2470
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:4261
void mem_alloc_error(size_t size)
Definition: sql_partition.cc:5258
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:3668
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:1791
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:4115
void prune_partition_set(const TABLE *table, part_id_range *part_spec)
Definition: sql_partition.cc:3615
Item * convert_charset_partition_constant(Item *item, const CHARSET_INFO *cs)
Definition: sql_partition.cc:211
key_range key_range
Definition: sql_partition.h:49
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:362
bool fix_partition_func(THD *thd, TABLE *table, bool create_table_ind)
Definition: sql_partition.cc:1470
enum_partition_keywords
Definition: sql_partition.h:155
@ PKW_COLUMNS
Definition: sql_partition.h:162
@ PKW_KEY
Definition: sql_partition.h:159
@ PKW_LINEAR
Definition: sql_partition.h:161
@ PKW_LIST
Definition: sql_partition.h:158
@ PKW_RANGE
Definition: sql_partition.h:157
@ PKW_ALGORITHM
Definition: sql_partition.h:163
@ PKW_MAXVALUE
Definition: sql_partition.h:160
@ PKW_HASH
Definition: sql_partition.h:156
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:3869
Definition: m_ctype.h:385
Struct to hold information about the table that should be created.
Definition: handler.h:3045
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
Definition: mysql_lex_string.h:40
Definition: my_bitmap.h:43
Definition: table.h:1399
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2622
Definition: my_base.h:1124
Definition: sql_partition.h:88
uint32 start_part
Definition: sql_partition.h:89
uint32 end_part
Definition: sql_partition.h:90
unsigned int uint
Definition: uca9-dump.cc:75