MySQL 8.4.0
Source Code Documentation
sql_gipk.h
Go to the documentation of this file.
1/* Copyright (c) 2022, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef SQL_GIPK_INCLUDED
25#define SQL_GIPK_INCLUDED
26
27#include "my_inttypes.h"
28
29class Alter_info;
30class Create_field;
31class KEY;
32template <class T>
33class List;
34struct TABLE;
35class THD;
36struct HA_CREATE_INFO;
37struct handlerton;
38
39/**
40 Check if generate invisible primary key mode is active.
41
42 Note: For bootstreap and initialize system threads, generate invisible
43 primary key mode is not applicable. If there are any system table
44 without explicit primary key then primary key is not generated for
45 them while bootstrapping or initializing.
46
47
48 @param[in] thd Thread handle.
49
50 @returns true if @@sql_generate_invisible_primary_key is ON for thread
51 other than bootstrap and initialize system threads.
52*/
54
55/**
56 Check if column_name matches generated invisible primary key column name.
57
58 @param[in] column_name Name of a column.
59
60 @retval true column_name matches generated invisible primary key
61 column name.
62 @retval false Otherwise.
63*/
64bool is_generated_invisible_primary_key_column_name(const char *column_name);
65
66/**
67 Check if table being created is suitable for invisible primary key
68 generation.
69
70 Primary key is generated only if
71 a) explicit primary key is not defined for a table
72 b) primary key generation is supported for the storage engine.
73
74 @param[in] create_info HA_CREATE_INFO instance describing table being
75 created.
76 @param[in] alter_info Alter_info instance describing table being created.
77
78 @retval true if table is suitable for primary key generation.
79 @retval false Otherwise.
80*/
82 const HA_CREATE_INFO *create_info, Alter_info *alter_info);
83
84/**
85 Validate and generate invisible primary key for a candidate table (table
86 being created).
87
88 Primary key is generated if,
89 a) Table is a non-partitioned table. Generating invisible primary
90 key is not supported for partitioned tables for now.
91 b) Table does *not* have a column with auto_increment attribute.
92 c) Table does *not* have a column with name "my_row_id".
93 d) Table is *not* created using CREATE TABLE ... SELECT in
94 binlog_format=STATEMENT mode.
95 Otherwise an error is reported in the validation of phase.
96
97 @param[in] thd Thread handle.
98 @param[in,out] alter_info Alter_info instance describing table
99 being created or altered.
100
101 @retval false On success.
102 @retval true On failure.
103*/
105 Alter_info *alter_info);
106
107/**
108 Adjust generated invisible primary key column position in prepared fields
109 list for the ALTER TABLE statement. Make sure generated invisible column is
110 positioned at the first place.
111
112 @param[in] thd Thread handle.
113 @param[in] se_handlerton Handlerton instance of table's storage
114 engine
115 @param[in] old_table Old definition of a table being altered.
116 @param[in,out] prepared_create_list Create_field list prepared for ALTER
117 in prepare_fields_and_keys().
118
119 @retval false On success.
120 @retval true On failure.
121*/
123 THD *thd, handlerton *se_handlerton, TABLE *old_table,
124 List<Create_field> *prepared_create_list);
125
126/**
127 Check ALTER restrictions on primary key and column.
128
129 Following ALTER restrictions are applicable on primary key and column,
130
131 *) When sql_generate_invisible_primary_key is enabled then, primary key
132 is allowed to drop only if new table definition has a primary key.
133
134 *) Generated invisible primary key is allowed to drop only if primary key
135 column is also dropped. This restriction is applicable irrespective of
136 sql_generate_invisible_primary_key's state.
137
138 *) CHANGE/MODIFY OR ALTER operations on generated invisible primary key
139 columns are *not* allowed except ALTER operation to change column
140 visibility attribute. This restriction is applicable irrespective of
141 sql_generate_invisible_primary_key's state.
142
143 @param[in] thd Thread handle.
144 @param[in] se_handlerton Handlerton instance of table's storage engine
145 @param[in] alter_info Alter_info instance describing new table definition
146 of a table being altered.
147 @param[in] old_table Old definition of a table being altered.
148
149 @retval false On success.
150 @retval true On failure.
151*/
152bool check_primary_key_alter_restrictions(THD *thd, handlerton *se_handlerton,
153 Alter_info *alter_info,
154 TABLE *old_table);
155
156/**
157 Check that definition of a table being created or altered has a generated
158 invisible primary key definition.
159
160 @param[in] thd Thread handle.
161 @param[in] se_handlerton Handlerton instance of table's storage engine
162 @param[in] create_fields List of Create_field instance for the table
163 columns.
164 @param[in] keys Number of KEY structs in the 'keyinfo'.
165 @param[in] keyinfo An array of KEY structs for the indexes.
166
167 @returns true if table definition has a generated invisible primary key
168 otherwise returns false.
169*/
171 THD *thd, handlerton *se_handlerton,
172 const List<Create_field> &create_fields, uint keys, const KEY *keyinfo);
173
174/**
175 Check if table has a generated invisible primary key.
176
177 @param[in] table TABLE instance of a table.
178
179 @retval true If table has a generated invisible primary key.
180 @retval false Otherwise.
181*/
183#endif // SQL_GIPK_INCLUDED
Data describing the table being created by CREATE TABLE or altered by ALTER TABLE.
Definition: sql_alter.h:205
Create_field is a description a field/column that may or may not exists in a table.
Definition: create_field.h:51
Definition: key.h:113
Definition: sql_list.h:467
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
static uint keys
Definition: hp_test2.cc:49
Some integer typedefs for easier portability.
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
bool is_generated_invisible_primary_key_column_name(const char *column_name)
Check if column_name matches generated invisible primary key column name.
Definition: sql_gipk.cc:38
bool table_has_generated_invisible_primary_key(const TABLE *table)
Check if table has a generated invisible primary key.
Definition: sql_gipk.cc:496
bool is_candidate_table_for_invisible_primary_key_generation(const HA_CREATE_INFO *create_info, Alter_info *alter_info)
Check if table being created is suitable for invisible primary key generation.
Definition: sql_gipk.cc:64
bool table_def_has_generated_invisible_primary_key(THD *thd, handlerton *se_handlerton, const List< Create_field > &create_fields, uint keys, const KEY *keyinfo)
Check that definition of a table being created or altered has a generated invisible primary key defin...
Definition: sql_gipk.cc:397
bool validate_and_generate_invisible_primary_key(THD *thd, Alter_info *alter_info)
Validate and generate invisible primary key for a candidate table (table being created).
Definition: sql_gipk.cc:185
bool adjust_generated_invisible_primary_key_column_position(THD *thd, handlerton *se_handlerton, TABLE *old_table, List< Create_field > *prepared_create_list)
Adjust generated invisible primary key column position in prepared fields list for the ALTER TABLE st...
Definition: sql_gipk.cc:191
bool check_primary_key_alter_restrictions(THD *thd, handlerton *se_handlerton, Alter_info *alter_info, TABLE *old_table)
Check ALTER restrictions on primary key and column.
Definition: sql_gipk.cc:265
bool is_generate_invisible_primary_key_mode_active(THD *thd)
Check if generate invisible primary key mode is active.
Definition: sql_gipk.cc:59
Struct to hold information about the table that should be created.
Definition: handler.h:3201
Definition: table.h:1405
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2733