34
45
const LEX_STRING null_lex_str= {NULL, 0};
36
/* Longest standard keyword name */
38
#define TOCK_NAME_LENGTH 24
41
The following data is based on the latin1 character set, and is only
42
used when comparing keywords
45
static unsigned char to_upper_lex[]=
47
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
48
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
49
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
50
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
51
64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
52
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
53
96, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
54
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,123,124,125,126,127,
55
128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
56
144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
57
160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
58
176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
59
192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
60
208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
61
192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
62
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
70
const char * index_hint_type_name[] =
77
inline int lex_casecmp(const char *s, const char *t, uint32_t len)
80
to_upper_lex[(unsigned char) *s++] == to_upper_lex[(unsigned char) *t++]) ;
90
for (i=0 ; i < array_elements(symbols) ; i++)
91
symbols[i].length=(unsigned char) strlen(symbols[i].name);
92
for (i=0 ; i < array_elements(sql_functions) ; i++)
93
sql_functions[i].length=(unsigned char) strlen(sql_functions[i].name);
100
{ // Call this when daemon ends
106
48
st_parsing_options::reset()
108
allows_variable= true;
109
allows_select_into= true;
110
50
allows_select_procedure= true;
111
allows_derived= true;
114
Lex_input_stream::Lex_input_stream(THD *thd,
53
Lex_input_stream::Lex_input_stream(Session *session,
115
54
const char* buffer,
116
55
unsigned int length)
1222
1101
The special comment format is very strict:
1223
'/' '*' '!', followed by exactly
1224
1 digit (major), 2 digits (minor), then 2 digits (dot).
1102
'/' '*' '!', followed by digits ended by a non-digit.
1103
There must be at least 5 digits for it to count
1229
char version_str[6];
1230
version_str[0]= lip->yyPeekn(0);
1231
version_str[1]= lip->yyPeekn(1);
1232
version_str[2]= lip->yyPeekn(2);
1233
version_str[3]= lip->yyPeekn(3);
1234
version_str[4]= lip->yyPeekn(4);
1236
if ( my_isdigit(cs, version_str[0])
1237
&& my_isdigit(cs, version_str[1])
1238
&& my_isdigit(cs, version_str[2])
1239
&& my_isdigit(cs, version_str[3])
1240
&& my_isdigit(cs, version_str[4])
1244
version=strtol(version_str, NULL, 10);
1105
const int MAX_VERSION_SIZE= 16;
1106
char version_str[MAX_VERSION_SIZE];
1111
version_str[pos]= lip->yyPeekn(pos);
1113
} while ((pos < MAX_VERSION_SIZE-1) && isdigit(version_str[pos-1]));
1114
version_str[pos]= 0;
1116
/* To keep some semblance of compatibility, we impose a 5 digit floor */
1120
version=strtoll(version_str, NULL, 10);
1246
1122
/* Accept 'M' 'm' 'm' 'd' 'd' */
1123
lip->yySkipn(pos-1);
1249
1125
if (version <= DRIZZLE_VERSION_ID)
1814
bool st_select_lex_node::set_braces(bool value __attribute__((unused)))
1816
bool st_select_lex_node::inc_in_sum_expr() { return 1; }
1817
uint32_t st_select_lex_node::get_in_sum_expr() { return 0; }
1818
TableList* st_select_lex_node::get_table_list() { return 0; }
1819
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)))
1687
bool Select_Lex_Node::set_braces(bool)
1690
bool Select_Lex_Node::inc_in_sum_expr()
1693
uint32_t Select_Lex_Node::get_in_sum_expr()
1696
TableList* Select_Lex_Node::get_table_list()
1699
List<Item>* Select_Lex_Node::get_item_list()
1702
TableList *Select_Lex_Node::add_table_to_list (Session *, Table_ident *, LEX_STRING *, uint32_t,
1703
thr_lock_type, List<Index_hint> *, LEX_STRING *)
1830
uint32_t st_select_lex_node::get_table_join_options()
1708
uint32_t Select_Lex_Node::get_table_join_options()
1836
1714
prohibit using LIMIT clause
1838
bool st_select_lex::test_limit()
1716
bool Select_Lex::test_limit()
1840
1718
if (select_limit != 0)
1842
1720
my_error(ER_NOT_SUPPORTED_YET, MYF(0),
1843
1721
"LIMIT & IN/ALL/ANY/SOME subquery");
1850
st_select_lex_unit* st_select_lex_unit::master_unit()
1728
Select_Lex_Unit* Select_Lex_Unit::master_unit()
1856
st_select_lex* st_select_lex_unit::outer_select()
1858
return (st_select_lex*) master;
1862
bool st_select_lex::add_order_to_list(THD *thd, Item *item, bool asc)
1864
return add_to_list(thd, order_list, item, asc);
1868
bool st_select_lex::add_item_to_list(THD *thd __attribute__((unused)),
1734
Select_Lex* Select_Lex_Unit::outer_select()
1736
return (Select_Lex*) master;
1740
bool Select_Lex::add_order_to_list(Session *session, Item *item, bool asc)
1742
return add_to_list(session, order_list, item, asc);
1746
bool Select_Lex::add_item_to_list(Session *, Item *item)
1871
1748
return(item_list.push_back(item));
1875
bool st_select_lex::add_group_to_list(THD *thd, Item *item, bool asc)
1877
return add_to_list(thd, group_list, item, asc);
1881
st_select_lex_unit* st_select_lex::master_unit()
1883
return (st_select_lex_unit*) master;
1887
st_select_lex* st_select_lex::outer_select()
1889
return (st_select_lex*) master->get_master();
1893
bool st_select_lex::set_braces(bool value)
1752
bool Select_Lex::add_group_to_list(Session *session, Item *item, bool asc)
1754
return add_to_list(session, group_list, item, asc);
1758
Select_Lex_Unit* Select_Lex::master_unit()
1760
return (Select_Lex_Unit*) master;
1764
Select_Lex* Select_Lex::outer_select()
1766
return (Select_Lex*) master->get_master();
1770
bool Select_Lex::set_braces(bool value)
1900
bool st_select_lex::inc_in_sum_expr()
1778
bool Select_Lex::inc_in_sum_expr()
1907
uint32_t st_select_lex::get_in_sum_expr()
1786
uint32_t Select_Lex::get_in_sum_expr()
1909
1788
return in_sum_expr;
1913
TableList* st_select_lex::get_table_list()
1792
TableList* Select_Lex::get_table_list()
1915
1794
return (TableList*) table_list.first;
1918
List<Item>* st_select_lex::get_item_list()
1797
List<Item>* Select_Lex::get_item_list()
1920
1799
return &item_list;
1923
uint32_t st_select_lex::get_table_join_options()
1802
uint32_t Select_Lex::get_table_join_options()
1925
1804
return table_join_options;
1929
bool st_select_lex::setup_ref_array(THD *thd, uint32_t order_group_num)
1808
bool Select_Lex::setup_ref_array(Session *session, uint32_t order_group_num)
1931
1810
if (ref_pointer_array)
1934
1813
return (ref_pointer_array=
1935
(Item **)thd->alloc(sizeof(Item*) * (n_child_sum_items +
1814
(Item **)session->alloc(sizeof(Item*) * (n_child_sum_items +
1936
1815
item_list.elements +
1937
1816
select_n_having_items +
1938
1817
select_n_where_fields +
2122
1970
Initialize LEX object.
2128
1976
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()
1977
Session object for which one can safely call open_tables(), lock_tables()
2130
1978
and close_thread_tables() functions. But it is not yet ready for
2131
1979
statement parsing. On should use lex_start() function to prepare LEX
2136
1984
:result(0), yacc_yyss(0), yacc_yyvs(0),
2137
1985
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
1987
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
1991
Detect that we need only table structure of derived table/view
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
Do end-of-prepare fixup for list of tables and their merge-VIEWed tables
2589
fix_prepare_info_in_table_list()
2591
tbl List of tables to process
2594
Perform end-end-of prepare fixup for list of tables, if any of the tables
2595
is a merge-algorithm VIEW, recursively fix up its underlying tables as
2600
static void fix_prepare_info_in_table_list(THD *thd, TableList *tbl)
2602
for (; tbl; tbl= tbl->next_local)
2606
tbl->prep_on_expr= tbl->on_expr;
2607
tbl->on_expr= tbl->on_expr->copy_andor_structure(thd);
2609
fix_prepare_info_in_table_list(thd, tbl->merge_underlying_list);
2615
There are st_select_lex::add_table_to_list &
2616
st_select_lex::set_lock_for_tables are in sql_parse.cc
2618
st_select_lex::print is in sql_select.cc
2620
st_select_lex_unit::prepare, st_select_lex_unit::exec,
2621
st_select_lex_unit::cleanup, st_select_lex_unit::reinit_exec_mechanism,
2622
st_select_lex_unit::change_result
2260
There are Select_Lex::add_table_to_list &
2261
Select_Lex::set_lock_for_tables are in sql_parse.cc
2263
Select_Lex::print is in sql_select.cc
2265
Select_Lex_Unit::prepare, Select_Lex_Unit::exec,
2266
Select_Lex_Unit::cleanup, Select_Lex_Unit::reinit_exec_mechanism,
2267
Select_Lex_Unit::change_result
2623
2268
are in sql_union.cc