45
34
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
48
106
st_parsing_options::reset()
108
allows_variable= true;
109
allows_select_into= true;
50
110
allows_select_procedure= true;
111
allows_derived= true;
53
Lex_input_stream::Lex_input_stream(Session *session,
114
Lex_input_stream::Lex_input_stream(THD *thd,
54
115
const char* buffer,
55
116
unsigned int length)
1104
1222
The special comment format is very strict:
1105
'/' '*' '!', followed by digits ended by a non-digit.
1106
There must be at least 5 digits for it to count
1223
'/' '*' '!', followed by exactly
1224
1 digit (major), 2 digits (minor), then 2 digits (dot).
1108
const int MAX_VERSION_SIZE= 16;
1109
char version_str[MAX_VERSION_SIZE];
1114
version_str[pos]= lip->yyPeekn(pos);
1116
} while ((pos < MAX_VERSION_SIZE-1) && isdigit(version_str[pos-1]));
1117
version_str[pos]= 0;
1119
/* To keep some semblance of compatibility, we impose a 5 digit floor */
1123
version=strtoll(version_str, NULL, 10);
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);
1125
1246
/* Accept 'M' 'm' 'm' 'd' 'd' */
1126
lip->yySkipn(pos-1);
1128
1249
if (version <= DRIZZLE_VERSION_ID)
1692
bool Select_Lex_Node::set_braces(bool)
1814
bool st_select_lex_node::set_braces(bool value __attribute__((unused)))
1694
bool Select_Lex_Node::inc_in_sum_expr() { return 1; }
1695
uint32_t Select_Lex_Node::get_in_sum_expr() { return 0; }
1696
TableList* Select_Lex_Node::get_table_list() { return 0; }
1697
List<Item>* Select_Lex_Node::get_item_list() { return 0; }
1698
TableList *Select_Lex_Node::add_table_to_list (Session *, Table_ident *, LEX_STRING *, uint32_t,
1699
thr_lock_type, List<Index_hint> *, LEX_STRING *)
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)))
1703
uint32_t Select_Lex_Node::get_table_join_options()
1830
uint32_t st_select_lex_node::get_table_join_options()
1723
Select_Lex_Unit* Select_Lex_Unit::master_unit()
1850
st_select_lex_unit* st_select_lex_unit::master_unit()
1729
Select_Lex* Select_Lex_Unit::outer_select()
1731
return (Select_Lex*) master;
1735
bool Select_Lex::add_order_to_list(Session *session, Item *item, bool asc)
1737
return add_to_list(session, order_list, item, asc);
1741
bool Select_Lex::add_item_to_list(Session *, Item *item)
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)),
1743
1871
return(item_list.push_back(item));
1747
bool Select_Lex::add_group_to_list(Session *session, Item *item, bool asc)
1749
return add_to_list(session, group_list, item, asc);
1753
Select_Lex_Unit* Select_Lex::master_unit()
1755
return (Select_Lex_Unit*) master;
1759
Select_Lex* Select_Lex::outer_select()
1761
return (Select_Lex*) master->get_master();
1765
bool Select_Lex::set_braces(bool value)
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)
1772
bool Select_Lex::inc_in_sum_expr()
1900
bool st_select_lex::inc_in_sum_expr()
1779
uint32_t Select_Lex::get_in_sum_expr()
1907
uint32_t st_select_lex::get_in_sum_expr()
1781
1909
return in_sum_expr;
1785
TableList* Select_Lex::get_table_list()
1913
TableList* st_select_lex::get_table_list()
1787
1915
return (TableList*) table_list.first;
1790
List<Item>* Select_Lex::get_item_list()
1918
List<Item>* st_select_lex::get_item_list()
1792
1920
return &item_list;
1795
uint32_t Select_Lex::get_table_join_options()
1923
uint32_t st_select_lex::get_table_join_options()
1797
1925
return table_join_options;
1801
bool Select_Lex::setup_ref_array(Session *session, uint32_t order_group_num)
1929
bool st_select_lex::setup_ref_array(THD *thd, uint32_t order_group_num)
1803
1931
if (ref_pointer_array)
1806
1934
return (ref_pointer_array=
1807
(Item **)session->alloc(sizeof(Item*) * (n_child_sum_items +
1935
(Item **)thd->alloc(sizeof(Item*) * (n_child_sum_items +
1808
1936
item_list.elements +
1809
1937
select_n_having_items +
1810
1938
select_n_where_fields +
1975
2122
Initialize LEX object.
1981
2128
LEX object initialized with this constructor can be used as part of
1982
Session object for which one can safely call open_tables(), lock_tables()
2129
THD object for which one can safely call open_tables(), lock_tables()
1983
2130
and close_thread_tables() functions. But it is not yet ready for
1984
2131
statement parsing. On should use lex_start() function to prepare LEX
1989
2136
:result(0), yacc_yyss(0), yacc_yyvs(0),
1990
2137
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);
1993
2144
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:
1997
2268
Detect that we need only table structure of derived table/view