1
/* Copyright (C) 2000-2006 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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.
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.
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
16
20
#ifndef DRIZZLE_SERVER_SQL_LEX_H
17
21
#define DRIZZLE_SERVER_SQL_LEX_H
66
72
SQLCOM_SHOW_KEYS, SQLCOM_SHOW_VARIABLES, SQLCOM_SHOW_STATUS,
67
73
SQLCOM_SHOW_ENGINE_LOGS, SQLCOM_SHOW_ENGINE_STATUS, SQLCOM_SHOW_ENGINE_MUTEX,
68
74
SQLCOM_SHOW_PROCESSLIST, SQLCOM_SHOW_MASTER_STAT, SQLCOM_SHOW_SLAVE_STAT,
69
SQLCOM_SHOW_CREATE, SQLCOM_SHOW_CHARSETS,
70
SQLCOM_SHOW_COLLATIONS, SQLCOM_SHOW_CREATE_DB, SQLCOM_SHOW_TABLE_STATUS,
76
SQLCOM_SHOW_CREATE_DB,
77
SQLCOM_SHOW_TABLE_STATUS,
71
78
SQLCOM_LOAD,SQLCOM_SET_OPTION,SQLCOM_LOCK_TABLES,SQLCOM_UNLOCK_TABLES,
72
79
SQLCOM_CHANGE_DB, SQLCOM_CREATE_DB, SQLCOM_DROP_DB, SQLCOM_ALTER_DB,
73
80
SQLCOM_REPAIR, SQLCOM_REPLACE, SQLCOM_REPLACE_SELECT,
81
88
SQLCOM_RENAME_TABLE,
82
89
SQLCOM_RESET, SQLCOM_PURGE, SQLCOM_PURGE_BEFORE, SQLCOM_SHOW_BINLOGS,
83
90
SQLCOM_SHOW_OPEN_TABLES,
84
SQLCOM_SHOW_SLAVE_HOSTS, SQLCOM_DELETE_MULTI, SQLCOM_UPDATE_MULTI,
85
SQLCOM_SHOW_BINLOG_EVENTS,
86
SQLCOM_SHOW_WARNS, SQLCOM_EMPTY_QUERY, SQLCOM_SHOW_ERRORS,
91
SQLCOM_DELETE_MULTI, SQLCOM_UPDATE_MULTI,
88
96
SQLCOM_BINLOG_BASE64_EVENT,
89
97
SQLCOM_SHOW_PLUGINS,
125
133
Enum is used for making it possible to detect if the user
126
134
changed variable or if it should be left at old value
128
enum {LEX_MI_UNCHANGED, LEX_MI_DISABLE, LEX_MI_ENABLE}
129
ssl, ssl_verify_server_cert, heartbeat_opt;
130
char *ssl_key, *ssl_cert, *ssl_ca, *ssl_capath, *ssl_cipher;
136
enum {LEX_MI_UNCHANGED, LEX_MI_DISABLE, LEX_MI_ENABLE} heartbeat_opt;
131
137
char *relay_log_name;
132
138
uint32_t relay_log_pos;
133
139
} LEX_MASTER_INFO;
154
160
Keep in sync with index_hint_type.
156
162
extern const char * index_hint_type_name[];
157
typedef uchar index_clause_map;
163
typedef unsigned char index_clause_map;
160
166
Bits in index_clause_map : one for each possible FOR clause in
368
374
virtual TableList* get_table_list();
369
375
virtual List<Item>* get_item_list();
370
376
virtual uint32_t get_table_join_options();
371
virtual TableList *add_table_to_list(THD *thd, Table_ident *table,
377
virtual TableList *add_table_to_list(Session *session, Table_ident *table,
372
378
LEX_STRING *alias,
373
379
uint32_t table_options,
374
380
thr_lock_type flags= TL_UNLOCK,
449
455
st_select_lex* outer_select();
450
456
st_select_lex* first_select()
452
return my_reinterpret_cast(st_select_lex*)(slave);
458
return reinterpret_cast<st_select_lex*>(slave);
454
460
st_select_lex_unit* next_unit()
456
return my_reinterpret_cast(st_select_lex_unit*)(next);
462
return reinterpret_cast<st_select_lex_unit*>(next);
458
464
st_select_lex* return_after_parsing() { return return_to; }
459
465
void exclude_level();
460
466
void exclude_tree();
462
468
/* UNION methods */
463
bool prepare(THD *thd, select_result *result, uint32_t additional_options);
469
bool prepare(Session *session, select_result *result, uint32_t additional_options);
466
472
inline void unclean() { cleaned= 0; }
469
475
void print(String *str, enum_query_type query_type);
471
bool add_fake_select_lex(THD *thd);
472
void init_prepare_fake_select_lex(THD *thd);
477
bool add_fake_select_lex(Session *session);
478
void init_prepare_fake_select_lex(Session *session);
473
479
bool change_result(select_result_interceptor *result,
474
480
select_result_interceptor *old_result);
475
481
void set_limit(st_select_lex *values);
476
void set_thd(THD *thd_arg) { thd= thd_arg; }
482
void set_session(Session *session_arg) { session= session_arg; }
477
483
inline bool is_union ();
479
friend void lex_start(THD *thd);
485
friend void lex_start(Session *session);
480
486
friend int subselect_union_engine::exec();
482
488
List<Item> *get_unit_column_types();
576
582
bool subquery_in_having;
577
583
/* true <=> this SELECT is correlated w.r.t. some ancestor select */
578
584
bool is_correlated;
580
This variable is required to ensure proper work of subqueries and
581
stored procedures. Generally, one should use the states of
582
Query_arena to determine if it's a statement prepare or first
583
execution of a stored procedure. However, in case when there was an
584
error during the first execution of a stored procedure, the SP body
585
is not expelled from the SP cache. Therefore, a deeply nested
586
subquery might be left unoptimized. So we need this per-subquery
587
variable to inidicate the optimization/execution state of every
588
subquery. Prepared statements work OK in that regard, as in
589
case of an error during prepare the PS is not created.
591
bool first_execution;
592
bool first_cond_optimization;
593
585
/* exclude this select from check of unique_table() */
594
586
bool exclude_from_table_unique_test;
595
587
/* List of fields that aren't under an aggregate function */
650
642
bool inc_in_sum_expr();
651
643
uint32_t get_in_sum_expr();
653
bool add_item_to_list(THD *thd, Item *item);
654
bool add_group_to_list(THD *thd, Item *item, bool asc);
655
bool add_order_to_list(THD *thd, Item *item, bool asc);
656
TableList* add_table_to_list(THD *thd, Table_ident *table,
645
bool add_item_to_list(Session *session, Item *item);
646
bool add_group_to_list(Session *session, Item *item, bool asc);
647
bool add_order_to_list(Session *session, Item *item, bool asc);
648
TableList* add_table_to_list(Session *session, Table_ident *table,
657
649
LEX_STRING *alias,
658
650
uint32_t table_options,
659
651
thr_lock_type flags= TL_UNLOCK,
660
652
List<Index_hint> *hints= 0,
661
653
LEX_STRING *option= 0);
662
654
TableList* get_table_list();
663
bool init_nested_join(THD *thd);
664
TableList *end_nested_join(THD *thd);
665
TableList *nest_last_join(THD *thd);
655
bool init_nested_join(Session *session);
656
TableList *end_nested_join(Session *session);
657
TableList *nest_last_join(Session *session);
666
658
void add_joined_table(TableList *table);
667
659
TableList *convert_right_join();
668
660
List<Item>* get_item_list();
683
675
void cut_subtree() { slave= 0; }
684
676
bool test_limit();
686
friend void lex_start(THD *thd);
678
friend void lex_start(Session *session);
687
679
st_select_lex() : n_sum_items(0), n_child_sum_items(0) {}
688
680
void make_empty_select()
693
bool setup_ref_array(THD *thd, uint32_t order_group_num);
694
void print(THD *thd, String *str, enum_query_type query_type);
685
bool setup_ref_array(Session *session, uint32_t order_group_num);
686
void print(Session *session, String *str, enum_query_type query_type);
695
687
static void print_order(String *str,
697
689
enum_query_type query_type);
698
void print_limit(THD *thd, String *str, enum_query_type query_type);
699
void fix_prepare_information(THD *thd, Item **conds, Item **having_conds);
690
void print_limit(Session *session, String *str, enum_query_type query_type);
691
void fix_prepare_information(Session *session, Item **conds, Item **having_conds);
701
693
Destroy the used execution plan (JOIN) of this subtree (this
702
694
SELECT_LEX and all nested SELECT_LEXes and SELECT_LEX_UNITs).
714
706
Add a index hint to the tagged list of hints. The type and clause of the
715
707
hint will be the current ones (set by set_index_hint())
717
bool add_index_hint (THD *thd, char *str, uint32_t length);
709
bool add_index_hint (Session *session, char *str, uint32_t length);
719
711
/* make a list to hold index hints */
720
void alloc_index_hints (THD *thd);
712
void alloc_index_hints (Session *session);
721
713
/* read and clear the index hints */
722
714
List<Index_hint>* pop_index_hints(void)
1237
1229
return m_body_utf8_ptr - m_body_utf8;
1240
void body_utf8_start(THD *thd, const char *begin_ptr);
1232
void body_utf8_start(Session *session, const char *begin_ptr);
1241
1233
void body_utf8_append(const char *ptr);
1242
1234
void body_utf8_append(const char *ptr, const char *end_ptr);
1243
void body_utf8_append_literal(THD *thd,
1235
void body_utf8_append_literal(Session *session,
1244
1236
const LEX_STRING *txt,
1245
1237
const CHARSET_INFO * const txt_cs,
1246
1238
const char *end_ptr);
1248
1240
/** Current thread. */
1251
1243
/** Current line number. */
1252
1244
uint32_t yylineno;
1336
1328
const char *found_semicolon;
1338
1330
/** Token character bitmaps, to detect 7bit strings. */
1331
unsigned char tok_bitmap;
1341
1333
/** SQL_MODE = IGNORE_SPACE. */
1342
1334
bool ignore_space;
1348
1340
Starting position of the TEXT_STRING or IDENT in the pre-processed
1351
NOTE: this member must be used within MYSQLlex() function only.
1343
NOTE: this member must be used within DRIZZLElex() function only.
1353
1345
const char *m_cpp_text_start;
1356
1348
Ending position of the TEXT_STRING or IDENT in the pre-processed
1359
NOTE: this member must be used within MYSQLlex() function only.
1351
NOTE: this member must be used within DRIZZLElex() function only.
1361
1353
const char *m_cpp_text_end;
1364
1356
Character set specified by the character-set-introducer.
1366
NOTE: this member must be used within MYSQLlex() function only.
1358
NOTE: this member must be used within DRIZZLElex() function only.
1368
1360
const CHARSET_INFO *m_underscore_cs;
1372
/* The state of the lex parsing. This is saved in the THD struct */
1364
/* The state of the lex parsing. This is saved in the Session struct */
1374
1366
typedef struct st_lex : public Query_tables_list
1384
1376
LEX_STRING name;
1385
1377
char *help_arg;
1386
1378
char* to_log; /* For PURGE MASTER LOGS TO */
1387
char* x509_subject,*x509_issuer,*ssl_cipher;
1389
1380
sql_exchange *exchange;
1390
1381
select_result *result;
1391
1382
Item *default_value, *on_update_value;
1392
1383
LEX_STRING comment, ident;
1394
uchar* yacc_yyss, *yacc_yyvs;
1385
unsigned char* yacc_yyss, *yacc_yyvs;
1387
virtual_column_info *vcol_info;
1397
1389
/* maintain a list of used plugins for this LEX */
1398
1390
DYNAMIC_ARRAY plugins;
1455
1447
syntax error back.
1457
1449
bool expr_allows_subselect;
1451
A special command "PARSE_VCOL_EXPR" is defined for the parser
1452
to translate an expression statement of a virtual column \
1453
(stored in the *.frm file as a string) into an Item object.
1454
The following flag is used to prevent other applications to use
1457
bool parse_vcol_expr;
1459
1459
thr_lock_type lock_option;
1460
1460
enum enum_duplicates duplicates;
1474
1474
enum Foreign_key::fk_match_opt fk_match_option;
1475
1475
enum Foreign_key::fk_option fk_update_opt;
1476
1476
enum Foreign_key::fk_option fk_delete_opt;
1477
uint32_t slave_thd_opt, start_transaction_opt;
1477
uint32_t slave_session_opt, start_transaction_opt;
1478
1478
int nest_level;
1480
1480
In LEX representing update which were transformed to multi-update
1559
1559
return context_stack.head();
1562
Restore the LEX and THD in case of a parse error.
1562
Restore the LEX and Session in case of a parse error.
1564
static void cleanup_lex_after_parse_error(THD *thd);
1564
static void cleanup_lex_after_parse_error(Session *session);
1566
1566
void reset_n_backup_query_tables_list(Query_tables_list *backup);
1567
1567
void restore_backup_query_tables_list(Query_tables_list *backup);
1612
1612
extern void lex_init(void);
1613
1613
extern void lex_free(void);
1614
extern void lex_start(THD *thd);
1614
extern void lex_start(Session *session);
1615
1615
extern void lex_end(LEX *lex);
1617
1617
extern void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str);