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