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, uint32_t len)
78
int lex_casecmp(const char *s, const char *t, uint32_t len)
79
80
while (len-- != 0 &&
80
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)
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
165
uint32_t body_utf8_length=
167
(m_buf_length / thd->variables.character_set_client->mbminlen) *
166
(m_buf_length / default_charset_info->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)
696
MYSQLlex remember the following states from the following MYSQLlex()
674
DRIZZLElex remember the following states from the following DRIZZLElex()
698
676
- MY_LEX_EOQ Found end of query
699
677
- MY_LEX_OPERATOR_OR_IDENT Last state was an ident, text or number
700
678
(which can't be followed by a signed number)
703
int MYSQLlex(void *arg, void *yythd)
681
int DRIZZLElex(void *arg, void *yysession)
705
THD *thd= (THD *)yythd;
706
Lex_input_stream *lip= thd->m_lip;
683
Session *session= (Session *)yysession;
684
Lex_input_stream *lip= session->m_lip;
707
685
YYSTYPE *yylval=(YYSTYPE*) arg;
757
int lex_one_token(void *arg, void *yythd)
735
int lex_one_token(void *arg, void *yysession)
759
737
register unsigned char c= 0; /* Just set to shutup GCC */
760
738
bool comment_closed;
761
739
int tokval, result_state;
762
740
unsigned int length;
763
741
enum my_lex_states state;
764
THD *thd= (THD *)yythd;
765
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;
767
745
YYSTYPE *yylval=(YYSTYPE*) arg;
768
const CHARSET_INFO * const cs= thd->charset();
746
const CHARSET_INFO * const cs= session->charset();
769
747
unsigned char *state_map= cs->state_map;
770
748
unsigned char *ident_map= cs->ident_map;
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
1794
uint32_t st_select_lex_node::get_in_sum_expr() { return 0; }
1818
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
TableList *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);
2122
2074
Initialize LEX object.
2128
2080
LEX object initialized with this constructor can be used as part of
2129
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()
2130
2082
and close_thread_tables() functions. But it is not yet ready for
2131
2083
statement parsing. On should use lex_start() function to prepare LEX
2136
2088
:result(0), yacc_yyss(0), yacc_yyvs(0),
2137
2089
sql_command(SQLCOM_END), option_type(OPT_DEFAULT), is_lex_started(0)
2140
my_init_dynamic_array2(&plugins, sizeof(plugin_ref),
2141
plugins_static_buffer,
2142
INITIAL_LEX_PLUGIN_LIST_SIZE,
2143
INITIAL_LEX_PLUGIN_LIST_SIZE);
2144
2092
reset_query_tables_list(true);
2149
Check whether the merging algorithm can be used on this VIEW
2152
st_lex::can_be_merged()
2155
We can apply merge algorithm if it is single SELECT view with
2156
subqueries only in WHERE clause (we do not count SELECTs of underlying
2157
views, and second level subqueries) and we have not grpouping, ordering,
2158
HAVING clause, aggregate functions, DISTINCT clause, LIMIT clause and
2159
several underlying tables.
2162
false - only temporary table algorithm can be used
2163
true - merge algorithm can be used
2166
bool st_lex::can_be_merged()
2168
// TODO: do not forget implement case when select_lex.table_list.elements==0
2170
/* find non VIEW subqueries/unions */
2171
bool selects_allow_merge= select_lex.next_select() == 0;
2172
if (selects_allow_merge)
2174
for (SELECT_LEX_UNIT *tmp_unit= select_lex.first_inner_unit();
2176
tmp_unit= tmp_unit->next_unit())
2178
if (tmp_unit->first_select()->parent_lex == this &&
2179
(tmp_unit->item == 0 ||
2180
(tmp_unit->item->place() != IN_WHERE &&
2181
tmp_unit->item->place() != IN_ON)))
2183
selects_allow_merge= 0;
2189
return (selects_allow_merge &&
2190
select_lex.group_list.elements == 0 &&
2191
select_lex.having == 0 &&
2192
select_lex.with_sum_func == 0 &&
2193
select_lex.table_list.elements >= 1 &&
2194
!(select_lex.options & SELECT_DISTINCT) &&
2195
select_lex.select_limit == 0);
2200
check if command can use VIEW with MERGE algorithm (for top VIEWs)
2203
st_lex::can_use_merged()
2206
Only listed here commands can use merge algorithm in top level
2207
SELECT_LEX (for subqueries will be used merge algorithm if
2208
st_lex::can_not_use_merged() is not true).
2211
false - command can't use merged VIEWs
2212
true - VIEWs with MERGE algorithms can be used
2215
bool st_lex::can_use_merged()
2217
switch (sql_command)
2220
case SQLCOM_CREATE_TABLE:
2222
case SQLCOM_UPDATE_MULTI:
2224
case SQLCOM_DELETE_MULTI:
2226
case SQLCOM_INSERT_SELECT:
2227
case SQLCOM_REPLACE:
2228
case SQLCOM_REPLACE_SELECT:
2237
Check if command can't use merged views in any part of command
2240
st_lex::can_not_use_merged()
2243
Temporary table algorithm will be used on all SELECT levels for queries
2244
listed here (see also st_lex::can_use_merged()).
2247
false - command can't use merged VIEWs
2248
true - VIEWs with MERGE algorithms can be used
2251
bool st_lex::can_not_use_merged()
2253
switch (sql_command)
2256
SQLCOM_SHOW_FIELDS is necessary to make
2257
information schema tables working correctly with views.
2258
see get_schema_tables_result function
2260
case SQLCOM_SHOW_FIELDS:
2268
2096
Detect that we need only table structure of derived table/view
2509
2335
to call Query_tables_list::reset_query_tables_list(false).
2512
void st_lex::cleanup_after_one_table_open()
2338
void LEX::cleanup_after_one_table_open()
2515
thd->lex->derived_tables & additional units may be set if we open
2516
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
2517
2343
to prevent processing of derived tables during next open_and_lock_tables
2518
2344
if next table is a real table and cleanup & remove underlying units
2519
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
2520
2346
have not UNION on most upper level.
2522
2348
if (all_selects_list != &select_lex)
2539
Save current state of Query_tables_list for this LEX, and prepare it
2540
for processing of new statemnt.
2543
reset_n_backup_query_tables_list()
2544
backup Pointer to Query_tables_list instance to be used for backup
2547
void st_lex::reset_n_backup_query_tables_list(Query_tables_list *backup __attribute__((unused)))
2553
Restore state of Query_tables_list for this LEX from backup.
2556
restore_backup_query_tables_list()
2557
backup Pointer to Query_tables_list instance used for backup
2560
void st_lex::restore_backup_query_tables_list(Query_tables_list *backup __attribute__((unused)))
2566
Checks for usage of routines and/or tables in a parsed statement
2569
st_lex:table_or_sp_used()
2572
false No routines and tables used
2573
true Either or both routines and tables are used.
2576
bool st_lex::table_or_sp_used()
2578
if (sroutines.records || query_tables)
2586
2365
Do end-of-prepare fixup for list of tables and their merge-VIEWed tables
2589
2368
fix_prepare_info_in_table_list()
2369
session Thread handle
2591
2370
tbl List of tables to process
2600
static void fix_prepare_info_in_table_list(THD *thd, TableList *tbl)
2379
static void fix_prepare_info_in_table_list(Session *session, TableList *tbl)
2602
2381
for (; tbl; tbl= tbl->next_local)
2604
2383
if (tbl->on_expr)
2606
2385
tbl->prep_on_expr= tbl->on_expr;
2607
tbl->on_expr= tbl->on_expr->copy_andor_structure(thd);
2386
tbl->on_expr= tbl->on_expr->copy_andor_structure(session);
2609
fix_prepare_info_in_table_list(thd, tbl->merge_underlying_list);
2388
fix_prepare_info_in_table_list(session, tbl->merge_underlying_list);
2653
2432
alloc_index_hints()
2433
session current thread.
2657
void st_select_lex::alloc_index_hints (THD *thd)
2659
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>();
2665
adds an element to the array storing index usage hints
2444
adds an element to the array storing index usage hints
2666
2445
(ADD/FORCE/IGNORE INDEX).
2669
2448
add_index_hint()
2449
session current thread.
2671
2450
str name of the index.
2672
2451
length number of characters in str.
2675
2454
0 on success, non-zero otherwise
2677
bool st_select_lex::add_index_hint (THD *thd, char *str, uint32_t length)
2456
bool st_select_lex::add_index_hint (Session *session, char *str, uint32_t length)
2679
return index_hints->push_front (new (thd->mem_root)
2458
return index_hints->push_front (new (session->mem_root)
2680
2459
Index_hint(current_index_hint_type,
2681
2460
current_index_hint_clause,