MySQL 8.0.40
Source Code Documentation
sql_lexer_yacc_state.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2022, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef ROUTING_SQL_LEXER_YACC_STATE_INCLUDED
27#define ROUTING_SQL_LEXER_YACC_STATE_INCLUDED
28
29#include <cstdlib>
30
31#include "my_inttypes.h" // uchar, uint, ...
32#include "mysql/service_mysql_alloc.h" // my_free
33
34/**
35 This class represents the character input stream consumed during lexical
36 analysis.
37
38 In addition to consuming the input stream, this class performs some comment
39 pre processing, by filtering out out-of-bound special text from the query
40 input stream.
41
42 Two buffers, with pointers inside each, are maintained in parallel. The
43 'raw' buffer is the original query text, which may contain out-of-bound
44 comments. The 'cpp' (for comments pre processor) is the pre-processed buffer
45 that contains only the query text that should be seen once out-of-bound data
46 is removed.
47*/
48
49/*
50 Important: if a new lock type is added, a matching lock description
51 must be added to sql_test.cc's lock_descriptions array.
52*/
55 TL_UNLOCK, /* UNLOCK ANY LOCK */
56 /*
57 Parser only! At open_tables() becomes TL_READ or
58 TL_READ_NO_INSERT depending on the binary log format
59 (SBR/RBR) and on the table category (log table).
60 Used for tables that are read by statements which
61 modify tables.
62 */
64 TL_READ, /* Read lock */
66 /* High prior. than TL_WRITE. Allow concurrent insert */
68 /* READ, Don't allow concurrent insert */
70 /*
71 Write lock, but allow other threads to read / write.
72 Used by BDB tables in MySQL to mark that someone is
73 reading/writing to the table.
74 */
76 /*
77 parser only! Late bound low_priority_flag.
78 At open_tables() becomes thd->insert_lock_default.
79 */
81 /*
82 WRITE lock used by concurrent insert. Will allow
83 READ, if one could use concurrent insert on table.
84 */
86 /*
87 parser only! Late bound low_priority flag.
88 At open_tables() becomes thd->update_lock_default.
89 */
91 /* WRITE lock that has lower priority than TL_READ */
93 /* Normal WRITE lock */
95 /* Abort new lock request with an error */
97};
98
99/**
100 Type of metadata lock request.
101
102 @sa Comments for MDL_object_lock::can_grant_lock() and
103 MDL_scoped_lock::can_grant_lock() for details.
104*/
105
107 /*
108 An intention exclusive metadata lock. Used only for scoped locks.
109 Owner of this type of lock can acquire upgradable exclusive locks on
110 individual objects.
111 This lock type is also used when doing lookups in the dictionary
112 cache. When acquiring objects in a schema, we lock the schema with IX
113 to prevent the schema from being deleted. This should conceptually
114 be an IS lock, but it would have the same behavior as the current IX.
115 Compatible with other IX locks, but is incompatible with scoped S and
116 X locks.
117 */
119 /*
120 A shared metadata lock.
121 To be used in cases when we are interested in object metadata only
122 and there is no intention to access object data (e.g. for stored
123 routines or during preparing prepared statements).
124 We also mis-use this type of lock for open HANDLERs, since lock
125 acquired by this statement has to be compatible with lock acquired
126 by LOCK TABLES ... WRITE statement, i.e. SNRW (We can't get by by
127 acquiring S lock at HANDLER ... OPEN time and upgrading it to SR
128 lock for HANDLER ... READ as it doesn't solve problem with need
129 to abort DML statements which wait on table level lock while having
130 open HANDLER in the same connection).
131 To avoid deadlock which may occur when SNRW lock is being upgraded to
132 X lock for table on which there is an active S lock which is owned by
133 thread which waits in its turn for table-level lock owned by thread
134 performing upgrade we have to use thr_abort_locks_for_thread()
135 facility in such situation.
136 This problem does not arise for locks on stored routines as we don't
137 use SNRW locks for them. It also does not arise when S locks are used
138 during PREPARE calls as table-level locks are not acquired in this
139 case.
140 */
142 /*
143 A high priority shared metadata lock.
144 Used for cases when there is no intention to access object data (i.e.
145 data in the table).
146 "High priority" means that, unlike other shared locks, it is granted
147 ignoring pending requests for exclusive locks. Intended for use in
148 cases when we only need to access metadata and not data, e.g. when
149 filling an INFORMATION_SCHEMA table.
150 Since SH lock is compatible with SNRW lock, the connection that
151 holds SH lock lock should not try to acquire any kind of table-level
152 or row-level lock, as this can lead to a deadlock. Moreover, after
153 acquiring SH lock, the connection should not wait for any other
154 resource, as it might cause starvation for X locks and a potential
155 deadlock during upgrade of SNW or SNRW to X lock (e.g. if the
156 upgrading connection holds the resource that is being waited for).
157 */
159 /*
160 A shared metadata lock for cases when there is an intention to read data
161 from table.
162 A connection holding this kind of lock can read table metadata and read
163 table data (after acquiring appropriate table and row-level locks).
164 This means that one can only acquire TL_READ, TL_READ_NO_INSERT, and
165 similar table-level locks on table if one holds SR MDL lock on it.
166 To be used for tables in SELECTs, subqueries, and LOCK TABLE ... READ
167 statements.
168 */
170 /*
171 A shared metadata lock for cases when there is an intention to modify
172 (and not just read) data in the table.
173 A connection holding SW lock can read table metadata and modify or read
174 table data (after acquiring appropriate table and row-level locks).
175 To be used for tables to be modified by INSERT, UPDATE, DELETE
176 statements, but not LOCK TABLE ... WRITE or DDL). Also taken by
177 SELECT ... FOR UPDATE.
178 */
180 /*
181 A version of MDL_SHARED_WRITE lock which has lower priority than
182 MDL_SHARED_READ_ONLY locks. Used by DML statements modifying
183 tables and using the LOW_PRIORITY clause.
184 */
186 /*
187 An upgradable shared metadata lock which allows concurrent updates and
188 reads of table data.
189 A connection holding this kind of lock can read table metadata and read
190 table data. It should not modify data as this lock is compatible with
191 SRO locks.
192 Can be upgraded to SNW, SNRW and X locks. Once SU lock is upgraded to X
193 or SNRW lock data modification can happen freely.
194 To be used for the first phase of ALTER TABLE.
195 */
197 /*
198 A shared metadata lock for cases when we need to read data from table
199 and block all concurrent modifications to it (for both data and metadata).
200 Used by LOCK TABLES READ statement.
201 */
203 /*
204 An upgradable shared metadata lock which blocks all attempts to update
205 table data, allowing reads.
206 A connection holding this kind of lock can read table metadata and read
207 table data.
208 Can be upgraded to X metadata lock.
209 Note, that since this type of lock is not compatible with SNRW or SW
210 lock types, acquiring appropriate engine-level locks for reading
211 (TL_READ* for MyISAM, shared row locks in InnoDB) should be
212 contention-free.
213 To be used for the first phase of ALTER TABLE, when copying data between
214 tables, to allow concurrent SELECTs from the table, but not UPDATEs.
215 */
217 /*
218 An upgradable shared metadata lock which allows other connections
219 to access table metadata, but not data.
220 It blocks all attempts to read or update table data, while allowing
221 INFORMATION_SCHEMA and SHOW queries.
222 A connection holding this kind of lock can read table metadata modify and
223 read table data.
224 Can be upgraded to X metadata lock.
225 To be used for LOCK TABLES WRITE statement.
226 Not compatible with any other lock type except S and SH.
227 */
229 /*
230 An exclusive metadata lock.
231 A connection holding this lock can modify both table's metadata and data.
232 No other type of metadata lock can be granted while this lock is held.
233 To be used for CREATE/DROP/RENAME TABLE statements and for execution of
234 certain phases of other DDL statements.
235 */
237 /* This should be the last !!! */
240
241/**
242 The internal state of the syntax parser.
243 This object is only available during parsing,
244 and is private to the syntax parser implementation (sql_yacc.yy).
245*/
247 public:
249 reset();
250 }
251
252 void reset() {
253 if (yacc_yyss != nullptr) {
255 yacc_yyss = nullptr;
256 }
257 if (yacc_yyvs != nullptr) {
259 yacc_yyvs = nullptr;
260 }
261 if (yacc_yyls != nullptr) {
263 yacc_yyls = nullptr;
264 }
267 }
268
270 if (yacc_yyss) {
274 }
275 }
276
277 /**
278 Reset part of the state which needs resetting before parsing
279 substatement.
280 */
284 }
285
286 /**
287 Bison internal state stack, yyss, when dynamically allocated using
288 my_yyoverflow().
289 */
291
292 /**
293 Bison internal semantic value stack, yyvs, when dynamically allocated using
294 my_yyoverflow().
295 */
297
298 /**
299 Bison internal location value stack, yyls, when dynamically allocated using
300 my_yyoverflow().
301 */
303
304 /**
305 Type of lock to be used for tables being added to the statement's
306 table list in table_factor, table_alias_ref, single_multi and
307 table_wild_one rules.
308 Statements which use these rules but require lock type different
309 from one specified by this member have to override it by using
310 Query_block::set_lock_for_tables() method.
311
312 The default value of this member is TL_READ_DEFAULT. The only two
313 cases in which we change it are:
314 - When parsing SELECT HIGH_PRIORITY.
315 - Rule for DELETE. In which we use this member to pass information
316 about type of lock from delete to single_multi part of rule.
317
318 We should try to avoid introducing new use cases as we would like
319 to get rid of this member eventually.
320 */
322
323 /**
324 The type of requested metadata lock for tables added to
325 the statement table list.
326 */
328
329 /*
330 TODO: move more attributes from the LEX structure here.
331 */
332};
333
334#endif
The internal state of the syntax parser.
Definition: sql_lexer_yacc_state.h:246
Yacc_state()
Definition: sql_lexer_yacc_state.h:248
void reset()
Definition: sql_lexer_yacc_state.h:252
thr_lock_type m_lock_type
Type of lock to be used for tables being added to the statement's table list in table_factor,...
Definition: sql_lexer_yacc_state.h:321
uchar * yacc_yyvs
Bison internal semantic value stack, yyvs, when dynamically allocated using my_yyoverflow().
Definition: sql_lexer_yacc_state.h:296
enum_mdl_type m_mdl_type
The type of requested metadata lock for tables added to the statement table list.
Definition: sql_lexer_yacc_state.h:327
~Yacc_state()
Definition: sql_lexer_yacc_state.h:269
uchar * yacc_yyss
Bison internal state stack, yyss, when dynamically allocated using my_yyoverflow().
Definition: sql_lexer_yacc_state.h:290
void reset_before_substatement()
Reset part of the state which needs resetting before parsing substatement.
Definition: sql_lexer_yacc_state.h:281
uchar * yacc_yyls
Bison internal location value stack, yyls, when dynamically allocated using my_yyoverflow().
Definition: sql_lexer_yacc_state.h:302
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:222
Some integer typedefs for easier portability.
unsigned char uchar
Definition: my_inttypes.h:52
void my_free(void *ptr)
Frees the memory pointed by the ptr.
Definition: my_memory.cc:81
@ TL_WRITE
Definition: sql_lexer_yacc_state.h:94
@ TL_WRITE_LOW_PRIORITY
Definition: sql_lexer_yacc_state.h:92
@ TL_WRITE_ONLY
Definition: sql_lexer_yacc_state.h:96
@ TL_READ_NO_INSERT
Definition: sql_lexer_yacc_state.h:69
@ TL_WRITE_DEFAULT
Definition: sql_lexer_yacc_state.h:90
@ TL_UNLOCK
Definition: sql_lexer_yacc_state.h:55
@ TL_READ_HIGH_PRIORITY
Definition: sql_lexer_yacc_state.h:67
@ TL_WRITE_CONCURRENT_DEFAULT
Definition: sql_lexer_yacc_state.h:80
@ TL_READ
Definition: sql_lexer_yacc_state.h:64
@ TL_WRITE_ALLOW_WRITE
Definition: sql_lexer_yacc_state.h:75
@ TL_READ_WITH_SHARED_LOCKS
Definition: sql_lexer_yacc_state.h:65
@ TL_IGNORE
Definition: sql_lexer_yacc_state.h:54
@ TL_WRITE_CONCURRENT_INSERT
Definition: sql_lexer_yacc_state.h:85
@ TL_READ_DEFAULT
Definition: sql_lexer_yacc_state.h:63
enum_mdl_type
Type of metadata lock request.
Definition: sql_lexer_yacc_state.h:106
@ MDL_SHARED_WRITE
Definition: sql_lexer_yacc_state.h:179
@ MDL_SHARED
Definition: sql_lexer_yacc_state.h:141
@ MDL_SHARED_UPGRADABLE
Definition: sql_lexer_yacc_state.h:196
@ MDL_SHARED_READ_ONLY
Definition: sql_lexer_yacc_state.h:202
@ MDL_SHARED_HIGH_PRIO
Definition: sql_lexer_yacc_state.h:158
@ MDL_SHARED_NO_WRITE
Definition: sql_lexer_yacc_state.h:216
@ MDL_SHARED_NO_READ_WRITE
Definition: sql_lexer_yacc_state.h:228
@ MDL_SHARED_WRITE_LOW_PRIO
Definition: sql_lexer_yacc_state.h:185
@ MDL_SHARED_READ
Definition: sql_lexer_yacc_state.h:169
@ MDL_TYPE_END
Definition: sql_lexer_yacc_state.h:238
@ MDL_EXCLUSIVE
Definition: sql_lexer_yacc_state.h:236
@ MDL_INTENTION_EXCLUSIVE
Definition: sql_lexer_yacc_state.h:118
thr_lock_type
Definition: thr_lock.h:51