17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#ifndef DRIZZLE_SERVER_SQL_LEX_H
21
#define DRIZZLE_SERVER_SQL_LEX_H
20
#ifndef DRIZZLED_SQL_LEX_H
21
#define DRIZZLED_SQL_LEX_H
24
24
@defgroup Semantic_Analysis Semantic Analysis
27
#include <drizzled/sql_udf.h>
28
#include <drizzled/name_resolution_context.h>
29
#include <drizzled/item/subselect.h>
30
#include <drizzled/table_list.h>
31
#include <drizzled/functions/real.h>
32
#include <drizzled/alter_drop.h>
33
#include <drizzled/alter_column.h>
34
#include <drizzled/key.h>
35
#include <drizzled/foreign_key.h>
26
#include "drizzled/sql_udf.h"
27
#include "drizzled/name_resolution_context.h"
28
#include "drizzled/item/subselect.h"
29
#include "drizzled/item/param.h"
30
#include "drizzled/item/outer_ref.h"
31
#include "drizzled/table_list.h"
32
#include "drizzled/function/math/real.h"
33
#include "drizzled/alter_drop.h"
34
#include "drizzled/alter_column.h"
35
#include "drizzled/key.h"
36
#include "drizzled/foreign_key.h"
37
#include "drizzled/item/param.h"
38
#include "drizzled/index_hint.h"
37
40
class select_result_interceptor;
38
class virtual_column_info;
40
42
/* YACC and LEX Definitions */
42
44
/* These may not be declared yet */
49
51
The following hack is needed because mysql_yacc.cc does not define
50
52
YYSTYPE before including this file
53
#include <drizzled/set_var.h>
54
#include <drizzled/item/func.h>
56
#define LEX_YYSTYPE void *
58
#if defined(DRIZZLE_LEX)
59
#include <drizzled/lex_symbol.h>
60
#include <drizzled/sql_yacc.h>
61
#define LEX_YYSTYPE YYSTYPE *
63
#define LEX_YYSTYPE void *
56
# include <drizzled/set_var.h>
57
# include <drizzled/item/func.h>
59
# define LEX_YYSTYPE void *
61
# if defined(DRIZZLE_LEX)
62
# include <drizzled/lex_symbol.h>
63
# include <drizzled/sql_yacc.h>
64
# define LEX_YYSTYPE YYSTYPE *
66
# define LEX_YYSTYPE void *
67
# endif /* defined(DRIZZLE_LEX) */
68
# endif /* DRIZZLE_YACC */
69
#endif /* DRIZZLE_SERVER */
68
71
// describe/explain types
69
72
#define DESCRIBE_NORMAL 1
84
87
char *server_name, *host, *db, *username, *password, *scheme, *owner;
85
88
} LEX_SERVER_OPTIONS;
87
typedef struct st_lex_master_info
89
char *host, *user, *password, *log_file_name;
90
uint32_t port, connect_retry;
91
float heartbeat_period;
95
Enum is used for making it possible to detect if the user
96
changed variable or if it should be left at old value
98
enum {LEX_MI_UNCHANGED, LEX_MI_DISABLE, LEX_MI_ENABLE} heartbeat_opt;
100
uint32_t relay_log_pos;
104
91
enum sub_select_type
117
104
NO_TABLESPACE_OP, DISCARD_TABLESPACE, IMPORT_TABLESPACE
121
String names used to print a statement with index hints.
122
Keep in sync with index_hint_type.
124
extern const char * index_hint_type_name[];
125
typedef unsigned char index_clause_map;
128
Bits in index_clause_map : one for each possible FOR clause in
129
USE/FORCE/IGNORE INDEX index hint specification
131
#define INDEX_HINT_MASK_JOIN (1)
132
#define INDEX_HINT_MASK_GROUP (1 << 1)
133
#define INDEX_HINT_MASK_ORDER (1 << 2)
135
#define INDEX_HINT_MASK_ALL (INDEX_HINT_MASK_JOIN | INDEX_HINT_MASK_GROUP | \
136
INDEX_HINT_MASK_ORDER)
138
/* Single element of an USE/FORCE/IGNORE INDEX list specified as a SQL hint */
139
class Index_hint : public Sql_alloc
142
/* The type of the hint : USE/FORCE/IGNORE */
143
enum index_hint_type type;
144
/* Where the hit applies to. A bitmask of INDEX_HINT_MASK_<place> values */
145
index_clause_map clause;
147
The index name. Empty (str=NULL) name represents an empty list
152
Index_hint (enum index_hint_type type_arg, index_clause_map clause_arg,
153
char *str, uint32_t length) :
154
type(type_arg), clause(clause_arg)
157
key_name.length= length;
160
void print(Session *session, String *str);
164
The state of the lex parsing for selects
108
The state of the lex parsing for selects
166
110
master and slaves are pointers to select_lex.
167
111
master is pointer to upper level node.
168
112
slave is pointer to lower level node
278
Base class for st_select_lex (SELECT_LEX) &
279
st_select_lex_unit (SELECT_LEX_UNIT)
222
Base class for Select_Lex (Select_Lex) &
223
Select_Lex_Unit (Select_Lex_Unit)
283
class st_select_lex_unit;
284
class st_select_lex_node {
227
class Select_Lex_Unit;
228
class Select_Lex_Node {
286
st_select_lex_node *next, **prev, /* neighbor list */
230
Select_Lex_Node *next, **prev, /* neighbor list */
287
231
*master, *slave, /* vertical links */
288
*link_next, **link_prev; /* list of whole SELECT_LEX */
232
*link_next, **link_prev; /* list of whole Select_Lex */
291
235
uint64_t options;
310
254
static void *operator new(size_t size, MEM_ROOT *mem_root)
311
255
{ return (void*) alloc_root(mem_root, (uint32_t) size); }
312
static void operator delete(void *ptr __attribute__((unused)),
313
size_t size __attribute__((unused)))
256
static void operator delete(void *, size_t)
314
257
{ TRASH(ptr, size); }
315
static void operator delete(void *ptr __attribute__((unused)),
316
MEM_ROOT *mem_root __attribute__((unused)))
258
static void operator delete(void *, MEM_ROOT *)
318
st_select_lex_node(): linkage(UNSPECIFIED_TYPE) {}
319
virtual ~st_select_lex_node() {}
320
inline st_select_lex_node* get_master() { return master; }
260
Select_Lex_Node(): linkage(UNSPECIFIED_TYPE) {}
261
virtual ~Select_Lex_Node() {}
262
inline Select_Lex_Node* get_master() { return master; }
321
263
virtual void init_query();
322
264
virtual void init_select();
323
void include_down(st_select_lex_node *upper);
324
void include_neighbour(st_select_lex_node *before);
325
void include_standalone(st_select_lex_node *sel, st_select_lex_node **ref);
326
void include_global(st_select_lex_node **plink);
265
void include_down(Select_Lex_Node *upper);
266
void include_neighbour(Select_Lex_Node *before);
267
void include_standalone(Select_Lex_Node *sel, Select_Lex_Node **ref);
268
void include_global(Select_Lex_Node **plink);
329
virtual st_select_lex_unit* master_unit()= 0;
330
virtual st_select_lex* outer_select()= 0;
331
virtual st_select_lex* return_after_parsing()= 0;
271
virtual Select_Lex_Unit* master_unit()= 0;
272
virtual Select_Lex* outer_select()= 0;
273
virtual Select_Lex* return_after_parsing()= 0;
333
275
virtual bool set_braces(bool value);
334
276
virtual bool inc_in_sum_expr();
342
284
thr_lock_type flags= TL_UNLOCK,
343
285
List<Index_hint> *hints= 0,
344
286
LEX_STRING *option= 0);
345
virtual void set_lock_for_tables(thr_lock_type lock_type __attribute__((unused)))
287
virtual void set_lock_for_tables(thr_lock_type)
348
friend class st_select_lex_unit;
290
friend class Select_Lex_Unit;
349
291
friend bool mysql_new_select(LEX *lex, bool move_down);
351
293
void fast_exclude();
353
typedef class st_select_lex_node SELECT_LEX_NODE;
356
SELECT_LEX_UNIT - unit of selects (UNION, INTERSECT, ...) group
297
Select_Lex_Unit - unit of selects (UNION, INTERSECT, ...) group
360
301
class select_result;
362
303
class select_union;
363
class st_select_lex_unit: public st_select_lex_node {
304
class Select_Lex_Unit: public Select_Lex_Node {
365
306
TableList result_table_list;
366
307
select_union *union_result;
394
335
Pointer to 'last' select or pointer to unit where stored
395
336
global parameters for union
397
st_select_lex *global_parameters;
338
Select_Lex *global_parameters;
398
339
//node on wich we should return current_select pointer after parsing subquery
399
st_select_lex *return_to;
340
Select_Lex *return_to;
400
341
/* LIMIT clause runtime counters */
401
342
ha_rows select_limit_cnt, offset_limit_cnt;
402
343
/* not NULL if unit used in subselect, point to subselect item */
404
345
/* thread handler */
405
346
Session *session;
407
SELECT_LEX for hidden SELECT in onion which process global
348
Select_Lex for hidden SELECT in onion which process global
408
349
ORDER BY and LIMIT
410
st_select_lex *fake_select_lex;
351
Select_Lex *fake_select_lex;
412
st_select_lex *union_distinct; /* pointer to the last UNION DISTINCT */
353
Select_Lex *union_distinct; /* pointer to the last UNION DISTINCT */
413
354
bool describe; /* union exec() called for EXPLAIN */
415
356
void init_query();
416
st_select_lex_unit* master_unit();
417
st_select_lex* outer_select();
418
st_select_lex* first_select()
420
return reinterpret_cast<st_select_lex*>(slave);
422
st_select_lex_unit* next_unit()
424
return reinterpret_cast<st_select_lex_unit*>(next);
426
st_select_lex* return_after_parsing() { return return_to; }
357
Select_Lex_Unit* master_unit();
358
Select_Lex* outer_select();
359
Select_Lex* first_select()
361
return reinterpret_cast<Select_Lex*>(slave);
363
Select_Lex_Unit* next_unit()
365
return reinterpret_cast<Select_Lex_Unit*>(next);
367
Select_Lex* return_after_parsing() { return return_to; }
427
368
void exclude_level();
428
369
void exclude_tree();
430
371
/* UNION methods */
431
bool prepare(Session *session, select_result *result, uint32_t additional_options);
372
bool prepare(Session *session, select_result *result,
373
uint64_t additional_options);
434
376
inline void unclean() { cleaned= 0; }
440
382
void init_prepare_fake_select_lex(Session *session);
441
383
bool change_result(select_result_interceptor *result,
442
384
select_result_interceptor *old_result);
443
void set_limit(st_select_lex *values);
385
void set_limit(Select_Lex *values);
444
386
void set_session(Session *session_arg) { session= session_arg; }
445
inline bool is_union ();
387
inline bool is_union ();
447
389
friend void lex_start(Session *session);
448
390
friend int subselect_union_engine::exec();
472
412
List<Item> item_list; /* list of fields & expressions */
473
413
List<String> interval_list;
474
414
bool is_item_list_lookup;
476
Despite their names, the following are used in unions. This should
479
List<Item_real_func> *ftfunc_list;
480
List<Item_real_func> ftfunc_list_alloc;
481
415
JOIN *join; /* after JOIN::prepare it is pointer to corresponding JOIN */
482
416
List<TableList> top_join_list; /* join list of the top level */
483
417
List<TableList> *join_list; /* list for the currently parsed join */
505
439
uint32_t select_n_having_items;
506
440
uint32_t cond_count; /* number of arguments of and/or/xor in where/having/on */
507
441
uint32_t between_count; /* number of between predicates in where/having/on */
508
uint32_t max_equal_elems; /* maximal number of elements in multiple equalities */
442
uint32_t max_equal_elems; /* maximal number of elements in multiple equalities */
510
444
Number of fields used in select list or where clause of current select
511
445
and all inner subselects.
513
447
uint32_t select_n_where_fields;
514
448
enum_parsing_place parsing_place; /* where we are parsing expression */
515
449
bool with_sum_func; /* sum function indicator */
517
PS or SP cond natural joins was alredy processed with permanent
518
arena and all additional items which we need alredy stored in it
520
bool conds_processed_with_permanent_arena;
522
451
uint32_t table_join_options;
523
452
uint32_t in_sum_expr;
524
453
uint32_t select_number; /* number of select (used for EXPLAIN) */
525
int nest_level; /* nesting level of select */
526
Item_sum *inner_sum_func_list; /* list of sum func in nested selects */
454
int8_t nest_level; /* nesting level of select */
455
Item_sum *inner_sum_func_list; /* list of sum func in nested selects */
527
456
uint32_t with_wild; /* item list contain '*' */
528
457
bool braces; /* SELECT ... UNION (SELECT ... ) <- this braces */
529
458
/* true when having fix field called in processing of this SELECT */
551
480
/* index in the select list of the expression currently being fixed */
552
481
int cur_pos_in_select_list;
554
List<udf_func> udf_list; /* udf function calls stack */
556
484
This is a copy of the original JOIN USING list that comes from
557
485
the parser. The parser :
558
486
1. Sets the natural_join of the second TableList in the join
559
and the st_select_lex::prev_join_using.
487
and the Select_Lex::prev_join_using.
560
488
2. Makes a parent TableList and sets its is_natural_join/
561
489
join_using_fields members.
562
490
3. Uses the wrapper TableList as a table in the upper level.
578
506
uint8_t full_group_by_flag;
579
507
void init_query();
580
508
void init_select();
581
st_select_lex_unit* master_unit();
582
st_select_lex_unit* first_inner_unit()
584
return (st_select_lex_unit*) slave;
586
st_select_lex* outer_select();
587
st_select_lex* next_select() { return (st_select_lex*) next; }
588
st_select_lex* next_select_in_list()
590
return (st_select_lex*) link_next;
592
st_select_lex_node** next_select_in_list_addr()
509
Select_Lex_Unit* master_unit();
510
Select_Lex_Unit* first_inner_unit()
512
return (Select_Lex_Unit*) slave;
514
Select_Lex* outer_select();
515
Select_Lex* next_select() { return (Select_Lex*) next; }
516
Select_Lex* next_select_in_list()
518
return (Select_Lex*) link_next;
520
Select_Lex_Node** next_select_in_list_addr()
594
522
return &link_next;
596
st_select_lex* return_after_parsing()
524
Select_Lex* return_after_parsing()
598
526
return master_unit()->return_after_parsing();
601
void mark_as_dependent(st_select_lex *last);
529
void mark_as_dependent(Select_Lex *last);
603
531
bool set_braces(bool value);
604
532
bool inc_in_sum_expr();
632
560
This method created for reiniting LEX in mysql_admin_table() and can be
633
used only if you are going remove all SELECT_LEX & units except belonger
561
used only if you are going remove all Select_Lex & units except belonger
634
562
to LEX (LEX::unit & LEX::select, for other purposes there are
635
SELECT_LEX_UNIT::exclude_level & SELECT_LEX_UNIT::exclude_tree
563
Select_Lex_Unit::exclude_level & Select_Lex_Unit::exclude_tree
637
565
void cut_subtree() { slave= 0; }
638
566
bool test_limit();
640
568
friend void lex_start(Session *session);
641
st_select_lex() : n_sum_items(0), n_child_sum_items(0) {}
569
Select_Lex() : n_sum_items(0), n_child_sum_items(0) {}
642
570
void make_empty_select()
665
593
void set_index_hint_type(enum index_hint_type type, index_clause_map clause);
668
596
Add a index hint to the tagged list of hints. The type and clause of the
669
hint will be the current ones (set by set_index_hint())
597
hint will be the current ones (set by set_index_hint())
671
599
bool add_index_hint (Session *session, char *str, uint32_t length);
673
601
/* make a list to hold index hints */
674
602
void alloc_index_hints (Session *session);
675
603
/* read and clear the index hints */
676
List<Index_hint>* pop_index_hints(void)
604
List<Index_hint>* pop_index_hints(void)
678
606
List<Index_hint> *hints= index_hints;
679
607
index_hints= NULL;
683
611
void clear_index_hints(void) { index_hints= NULL; }
686
614
/* current index hint kind. used in filling up index_hints */
687
615
enum index_hint_type current_index_hint_type;
688
616
index_clause_map current_index_hint_clause;
689
617
/* a list of USE/FORCE/IGNORE INDEX */
690
618
List<Index_hint> *index_hints;
692
typedef class st_select_lex SELECT_LEX;
694
inline bool st_select_lex_unit::is_union ()
696
return first_select()->next_select() &&
621
inline bool Select_Lex_Unit::is_union ()
623
return first_select()->next_select() &&
697
624
first_select()->next_select()->linkage == UNION_TYPE;
1268
1191
class LEX : public Query_tables_list
1271
SELECT_LEX_UNIT unit; /* most upper unit */
1272
SELECT_LEX select_lex; /* first SELECT_LEX */
1273
/* current SELECT_LEX in parsing */
1274
SELECT_LEX *current_select;
1275
/* list of all SELECT_LEX */
1276
SELECT_LEX *all_selects_list;
1194
Select_Lex_Unit unit; /* most upper unit */
1195
Select_Lex select_lex; /* first Select_Lex */
1196
/* current Select_Lex in parsing */
1197
Select_Lex *current_select;
1198
/* list of all Select_Lex */
1199
Select_Lex *all_selects_list;
1278
1201
char *length,*dec,*change;
1279
1202
LEX_STRING name;
1281
char* to_log; /* For PURGE MASTER LOGS TO */
1283
sql_exchange *exchange;
1204
file_exchange *exchange;
1284
1205
select_result *result;
1285
1206
Item *default_value, *on_update_value;
1286
1207
LEX_STRING comment, ident;
1288
1209
unsigned char* yacc_yyss, *yacc_yyvs;
1289
1210
Session *session;
1290
virtual_column_info *vcol_info;
1292
/* maintain a list of used plugins for this LEX */
1293
DYNAMIC_ARRAY plugins;
1294
plugin_ref plugins_static_buffer[INITIAL_LEX_PLUGIN_LIST_SIZE];
1296
1212
const CHARSET_INFO *charset;
1297
1213
bool text_string_is_7bit;
1301
1217
List<Key_part_spec> col_list;
1302
1218
List<Key_part_spec> ref_list;
1303
1219
List<String> interval_list;
1304
List<LEX_COLUMN> columns;
1220
List<Lex_Column> columns;
1305
1221
List<Item> *insert_list,field_list,value_list,update_list;
1306
1222
List<List_item> many_values;
1307
1223
List<set_var_base> var_list;
1322
1238
List<Name_resolution_context> context_stack;
1323
1239
List<LEX_STRING> db_list;
1325
SQL_LIST proc_list, auxiliary_table_list, save_list;
1241
SQL_LIST auxiliary_table_list, save_list;
1326
1242
Create_field *last_field;
1327
1243
Item_sum *in_sum_func;
1244
Function_builder *udf;
1329
1245
HA_CHECK_OPT check_opt; // check/repair options
1330
1246
HA_CREATE_INFO create_info;
1331
1247
KEY_CREATE_INFO key_create_info;
1332
LEX_MASTER_INFO mi; // used by CHANGE MASTER
1335
1250
This variable is used in post-parse stage to declare that sum-functions,
1400
1307
Alter_info alter_info;
1403
field_list was created for view and should be removed before PS/SP
1406
bool empty_field_list_on_rset;
1409
1310
Pointers to part of LOAD DATA statement that should be rewritten
1410
1311
during replication ("LOCAL 'filename' REPLACE INTO" part).
1412
1313
const char *fname_start;
1413
1314
const char *fname_end;
1416
During name resolution search only in the table list given by
1317
During name resolution search only in the table list given by
1417
1318
Name_resolution_context::first_name_resolution_table and
1418
1319
Name_resolution_context::last_name_resolution_table
1419
(see Item_field::fix_fields()).
1320
(see Item_field::fix_fields()).
1421
1322
bool use_only_table_context;
1423
1324
bool escape_used;
1424
1325
bool is_lex_started; /* If lex_start() did run. For debugging. */
1463
1361
static void cleanup_lex_after_parse_error(Session *session);
1465
void reset_n_backup_query_tables_list(Query_tables_list *backup);
1466
void restore_backup_query_tables_list(Query_tables_list *backup);
1468
bool table_or_sp_used();
1471
1364
@brief check if the statement is a single-level join
1472
1365
@return result of the check
1473
@retval true The statement doesn't contain subqueries, unions and
1366
@retval true The statement doesn't contain subqueries, unions and
1474
1367
stored procedure calls.
1475
1368
@retval false There are subqueries, UNIONs or stored procedure calls.
1477
bool is_single_level_stmt()
1370
bool is_single_level_stmt()
1480
1373
This check exploits the fact that the last added to all_select_list is
1481
on its top. So select_lex (as the first added) will be at the tail
1374
on its top. So select_lex (as the first added) will be at the tail
1484
1377
if (&select_lex == all_selects_list)
1486
1379
assert(!all_selects_list->next_select_in_list());
1493
struct st_lex_local: public LEX
1495
static void *operator new(size_t size) throw()
1497
return sql_alloc(size);
1499
static void *operator new(size_t size, MEM_ROOT *mem_root) throw()
1501
return (void*) alloc_root(mem_root, (uint32_t) size);
1503
static void operator delete(void *ptr __attribute__((unused)),
1504
size_t size __attribute__((unused)))
1505
{ TRASH(ptr, size); }
1506
static void operator delete(void *ptr __attribute__((unused)),
1507
MEM_ROOT *mem_root __attribute__((unused)))
1508
{ /* Never called */ }
1511
extern void lex_init(void);
1512
extern void lex_free(void);
1513
1386
extern void lex_start(Session *session);
1514
1387
extern void lex_end(LEX *lex);