390.1.2
by Monty Taylor
Fixed copyright headers in drizzled/ |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2008 Sun Microsystems
|
|
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 as published by
|
|
8 |
* the Free Software Foundation; version 2 of the License.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18 |
*/
|
|
1
by brian
clean slate |
19 |
|
243.1.8
by Jay Pipes
More cleanup and revert broken base.h |
20 |
#ifndef DRIZZLE_SERVER_SQL_LEX_H
|
21 |
#define DRIZZLE_SERVER_SQL_LEX_H
|
|
22 |
||
1
by brian
clean slate |
23 |
/**
|
24 |
@defgroup Semantic_Analysis Semantic Analysis
|
|
25 |
*/
|
|
26 |
||
584.4.4
by Monty Taylor
Split out Name_resolution_context. |
27 |
#include <drizzled/sql_udf.h> |
28 |
#include <drizzled/name_resolution_context.h> |
|
584.4.7
by Monty Taylor
Removed a big bank of includes from item.h. |
29 |
#include <drizzled/item/subselect.h> |
139.1.8
by Stewart Smith
UDFs are now normal Item_func objects. Simplifies handling them a lot. |
30 |
|
584.4.7
by Monty Taylor
Removed a big bank of includes from item.h. |
31 |
class select_result_interceptor; |
1
by brian
clean slate |
32 |
/* YACC and LEX Definitions */
|
33 |
||
34 |
/* These may not be declared yet */
|
|
35 |
class Table_ident; |
|
36 |
class sql_exchange; |
|
37 |
class LEX_COLUMN; |
|
38 |
||
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
39 |
#ifdef DRIZZLE_SERVER
|
1
by brian
clean slate |
40 |
/*
|
41 |
The following hack is needed because mysql_yacc.cc does not define
|
|
42 |
YYSTYPE before including this file
|
|
43 |
*/
|
|
44 |
||
520.4.14
by Monty Taylor
Removed korr.h and tztime.h from common_includes. Also removed the HAVE_DTRACE block and stuck it in autoconf. |
45 |
#include <drizzled/set_var.h> |
1
by brian
clean slate |
46 |
|
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
47 |
#ifdef DRIZZLE_YACC
|
1
by brian
clean slate |
48 |
#define LEX_YYSTYPE void *
|
49 |
#else
|
|
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
50 |
#if defined(DRIZZLE_LEX)
|
1
by brian
clean slate |
51 |
#include "lex_symbol.h" |
52 |
#include "sql_yacc.h" |
|
53 |
#define LEX_YYSTYPE YYSTYPE *
|
|
54 |
#else
|
|
55 |
#define LEX_YYSTYPE void *
|
|
56 |
#endif
|
|
57 |
#endif
|
|
58 |
#endif
|
|
59 |
||
60 |
// describe/explain types
|
|
61 |
#define DESCRIBE_NORMAL 1
|
|
62 |
#define DESCRIBE_EXTENDED 2
|
|
63 |
||
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
64 |
#ifdef DRIZZLE_SERVER
|
1
by brian
clean slate |
65 |
|
66 |
#define DERIVED_NONE 0
|
|
67 |
#define DERIVED_SUBQUERY 1
|
|
68 |
||
69 |
typedef List<Item> List_item; |
|
70 |
||
71 |
/* SERVERS CACHE CHANGES */
|
|
72 |
typedef struct st_lex_server_options |
|
73 |
{
|
|
202
by Brian Aker
Cleanup sql_lex to modern types. |
74 |
int32_t port; |
75 |
uint32_t server_name_length; |
|
185
by Brian Aker
More dead code baby... it has become a little like drilling for oil. Alaska |
76 |
char *server_name, *host, *db, *username, *password, *scheme, *owner; |
1
by brian
clean slate |
77 |
} LEX_SERVER_OPTIONS; |
78 |
||
79 |
typedef struct st_lex_master_info |
|
80 |
{
|
|
81 |
char *host, *user, *password, *log_file_name; |
|
202
by Brian Aker
Cleanup sql_lex to modern types. |
82 |
uint32_t port, connect_retry; |
1
by brian
clean slate |
83 |
float heartbeat_period; |
151
by Brian Aker
Ulonglong to uint64_t |
84 |
uint64_t pos; |
202
by Brian Aker
Cleanup sql_lex to modern types. |
85 |
uint32_t server_id; |
1
by brian
clean slate |
86 |
/*
|
87 |
Enum is used for making it possible to detect if the user
|
|
88 |
changed variable or if it should be left at old value
|
|
89 |
*/
|
|
484
by Brian Aker
Random dead cleanup (mainly around SSL in the replication master.info) |
90 |
enum {LEX_MI_UNCHANGED, LEX_MI_DISABLE, LEX_MI_ENABLE} heartbeat_opt; |
1
by brian
clean slate |
91 |
char *relay_log_name; |
202
by Brian Aker
Cleanup sql_lex to modern types. |
92 |
uint32_t relay_log_pos; |
1
by brian
clean slate |
93 |
} LEX_MASTER_INFO; |
94 |
||
95 |
||
96 |
enum sub_select_type |
|
97 |
{
|
|
98 |
UNSPECIFIED_TYPE,UNION_TYPE, INTERSECT_TYPE, |
|
99 |
EXCEPT_TYPE, GLOBAL_OPTIONS_TYPE, DERIVED_TABLE_TYPE, OLAP_TYPE |
|
100 |
};
|
|
101 |
||
102 |
enum olap_type |
|
103 |
{
|
|
104 |
UNSPECIFIED_OLAP_TYPE, CUBE_TYPE, ROLLUP_TYPE |
|
105 |
};
|
|
106 |
||
107 |
enum tablespace_op_type |
|
108 |
{
|
|
109 |
NO_TABLESPACE_OP, DISCARD_TABLESPACE, IMPORT_TABLESPACE |
|
110 |
};
|
|
111 |
||
112 |
/*
|
|
113 |
String names used to print a statement with index hints.
|
|
114 |
Keep in sync with index_hint_type.
|
|
115 |
*/
|
|
116 |
extern const char * index_hint_type_name[]; |
|
481
by Brian Aker
Remove all of uchar. |
117 |
typedef unsigned char index_clause_map; |
1
by brian
clean slate |
118 |
|
119 |
/*
|
|
120 |
Bits in index_clause_map : one for each possible FOR clause in
|
|
121 |
USE/FORCE/IGNORE INDEX index hint specification
|
|
122 |
*/
|
|
123 |
#define INDEX_HINT_MASK_JOIN (1)
|
|
124 |
#define INDEX_HINT_MASK_GROUP (1 << 1)
|
|
125 |
#define INDEX_HINT_MASK_ORDER (1 << 2)
|
|
126 |
||
127 |
#define INDEX_HINT_MASK_ALL (INDEX_HINT_MASK_JOIN | INDEX_HINT_MASK_GROUP | \
|
|
128 |
INDEX_HINT_MASK_ORDER)
|
|
129 |
||
130 |
/* Single element of an USE/FORCE/IGNORE INDEX list specified as a SQL hint */
|
|
131 |
class Index_hint : public Sql_alloc |
|
132 |
{
|
|
133 |
public: |
|
134 |
/* The type of the hint : USE/FORCE/IGNORE */
|
|
135 |
enum index_hint_type type; |
|
136 |
/* Where the hit applies to. A bitmask of INDEX_HINT_MASK_<place> values */
|
|
137 |
index_clause_map clause; |
|
138 |
/*
|
|
139 |
The index name. Empty (str=NULL) name represents an empty list
|
|
140 |
USE INDEX () clause
|
|
141 |
*/
|
|
142 |
LEX_STRING key_name; |
|
143 |
||
144 |
Index_hint (enum index_hint_type type_arg, index_clause_map clause_arg, |
|
202
by Brian Aker
Cleanup sql_lex to modern types. |
145 |
char *str, uint32_t length) : |
1
by brian
clean slate |
146 |
type(type_arg), clause(clause_arg) |
147 |
{
|
|
148 |
key_name.str= str; |
|
149 |
key_name.length= length; |
|
150 |
}
|
|
151 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
152 |
void print(Session *session, String *str); |
1
by brian
clean slate |
153 |
};
|
154 |
||
155 |
/*
|
|
156 |
The state of the lex parsing for selects
|
|
157 |
|
|
158 |
master and slaves are pointers to select_lex.
|
|
159 |
master is pointer to upper level node.
|
|
160 |
slave is pointer to lower level node
|
|
161 |
select_lex is a SELECT without union
|
|
162 |
unit is container of either
|
|
163 |
- One SELECT
|
|
164 |
- UNION of selects
|
|
165 |
select_lex and unit are both inherited form select_lex_node
|
|
166 |
neighbors are two select_lex or units on the same level
|
|
167 |
||
168 |
All select describing structures linked with following pointers:
|
|
169 |
- list of neighbors (next/prev) (prev of first element point to slave
|
|
170 |
pointer of upper structure)
|
|
171 |
- For select this is a list of UNION's (or one element list)
|
|
172 |
- For units this is a list of sub queries for the upper level select
|
|
173 |
||
174 |
- pointer to master (master), which is
|
|
175 |
If this is a unit
|
|
176 |
- pointer to outer select_lex
|
|
177 |
If this is a select_lex
|
|
178 |
- pointer to outer unit structure for select
|
|
179 |
||
180 |
- pointer to slave (slave), which is either:
|
|
181 |
If this is a unit:
|
|
182 |
- first SELECT that belong to this unit
|
|
183 |
If this is a select_lex
|
|
184 |
- first unit that belong to this SELECT (subquries or derived tables)
|
|
185 |
||
186 |
- list of all select_lex (link_next/link_prev)
|
|
187 |
This is to be used for things like derived tables creation, where we
|
|
188 |
go through this list and create the derived tables.
|
|
189 |
||
190 |
If unit contain several selects (UNION now, INTERSECT etc later)
|
|
191 |
then it have special select_lex called fake_select_lex. It used for
|
|
192 |
storing global parameters (like ORDER BY, LIMIT) and executing union.
|
|
193 |
Subqueries used in global ORDER BY clause will be attached to this
|
|
194 |
fake_select_lex, which will allow them correctly resolve fields of
|
|
195 |
'upper' UNION and outer selects.
|
|
196 |
||
197 |
For example for following query:
|
|
198 |
||
199 |
select *
|
|
200 |
from table1
|
|
201 |
where table1.field IN (select * from table1_1_1 union
|
|
202 |
select * from table1_1_2)
|
|
203 |
union
|
|
204 |
select *
|
|
205 |
from table2
|
|
206 |
where table2.field=(select (select f1 from table2_1_1_1_1
|
|
207 |
where table2_1_1_1_1.f2=table2_1_1.f3)
|
|
208 |
from table2_1_1
|
|
209 |
where table2_1_1.f1=table2.f2)
|
|
210 |
union
|
|
211 |
select * from table3;
|
|
212 |
||
213 |
we will have following structure:
|
|
214 |
||
215 |
select1: (select * from table1 ...)
|
|
216 |
select2: (select * from table2 ...)
|
|
217 |
select3: (select * from table3)
|
|
218 |
select1.1.1: (select * from table1_1_1)
|
|
219 |
...
|
|
220 |
||
221 |
main unit
|
|
222 |
fake0
|
|
223 |
select1 select2 select3
|
|
224 |
|^^ |^
|
|
225 |
s||| ||master
|
|
226 |
l||| |+---------------------------------+
|
|
227 |
a||| +---------------------------------+|
|
|
228 |
v|||master slave ||
|
|
229 |
e||+-------------------------+ ||
|
|
230 |
V| neighbor | V|
|
|
231 |
unit1.1<+==================>unit1.2 unit2.1
|
|
232 |
fake1.1
|
|
233 |
select1.1.1 select 1.1.2 select1.2.1 select2.1.1
|
|
234 |
|^
|
|
235 |
||
|
|
236 |
V|
|
|
237 |
unit2.1.1.1
|
|
238 |
select2.1.1.1.1
|
|
239 |
||
240 |
||
241 |
relation in main unit will be following:
|
|
242 |
(bigger picture for:
|
|
243 |
main unit
|
|
244 |
fake0
|
|
245 |
select1 select2 select3
|
|
246 |
in the above picture)
|
|
247 |
||
248 |
main unit
|
|
249 |
|^^^^|fake_select_lex
|
|
250 |
|||||+--------------------------------------------+
|
|
251 |
||||+--------------------------------------------+|
|
|
252 |
|||+------------------------------+ ||
|
|
253 |
||+--------------+ | ||
|
|
254 |
slave||master | | ||
|
|
255 |
V| neighbor | neighbor | master|V
|
|
256 |
select1<========>select2<========>select3 fake0
|
|
257 |
||
258 |
list of all select_lex will be following (as it will be constructed by
|
|
259 |
parser):
|
|
260 |
||
261 |
select1->select2->select3->select2.1.1->select 2.1.2->select2.1.1.1.1-+
|
|
262 |
|
|
|
263 |
+---------------------------------------------------------------------+
|
|
264 |
|
|
|
265 |
+->select1.1.1->select1.1.2
|
|
266 |
||
267 |
*/
|
|
268 |
||
269 |
/*
|
|
270 |
Base class for st_select_lex (SELECT_LEX) &
|
|
271 |
st_select_lex_unit (SELECT_LEX_UNIT)
|
|
272 |
*/
|
|
575.4.7
by Monty Taylor
More header cleanup. |
273 |
class LEX; |
1
by brian
clean slate |
274 |
class st_select_lex; |
275 |
class st_select_lex_unit; |
|
276 |
class st_select_lex_node { |
|
277 |
protected: |
|
278 |
st_select_lex_node *next, **prev, /* neighbor list */ |
|
279 |
*master, *slave, /* vertical links */ |
|
280 |
*link_next, **link_prev; /* list of whole SELECT_LEX */ |
|
281 |
public: |
|
282 |
||
151
by Brian Aker
Ulonglong to uint64_t |
283 |
uint64_t options; |
1
by brian
clean slate |
284 |
|
285 |
/*
|
|
286 |
result of this query can't be cached, bit field, can be :
|
|
287 |
UNCACHEABLE_DEPENDENT
|
|
288 |
UNCACHEABLE_RAND
|
|
289 |
UNCACHEABLE_SIDEEFFECT
|
|
290 |
UNCACHEABLE_EXPLAIN
|
|
291 |
UNCACHEABLE_PREPARE
|
|
292 |
*/
|
|
202
by Brian Aker
Cleanup sql_lex to modern types. |
293 |
uint8_t uncacheable; |
1
by brian
clean slate |
294 |
enum sub_select_type linkage; |
295 |
bool no_table_names_allowed; /* used for global order by */ |
|
296 |
bool no_error; /* suppress error message (convert it to warnings) */ |
|
297 |
||
298 |
static void *operator new(size_t size) |
|
299 |
{
|
|
300 |
return sql_alloc(size); |
|
301 |
}
|
|
302 |
static void *operator new(size_t size, MEM_ROOT *mem_root) |
|
202
by Brian Aker
Cleanup sql_lex to modern types. |
303 |
{ return (void*) alloc_root(mem_root, (uint32_t) size); } |
212.1.3
by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)). |
304 |
static void operator delete(void *ptr __attribute__((unused)), |
305 |
size_t size __attribute__((unused))) |
|
77.1.7
by Monty Taylor
Heap builds clean. |
306 |
{ TRASH(ptr, size); } |
212.1.3
by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)). |
307 |
static void operator delete(void *ptr __attribute__((unused)), |
308 |
MEM_ROOT *mem_root __attribute__((unused))) |
|
77.1.7
by Monty Taylor
Heap builds clean. |
309 |
{}
|
1
by brian
clean slate |
310 |
st_select_lex_node(): linkage(UNSPECIFIED_TYPE) {} |
311 |
virtual ~st_select_lex_node() {} |
|
312 |
inline st_select_lex_node* get_master() { return master; } |
|
313 |
virtual void init_query(); |
|
314 |
virtual void init_select(); |
|
315 |
void include_down(st_select_lex_node *upper); |
|
316 |
void include_neighbour(st_select_lex_node *before); |
|
317 |
void include_standalone(st_select_lex_node *sel, st_select_lex_node **ref); |
|
318 |
void include_global(st_select_lex_node **plink); |
|
319 |
void exclude(); |
|
320 |
||
321 |
virtual st_select_lex_unit* master_unit()= 0; |
|
322 |
virtual st_select_lex* outer_select()= 0; |
|
323 |
virtual st_select_lex* return_after_parsing()= 0; |
|
324 |
||
325 |
virtual bool set_braces(bool value); |
|
326 |
virtual bool inc_in_sum_expr(); |
|
202
by Brian Aker
Cleanup sql_lex to modern types. |
327 |
virtual uint32_t get_in_sum_expr(); |
327.2.4
by Brian Aker
Refactoring table.h |
328 |
virtual TableList* get_table_list(); |
1
by brian
clean slate |
329 |
virtual List<Item>* get_item_list(); |
202
by Brian Aker
Cleanup sql_lex to modern types. |
330 |
virtual uint32_t get_table_join_options(); |
520.1.22
by Brian Aker
Second pass of thd cleanup |
331 |
virtual TableList *add_table_to_list(Session *session, Table_ident *table, |
77.1.7
by Monty Taylor
Heap builds clean. |
332 |
LEX_STRING *alias, |
202
by Brian Aker
Cleanup sql_lex to modern types. |
333 |
uint32_t table_options, |
77.1.7
by Monty Taylor
Heap builds clean. |
334 |
thr_lock_type flags= TL_UNLOCK, |
335 |
List<Index_hint> *hints= 0, |
|
1
by brian
clean slate |
336 |
LEX_STRING *option= 0); |
212.1.3
by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)). |
337 |
virtual void set_lock_for_tables(thr_lock_type lock_type __attribute__((unused))) |
77.1.7
by Monty Taylor
Heap builds clean. |
338 |
{}
|
1
by brian
clean slate |
339 |
|
340 |
friend class st_select_lex_unit; |
|
575.4.7
by Monty Taylor
More header cleanup. |
341 |
friend bool mysql_new_select(LEX *lex, bool move_down); |
1
by brian
clean slate |
342 |
private: |
343 |
void fast_exclude(); |
|
344 |
};
|
|
345 |
typedef class st_select_lex_node SELECT_LEX_NODE; |
|
346 |
||
347 |
/*
|
|
348 |
SELECT_LEX_UNIT - unit of selects (UNION, INTERSECT, ...) group
|
|
349 |
SELECT_LEXs
|
|
350 |
*/
|
|
520.1.21
by Brian Aker
THD -> Session rename |
351 |
class Session; |
1
by brian
clean slate |
352 |
class select_result; |
353 |
class JOIN; |
|
354 |
class select_union; |
|
355 |
class st_select_lex_unit: public st_select_lex_node { |
|
356 |
protected: |
|
327.2.4
by Brian Aker
Refactoring table.h |
357 |
TableList result_table_list; |
1
by brian
clean slate |
358 |
select_union *union_result; |
327.1.5
by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h |
359 |
Table *table; /* temporary table using for appending UNION results */ |
1
by brian
clean slate |
360 |
|
361 |
select_result *result; |
|
151
by Brian Aker
Ulonglong to uint64_t |
362 |
uint64_t found_rows_for_union; |
1
by brian
clean slate |
363 |
bool saved_error; |
364 |
||
365 |
public: |
|
366 |
bool prepared, // prepare phase already performed for UNION (unit) |
|
367 |
optimized, // optimize phase already performed for UNION (unit) |
|
368 |
executed, // already executed |
|
369 |
cleaned; |
|
370 |
||
371 |
// list of fields which points to temporary table for union
|
|
372 |
List<Item> item_list; |
|
373 |
/*
|
|
374 |
list of types of items inside union (used for union & derived tables)
|
|
375 |
|
|
376 |
Item_type_holders from which this list consist may have pointers to Field,
|
|
377 |
pointers is valid only after preparing SELECTS of this unit and before
|
|
378 |
any SELECT of this unit execution
|
|
379 |
||
380 |
TODO:
|
|
381 |
Possibly this member should be protected, and its direct use replaced
|
|
382 |
by get_unit_column_types(). Check the places where it is used.
|
|
383 |
*/
|
|
384 |
List<Item> types; |
|
385 |
/*
|
|
386 |
Pointer to 'last' select or pointer to unit where stored
|
|
387 |
global parameters for union
|
|
388 |
*/
|
|
389 |
st_select_lex *global_parameters; |
|
390 |
//node on wich we should return current_select pointer after parsing subquery
|
|
391 |
st_select_lex *return_to; |
|
392 |
/* LIMIT clause runtime counters */
|
|
393 |
ha_rows select_limit_cnt, offset_limit_cnt; |
|
394 |
/* not NULL if unit used in subselect, point to subselect item */
|
|
395 |
Item_subselect *item; |
|
396 |
/* thread handler */
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
397 |
Session *session; |
1
by brian
clean slate |
398 |
/*
|
399 |
SELECT_LEX for hidden SELECT in onion which process global
|
|
400 |
ORDER BY and LIMIT
|
|
401 |
*/
|
|
402 |
st_select_lex *fake_select_lex; |
|
403 |
||
404 |
st_select_lex *union_distinct; /* pointer to the last UNION DISTINCT */ |
|
405 |
bool describe; /* union exec() called for EXPLAIN */ |
|
406 |
||
407 |
void init_query(); |
|
408 |
st_select_lex_unit* master_unit(); |
|
409 |
st_select_lex* outer_select(); |
|
410 |
st_select_lex* first_select() |
|
411 |
{
|
|
451
by Monty Taylor
Removed my_reinterpret_cast. It's not GNU specific. |
412 |
return reinterpret_cast<st_select_lex*>(slave); |
1
by brian
clean slate |
413 |
}
|
414 |
st_select_lex_unit* next_unit() |
|
415 |
{
|
|
451
by Monty Taylor
Removed my_reinterpret_cast. It's not GNU specific. |
416 |
return reinterpret_cast<st_select_lex_unit*>(next); |
1
by brian
clean slate |
417 |
}
|
418 |
st_select_lex* return_after_parsing() { return return_to; } |
|
419 |
void exclude_level(); |
|
420 |
void exclude_tree(); |
|
421 |
||
422 |
/* UNION methods */
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
423 |
bool prepare(Session *session, select_result *result, uint32_t additional_options); |
1
by brian
clean slate |
424 |
bool exec(); |
425 |
bool cleanup(); |
|
426 |
inline void unclean() { cleaned= 0; } |
|
427 |
void reinit_exec_mechanism(); |
|
428 |
||
429 |
void print(String *str, enum_query_type query_type); |
|
430 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
431 |
bool add_fake_select_lex(Session *session); |
432 |
void init_prepare_fake_select_lex(Session *session); |
|
1
by brian
clean slate |
433 |
bool change_result(select_result_interceptor *result, |
434 |
select_result_interceptor *old_result); |
|
435 |
void set_limit(st_select_lex *values); |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
436 |
void set_session(Session *session_arg) { session= session_arg; } |
1
by brian
clean slate |
437 |
inline bool is_union (); |
438 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
439 |
friend void lex_start(Session *session); |
1
by brian
clean slate |
440 |
friend int subselect_union_engine::exec(); |
441 |
||
442 |
List<Item> *get_unit_column_types(); |
|
443 |
};
|
|
444 |
||
445 |
typedef class st_select_lex_unit SELECT_LEX_UNIT; |
|
446 |
||
447 |
/*
|
|
448 |
SELECT_LEX - store information of parsed SELECT statment
|
|
449 |
*/
|
|
450 |
class st_select_lex: public st_select_lex_node |
|
451 |
{
|
|
452 |
public: |
|
453 |
Name_resolution_context context; |
|
454 |
char *db; |
|
455 |
Item *where, *having; /* WHERE & HAVING clauses */ |
|
456 |
/* Saved values of the WHERE and HAVING clauses*/
|
|
457 |
Item::cond_result cond_value, having_value; |
|
458 |
/* point on lex in which it was created, used in view subquery detection */
|
|
575.4.7
by Monty Taylor
More header cleanup. |
459 |
LEX *parent_lex; |
1
by brian
clean slate |
460 |
enum olap_type olap; |
327.2.4
by Brian Aker
Refactoring table.h |
461 |
/* FROM clause - points to the beginning of the TableList::next_local list. */
|
1
by brian
clean slate |
462 |
SQL_LIST table_list; |
463 |
SQL_LIST group_list; /* GROUP BY clause. */ |
|
464 |
List<Item> item_list; /* list of fields & expressions */ |
|
465 |
List<String> interval_list; |
|
466 |
bool is_item_list_lookup; |
|
467 |
/*
|
|
468 |
Despite their names, the following are used in unions. This should
|
|
469 |
be rewritten. -Brian
|
|
470 |
*/
|
|
471 |
List<Item_real_func> *ftfunc_list; |
|
472 |
List<Item_real_func> ftfunc_list_alloc; |
|
473 |
JOIN *join; /* after JOIN::prepare it is pointer to corresponding JOIN */ |
|
327.2.4
by Brian Aker
Refactoring table.h |
474 |
List<TableList> top_join_list; /* join list of the top level */ |
475 |
List<TableList> *join_list; /* list for the currently parsed join */ |
|
476 |
TableList *embedding; /* table embedding to the above list */ |
|
477 |
List<TableList> sj_nests; |
|
1
by brian
clean slate |
478 |
/*
|
479 |
Beginning of the list of leaves in a FROM clause, where the leaves
|
|
480 |
inlcude all base tables including view tables. The tables are connected
|
|
327.2.4
by Brian Aker
Refactoring table.h |
481 |
by TableList::next_leaf, so leaf_tables points to the left-most leaf.
|
1
by brian
clean slate |
482 |
*/
|
327.2.4
by Brian Aker
Refactoring table.h |
483 |
TableList *leaf_tables; |
1
by brian
clean slate |
484 |
const char *type; /* type of select for EXPLAIN */ |
485 |
||
486 |
SQL_LIST order_list; /* ORDER clause */ |
|
487 |
SQL_LIST *gorder_list; |
|
488 |
Item *select_limit, *offset_limit; /* LIMIT clause parameters */ |
|
489 |
// Arrays of pointers to top elements of all_fields list
|
|
490 |
Item **ref_pointer_array; |
|
491 |
||
492 |
/*
|
|
493 |
number of items in select_list and HAVING clause used to get number
|
|
494 |
bigger then can be number of entries that will be added to all item
|
|
495 |
list during split_sum_func
|
|
496 |
*/
|
|
202
by Brian Aker
Cleanup sql_lex to modern types. |
497 |
uint32_t select_n_having_items; |
498 |
uint32_t cond_count; /* number of arguments of and/or/xor in where/having/on */ |
|
499 |
uint32_t between_count; /* number of between predicates in where/having/on */ |
|
500 |
uint32_t max_equal_elems; /* maximal number of elements in multiple equalities */ |
|
1
by brian
clean slate |
501 |
/*
|
502 |
Number of fields used in select list or where clause of current select
|
|
503 |
and all inner subselects.
|
|
504 |
*/
|
|
202
by Brian Aker
Cleanup sql_lex to modern types. |
505 |
uint32_t select_n_where_fields; |
1
by brian
clean slate |
506 |
enum_parsing_place parsing_place; /* where we are parsing expression */ |
507 |
bool with_sum_func; /* sum function indicator */ |
|
508 |
/*
|
|
509 |
PS or SP cond natural joins was alredy processed with permanent
|
|
510 |
arena and all additional items which we need alredy stored in it
|
|
511 |
*/
|
|
512 |
bool conds_processed_with_permanent_arena; |
|
513 |
||
202
by Brian Aker
Cleanup sql_lex to modern types. |
514 |
uint32_t table_join_options; |
515 |
uint32_t in_sum_expr; |
|
516 |
uint32_t select_number; /* number of select (used for EXPLAIN) */ |
|
1
by brian
clean slate |
517 |
int nest_level; /* nesting level of select */ |
518 |
Item_sum *inner_sum_func_list; /* list of sum func in nested selects */ |
|
202
by Brian Aker
Cleanup sql_lex to modern types. |
519 |
uint32_t with_wild; /* item list contain '*' */ |
1
by brian
clean slate |
520 |
bool braces; /* SELECT ... UNION (SELECT ... ) <- this braces */ |
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
521 |
/* true when having fix field called in processing of this SELECT */
|
1
by brian
clean slate |
522 |
bool having_fix_field; |
523 |
/* List of references to fields referenced from inner selects */
|
|
524 |
List<Item_outer_ref> inner_refs_list; |
|
525 |
/* Number of Item_sum-derived objects in this SELECT */
|
|
202
by Brian Aker
Cleanup sql_lex to modern types. |
526 |
uint32_t n_sum_items; |
1
by brian
clean slate |
527 |
/* Number of Item_sum-derived objects in children and descendant SELECTs */
|
202
by Brian Aker
Cleanup sql_lex to modern types. |
528 |
uint32_t n_child_sum_items; |
1
by brian
clean slate |
529 |
|
530 |
/* explicit LIMIT clause was used */
|
|
531 |
bool explicit_limit; |
|
532 |
/*
|
|
533 |
there are subquery in HAVING clause => we can't close tables before
|
|
534 |
query processing end even if we use temporary table
|
|
535 |
*/
|
|
536 |
bool subquery_in_having; |
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
537 |
/* true <=> this SELECT is correlated w.r.t. some ancestor select */
|
1
by brian
clean slate |
538 |
bool is_correlated; |
539 |
/* exclude this select from check of unique_table() */
|
|
540 |
bool exclude_from_table_unique_test; |
|
541 |
/* List of fields that aren't under an aggregate function */
|
|
542 |
List<Item_field> non_agg_fields; |
|
543 |
/* index in the select list of the expression currently being fixed */
|
|
544 |
int cur_pos_in_select_list; |
|
545 |
||
546 |
List<udf_func> udf_list; /* udf function calls stack */ |
|
547 |
/*
|
|
548 |
This is a copy of the original JOIN USING list that comes from
|
|
549 |
the parser. The parser :
|
|
327.2.4
by Brian Aker
Refactoring table.h |
550 |
1. Sets the natural_join of the second TableList in the join
|
1
by brian
clean slate |
551 |
and the st_select_lex::prev_join_using.
|
327.2.4
by Brian Aker
Refactoring table.h |
552 |
2. Makes a parent TableList and sets its is_natural_join/
|
1
by brian
clean slate |
553 |
join_using_fields members.
|
327.2.4
by Brian Aker
Refactoring table.h |
554 |
3. Uses the wrapper TableList as a table in the upper level.
|
1
by brian
clean slate |
555 |
We cannot assign directly to join_using_fields in the parser because
|
327.2.4
by Brian Aker
Refactoring table.h |
556 |
at stage (1.) the parent TableList is not constructed yet and
|
1
by brian
clean slate |
557 |
the assignment will override the JOIN USING fields of the lower level
|
558 |
joins on the right.
|
|
559 |
*/
|
|
560 |
List<String> *prev_join_using; |
|
561 |
/*
|
|
562 |
Bitmap used in the ONLY_FULL_GROUP_BY_MODE to prevent mixture of aggregate
|
|
563 |
functions and non aggregated fields when GROUP BY list is absent.
|
|
564 |
Bits:
|
|
565 |
0 - non aggregated fields are used in this select,
|
|
566 |
defined as NON_AGG_FIELD_USED.
|
|
567 |
1 - aggregate functions are used in this select,
|
|
568 |
defined as SUM_FUNC_USED.
|
|
569 |
*/
|
|
202
by Brian Aker
Cleanup sql_lex to modern types. |
570 |
uint8_t full_group_by_flag; |
1
by brian
clean slate |
571 |
void init_query(); |
572 |
void init_select(); |
|
573 |
st_select_lex_unit* master_unit(); |
|
574 |
st_select_lex_unit* first_inner_unit() |
|
575 |
{
|
|
576 |
return (st_select_lex_unit*) slave; |
|
577 |
}
|
|
578 |
st_select_lex* outer_select(); |
|
579 |
st_select_lex* next_select() { return (st_select_lex*) next; } |
|
580 |
st_select_lex* next_select_in_list() |
|
581 |
{
|
|
582 |
return (st_select_lex*) link_next; |
|
583 |
}
|
|
584 |
st_select_lex_node** next_select_in_list_addr() |
|
585 |
{
|
|
586 |
return &link_next; |
|
587 |
}
|
|
588 |
st_select_lex* return_after_parsing() |
|
589 |
{
|
|
590 |
return master_unit()->return_after_parsing(); |
|
591 |
}
|
|
592 |
||
593 |
void mark_as_dependent(st_select_lex *last); |
|
594 |
||
595 |
bool set_braces(bool value); |
|
596 |
bool inc_in_sum_expr(); |
|
202
by Brian Aker
Cleanup sql_lex to modern types. |
597 |
uint32_t get_in_sum_expr(); |
1
by brian
clean slate |
598 |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
599 |
bool add_item_to_list(Session *session, Item *item); |
600 |
bool add_group_to_list(Session *session, Item *item, bool asc); |
|
601 |
bool add_order_to_list(Session *session, Item *item, bool asc); |
|
602 |
TableList* add_table_to_list(Session *session, Table_ident *table, |
|
1
by brian
clean slate |
603 |
LEX_STRING *alias, |
202
by Brian Aker
Cleanup sql_lex to modern types. |
604 |
uint32_t table_options, |
1
by brian
clean slate |
605 |
thr_lock_type flags= TL_UNLOCK, |
606 |
List<Index_hint> *hints= 0, |
|
607 |
LEX_STRING *option= 0); |
|
327.2.4
by Brian Aker
Refactoring table.h |
608 |
TableList* get_table_list(); |
520.1.22
by Brian Aker
Second pass of thd cleanup |
609 |
bool init_nested_join(Session *session); |
610 |
TableList *end_nested_join(Session *session); |
|
611 |
TableList *nest_last_join(Session *session); |
|
327.2.4
by Brian Aker
Refactoring table.h |
612 |
void add_joined_table(TableList *table); |
613 |
TableList *convert_right_join(); |
|
1
by brian
clean slate |
614 |
List<Item>* get_item_list(); |
202
by Brian Aker
Cleanup sql_lex to modern types. |
615 |
uint32_t get_table_join_options(); |
1
by brian
clean slate |
616 |
void set_lock_for_tables(thr_lock_type lock_type); |
617 |
inline void init_order() |
|
618 |
{
|
|
619 |
order_list.elements= 0; |
|
620 |
order_list.first= 0; |
|
481
by Brian Aker
Remove all of uchar. |
621 |
order_list.next= (unsigned char**) &order_list.first; |
1
by brian
clean slate |
622 |
}
|
623 |
/*
|
|
624 |
This method created for reiniting LEX in mysql_admin_table() and can be
|
|
625 |
used only if you are going remove all SELECT_LEX & units except belonger
|
|
626 |
to LEX (LEX::unit & LEX::select, for other purposes there are
|
|
627 |
SELECT_LEX_UNIT::exclude_level & SELECT_LEX_UNIT::exclude_tree
|
|
628 |
*/
|
|
629 |
void cut_subtree() { slave= 0; } |
|
630 |
bool test_limit(); |
|
631 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
632 |
friend void lex_start(Session *session); |
1
by brian
clean slate |
633 |
st_select_lex() : n_sum_items(0), n_child_sum_items(0) {} |
634 |
void make_empty_select() |
|
635 |
{
|
|
636 |
init_query(); |
|
637 |
init_select(); |
|
638 |
}
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
639 |
bool setup_ref_array(Session *session, uint32_t order_group_num); |
640 |
void print(Session *session, String *str, enum_query_type query_type); |
|
1
by brian
clean slate |
641 |
static void print_order(String *str, |
327.2.3
by Brian Aker
Refactoring of class Table |
642 |
order_st *order, |
1
by brian
clean slate |
643 |
enum_query_type query_type); |
520.1.22
by Brian Aker
Second pass of thd cleanup |
644 |
void print_limit(Session *session, String *str, enum_query_type query_type); |
645 |
void fix_prepare_information(Session *session, Item **conds, Item **having_conds); |
|
1
by brian
clean slate |
646 |
/*
|
647 |
Destroy the used execution plan (JOIN) of this subtree (this
|
|
648 |
SELECT_LEX and all nested SELECT_LEXes and SELECT_LEX_UNITs).
|
|
649 |
*/
|
|
650 |
bool cleanup(); |
|
651 |
/*
|
|
652 |
Recursively cleanup the join of this select lex and of all nested
|
|
653 |
select lexes.
|
|
654 |
*/
|
|
655 |
void cleanup_all_joins(bool full); |
|
656 |
||
657 |
void set_index_hint_type(enum index_hint_type type, index_clause_map clause); |
|
658 |
||
659 |
/*
|
|
660 |
Add a index hint to the tagged list of hints. The type and clause of the
|
|
661 |
hint will be the current ones (set by set_index_hint())
|
|
662 |
*/
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
663 |
bool add_index_hint (Session *session, char *str, uint32_t length); |
1
by brian
clean slate |
664 |
|
665 |
/* make a list to hold index hints */
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
666 |
void alloc_index_hints (Session *session); |
1
by brian
clean slate |
667 |
/* read and clear the index hints */
|
668 |
List<Index_hint>* pop_index_hints(void) |
|
669 |
{
|
|
670 |
List<Index_hint> *hints= index_hints; |
|
671 |
index_hints= NULL; |
|
672 |
return hints; |
|
673 |
}
|
|
674 |
||
675 |
void clear_index_hints(void) { index_hints= NULL; } |
|
676 |
||
677 |
private: |
|
678 |
/* current index hint kind. used in filling up index_hints */
|
|
679 |
enum index_hint_type current_index_hint_type; |
|
680 |
index_clause_map current_index_hint_clause; |
|
681 |
/* a list of USE/FORCE/IGNORE INDEX */
|
|
682 |
List<Index_hint> *index_hints; |
|
683 |
};
|
|
684 |
typedef class st_select_lex SELECT_LEX; |
|
685 |
||
686 |
inline bool st_select_lex_unit::is_union () |
|
687 |
{
|
|
688 |
return first_select()->next_select() && |
|
689 |
first_select()->next_select()->linkage == UNION_TYPE; |
|
690 |
}
|
|
691 |
||
692 |
#define ALTER_ADD_COLUMN (1L << 0)
|
|
693 |
#define ALTER_DROP_COLUMN (1L << 1)
|
|
694 |
#define ALTER_CHANGE_COLUMN (1L << 2)
|
|
695 |
#define ALTER_COLUMN_STORAGE (1L << 3)
|
|
696 |
#define ALTER_COLUMN_FORMAT (1L << 4)
|
|
697 |
#define ALTER_COLUMN_ORDER (1L << 5)
|
|
698 |
#define ALTER_ADD_INDEX (1L << 6)
|
|
699 |
#define ALTER_DROP_INDEX (1L << 7)
|
|
700 |
#define ALTER_RENAME (1L << 8)
|
|
701 |
#define ALTER_ORDER (1L << 9)
|
|
702 |
#define ALTER_OPTIONS (1L << 10)
|
|
703 |
#define ALTER_COLUMN_DEFAULT (1L << 11)
|
|
704 |
#define ALTER_KEYS_ONOFF (1L << 12)
|
|
705 |
#define ALTER_STORAGE (1L << 13)
|
|
706 |
#define ALTER_ROW_FORMAT (1L << 14)
|
|
707 |
#define ALTER_CONVERT (1L << 15)
|
|
708 |
#define ALTER_FORCE (1L << 16)
|
|
709 |
#define ALTER_RECREATE (1L << 17)
|
|
710 |
#define ALTER_TABLE_REORG (1L << 24)
|
|
711 |
#define ALTER_FOREIGN_KEY (1L << 31)
|
|
712 |
||
713 |
/**
|
|
327.1.5
by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h |
714 |
@brief Parsing data for CREATE or ALTER Table.
|
1
by brian
clean slate |
715 |
|
716 |
This structure contains a list of columns or indexes to be created,
|
|
717 |
altered or dropped.
|
|
718 |
*/
|
|
719 |
||
720 |
class Alter_info |
|
721 |
{
|
|
722 |
public: |
|
723 |
List<Alter_drop> drop_list; |
|
724 |
List<Alter_column> alter_list; |
|
725 |
List<Key> key_list; |
|
726 |
List<Create_field> create_list; |
|
202
by Brian Aker
Cleanup sql_lex to modern types. |
727 |
uint32_t flags; |
1
by brian
clean slate |
728 |
enum enum_enable_or_disable keys_onoff; |
729 |
enum tablespace_op_type tablespace_op; |
|
202
by Brian Aker
Cleanup sql_lex to modern types. |
730 |
uint32_t no_parts; |
1
by brian
clean slate |
731 |
enum ha_build_method build_method; |
732 |
Create_field *datetime_field; |
|
733 |
bool error_if_not_empty; |
|
734 |
||
735 |
||
736 |
Alter_info() : |
|
737 |
flags(0), |
|
738 |
keys_onoff(LEAVE_AS_IS), |
|
739 |
tablespace_op(NO_TABLESPACE_OP), |
|
740 |
no_parts(0), |
|
741 |
build_method(HA_BUILD_DEFAULT), |
|
742 |
datetime_field(NULL), |
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
743 |
error_if_not_empty(false) |
1
by brian
clean slate |
744 |
{}
|
745 |
||
746 |
void reset() |
|
747 |
{
|
|
748 |
drop_list.empty(); |
|
749 |
alter_list.empty(); |
|
750 |
key_list.empty(); |
|
751 |
create_list.empty(); |
|
752 |
flags= 0; |
|
753 |
keys_onoff= LEAVE_AS_IS; |
|
754 |
tablespace_op= NO_TABLESPACE_OP; |
|
755 |
no_parts= 0; |
|
756 |
build_method= HA_BUILD_DEFAULT; |
|
757 |
datetime_field= 0; |
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
758 |
error_if_not_empty= false; |
1
by brian
clean slate |
759 |
}
|
760 |
Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root); |
|
761 |
private: |
|
762 |
Alter_info &operator=(const Alter_info &rhs); // not implemented |
|
763 |
Alter_info(const Alter_info &rhs); // not implemented |
|
764 |
};
|
|
765 |
||
766 |
enum xa_option_words {XA_NONE, XA_JOIN, XA_RESUME, XA_ONE_PHASE, |
|
767 |
XA_SUSPEND, XA_FOR_MIGRATE}; |
|
768 |
||
769 |
extern const LEX_STRING null_lex_str; |
|
770 |
||
771 |
||
772 |
/*
|
|
773 |
Class representing list of all tables used by statement.
|
|
774 |
It also contains information about stored functions used by statement
|
|
775 |
since during its execution we may have to add all tables used by its
|
|
776 |
stored functions/triggers to this list in order to pre-open and lock
|
|
777 |
them.
|
|
778 |
||
779 |
Also used by st_lex::reset_n_backup/restore_backup_query_tables_list()
|
|
780 |
methods to save and restore this information.
|
|
781 |
*/
|
|
782 |
||
783 |
class Query_tables_list |
|
784 |
{
|
|
785 |
public: |
|
786 |
/* Global list of all tables used by this statement */
|
|
327.2.4
by Brian Aker
Refactoring table.h |
787 |
TableList *query_tables; |
1
by brian
clean slate |
788 |
/* Pointer to next_global member of last element in the previous list. */
|
327.2.4
by Brian Aker
Refactoring table.h |
789 |
TableList **query_tables_last; |
1
by brian
clean slate |
790 |
/*
|
791 |
If non-0 then indicates that query requires prelocking and points to
|
|
792 |
next_global member of last own element in query table list (i.e. last
|
|
793 |
table which was not added to it as part of preparation to prelocking).
|
|
794 |
0 - indicates that this query does not need prelocking.
|
|
795 |
*/
|
|
327.2.4
by Brian Aker
Refactoring table.h |
796 |
TableList **query_tables_own_last; |
1
by brian
clean slate |
797 |
/*
|
798 |
Set of stored routines called by statement.
|
|
799 |
(Note that we use lazy-initialization for this hash).
|
|
800 |
*/
|
|
801 |
enum { START_SROUTINES_HASH_SIZE= 16 }; |
|
802 |
HASH sroutines; |
|
803 |
/*
|
|
804 |
List linking elements of 'sroutines' set. Allows you to add new elements
|
|
805 |
to this set as you iterate through the list of existing elements.
|
|
806 |
'sroutines_list_own_last' is pointer to ::next member of last element of
|
|
807 |
this list which represents routine which is explicitly used by query.
|
|
808 |
'sroutines_list_own_elements' number of explicitly used routines.
|
|
809 |
We use these two members for restoring of 'sroutines_list' to the state
|
|
810 |
in which it was right after query parsing.
|
|
811 |
*/
|
|
812 |
SQL_LIST sroutines_list; |
|
481
by Brian Aker
Remove all of uchar. |
813 |
unsigned char **sroutines_list_own_last; |
202
by Brian Aker
Cleanup sql_lex to modern types. |
814 |
uint32_t sroutines_list_own_elements; |
1
by brian
clean slate |
815 |
|
816 |
/*
|
|
817 |
These constructor and destructor serve for creation/destruction
|
|
818 |
of Query_tables_list instances which are used as backup storage.
|
|
819 |
*/
|
|
820 |
Query_tables_list() {} |
|
821 |
~Query_tables_list() {} |
|
822 |
||
823 |
/* Initializes (or resets) Query_tables_list object for "real" use. */
|
|
824 |
void reset_query_tables_list(bool init); |
|
825 |
void destroy_query_tables_list(); |
|
826 |
void set_query_tables_list(Query_tables_list *state) |
|
827 |
{
|
|
828 |
*this= *state; |
|
829 |
}
|
|
830 |
||
831 |
/*
|
|
832 |
Direct addition to the list of query tables.
|
|
833 |
If you are using this function, you must ensure that the table
|
|
834 |
object, in particular table->db member, is initialized.
|
|
835 |
*/
|
|
327.2.4
by Brian Aker
Refactoring table.h |
836 |
void add_to_query_tables(TableList *table) |
1
by brian
clean slate |
837 |
{
|
838 |
*(table->prev_global= query_tables_last)= table; |
|
839 |
query_tables_last= &table->next_global; |
|
840 |
}
|
|
841 |
/* Return pointer to first not-own table in query-tables or 0 */
|
|
327.2.4
by Brian Aker
Refactoring table.h |
842 |
TableList* first_not_own_table() |
1
by brian
clean slate |
843 |
{
|
844 |
return ( query_tables_own_last ? *query_tables_own_last : 0); |
|
845 |
}
|
|
846 |
void chop_off_not_own_tables() |
|
847 |
{
|
|
848 |
if (query_tables_own_last) |
|
849 |
{
|
|
850 |
*query_tables_own_last= 0; |
|
851 |
query_tables_last= query_tables_own_last; |
|
852 |
query_tables_own_last= 0; |
|
853 |
}
|
|
854 |
}
|
|
855 |
||
856 |
/**
|
|
857 |
Has the parser/scanner detected that this statement is unsafe?
|
|
858 |
*/
|
|
859 |
inline bool is_stmt_unsafe() const { |
|
860 |
return binlog_stmt_flags & (1U << BINLOG_STMT_FLAG_UNSAFE); |
|
861 |
}
|
|
862 |
||
863 |
/**
|
|
864 |
Flag the current (top-level) statement as unsafe.
|
|
865 |
||
866 |
The flag will be reset after the statement has finished.
|
|
867 |
||
868 |
*/
|
|
869 |
inline void set_stmt_unsafe() { |
|
870 |
binlog_stmt_flags|= (1U << BINLOG_STMT_FLAG_UNSAFE); |
|
871 |
}
|
|
872 |
||
873 |
inline void clear_stmt_unsafe() { |
|
874 |
binlog_stmt_flags&= ~(1U << BINLOG_STMT_FLAG_UNSAFE); |
|
875 |
}
|
|
876 |
||
877 |
/**
|
|
878 |
true if the parsed tree contains references to stored procedures
|
|
879 |
or functions, false otherwise
|
|
880 |
*/
|
|
881 |
bool uses_stored_routines() const |
|
882 |
{ return sroutines_list.elements != 0; } |
|
883 |
||
884 |
private: |
|
885 |
enum enum_binlog_stmt_flag { |
|
886 |
BINLOG_STMT_FLAG_UNSAFE, |
|
887 |
BINLOG_STMT_FLAG_COUNT
|
|
888 |
};
|
|
889 |
||
890 |
/*
|
|
891 |
Tells if the parsing stage detected properties of the statement,
|
|
892 |
for example: that some items require row-based binlogging to give
|
|
893 |
a reliable binlog/replication, or if we will use stored functions
|
|
894 |
or triggers which themselves need require row-based binlogging.
|
|
895 |
*/
|
|
205
by Brian Aker
uint32 -> uin32_t |
896 |
uint32_t binlog_stmt_flags; |
1
by brian
clean slate |
897 |
};
|
898 |
||
899 |
||
900 |
/*
|
|
901 |
st_parsing_options contains the flags for constructions that are
|
|
902 |
allowed in the current statement.
|
|
903 |
*/
|
|
904 |
||
905 |
struct st_parsing_options |
|
906 |
{
|
|
907 |
bool allows_variable; |
|
908 |
bool allows_select_into; |
|
909 |
bool allows_select_procedure; |
|
910 |
bool allows_derived; |
|
911 |
||
912 |
st_parsing_options() { reset(); } |
|
913 |
void reset(); |
|
914 |
};
|
|
915 |
||
916 |
||
917 |
/**
|
|
918 |
The state of the lexical parser, when parsing comments.
|
|
919 |
*/
|
|
920 |
enum enum_comment_state |
|
921 |
{
|
|
922 |
/**
|
|
923 |
Not parsing comments.
|
|
924 |
*/
|
|
925 |
NO_COMMENT, |
|
926 |
/**
|
|
927 |
Parsing comments that need to be preserved.
|
|
928 |
Typically, these are user comments '/' '*' ... '*' '/'.
|
|
929 |
*/
|
|
930 |
PRESERVE_COMMENT, |
|
931 |
/**
|
|
932 |
Parsing comments that need to be discarded.
|
|
933 |
Typically, these are special comments '/' '*' '!' ... '*' '/',
|
|
934 |
or '/' '*' '!' 'M' 'M' 'm' 'm' 'm' ... '*' '/', where the comment
|
|
935 |
markers should not be expanded.
|
|
936 |
*/
|
|
937 |
DISCARD_COMMENT
|
|
938 |
};
|
|
939 |
||
940 |
||
941 |
/**
|
|
942 |
@brief This class represents the character input stream consumed during
|
|
943 |
lexical analysis.
|
|
944 |
||
945 |
In addition to consuming the input stream, this class performs some
|
|
946 |
comment pre processing, by filtering out out of bound special text
|
|
947 |
from the query input stream.
|
|
948 |
Two buffers, with pointers inside each buffers, are maintained in
|
|
949 |
parallel. The 'raw' buffer is the original query text, which may
|
|
950 |
contain out-of-bound comments. The 'cpp' (for comments pre processor)
|
|
951 |
is the pre-processed buffer that contains only the query text that
|
|
952 |
should be seen once out-of-bound data is removed.
|
|
953 |
*/
|
|
954 |
||
955 |
class Lex_input_stream |
|
956 |
{
|
|
957 |
public: |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
958 |
Lex_input_stream(Session *session, const char* buff, unsigned int length); |
1
by brian
clean slate |
959 |
~Lex_input_stream(); |
960 |
||
961 |
/**
|
|
962 |
Set the echo mode.
|
|
963 |
||
964 |
When echo is true, characters parsed from the raw input stream are
|
|
965 |
preserved. When false, characters parsed are silently ignored.
|
|
966 |
@param echo the echo mode.
|
|
967 |
*/
|
|
968 |
void set_echo(bool echo) |
|
969 |
{
|
|
970 |
m_echo= echo; |
|
971 |
}
|
|
972 |
||
973 |
/**
|
|
974 |
Skip binary from the input stream.
|
|
975 |
@param n number of bytes to accept.
|
|
976 |
*/
|
|
977 |
void skip_binary(int n) |
|
978 |
{
|
|
979 |
if (m_echo) |
|
980 |
{
|
|
981 |
memcpy(m_cpp_ptr, m_ptr, n); |
|
982 |
m_cpp_ptr += n; |
|
983 |
}
|
|
984 |
m_ptr += n; |
|
985 |
}
|
|
986 |
||
987 |
/**
|
|
988 |
Get a character, and advance in the stream.
|
|
989 |
@return the next character to parse.
|
|
990 |
*/
|
|
991 |
char yyGet() |
|
992 |
{
|
|
993 |
char c= *m_ptr++; |
|
994 |
if (m_echo) |
|
995 |
*m_cpp_ptr++ = c; |
|
996 |
return c; |
|
997 |
}
|
|
998 |
||
999 |
/**
|
|
1000 |
Get the last character accepted.
|
|
1001 |
@return the last character accepted.
|
|
1002 |
*/
|
|
1003 |
char yyGetLast() |
|
1004 |
{
|
|
1005 |
return m_ptr[-1]; |
|
1006 |
}
|
|
1007 |
||
1008 |
/**
|
|
1009 |
Look at the next character to parse, but do not accept it.
|
|
1010 |
*/
|
|
1011 |
char yyPeek() |
|
1012 |
{
|
|
1013 |
return m_ptr[0]; |
|
1014 |
}
|
|
1015 |
||
1016 |
/**
|
|
1017 |
Look ahead at some character to parse.
|
|
1018 |
@param n offset of the character to look up
|
|
1019 |
*/
|
|
1020 |
char yyPeekn(int n) |
|
1021 |
{
|
|
1022 |
return m_ptr[n]; |
|
1023 |
}
|
|
1024 |
||
1025 |
/**
|
|
1026 |
Cancel the effect of the last yyGet() or yySkip().
|
|
1027 |
Note that the echo mode should not change between calls to yyGet / yySkip
|
|
1028 |
and yyUnget. The caller is responsible for ensuring that.
|
|
1029 |
*/
|
|
1030 |
void yyUnget() |
|
1031 |
{
|
|
1032 |
m_ptr--; |
|
1033 |
if (m_echo) |
|
1034 |
m_cpp_ptr--; |
|
1035 |
}
|
|
1036 |
||
1037 |
/**
|
|
1038 |
Accept a character, by advancing the input stream.
|
|
1039 |
*/
|
|
1040 |
void yySkip() |
|
1041 |
{
|
|
1042 |
if (m_echo) |
|
1043 |
*m_cpp_ptr++ = *m_ptr++; |
|
1044 |
else
|
|
1045 |
m_ptr++; |
|
1046 |
}
|
|
1047 |
||
1048 |
/**
|
|
1049 |
Accept multiple characters at once.
|
|
1050 |
@param n the number of characters to accept.
|
|
1051 |
*/
|
|
1052 |
void yySkipn(int n) |
|
1053 |
{
|
|
1054 |
if (m_echo) |
|
1055 |
{
|
|
1056 |
memcpy(m_cpp_ptr, m_ptr, n); |
|
1057 |
m_cpp_ptr += n; |
|
1058 |
}
|
|
1059 |
m_ptr += n; |
|
1060 |
}
|
|
1061 |
||
1062 |
/**
|
|
1063 |
End of file indicator for the query text to parse.
|
|
1064 |
@return true if there are no more characters to parse
|
|
1065 |
*/
|
|
1066 |
bool eof() |
|
1067 |
{
|
|
1068 |
return (m_ptr >= m_end_of_query); |
|
1069 |
}
|
|
1070 |
||
1071 |
/**
|
|
1072 |
End of file indicator for the query text to parse.
|
|
1073 |
@param n number of characters expected
|
|
1074 |
@return true if there are less than n characters to parse
|
|
1075 |
*/
|
|
1076 |
bool eof(int n) |
|
1077 |
{
|
|
1078 |
return ((m_ptr + n) >= m_end_of_query); |
|
1079 |
}
|
|
1080 |
||
1081 |
/** Get the raw query buffer. */
|
|
1082 |
const char *get_buf() |
|
1083 |
{
|
|
1084 |
return m_buf; |
|
1085 |
}
|
|
1086 |
||
1087 |
/** Get the pre-processed query buffer. */
|
|
1088 |
const char *get_cpp_buf() |
|
1089 |
{
|
|
1090 |
return m_cpp_buf; |
|
1091 |
}
|
|
1092 |
||
1093 |
/** Get the end of the raw query buffer. */
|
|
1094 |
const char *get_end_of_query() |
|
1095 |
{
|
|
1096 |
return m_end_of_query; |
|
1097 |
}
|
|
1098 |
||
1099 |
/** Mark the stream position as the start of a new token. */
|
|
1100 |
void start_token() |
|
1101 |
{
|
|
1102 |
m_tok_start_prev= m_tok_start; |
|
1103 |
m_tok_start= m_ptr; |
|
1104 |
m_tok_end= m_ptr; |
|
1105 |
||
1106 |
m_cpp_tok_start_prev= m_cpp_tok_start; |
|
1107 |
m_cpp_tok_start= m_cpp_ptr; |
|
1108 |
m_cpp_tok_end= m_cpp_ptr; |
|
1109 |
}
|
|
1110 |
||
1111 |
/**
|
|
1112 |
Adjust the starting position of the current token.
|
|
1113 |
This is used to compensate for starting whitespace.
|
|
1114 |
*/
|
|
1115 |
void restart_token() |
|
1116 |
{
|
|
1117 |
m_tok_start= m_ptr; |
|
1118 |
m_cpp_tok_start= m_cpp_ptr; |
|
1119 |
}
|
|
1120 |
||
1121 |
/** Get the token start position, in the raw buffer. */
|
|
1122 |
const char *get_tok_start() |
|
1123 |
{
|
|
1124 |
return m_tok_start; |
|
1125 |
}
|
|
1126 |
||
1127 |
/** Get the token start position, in the pre-processed buffer. */
|
|
1128 |
const char *get_cpp_tok_start() |
|
1129 |
{
|
|
1130 |
return m_cpp_tok_start; |
|
1131 |
}
|
|
1132 |
||
1133 |
/** Get the token end position, in the raw buffer. */
|
|
1134 |
const char *get_tok_end() |
|
1135 |
{
|
|
1136 |
return m_tok_end; |
|
1137 |
}
|
|
1138 |
||
1139 |
/** Get the token end position, in the pre-processed buffer. */
|
|
1140 |
const char *get_cpp_tok_end() |
|
1141 |
{
|
|
1142 |
return m_cpp_tok_end; |
|
1143 |
}
|
|
1144 |
||
1145 |
/** Get the previous token start position, in the raw buffer. */
|
|
1146 |
const char *get_tok_start_prev() |
|
1147 |
{
|
|
1148 |
return m_tok_start_prev; |
|
1149 |
}
|
|
1150 |
||
1151 |
/** Get the current stream pointer, in the raw buffer. */
|
|
1152 |
const char *get_ptr() |
|
1153 |
{
|
|
1154 |
return m_ptr; |
|
1155 |
}
|
|
1156 |
||
1157 |
/** Get the current stream pointer, in the pre-processed buffer. */
|
|
1158 |
const char *get_cpp_ptr() |
|
1159 |
{
|
|
1160 |
return m_cpp_ptr; |
|
1161 |
}
|
|
1162 |
||
1163 |
/** Get the length of the current token, in the raw buffer. */
|
|
202
by Brian Aker
Cleanup sql_lex to modern types. |
1164 |
uint32_t yyLength() |
1
by brian
clean slate |
1165 |
{
|
1166 |
/*
|
|
1167 |
The assumption is that the lexical analyser is always 1 character ahead,
|
|
1168 |
which the -1 account for.
|
|
1169 |
*/
|
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1170 |
assert(m_ptr > m_tok_start); |
202
by Brian Aker
Cleanup sql_lex to modern types. |
1171 |
return (uint32_t) ((m_ptr - m_tok_start) - 1); |
1
by brian
clean slate |
1172 |
}
|
1173 |
||
1174 |
/** Get the utf8-body string. */
|
|
1175 |
const char *get_body_utf8_str() |
|
1176 |
{
|
|
1177 |
return m_body_utf8; |
|
1178 |
}
|
|
1179 |
||
1180 |
/** Get the utf8-body length. */
|
|
202
by Brian Aker
Cleanup sql_lex to modern types. |
1181 |
uint32_t get_body_utf8_length() |
1
by brian
clean slate |
1182 |
{
|
1183 |
return m_body_utf8_ptr - m_body_utf8; |
|
1184 |
}
|
|
1185 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
1186 |
void body_utf8_start(Session *session, const char *begin_ptr); |
1
by brian
clean slate |
1187 |
void body_utf8_append(const char *ptr); |
1188 |
void body_utf8_append(const char *ptr, const char *end_ptr); |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1189 |
void body_utf8_append_literal(Session *session, |
1
by brian
clean slate |
1190 |
const LEX_STRING *txt, |
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
1191 |
const CHARSET_INFO * const txt_cs, |
1
by brian
clean slate |
1192 |
const char *end_ptr); |
1193 |
||
1194 |
/** Current thread. */
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1195 |
Session *m_session; |
1
by brian
clean slate |
1196 |
|
1197 |
/** Current line number. */
|
|
202
by Brian Aker
Cleanup sql_lex to modern types. |
1198 |
uint32_t yylineno; |
1
by brian
clean slate |
1199 |
|
1200 |
/** Length of the last token parsed. */
|
|
202
by Brian Aker
Cleanup sql_lex to modern types. |
1201 |
uint32_t yytoklen; |
1
by brian
clean slate |
1202 |
|
1203 |
/** Interface with bison, value of the last token parsed. */
|
|
1204 |
LEX_YYSTYPE yylval; |
|
1205 |
||
1206 |
/** LALR(2) resolution, look ahead token.*/
|
|
1207 |
int lookahead_token; |
|
1208 |
||
1209 |
/** LALR(2) resolution, value of the look ahead token.*/
|
|
1210 |
LEX_YYSTYPE lookahead_yylval; |
|
1211 |
||
1212 |
private: |
|
1213 |
/** Pointer to the current position in the raw input stream. */
|
|
1214 |
const char *m_ptr; |
|
1215 |
||
1216 |
/** Starting position of the last token parsed, in the raw buffer. */
|
|
1217 |
const char *m_tok_start; |
|
1218 |
||
1219 |
/** Ending position of the previous token parsed, in the raw buffer. */
|
|
1220 |
const char *m_tok_end; |
|
1221 |
||
1222 |
/** End of the query text in the input stream, in the raw buffer. */
|
|
1223 |
const char *m_end_of_query; |
|
1224 |
||
1225 |
/** Starting position of the previous token parsed, in the raw buffer. */
|
|
1226 |
const char *m_tok_start_prev; |
|
1227 |
||
1228 |
/** Begining of the query text in the input stream, in the raw buffer. */
|
|
1229 |
const char *m_buf; |
|
1230 |
||
1231 |
/** Length of the raw buffer. */
|
|
202
by Brian Aker
Cleanup sql_lex to modern types. |
1232 |
uint32_t m_buf_length; |
1
by brian
clean slate |
1233 |
|
1234 |
/** Echo the parsed stream to the pre-processed buffer. */
|
|
1235 |
bool m_echo; |
|
1236 |
||
1237 |
/** Pre-processed buffer. */
|
|
1238 |
char *m_cpp_buf; |
|
1239 |
||
1240 |
/** Pointer to the current position in the pre-processed input stream. */
|
|
1241 |
char *m_cpp_ptr; |
|
1242 |
||
1243 |
/**
|
|
1244 |
Starting position of the last token parsed,
|
|
1245 |
in the pre-processed buffer.
|
|
1246 |
*/
|
|
1247 |
const char *m_cpp_tok_start; |
|
1248 |
||
1249 |
/**
|
|
1250 |
Starting position of the previous token parsed,
|
|
1251 |
in the pre-procedded buffer.
|
|
1252 |
*/
|
|
1253 |
const char *m_cpp_tok_start_prev; |
|
1254 |
||
1255 |
/**
|
|
1256 |
Ending position of the previous token parsed,
|
|
1257 |
in the pre-processed buffer.
|
|
1258 |
*/
|
|
1259 |
const char *m_cpp_tok_end; |
|
1260 |
||
1261 |
/** UTF8-body buffer created during parsing. */
|
|
1262 |
char *m_body_utf8; |
|
1263 |
||
1264 |
/** Pointer to the current position in the UTF8-body buffer. */
|
|
1265 |
char *m_body_utf8_ptr; |
|
1266 |
||
1267 |
/**
|
|
1268 |
Position in the pre-processed buffer. The query from m_cpp_buf to
|
|
1269 |
m_cpp_utf_processed_ptr is converted to UTF8-body.
|
|
1270 |
*/
|
|
1271 |
const char *m_cpp_utf8_processed_ptr; |
|
1272 |
||
1273 |
public: |
|
1274 |
||
1275 |
/** Current state of the lexical analyser. */
|
|
1276 |
enum my_lex_states next_state; |
|
1277 |
||
1278 |
/**
|
|
1279 |
Position of ';' in the stream, to delimit multiple queries.
|
|
1280 |
This delimiter is in the raw buffer.
|
|
1281 |
*/
|
|
1282 |
const char *found_semicolon; |
|
1283 |
||
1284 |
/** Token character bitmaps, to detect 7bit strings. */
|
|
481
by Brian Aker
Remove all of uchar. |
1285 |
unsigned char tok_bitmap; |
1
by brian
clean slate |
1286 |
|
1287 |
/** SQL_MODE = IGNORE_SPACE. */
|
|
1288 |
bool ignore_space; |
|
1289 |
||
1290 |
/** State of the lexical analyser for comments. */
|
|
1291 |
enum_comment_state in_comment; |
|
1292 |
||
1293 |
/**
|
|
1294 |
Starting position of the TEXT_STRING or IDENT in the pre-processed
|
|
1295 |
buffer.
|
|
1296 |
||
520.4.50
by Monty Taylor
Finish changing the bison namespace argument from MYSQL to DRIZZLE |
1297 |
NOTE: this member must be used within DRIZZLElex() function only.
|
1
by brian
clean slate |
1298 |
*/
|
1299 |
const char *m_cpp_text_start; |
|
1300 |
||
1301 |
/**
|
|
1302 |
Ending position of the TEXT_STRING or IDENT in the pre-processed
|
|
1303 |
buffer.
|
|
1304 |
||
520.4.50
by Monty Taylor
Finish changing the bison namespace argument from MYSQL to DRIZZLE |
1305 |
NOTE: this member must be used within DRIZZLElex() function only.
|
1
by brian
clean slate |
1306 |
*/
|
1307 |
const char *m_cpp_text_end; |
|
1308 |
||
1309 |
/**
|
|
1310 |
Character set specified by the character-set-introducer.
|
|
1311 |
||
520.4.50
by Monty Taylor
Finish changing the bison namespace argument from MYSQL to DRIZZLE |
1312 |
NOTE: this member must be used within DRIZZLElex() function only.
|
1
by brian
clean slate |
1313 |
*/
|
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
1314 |
const CHARSET_INFO *m_underscore_cs; |
1
by brian
clean slate |
1315 |
};
|
1316 |
||
1317 |
||
520.1.21
by Brian Aker
THD -> Session rename |
1318 |
/* The state of the lex parsing. This is saved in the Session struct */
|
1
by brian
clean slate |
1319 |
|
575.4.7
by Monty Taylor
More header cleanup. |
1320 |
class LEX : public Query_tables_list |
1
by brian
clean slate |
1321 |
{
|
575.4.7
by Monty Taylor
More header cleanup. |
1322 |
public: |
1
by brian
clean slate |
1323 |
SELECT_LEX_UNIT unit; /* most upper unit */ |
1324 |
SELECT_LEX select_lex; /* first SELECT_LEX */ |
|
1325 |
/* current SELECT_LEX in parsing */
|
|
1326 |
SELECT_LEX *current_select; |
|
1327 |
/* list of all SELECT_LEX */
|
|
1328 |
SELECT_LEX *all_selects_list; |
|
1329 |
||
1330 |
char *length,*dec,*change; |
|
1331 |
LEX_STRING name; |
|
1332 |
char *help_arg; |
|
1333 |
char* to_log; /* For PURGE MASTER LOGS TO */ |
|
1334 |
String *wild; |
|
1335 |
sql_exchange *exchange; |
|
1336 |
select_result *result; |
|
1337 |
Item *default_value, *on_update_value; |
|
1338 |
LEX_STRING comment, ident; |
|
1339 |
XID *xid; |
|
481
by Brian Aker
Remove all of uchar. |
1340 |
unsigned char* yacc_yyss, *yacc_yyvs; |
520.1.22
by Brian Aker
Second pass of thd cleanup |
1341 |
Session *session; |
383.7.1
by Andrey Zhakov
Initial submit of code and tests |
1342 |
virtual_column_info *vcol_info; |
1
by brian
clean slate |
1343 |
|
1344 |
/* maintain a list of used plugins for this LEX */
|
|
1345 |
DYNAMIC_ARRAY plugins; |
|
1346 |
plugin_ref plugins_static_buffer[INITIAL_LEX_PLUGIN_LIST_SIZE]; |
|
1347 |
||
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
1348 |
const CHARSET_INFO *charset; |
1
by brian
clean slate |
1349 |
bool text_string_is_7bit; |
1350 |
/* store original leaf_tables for INSERT SELECT and PS/SP */
|
|
327.2.4
by Brian Aker
Refactoring table.h |
1351 |
TableList *leaf_tables_insert; |
1
by brian
clean slate |
1352 |
|
1353 |
List<Key_part_spec> col_list; |
|
1354 |
List<Key_part_spec> ref_list; |
|
1355 |
List<String> interval_list; |
|
1356 |
List<LEX_COLUMN> columns; |
|
1357 |
List<Item> *insert_list,field_list,value_list,update_list; |
|
1358 |
List<List_item> many_values; |
|
1359 |
List<set_var_base> var_list; |
|
1360 |
List<Item_param> param_list; |
|
1361 |
/*
|
|
1362 |
A stack of name resolution contexts for the query. This stack is used
|
|
1363 |
at parse time to set local name resolution contexts for various parts
|
|
1364 |
of a query. For example, in a JOIN ... ON (some_condition) clause the
|
|
1365 |
Items in 'some_condition' must be resolved only against the operands
|
|
1366 |
of the the join, and not against the whole clause. Similarly, Items in
|
|
1367 |
subqueries should be resolved against the subqueries (and outer queries).
|
|
1368 |
The stack is used in the following way: when the parser detects that
|
|
1369 |
all Items in some clause need a local context, it creates a new context
|
|
1370 |
and pushes it on the stack. All newly created Items always store the
|
|
1371 |
top-most context in the stack. Once the parser leaves the clause that
|
|
1372 |
required a local context, the parser pops the top-most context.
|
|
1373 |
*/
|
|
1374 |
List<Name_resolution_context> context_stack; |
|
1375 |
List<LEX_STRING> db_list; |
|
1376 |
||
1377 |
SQL_LIST proc_list, auxiliary_table_list, save_list; |
|
1378 |
Create_field *last_field; |
|
1379 |
Item_sum *in_sum_func; |
|
1380 |
udf_func udf; |
|
1381 |
HA_CHECK_OPT check_opt; // check/repair options |
|
1382 |
HA_CREATE_INFO create_info; |
|
1383 |
KEY_CREATE_INFO key_create_info; |
|
1384 |
LEX_MASTER_INFO mi; // used by CHANGE MASTER |
|
1385 |
LEX_SERVER_OPTIONS server_options; |
|
202
by Brian Aker
Cleanup sql_lex to modern types. |
1386 |
uint32_t type; |
1
by brian
clean slate |
1387 |
/*
|
1388 |
This variable is used in post-parse stage to declare that sum-functions,
|
|
1389 |
or functions which have sense only if GROUP BY is present, are allowed.
|
|
1390 |
For example in a query
|
|
1391 |
SELECT ... FROM ...WHERE MIN(i) == 1 GROUP BY ... HAVING MIN(i) > 2
|
|
1392 |
MIN(i) in the WHERE clause is not allowed in the opposite to MIN(i)
|
|
1393 |
in the HAVING clause. Due to possible nesting of select construct
|
|
1394 |
the variable can contain 0 or 1 for each nest level.
|
|
1395 |
*/
|
|
1396 |
nesting_map allow_sum_func; |
|
1397 |
enum_sql_command sql_command; |
|
1398 |
/*
|
|
1399 |
Usually `expr` rule of yacc is quite reused but some commands better
|
|
1400 |
not support subqueries which comes standard with this rule, like
|
|
1401 |
KILL, HA_READ, CREATE/ALTER EVENT etc. Set this to `false` to get
|
|
1402 |
syntax error back.
|
|
1403 |
*/
|
|
1404 |
bool expr_allows_subselect; |
|
383.7.1
by Andrey Zhakov
Initial submit of code and tests |
1405 |
/*
|
1406 |
A special command "PARSE_VCOL_EXPR" is defined for the parser
|
|
1407 |
to translate an expression statement of a virtual column \
|
|
1408 |
(stored in the *.frm file as a string) into an Item object.
|
|
1409 |
The following flag is used to prevent other applications to use
|
|
1410 |
this command.
|
|
1411 |
*/
|
|
1412 |
bool parse_vcol_expr; |
|
1
by brian
clean slate |
1413 |
|
1414 |
thr_lock_type lock_option; |
|
1415 |
enum enum_duplicates duplicates; |
|
1416 |
enum enum_tx_isolation tx_isolation; |
|
1417 |
enum enum_ha_read_modes ha_read_mode; |
|
1418 |
union { |
|
1419 |
enum ha_rkey_function ha_rkey_mode; |
|
1420 |
enum xa_option_words xa_opt; |
|
327.1.5
by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h |
1421 |
bool lock_transactional; /* For LOCK Table ... IN ... MODE */ |
1
by brian
clean slate |
1422 |
};
|
1423 |
enum enum_var_type option_type; |
|
1424 |
||
202
by Brian Aker
Cleanup sql_lex to modern types. |
1425 |
uint32_t profile_query_id; |
1426 |
uint32_t profile_options; |
|
1
by brian
clean slate |
1427 |
enum column_format_type column_format; |
202
by Brian Aker
Cleanup sql_lex to modern types. |
1428 |
uint32_t which_columns; |
1
by brian
clean slate |
1429 |
enum Foreign_key::fk_match_opt fk_match_option; |
1430 |
enum Foreign_key::fk_option fk_update_opt; |
|
1431 |
enum Foreign_key::fk_option fk_delete_opt; |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1432 |
uint32_t slave_session_opt, start_transaction_opt; |
1
by brian
clean slate |
1433 |
int nest_level; |
1434 |
/*
|
|
1435 |
In LEX representing update which were transformed to multi-update
|
|
1436 |
stores total number of tables. For LEX representing multi-delete
|
|
1437 |
holds number of tables from which we will delete records.
|
|
1438 |
*/
|
|
202
by Brian Aker
Cleanup sql_lex to modern types. |
1439 |
uint32_t table_count; |
1440 |
uint8_t describe; |
|
1
by brian
clean slate |
1441 |
/*
|
1442 |
A flag that indicates what kinds of derived tables are present in the
|
|
1443 |
query (0 if no derived tables, otherwise DERIVED_SUBQUERY).
|
|
1444 |
*/
|
|
202
by Brian Aker
Cleanup sql_lex to modern types. |
1445 |
uint8_t derived_tables; |
1
by brian
clean slate |
1446 |
bool drop_if_exists, drop_temporary, local_file, one_shot_set; |
1447 |
bool autocommit; |
|
383.1.26
by Brian Aker
Removed option for single command replication and have now left disable of |
1448 |
bool verbose; |
1
by brian
clean slate |
1449 |
|
1450 |
bool tx_chain, tx_release; |
|
1451 |
bool subqueries, ignore; |
|
1452 |
st_parsing_options parsing_options; |
|
1453 |
Alter_info alter_info; |
|
1454 |
||
1455 |
/*
|
|
1456 |
field_list was created for view and should be removed before PS/SP
|
|
1457 |
rexecuton
|
|
1458 |
*/
|
|
1459 |
bool empty_field_list_on_rset; |
|
1460 |
||
1461 |
/*
|
|
1462 |
Pointers to part of LOAD DATA statement that should be rewritten
|
|
1463 |
during replication ("LOCAL 'filename' REPLACE INTO" part).
|
|
1464 |
*/
|
|
1465 |
const char *fname_start; |
|
1466 |
const char *fname_end; |
|
1467 |
||
1468 |
/**
|
|
1469 |
During name resolution search only in the table list given by
|
|
1470 |
Name_resolution_context::first_name_resolution_table and
|
|
1471 |
Name_resolution_context::last_name_resolution_table
|
|
1472 |
(see Item_field::fix_fields()).
|
|
1473 |
*/
|
|
1474 |
bool use_only_table_context; |
|
1475 |
||
1476 |
bool escape_used; |
|
1477 |
bool is_lex_started; /* If lex_start() did run. For debugging. */ |
|
1478 |
||
575.4.7
by Monty Taylor
More header cleanup. |
1479 |
LEX(); |
1
by brian
clean slate |
1480 |
|
575.4.7
by Monty Taylor
More header cleanup. |
1481 |
virtual ~LEX() |
1
by brian
clean slate |
1482 |
{
|
1483 |
destroy_query_tables_list(); |
|
1484 |
plugin_unlock_list(NULL, (plugin_ref *)plugins.buffer, plugins.elements); |
|
1485 |
delete_dynamic(&plugins); |
|
1486 |
}
|
|
1487 |
||
327.2.4
by Brian Aker
Refactoring table.h |
1488 |
TableList *unlink_first_table(bool *link_to_local); |
1489 |
void link_first_table_back(TableList *first, bool link_to_local); |
|
1
by brian
clean slate |
1490 |
void first_lists_tables_same(); |
1491 |
||
1492 |
bool can_be_merged(); |
|
1493 |
bool can_use_merged(); |
|
1494 |
bool can_not_use_merged(); |
|
1495 |
bool only_view_structure(); |
|
1496 |
bool need_correct_ident(); |
|
1497 |
||
1498 |
void cleanup_after_one_table_open(); |
|
1499 |
||
1500 |
bool push_context(Name_resolution_context *context) |
|
1501 |
{
|
|
1502 |
return context_stack.push_front(context); |
|
1503 |
}
|
|
1504 |
||
1505 |
void pop_context() |
|
1506 |
{
|
|
1507 |
context_stack.pop(); |
|
1508 |
}
|
|
1509 |
||
1510 |
bool copy_db_to(char **p_db, size_t *p_db_length) const; |
|
1511 |
||
1512 |
Name_resolution_context *current_context() |
|
1513 |
{
|
|
1514 |
return context_stack.head(); |
|
1515 |
}
|
|
1516 |
/*
|
|
520.1.21
by Brian Aker
THD -> Session rename |
1517 |
Restore the LEX and Session in case of a parse error.
|
1
by brian
clean slate |
1518 |
*/
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1519 |
static void cleanup_lex_after_parse_error(Session *session); |
1
by brian
clean slate |
1520 |
|
1521 |
void reset_n_backup_query_tables_list(Query_tables_list *backup); |
|
1522 |
void restore_backup_query_tables_list(Query_tables_list *backup); |
|
1523 |
||
1524 |
bool table_or_sp_used(); |
|
1525 |
||
1526 |
/**
|
|
1527 |
@brief check if the statement is a single-level join
|
|
1528 |
@return result of the check
|
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1529 |
@retval true The statement doesn't contain subqueries, unions and
|
1
by brian
clean slate |
1530 |
stored procedure calls.
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1531 |
@retval false There are subqueries, UNIONs or stored procedure calls.
|
1
by brian
clean slate |
1532 |
*/
|
1533 |
bool is_single_level_stmt() |
|
1534 |
{
|
|
1535 |
/*
|
|
1536 |
This check exploits the fact that the last added to all_select_list is
|
|
1537 |
on its top. So select_lex (as the first added) will be at the tail
|
|
1538 |
of the list.
|
|
1539 |
*/
|
|
1540 |
if (&select_lex == all_selects_list && !sroutines.records) |
|
1541 |
{
|
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1542 |
assert(!all_selects_list->next_select_in_list()); |
1543 |
return true; |
|
1
by brian
clean slate |
1544 |
}
|
51.1.52
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1545 |
return false; |
1
by brian
clean slate |
1546 |
}
|
575.4.7
by Monty Taylor
More header cleanup. |
1547 |
};
|
1
by brian
clean slate |
1548 |
|
575.4.7
by Monty Taylor
More header cleanup. |
1549 |
struct st_lex_local: public LEX |
1
by brian
clean slate |
1550 |
{
|
1551 |
static void *operator new(size_t size) throw() |
|
1552 |
{
|
|
1553 |
return sql_alloc(size); |
|
1554 |
}
|
|
1555 |
static void *operator new(size_t size, MEM_ROOT *mem_root) throw() |
|
1556 |
{
|
|
202
by Brian Aker
Cleanup sql_lex to modern types. |
1557 |
return (void*) alloc_root(mem_root, (uint32_t) size); |
1
by brian
clean slate |
1558 |
}
|
212.1.3
by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)). |
1559 |
static void operator delete(void *ptr __attribute__((unused)), |
1560 |
size_t size __attribute__((unused))) |
|
1
by brian
clean slate |
1561 |
{ TRASH(ptr, size); } |
212.1.3
by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)). |
1562 |
static void operator delete(void *ptr __attribute__((unused)), |
1563 |
MEM_ROOT *mem_root __attribute__((unused))) |
|
1
by brian
clean slate |
1564 |
{ /* Never called */ } |
1565 |
};
|
|
1566 |
||
1567 |
extern void lex_init(void); |
|
1568 |
extern void lex_free(void); |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1569 |
extern void lex_start(Session *session); |
1
by brian
clean slate |
1570 |
extern void lex_end(LEX *lex); |
1571 |
||
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
1572 |
extern void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str); |
1
by brian
clean slate |
1573 |
|
1574 |
extern bool is_lex_native_function(const LEX_STRING *name); |
|
1575 |
||
1576 |
/**
|
|
1577 |
@} (End of group Semantic_Analysis)
|
|
1578 |
*/
|
|
1579 |
||
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
1580 |
#endif /* DRIZZLE_SERVER */ |
243.1.8
by Jay Pipes
More cleanup and revert broken base.h |
1581 |
#endif /* DRIZZLE_SERVER_SQL_LEX_H */ |