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