34
38
const LEX_STRING null_lex_str= {NULL, 0};
36
/* Longest standard keyword name */
38
#define TOCK_NAME_LENGTH 24
41
42
The following data is based on the latin1 character set, and is only
42
43
used when comparing keywords
45
static uchar to_upper_lex[]=
46
static unsigned char to_upper_lex[]=
47
48
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
48
49
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
62
63
208,209,210,211,212,213,214,247,216,217,218,219,220,221,222,255
66
Names of the index hints (for error messages). Keep in sync with
67
Names of the index hints (for error messages). Keep in sync with
70
71
const char * index_hint_type_name[] =
77
inline int lex_casecmp(const char *s, const char *t, uint len)
78
int lex_casecmp(const char *s, const char *t, uint32_t len)
79
80
while (len-- != 0 &&
80
to_upper_lex[(uchar) *s++] == to_upper_lex[(uchar) *t++]) ;
81
to_upper_lex[(unsigned char) *s++] == to_upper_lex[(unsigned char) *t++]) ;
81
82
return (int) len+1;
85
/* EVIL EVIL - this is included here so that it will have to_upper_lex */
86
#include <drizzled/lex_hash.h>
87
89
void lex_init(void)
90
92
for (i=0 ; i < array_elements(symbols) ; i++)
91
symbols[i].length=(uchar) strlen(symbols[i].name);
93
symbols[i].length=(unsigned char) strlen(symbols[i].name);
92
94
for (i=0 ; i < array_elements(sql_functions) ; i++)
93
sql_functions[i].length=(uchar) strlen(sql_functions[i].name);
95
sql_functions[i].length=(unsigned char) strlen(sql_functions[i].name);
154
153
2) Determine the beginning of the body.
156
@param thd Thread context.
155
@param session Thread context.
157
156
@param begin_ptr Pointer to the start of the body in the pre-processed
161
void Lex_input_stream::body_utf8_start(THD *thd, const char *begin_ptr)
160
void Lex_input_stream::body_utf8_start(Session *session, const char *begin_ptr)
163
162
assert(begin_ptr);
164
163
assert(m_cpp_buf <= begin_ptr && begin_ptr <= m_cpp_buf + m_buf_length);
166
uint body_utf8_length=
167
(m_buf_length / thd->variables.character_set_client->mbminlen) *
165
uint32_t body_utf8_length=
166
(m_buf_length / session->variables.character_set_client->mbminlen) *
168
167
my_charset_utf8_bin.mbmaxlen;
170
m_body_utf8= (char *) thd->alloc(body_utf8_length + 1);
169
m_body_utf8= (char *) session->alloc(body_utf8_length + 1);
171
170
m_body_utf8_ptr= m_body_utf8;
172
171
*m_body_utf8_ptr= 0;
331
329
lex->reset_query_tables_list(false);
332
330
lex->expr_allows_subselect= true;
333
331
lex->use_only_table_context= false;
332
lex->parse_vcol_expr= false;
335
334
lex->name.str= 0;
336
335
lex->name.length= 0;
337
336
lex->nest_level=0 ;
338
337
lex->allow_sum_func= 0;
339
338
lex->in_sum_func= NULL;
341
ok, there must be a better solution for this, long-term
342
I tried "memset" in the sql_yacc.yy code, but that for
343
some reason made the values zero, even if they were set
345
lex->server_options.server_name= 0;
346
lex->server_options.server_name_length= 0;
347
lex->server_options.host= 0;
348
lex->server_options.db= 0;
349
lex->server_options.username= 0;
350
lex->server_options.password= 0;
351
lex->server_options.scheme= 0;
352
lex->server_options.owner= 0;
353
lex->server_options.port= -1;
355
340
lex->is_lex_started= true;
359
343
void lex_end(LEX *lex)
361
345
if (lex->yacc_yyss)
363
my_free(lex->yacc_yyss, MYF(0));
364
my_free(lex->yacc_yyvs, MYF(0));
347
free(lex->yacc_yyss);
348
free(lex->yacc_yyvs);
365
349
lex->yacc_yyss= 0;
366
350
lex->yacc_yyvs= 0;
369
/* release used plugins */
370
plugin_unlock_list(0, (plugin_ref*)lex->plugins.buffer,
371
lex->plugins.elements);
372
reset_dynamic(&lex->plugins);
378
static int find_keyword(Lex_input_stream *lip, uint len, bool function)
358
static int find_keyword(Lex_input_stream *lip, uint32_t len, bool function)
380
360
const char *tok= lip->get_tok_start();
419
400
/* make a copy of token before ptr and set yytoklen */
421
static LEX_STRING get_token(Lex_input_stream *lip, uint skip, uint length)
402
static LEX_STRING get_token(Lex_input_stream *lip, uint32_t skip, uint32_t length)
424
405
lip->yyUnget(); // ptr points now after last token char
425
406
tmp.length=lip->yytoklen=length;
426
tmp.str= lip->m_thd->strmake(lip->get_tok_start() + skip, tmp.length);
407
tmp.str= lip->m_session->strmake(lip->get_tok_start() + skip, tmp.length);
428
409
lip->m_cpp_text_start= lip->get_cpp_tok_start() + skip;
429
410
lip->m_cpp_text_end= lip->m_cpp_text_start + tmp.length;
436
There are no dangerous charsets in mysql for function
437
get_quoted_token yet. But it should be fixed in the
417
There are no dangerous charsets in mysql for function
418
get_quoted_token yet. But it should be fixed in the
438
419
future to operate multichar strings (like ucs2)
441
422
static LEX_STRING get_quoted_token(Lex_input_stream *lip,
443
uint length, char quote)
424
uint32_t length, char quote)
446
427
const char *from, *end;
448
429
lip->yyUnget(); // ptr points now after last token char
449
430
tmp.length= lip->yytoklen=length;
450
tmp.str=(char*) lip->m_thd->alloc(tmp.length+1);
431
tmp.str=(char*) lip->m_session->alloc(tmp.length+1);
451
432
from= lip->get_tok_start() + skip;
603
583
** Calc type of integer; long integer, int64_t integer or real.
604
584
** Returns smallest type that match the string.
605
** When using unsigned long long values the result is converted to a real
585
** When using uint64_t values the result is converted to a real
606
586
** because else they will be unexpected sign changes because all calculation
607
587
** is done with int64_t or double.
610
590
static const char *long_str="2147483647";
611
static const uint long_len=10;
591
static const uint32_t long_len=10;
612
592
static const char *signed_long_str="-2147483648";
613
593
static const char *int64_t_str="9223372036854775807";
614
static const uint int64_t_len=19;
594
static const uint32_t int64_t_len=19;
615
595
static const char *signed_int64_t_str="-9223372036854775808";
616
static const uint signed_int64_t_len=19;
596
static const uint32_t signed_int64_t_len=19;
617
597
static const char *unsigned_int64_t_str="18446744073709551615";
618
static const uint unsigned_int64_t_len=20;
598
static const uint32_t unsigned_int64_t_len=20;
620
static inline uint int_token(const char *str,uint length)
600
static inline uint32_t int_token(const char *str,uint32_t length)
622
602
if (length < long_len) // quick normal case
688
668
while (*cmp && *cmp++ == *str++) ;
689
return ((uchar) str[-1] <= (uchar) cmp[-1]) ? smaller : bigger;
669
return ((unsigned char) str[-1] <= (unsigned char) cmp[-1]) ? smaller : bigger;
694
MYSQLlex remember the following states from the following MYSQLlex()
674
DRIZZLElex remember the following states from the following DRIZZLElex()
696
676
- MY_LEX_EOQ Found end of query
697
677
- MY_LEX_OPERATOR_OR_IDENT Last state was an ident, text or number
698
678
(which can't be followed by a signed number)
701
int MYSQLlex(void *arg, void *yythd)
681
int DRIZZLElex(void *arg, void *yysession)
703
THD *thd= (THD *)yythd;
704
Lex_input_stream *lip= thd->m_lip;
683
Session *session= (Session *)yysession;
684
Lex_input_stream *lip= session->m_lip;
705
685
YYSTYPE *yylval=(YYSTYPE*) arg;
721
token= lex_one_token(arg, yythd);
701
token= lex_one_token(arg, yysession);
726
Parsing 'WITH' 'ROLLUP' or 'WITH' 'CUBE' requires 2 look ups,
706
Parsing 'WITH' 'ROLLUP' requires 2 look ups,
727
707
which makes the grammar LALR(2).
728
708
Replace by a single 'WITH_ROLLUP' or 'WITH_CUBE' token,
729
709
to transform the grammar into a LALR(1) grammar,
730
710
which sql_yacc.yy can process.
732
token= lex_one_token(arg, yythd);
735
return WITH_CUBE_SYM;
712
token= lex_one_token(arg, yysession);
713
if (token == ROLLUP_SYM)
737
715
return WITH_ROLLUP_SYM;
740
720
Save the token following 'WITH'
755
int lex_one_token(void *arg, void *yythd)
735
int lex_one_token(void *arg, void *yysession)
757
737
register unsigned char c= 0; /* Just set to shutup GCC */
758
738
bool comment_closed;
759
739
int tokval, result_state;
760
740
unsigned int length;
761
741
enum my_lex_states state;
762
THD *thd= (THD *)yythd;
763
Lex_input_stream *lip= thd->m_lip;
742
Session *session= (Session *)yysession;
743
Lex_input_stream *lip= session->m_lip;
744
LEX *lex= session->lex;
765
745
YYSTYPE *yylval=(YYSTYPE*) arg;
766
const CHARSET_INFO * const cs= thd->charset();
767
uchar *state_map= cs->state_map;
768
uchar *ident_map= cs->ident_map;
746
const CHARSET_INFO * const cs= session->charset();
747
unsigned char *state_map= cs->state_map;
748
unsigned char *ident_map= cs->ident_map;
770
750
lip->yylval=yylval; // The global state
1814
bool st_select_lex_node::set_braces(bool value __attribute__((unused)))
1791
bool st_select_lex_node::set_braces(bool)
1816
1793
bool st_select_lex_node::inc_in_sum_expr() { return 1; }
1817
uint st_select_lex_node::get_in_sum_expr() { return 0; }
1818
TABLE_LIST* st_select_lex_node::get_table_list() { return 0; }
1794
uint32_t st_select_lex_node::get_in_sum_expr() { return 0; }
1795
TableList* st_select_lex_node::get_table_list() { return 0; }
1819
1796
List<Item>* st_select_lex_node::get_item_list() { return 0; }
1820
TABLE_LIST *st_select_lex_node::add_table_to_list (THD *thd __attribute__((unused)),
1821
Table_ident *table __attribute__((unused)),
1822
LEX_STRING *alias __attribute__((unused)),
1823
uint32_t table_join_options __attribute__((unused)),
1824
thr_lock_type flags __attribute__((unused)),
1825
List<Index_hint> *hints __attribute__((unused)),
1826
LEX_STRING *option __attribute__((unused)))
1797
TableList *st_select_lex_node::add_table_to_list (Session *, Table_ident *, LEX_STRING *, uint32_t,
1798
thr_lock_type, List<Index_hint> *, LEX_STRING *)
1862
bool st_select_lex::add_order_to_list(THD *thd, Item *item, bool asc)
1834
bool st_select_lex::add_order_to_list(Session *session, Item *item, bool asc)
1864
return add_to_list(thd, order_list, item, asc);
1836
return add_to_list(session, order_list, item, asc);
1868
bool st_select_lex::add_item_to_list(THD *thd __attribute__((unused)),
1840
bool st_select_lex::add_item_to_list(Session *, Item *item)
1871
1842
return(item_list.push_back(item));
1875
bool st_select_lex::add_group_to_list(THD *thd, Item *item, bool asc)
1846
bool st_select_lex::add_group_to_list(Session *session, Item *item, bool asc)
1877
return add_to_list(thd, group_list, item, asc);
1848
return add_to_list(session, group_list, item, asc);
1971
1937
str->append(STRING_WITH_LEN(" order by "));
1972
1938
fake_select_lex->print_order(
1974
(ORDER *) fake_select_lex->order_list.first,
1940
(order_st *) fake_select_lex->order_list.first,
1977
fake_select_lex->print_limit(thd, str, query_type);
1943
fake_select_lex->print_limit(session, str, query_type);
1982
1948
void st_select_lex::print_order(String *str,
1984
1950
enum_query_type query_type)
1986
1952
for (; order; order= order->next)
2127
2074
Initialize LEX object.
2133
2080
LEX object initialized with this constructor can be used as part of
2134
THD object for which one can safely call open_tables(), lock_tables()
2081
Session object for which one can safely call open_tables(), lock_tables()
2135
2082
and close_thread_tables() functions. But it is not yet ready for
2136
2083
statement parsing. On should use lex_start() function to prepare LEX
2141
2088
:result(0), yacc_yyss(0), yacc_yyvs(0),
2142
2089
sql_command(SQLCOM_END), option_type(OPT_DEFAULT), is_lex_started(0)
2145
my_init_dynamic_array2(&plugins, sizeof(plugin_ref),
2146
plugins_static_buffer,
2147
INITIAL_LEX_PLUGIN_LIST_SIZE,
2148
INITIAL_LEX_PLUGIN_LIST_SIZE);
2149
2092
reset_query_tables_list(true);
2154
Check whether the merging algorithm can be used on this VIEW
2157
st_lex::can_be_merged()
2160
We can apply merge algorithm if it is single SELECT view with
2161
subqueries only in WHERE clause (we do not count SELECTs of underlying
2162
views, and second level subqueries) and we have not grpouping, ordering,
2163
HAVING clause, aggregate functions, DISTINCT clause, LIMIT clause and
2164
several underlying tables.
2167
false - only temporary table algorithm can be used
2168
true - merge algorithm can be used
2171
bool st_lex::can_be_merged()
2173
// TODO: do not forget implement case when select_lex.table_list.elements==0
2175
/* find non VIEW subqueries/unions */
2176
bool selects_allow_merge= select_lex.next_select() == 0;
2177
if (selects_allow_merge)
2179
for (SELECT_LEX_UNIT *tmp_unit= select_lex.first_inner_unit();
2181
tmp_unit= tmp_unit->next_unit())
2183
if (tmp_unit->first_select()->parent_lex == this &&
2184
(tmp_unit->item == 0 ||
2185
(tmp_unit->item->place() != IN_WHERE &&
2186
tmp_unit->item->place() != IN_ON)))
2188
selects_allow_merge= 0;
2194
return (selects_allow_merge &&
2195
select_lex.group_list.elements == 0 &&
2196
select_lex.having == 0 &&
2197
select_lex.with_sum_func == 0 &&
2198
select_lex.table_list.elements >= 1 &&
2199
!(select_lex.options & SELECT_DISTINCT) &&
2200
select_lex.select_limit == 0);
2205
check if command can use VIEW with MERGE algorithm (for top VIEWs)
2208
st_lex::can_use_merged()
2211
Only listed here commands can use merge algorithm in top level
2212
SELECT_LEX (for subqueries will be used merge algorithm if
2213
st_lex::can_not_use_merged() is not true).
2216
false - command can't use merged VIEWs
2217
true - VIEWs with MERGE algorithms can be used
2220
bool st_lex::can_use_merged()
2222
switch (sql_command)
2225
case SQLCOM_CREATE_TABLE:
2227
case SQLCOM_UPDATE_MULTI:
2229
case SQLCOM_DELETE_MULTI:
2231
case SQLCOM_INSERT_SELECT:
2232
case SQLCOM_REPLACE:
2233
case SQLCOM_REPLACE_SELECT:
2242
Check if command can't use merged views in any part of command
2245
st_lex::can_not_use_merged()
2248
Temporary table algorithm will be used on all SELECT levels for queries
2249
listed here (see also st_lex::can_use_merged()).
2252
false - command can't use merged VIEWs
2253
true - VIEWs with MERGE algorithms can be used
2256
bool st_lex::can_not_use_merged()
2258
switch (sql_command)
2261
SQLCOM_SHOW_FIELDS is necessary to make
2262
information schema tables working correctly with views.
2263
see get_schema_tables_result function
2265
case SQLCOM_SHOW_FIELDS:
2273
2096
Detect that we need only table structure of derived table/view
2514
2335
to call Query_tables_list::reset_query_tables_list(false).
2517
void st_lex::cleanup_after_one_table_open()
2338
void LEX::cleanup_after_one_table_open()
2520
thd->lex->derived_tables & additional units may be set if we open
2521
a view. It is necessary to clear thd->lex->derived_tables flag
2341
session->lex->derived_tables & additional units may be set if we open
2342
a view. It is necessary to clear session->lex->derived_tables flag
2522
2343
to prevent processing of derived tables during next open_and_lock_tables
2523
2344
if next table is a real table and cleanup & remove underlying units
2524
NOTE: all units will be connected to thd->lex->select_lex, because we
2345
NOTE: all units will be connected to session->lex->select_lex, because we
2525
2346
have not UNION on most upper level.
2527
2348
if (all_selects_list != &select_lex)
2544
Save current state of Query_tables_list for this LEX, and prepare it
2545
for processing of new statemnt.
2548
reset_n_backup_query_tables_list()
2549
backup Pointer to Query_tables_list instance to be used for backup
2552
void st_lex::reset_n_backup_query_tables_list(Query_tables_list *backup __attribute__((unused)))
2558
Restore state of Query_tables_list for this LEX from backup.
2561
restore_backup_query_tables_list()
2562
backup Pointer to Query_tables_list instance used for backup
2565
void st_lex::restore_backup_query_tables_list(Query_tables_list *backup __attribute__((unused)))
2571
Checks for usage of routines and/or tables in a parsed statement
2574
st_lex:table_or_sp_used()
2577
false No routines and tables used
2578
true Either or both routines and tables are used.
2581
bool st_lex::table_or_sp_used()
2583
if (sroutines.records || query_tables)
2591
2365
Do end-of-prepare fixup for list of tables and their merge-VIEWed tables
2594
2368
fix_prepare_info_in_table_list()
2369
session Thread handle
2596
2370
tbl List of tables to process
2605
static void fix_prepare_info_in_table_list(THD *thd, TABLE_LIST *tbl)
2379
static void fix_prepare_info_in_table_list(Session *session, TableList *tbl)
2607
2381
for (; tbl; tbl= tbl->next_local)
2609
2383
if (tbl->on_expr)
2611
2385
tbl->prep_on_expr= tbl->on_expr;
2612
tbl->on_expr= tbl->on_expr->copy_andor_structure(thd);
2386
tbl->on_expr= tbl->on_expr->copy_andor_structure(session);
2614
fix_prepare_info_in_table_list(thd, tbl->merge_underlying_list);
2388
fix_prepare_info_in_table_list(session, tbl->merge_underlying_list);
2658
2432
alloc_index_hints()
2433
session current thread.
2662
void st_select_lex::alloc_index_hints (THD *thd)
2664
index_hints= new (thd->mem_root) List<Index_hint>();
2436
void st_select_lex::alloc_index_hints (Session *session)
2438
index_hints= new (session->mem_root) List<Index_hint>();
2670
adds an element to the array storing index usage hints
2444
adds an element to the array storing index usage hints
2671
2445
(ADD/FORCE/IGNORE INDEX).
2674
2448
add_index_hint()
2449
session current thread.
2676
2450
str name of the index.
2677
2451
length number of characters in str.
2680
2454
0 on success, non-zero otherwise
2682
bool st_select_lex::add_index_hint (THD *thd, char *str, uint length)
2456
bool st_select_lex::add_index_hint (Session *session, char *str, uint32_t length)
2684
return index_hints->push_front (new (thd->mem_root)
2458
return index_hints->push_front (new (session->mem_root)
2685
2459
Index_hint(current_index_hint_type,
2686
2460
current_index_hint_clause,