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/item/param.h>
31
#include <drizzled/item/outer_ref.h>
32
#include <drizzled/table_list.h>
33
#include <drizzled/function/math/real.h>
34
#include <drizzled/alter_drop.h>
35
#include <drizzled/alter_column.h>
36
#include <drizzled/key.h>
37
#include <drizzled/foreign_key.h>
38
#include <drizzled/item/param.h>
40
class select_result_interceptor;
41
class virtual_column_info;
29
43
/* YACC and LEX Definitions */
31
45
/* These may not be declared yet */
38
52
The following hack is needed because mysql_yacc.cc does not define
39
53
YYSTYPE before including this file
45
#define LEX_YYSTYPE void *
47
#if defined(DRIZZLE_LEX)
48
#include "lex_symbol.h"
50
#define LEX_YYSTYPE YYSTYPE *
52
#define LEX_YYSTYPE void *
58
When a command is added here, be sure it's also added in mysqld.cc
59
in "struct show_var_st status_vars[]= {" ...
61
If the command returns a result set or is not allowed in stored
62
functions or triggers, please also make sure that
63
sp_get_flags_for_command (sp_head.cc) returns proper flags for the
67
enum enum_sql_command {
68
SQLCOM_SELECT, SQLCOM_CREATE_TABLE, SQLCOM_CREATE_INDEX, SQLCOM_ALTER_TABLE,
69
SQLCOM_UPDATE, SQLCOM_INSERT, SQLCOM_INSERT_SELECT,
70
SQLCOM_DELETE, SQLCOM_TRUNCATE, SQLCOM_DROP_TABLE, SQLCOM_DROP_INDEX,
71
SQLCOM_SHOW_DATABASES, SQLCOM_SHOW_TABLES, SQLCOM_SHOW_FIELDS,
72
SQLCOM_SHOW_KEYS, SQLCOM_SHOW_VARIABLES, SQLCOM_SHOW_STATUS,
73
SQLCOM_SHOW_ENGINE_LOGS, SQLCOM_SHOW_ENGINE_STATUS, SQLCOM_SHOW_ENGINE_MUTEX,
74
SQLCOM_SHOW_PROCESSLIST, SQLCOM_SHOW_MASTER_STAT, SQLCOM_SHOW_SLAVE_STAT,
75
SQLCOM_SHOW_CREATE, SQLCOM_SHOW_CHARSETS,
76
SQLCOM_SHOW_COLLATIONS, SQLCOM_SHOW_CREATE_DB, SQLCOM_SHOW_TABLE_STATUS,
77
SQLCOM_LOAD,SQLCOM_SET_OPTION,SQLCOM_LOCK_TABLES,SQLCOM_UNLOCK_TABLES,
78
SQLCOM_CHANGE_DB, SQLCOM_CREATE_DB, SQLCOM_DROP_DB, SQLCOM_ALTER_DB,
79
SQLCOM_REPAIR, SQLCOM_REPLACE, SQLCOM_REPLACE_SELECT,
80
SQLCOM_OPTIMIZE, SQLCOM_CHECK,
81
SQLCOM_ASSIGN_TO_KEYCACHE,
82
SQLCOM_FLUSH, SQLCOM_KILL, SQLCOM_ANALYZE,
83
SQLCOM_ROLLBACK, SQLCOM_ROLLBACK_TO_SAVEPOINT,
84
SQLCOM_COMMIT, SQLCOM_SAVEPOINT, SQLCOM_RELEASE_SAVEPOINT,
85
SQLCOM_SLAVE_START, SQLCOM_SLAVE_STOP,
86
SQLCOM_BEGIN, SQLCOM_CHANGE_MASTER,
88
SQLCOM_RESET, SQLCOM_PURGE, SQLCOM_PURGE_BEFORE, SQLCOM_SHOW_BINLOGS,
89
SQLCOM_SHOW_OPEN_TABLES,
90
SQLCOM_SHOW_SLAVE_HOSTS, SQLCOM_DELETE_MULTI, SQLCOM_UPDATE_MULTI,
91
SQLCOM_SHOW_BINLOG_EVENTS,
92
SQLCOM_SHOW_WARNS, SQLCOM_EMPTY_QUERY, SQLCOM_SHOW_ERRORS,
94
SQLCOM_BINLOG_BASE64_EVENT,
97
When a command is added here, be sure it's also added in mysqld.cc
98
in "struct show_var_st status_vars[]= {" ...
100
/* This should be the last !!! */
57
# include <drizzled/set_var.h>
58
# include <drizzled/item/func.h>
60
# define LEX_YYSTYPE void *
62
# if defined(DRIZZLE_LEX)
63
# include <drizzled/lex_symbol.h>
64
# include <drizzled/sql_yacc.h>
65
# define LEX_YYSTYPE YYSTYPE *
67
# define LEX_YYSTYPE void *
68
# endif /* defined(DRIZZLE_LEX) */
69
# endif /* DRIZZLE_YACC */
70
#endif /* DRIZZLE_SERVER */
104
72
// describe/explain types
105
73
#define DESCRIBE_NORMAL 1
120
88
char *server_name, *host, *db, *username, *password, *scheme, *owner;
121
89
} LEX_SERVER_OPTIONS;
123
typedef struct st_lex_master_info
125
char *host, *user, *password, *log_file_name;
126
uint32_t port, connect_retry;
127
float heartbeat_period;
131
Enum is used for making it possible to detect if the user
132
changed variable or if it should be left at old value
134
enum {LEX_MI_UNCHANGED, LEX_MI_DISABLE, LEX_MI_ENABLE}
135
ssl, ssl_verify_server_cert, heartbeat_opt;
136
char *ssl_key, *ssl_cert, *ssl_ca, *ssl_capath, *ssl_cipher;
137
char *relay_log_name;
138
uint32_t relay_log_pos;
142
92
enum sub_select_type
348
298
static void *operator new(size_t size, MEM_ROOT *mem_root)
349
299
{ return (void*) alloc_root(mem_root, (uint32_t) size); }
350
static void operator delete(void *ptr __attribute__((unused)),
351
size_t size __attribute__((unused)))
300
static void operator delete(void *, size_t)
352
301
{ TRASH(ptr, size); }
353
static void operator delete(void *ptr __attribute__((unused)),
354
MEM_ROOT *mem_root __attribute__((unused)))
302
static void operator delete(void *, MEM_ROOT *)
356
st_select_lex_node(): linkage(UNSPECIFIED_TYPE) {}
357
virtual ~st_select_lex_node() {}
358
inline st_select_lex_node* get_master() { return master; }
304
Select_Lex_Node(): linkage(UNSPECIFIED_TYPE) {}
305
virtual ~Select_Lex_Node() {}
306
inline Select_Lex_Node* get_master() { return master; }
359
307
virtual void init_query();
360
308
virtual void init_select();
361
void include_down(st_select_lex_node *upper);
362
void include_neighbour(st_select_lex_node *before);
363
void include_standalone(st_select_lex_node *sel, st_select_lex_node **ref);
364
void include_global(st_select_lex_node **plink);
309
void include_down(Select_Lex_Node *upper);
310
void include_neighbour(Select_Lex_Node *before);
311
void include_standalone(Select_Lex_Node *sel, Select_Lex_Node **ref);
312
void include_global(Select_Lex_Node **plink);
367
virtual st_select_lex_unit* master_unit()= 0;
368
virtual st_select_lex* outer_select()= 0;
369
virtual st_select_lex* return_after_parsing()= 0;
315
virtual Select_Lex_Unit* master_unit()= 0;
316
virtual Select_Lex* outer_select()= 0;
317
virtual Select_Lex* return_after_parsing()= 0;
371
319
virtual bool set_braces(bool value);
372
320
virtual bool inc_in_sum_expr();
374
322
virtual TableList* get_table_list();
375
323
virtual List<Item>* get_item_list();
376
324
virtual uint32_t get_table_join_options();
377
virtual TableList *add_table_to_list(THD *thd, Table_ident *table,
325
virtual TableList *add_table_to_list(Session *session, Table_ident *table,
378
326
LEX_STRING *alias,
379
327
uint32_t table_options,
380
328
thr_lock_type flags= TL_UNLOCK,
381
329
List<Index_hint> *hints= 0,
382
330
LEX_STRING *option= 0);
383
virtual void set_lock_for_tables(thr_lock_type lock_type __attribute__((unused)))
331
virtual void set_lock_for_tables(thr_lock_type)
386
friend class st_select_lex_unit;
387
friend bool mysql_new_select(struct st_lex *lex, bool move_down);
334
friend class Select_Lex_Unit;
335
friend bool mysql_new_select(LEX *lex, bool move_down);
389
337
void fast_exclude();
391
typedef class st_select_lex_node SELECT_LEX_NODE;
394
SELECT_LEX_UNIT - unit of selects (UNION, INTERSECT, ...) group
341
Select_Lex_Unit - unit of selects (UNION, INTERSECT, ...) group
398
345
class select_result;
400
347
class select_union;
401
class st_select_lex_unit: public st_select_lex_node {
348
class Select_Lex_Unit: public Select_Lex_Node {
403
350
TableList result_table_list;
404
351
select_union *union_result;
432
379
Pointer to 'last' select or pointer to unit where stored
433
380
global parameters for union
435
st_select_lex *global_parameters;
382
Select_Lex *global_parameters;
436
383
//node on wich we should return current_select pointer after parsing subquery
437
st_select_lex *return_to;
384
Select_Lex *return_to;
438
385
/* LIMIT clause runtime counters */
439
386
ha_rows select_limit_cnt, offset_limit_cnt;
440
387
/* not NULL if unit used in subselect, point to subselect item */
441
388
Item_subselect *item;
442
389
/* thread handler */
445
SELECT_LEX for hidden SELECT in onion which process global
392
Select_Lex for hidden SELECT in onion which process global
446
393
ORDER BY and LIMIT
448
st_select_lex *fake_select_lex;
395
Select_Lex *fake_select_lex;
450
st_select_lex *union_distinct; /* pointer to the last UNION DISTINCT */
397
Select_Lex *union_distinct; /* pointer to the last UNION DISTINCT */
451
398
bool describe; /* union exec() called for EXPLAIN */
453
400
void init_query();
454
st_select_lex_unit* master_unit();
455
st_select_lex* outer_select();
456
st_select_lex* first_select()
458
return reinterpret_cast<st_select_lex*>(slave);
460
st_select_lex_unit* next_unit()
462
return reinterpret_cast<st_select_lex_unit*>(next);
464
st_select_lex* return_after_parsing() { return return_to; }
401
Select_Lex_Unit* master_unit();
402
Select_Lex* outer_select();
403
Select_Lex* first_select()
405
return reinterpret_cast<Select_Lex*>(slave);
407
Select_Lex_Unit* next_unit()
409
return reinterpret_cast<Select_Lex_Unit*>(next);
411
Select_Lex* return_after_parsing() { return return_to; }
465
412
void exclude_level();
466
413
void exclude_tree();
468
415
/* UNION methods */
469
bool prepare(THD *thd, select_result *result, uint32_t additional_options);
416
bool prepare(Session *session, select_result *result, uint32_t additional_options);
472
419
inline void unclean() { cleaned= 0; }
475
422
void print(String *str, enum_query_type query_type);
477
bool add_fake_select_lex(THD *thd);
478
void init_prepare_fake_select_lex(THD *thd);
424
bool add_fake_select_lex(Session *session);
425
void init_prepare_fake_select_lex(Session *session);
479
426
bool change_result(select_result_interceptor *result,
480
427
select_result_interceptor *old_result);
481
void set_limit(st_select_lex *values);
482
void set_thd(THD *thd_arg) { thd= thd_arg; }
483
inline bool is_union ();
428
void set_limit(Select_Lex *values);
429
void set_session(Session *session_arg) { session= session_arg; }
430
inline bool is_union ();
485
friend void lex_start(THD *thd);
432
friend void lex_start(Session *session);
486
433
friend int subselect_union_engine::exec();
488
435
List<Item> *get_unit_column_types();
491
typedef class st_select_lex_unit SELECT_LEX_UNIT;
494
SELECT_LEX - store information of parsed SELECT statment
439
Select_Lex - store information of parsed SELECT statment
496
class st_select_lex: public st_select_lex_node
441
class Select_Lex: public Select_Lex_Node
499
444
Name_resolution_context context;
616
556
uint8_t full_group_by_flag;
617
557
void init_query();
618
558
void init_select();
619
st_select_lex_unit* master_unit();
620
st_select_lex_unit* first_inner_unit()
622
return (st_select_lex_unit*) slave;
624
st_select_lex* outer_select();
625
st_select_lex* next_select() { return (st_select_lex*) next; }
626
st_select_lex* next_select_in_list()
628
return (st_select_lex*) link_next;
630
st_select_lex_node** next_select_in_list_addr()
559
Select_Lex_Unit* master_unit();
560
Select_Lex_Unit* first_inner_unit()
562
return (Select_Lex_Unit*) slave;
564
Select_Lex* outer_select();
565
Select_Lex* next_select() { return (Select_Lex*) next; }
566
Select_Lex* next_select_in_list()
568
return (Select_Lex*) link_next;
570
Select_Lex_Node** next_select_in_list_addr()
632
572
return &link_next;
634
st_select_lex* return_after_parsing()
574
Select_Lex* return_after_parsing()
636
576
return master_unit()->return_after_parsing();
639
void mark_as_dependent(st_select_lex *last);
579
void mark_as_dependent(Select_Lex *last);
641
581
bool set_braces(bool value);
642
582
bool inc_in_sum_expr();
643
583
uint32_t get_in_sum_expr();
645
bool add_item_to_list(THD *thd, Item *item);
646
bool add_group_to_list(THD *thd, Item *item, bool asc);
647
bool add_order_to_list(THD *thd, Item *item, bool asc);
648
TableList* add_table_to_list(THD *thd, Table_ident *table,
585
bool add_item_to_list(Session *session, Item *item);
586
bool add_group_to_list(Session *session, Item *item, bool asc);
587
bool add_order_to_list(Session *session, Item *item, bool asc);
588
TableList* add_table_to_list(Session *session, Table_ident *table,
649
589
LEX_STRING *alias,
650
590
uint32_t table_options,
651
591
thr_lock_type flags= TL_UNLOCK,
652
592
List<Index_hint> *hints= 0,
653
593
LEX_STRING *option= 0);
654
594
TableList* get_table_list();
655
bool init_nested_join(THD *thd);
656
TableList *end_nested_join(THD *thd);
657
TableList *nest_last_join(THD *thd);
595
bool init_nested_join(Session *session);
596
TableList *end_nested_join(Session *session);
597
TableList *nest_last_join(Session *session);
658
598
void add_joined_table(TableList *table);
659
599
TableList *convert_right_join();
660
600
List<Item>* get_item_list();
670
610
This method created for reiniting LEX in mysql_admin_table() and can be
671
used only if you are going remove all SELECT_LEX & units except belonger
611
used only if you are going remove all Select_Lex & units except belonger
672
612
to LEX (LEX::unit & LEX::select, for other purposes there are
673
SELECT_LEX_UNIT::exclude_level & SELECT_LEX_UNIT::exclude_tree
613
Select_Lex_Unit::exclude_level & Select_Lex_Unit::exclude_tree
675
615
void cut_subtree() { slave= 0; }
676
616
bool test_limit();
678
friend void lex_start(THD *thd);
679
st_select_lex() : n_sum_items(0), n_child_sum_items(0) {}
618
friend void lex_start(Session *session);
619
Select_Lex() : n_sum_items(0), n_child_sum_items(0) {}
680
620
void make_empty_select()
685
bool setup_ref_array(THD *thd, uint32_t order_group_num);
686
void print(THD *thd, String *str, enum_query_type query_type);
625
bool setup_ref_array(Session *session, uint32_t order_group_num);
626
void print(Session *session, String *str, enum_query_type query_type);
687
627
static void print_order(String *str,
689
629
enum_query_type query_type);
690
void print_limit(THD *thd, String *str, enum_query_type query_type);
691
void fix_prepare_information(THD *thd, Item **conds, Item **having_conds);
630
void print_limit(Session *session, String *str, enum_query_type query_type);
631
void fix_prepare_information(Session *session, Item **conds, Item **having_conds);
693
633
Destroy the used execution plan (JOIN) of this subtree (this
694
SELECT_LEX and all nested SELECT_LEXes and SELECT_LEX_UNITs).
634
Select_Lex and all nested Select_Lexes and Select_Lex_Units).
898
819
query_tables_own_last= 0;
903
Has the parser/scanner detected that this statement is unsafe?
905
inline bool is_stmt_unsafe() const {
906
return binlog_stmt_flags & (1U << BINLOG_STMT_FLAG_UNSAFE);
910
Flag the current (top-level) statement as unsafe.
912
The flag will be reset after the statement has finished.
915
inline void set_stmt_unsafe() {
916
binlog_stmt_flags|= (1U << BINLOG_STMT_FLAG_UNSAFE);
919
inline void clear_stmt_unsafe() {
920
binlog_stmt_flags&= ~(1U << BINLOG_STMT_FLAG_UNSAFE);
924
true if the parsed tree contains references to stored procedures
925
or functions, false otherwise
927
bool uses_stored_routines() const
928
{ return sroutines_list.elements != 0; }
931
enum enum_binlog_stmt_flag {
932
BINLOG_STMT_FLAG_UNSAFE,
933
BINLOG_STMT_FLAG_COUNT
937
Tells if the parsing stage detected properties of the statement,
938
for example: that some items require row-based binlogging to give
939
a reliable binlog/replication, or if we will use stored functions
940
or triggers which themselves need require row-based binlogging.
942
uint32_t binlog_stmt_flags;
1348
1224
Ending position of the TEXT_STRING or IDENT in the pre-processed
1351
NOTE: this member must be used within MYSQLlex() function only.
1227
NOTE: this member must be used within DRIZZLElex() function only.
1353
1229
const char *m_cpp_text_end;
1356
1232
Character set specified by the character-set-introducer.
1358
NOTE: this member must be used within MYSQLlex() function only.
1234
NOTE: this member must be used within DRIZZLElex() function only.
1360
1236
const CHARSET_INFO *m_underscore_cs;
1364
/* The state of the lex parsing. This is saved in the THD struct */
1240
/* The state of the lex parsing. This is saved in the Session struct */
1366
typedef struct st_lex : public Query_tables_list
1242
class LEX : public Query_tables_list
1368
SELECT_LEX_UNIT unit; /* most upper unit */
1369
SELECT_LEX select_lex; /* first SELECT_LEX */
1370
/* current SELECT_LEX in parsing */
1371
SELECT_LEX *current_select;
1372
/* list of all SELECT_LEX */
1373
SELECT_LEX *all_selects_list;
1245
Select_Lex_Unit unit; /* most upper unit */
1246
Select_Lex select_lex; /* first Select_Lex */
1247
/* current Select_Lex in parsing */
1248
Select_Lex *current_select;
1249
/* list of all Select_Lex */
1250
Select_Lex *all_selects_list;
1375
1252
char *length,*dec,*change;
1376
1253
LEX_STRING name;
1378
char* to_log; /* For PURGE MASTER LOGS TO */
1379
char* x509_subject,*x509_issuer,*ssl_cipher;
1381
sql_exchange *exchange;
1255
file_exchange *exchange;
1382
1256
select_result *result;
1383
1257
Item *default_value, *on_update_value;
1384
1258
LEX_STRING comment, ident;
1386
1260
unsigned char* yacc_yyss, *yacc_yyvs;
1389
/* maintain a list of used plugins for this LEX */
1390
DYNAMIC_ARRAY plugins;
1391
plugin_ref plugins_static_buffer[INITIAL_LEX_PLUGIN_LIST_SIZE];
1262
virtual_column_info *vcol_info;
1393
1264
const CHARSET_INFO *charset;
1394
1265
bool text_string_is_7bit;
1490
1367
Alter_info alter_info;
1493
field_list was created for view and should be removed before PS/SP
1496
bool empty_field_list_on_rset;
1499
1370
Pointers to part of LOAD DATA statement that should be rewritten
1500
1371
during replication ("LOCAL 'filename' REPLACE INTO" part).
1502
1373
const char *fname_start;
1503
1374
const char *fname_end;
1506
During name resolution search only in the table list given by
1377
During name resolution search only in the table list given by
1507
1378
Name_resolution_context::first_name_resolution_table and
1508
1379
Name_resolution_context::last_name_resolution_table
1509
(see Item_field::fix_fields()).
1380
(see Item_field::fix_fields()).
1511
1382
bool use_only_table_context;
1513
1384
bool escape_used;
1514
1385
bool is_lex_started; /* If lex_start() did run. For debugging. */
1520
1391
destroy_query_tables_list();
1521
plugin_unlock_list(NULL, (plugin_ref *)plugins.buffer, plugins.elements);
1522
delete_dynamic(&plugins);
1525
1394
TableList *unlink_first_table(bool *link_to_local);
1526
1395
void link_first_table_back(TableList *first, bool link_to_local);
1527
1396
void first_lists_tables_same();
1529
bool can_be_merged();
1530
bool can_use_merged();
1531
bool can_not_use_merged();
1532
1398
bool only_view_structure();
1533
1399
bool need_correct_ident();
1551
1417
return context_stack.head();
1554
Restore the LEX and THD in case of a parse error.
1420
Restore the LEX and Session in case of a parse error.
1556
static void cleanup_lex_after_parse_error(THD *thd);
1558
void reset_n_backup_query_tables_list(Query_tables_list *backup);
1559
void restore_backup_query_tables_list(Query_tables_list *backup);
1561
bool table_or_sp_used();
1422
static void cleanup_lex_after_parse_error(Session *session);
1564
1425
@brief check if the statement is a single-level join
1565
1426
@return result of the check
1566
@retval true The statement doesn't contain subqueries, unions and
1427
@retval true The statement doesn't contain subqueries, unions and
1567
1428
stored procedure calls.
1568
1429
@retval false There are subqueries, UNIONs or stored procedure calls.
1570
bool is_single_level_stmt()
1431
bool is_single_level_stmt()
1573
1434
This check exploits the fact that the last added to all_select_list is
1574
on its top. So select_lex (as the first added) will be at the tail
1435
on its top. So select_lex (as the first added) will be at the tail
1577
if (&select_lex == all_selects_list && !sroutines.records)
1438
if (&select_lex == all_selects_list)
1579
1440
assert(!all_selects_list->next_select_in_list());
1586
struct st_lex_local: public st_lex
1447
struct st_lex_local: public LEX
1588
1449
static void *operator new(size_t size) throw()