12
12
You should have received a copy of the GNU General Public License
13
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
17
/* A lexical scanner on a temporary buffer with a yacc interface */
21
19
#define DRIZZLE_LEX 1
23
#include <drizzled/sql_reserved_words.h>
25
#include <drizzled/configmake.h>
26
#include <drizzled/item/num.h>
27
#include <drizzled/error.h>
28
#include <drizzled/session.h>
29
#include <drizzled/sql_base.h>
30
#include <drizzled/lookup_symbol.h>
31
#include <drizzled/index_hint.h>
32
#include <drizzled/select_result.h>
41
/* Stay outside of the namespace because otherwise bison goes nuts */
42
int base_sql_lex(ParserType *arg, drizzled::Session *yysession);
47
static int lex_one_token(ParserType *arg, drizzled::Session *yysession);
50
save order by and tables in own lists.
20
#include <drizzled/server_includes.h>
22
static int lex_one_token(void *arg, void *yythd);
25
We are using pointer to this variable for distinguishing between assignment
26
to NEW row field (when parsing trigger definition) and structured variable.
52
static bool add_to_list(Session *session, SQL_LIST &list, Item *item, bool asc)
56
if (!(order = (Order *) session->getMemRoot()->allocate(sizeof(Order))))
59
order->item_ptr= item;
60
order->item= &order->item_ptr;
64
order->counter_used= 0;
65
list.link_in_list((unsigned char*) order, (unsigned char**) &order->next);
29
sys_var *trg_new_row_fake_var= (sys_var*) 0x01;
71
32
LEX_STRING constant for null-string to be used in parser and other places.
73
34
const LEX_STRING null_lex_str= {NULL, 0};
75
Lex_input_stream::Lex_input_stream(Session *session,
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 uchar 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, uint len)
80
to_upper_lex[(uchar) *s++] == to_upper_lex[(uchar) *t++]) ;
90
for (i=0 ; i < array_elements(symbols) ; i++)
91
symbols[i].length=(uchar) strlen(symbols[i].name);
92
for (i=0 ; i < array_elements(sql_functions) ; i++)
93
sql_functions[i].length=(uchar) strlen(sql_functions[i].name);
100
{ // Call this when daemon ends
106
st_parsing_options::reset()
108
allows_variable= true;
109
allows_select_into= true;
110
allows_select_procedure= true;
111
allows_derived= true;
114
Lex_input_stream::Lex_input_stream(THD *thd,
76
115
const char* buffer,
77
unsigned int length) :
189
233
The operation converts the specified text literal to the utf8 and appends
190
234
the result to the utf8-body.
192
@param session Thread context.
236
@param thd Thread context.
193
237
@param txt Text literal.
194
238
@param txt_cs Character set of the text literal.
195
239
@param end_ptr Pointer in the pre-processed buffer, to which
196
240
m_cpp_utf8_processed_ptr will be set in the end of the
199
void Lex_input_stream::body_utf8_append_literal(const LEX_STRING *txt,
244
void Lex_input_stream::body_utf8_append_literal(THD *thd,
245
const LEX_STRING *txt,
246
const CHARSET_INFO * const txt_cs,
200
247
const char *end_ptr)
202
249
if (!m_cpp_utf8_processed_ptr)
254
if (!my_charset_same(txt_cs, &my_charset_utf8_general_ci))
256
thd->convert_string(&utf_txt,
257
&my_charset_utf8_general_ci,
258
txt->str, txt->length,
263
utf_txt.str= txt->str;
264
utf_txt.length= txt->length;
205
267
/* NOTE: utf_txt.length is in bytes, not in symbols. */
207
memcpy(m_body_utf8_ptr, txt->str, txt->length);
208
m_body_utf8_ptr += txt->length;
269
memcpy(m_body_utf8_ptr, utf_txt.str, utf_txt.length);
270
m_body_utf8_ptr += utf_txt.length;
209
271
*m_body_utf8_ptr= 0;
211
273
m_cpp_utf8_processed_ptr= end_ptr;
215
278
This is called before every query that is to be parsed.
216
279
Because of this, it's critical to not do too much things here.
217
280
(We already do too much here)
219
void LEX::start(Session *arg)
224
void lex_start(Session *session)
226
LEX *lex= session->getLex();
228
lex->session= lex->unit.session= session;
230
lex->context_stack.clear();
283
void lex_start(THD *thd)
287
lex->thd= lex->unit.thd= thd;
289
lex->context_stack.empty();
231
290
lex->unit.init_query();
232
291
lex->unit.init_select();
233
292
/* 'parent_lex' is used in init_query() so it must be before it. */
234
293
lex->select_lex.parent_lex= lex;
235
294
lex->select_lex.init_query();
236
lex->value_list.clear();
237
lex->update_list.clear();
238
lex->auxiliary_table_list.clear();
295
lex->value_list.empty();
296
lex->update_list.empty();
297
lex->param_list.empty();
298
lex->auxiliary_table_list.empty();
239
299
lex->unit.next= lex->unit.master=
240
300
lex->unit.link_next= lex->unit.return_to= 0;
241
301
lex->unit.prev= lex->unit.link_prev= 0;
272
337
lex->nest_level=0 ;
273
338
lex->allow_sum_func= 0;
274
339
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;
277
355
lex->is_lex_started= true;
278
lex->statement= NULL;
280
lex->is_cross= false;
359
void lex_end(LEX *lex)
363
my_free(lex->yacc_yyss, MYF(0));
364
my_free(lex->yacc_yyvs, MYF(0));
295
safe_delete(_create_table);
302
safe_delete(statement);
369
/* release used plugins */
370
plugin_unlock_list(0, (plugin_ref*)lex->plugins.buffer,
371
lex->plugins.elements);
372
reset_dynamic(&lex->plugins);
305
static int find_keyword(Lex_input_stream *lip, uint32_t len, bool function)
378
static int find_keyword(Lex_input_stream *lip, uint len, bool function)
307
/* Plenty of memory for the largest lex symbol we have */
309
380
const char *tok= lip->get_tok_start();
311
for (;tok_pos<len && tok_pos<63;tok_pos++)
312
tok_upper[tok_pos]=my_toupper(system_charset_info, tok[tok_pos]);
313
tok_upper[tok_pos]=0;
315
const SYMBOL *symbol= lookup_symbol(tok_upper, len, function);
382
SYMBOL *symbol= get_hash_symbol(tok, len, function);
318
385
lip->yylval->symbol.symbol=symbol;
855
973
while (my_isdigit(cs, (c = lip->yyGet()))) ;
856
974
if (!ident_map[c])
857
975
{ // Can't be identifier
858
state=MY_LEX_INT_OR_REAL;
976
state=MY_LEX_INT_OR_REAL;
861
979
if (c == 'e' || c == 'E')
863
// The following test is written this way to allow numbers of type 1e1
981
// The following test is written this way to allow numbers of type 1e1
864
982
if (my_isdigit(cs,lip->yyPeek()) ||
865
983
(c=(lip->yyGet())) == '+' || c == '-')
867
985
if (my_isdigit(cs,lip->yyPeek())) // Number must have digit after sign
870
988
while (my_isdigit(cs,lip->yyGet())) ;
871
989
yylval->lex_str=get_token(lip, 0, lip->yyLength());
878
996
case MY_LEX_IDENT_START: // We come here after '.'
879
997
result_state= IDENT;
998
#if defined(USE_MB) && defined(USE_MB_IDENT)
882
result_state= IDENT_QUOTED;
1001
result_state= IDENT_QUOTED;
883
1002
while (ident_map[c=lip->yyGet()])
885
1004
if (my_mbcharlen(cs, c) > 1)
887
int l= my_ismbchar(cs, lip->get_ptr() -1, lip->get_end_of_query());
1007
if ((l = my_ismbchar(cs,
1009
lip->get_end_of_query())) == 0)
890
1011
lip->skip_binary(l-1);
896
1018
for (result_state=0; ident_map[c= lip->yyGet()]; result_state|= c) {};
897
1019
/* If there were non-ASCII characters, mark that we must convert */
898
1020
result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
900
1022
if (c == '.' && ident_map[(uint8_t)lip->yyPeek()])
901
lip->next_state=MY_LEX_IDENT_SEP;// Next is '.'
1023
lip->next_state=MY_LEX_IDENT_SEP;// Next is '.'
903
1025
yylval->lex_str= get_token(lip, 0, lip->yyLength());
905
1027
lip->body_utf8_append(lip->m_cpp_text_start);
907
lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
1029
lip->body_utf8_append_literal(thd, &yylval->lex_str, cs,
1030
lip->m_cpp_text_end);
909
1032
return(result_state);
911
1034
case MY_LEX_USER_VARIABLE_DELIMITER: // Found quote char
913
uint32_t double_quotes= 0;
1036
uint double_quotes= 0;
914
1037
char quote_char= c; // Used char
915
1038
while ((c=lip->yyGet()))
918
if ((var_length= my_mbcharlen(cs, c)) == 1)
922
if (lip->yyPeek() != quote_char)
929
else if (var_length < 1)
1041
if ((var_length= my_mbcharlen(cs, c)) == 1)
1043
if (c == quote_char)
1045
if (lip->yyPeek() != quote_char)
1053
else if (var_length < 1)
931
1055
lip->skip_binary(var_length-1);
933
1058
if (double_quotes)
934
yylval->lex_str=get_quoted_token(lip, 1, lip->yyLength() - double_quotes -1, quote_char);
1059
yylval->lex_str=get_quoted_token(lip, 1,
1060
lip->yyLength() - double_quotes -1,
936
1063
yylval->lex_str=get_token(lip, 1, lip->yyLength() -1);
937
1064
if (c == quote_char)
938
1065
lip->yySkip(); // Skip end `
939
1066
lip->next_state= MY_LEX_START;
940
1068
lip->body_utf8_append(lip->m_cpp_text_start);
941
lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
1070
lip->body_utf8_append_literal(thd, &yylval->lex_str, cs,
1071
lip->m_cpp_text_end);
942
1073
return(IDENT_QUOTED);
944
1075
case MY_LEX_INT_OR_REAL: // Complete int or incomplete real
946
1077
{ // Found complete integer number.
947
1078
yylval->lex_str=get_token(lip, 0, lip->yyLength());
948
return int_token(yylval->lex_str.str,yylval->lex_str.length);
1079
return int_token(yylval->lex_str.str,yylval->lex_str.length);
951
1082
case MY_LEX_REAL: // Incomplete real number
1262
1408
result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
1265
lip->next_state=MY_LEX_IDENT_SEP;
1411
lip->next_state=MY_LEX_IDENT_SEP;
1266
1412
length= lip->yyLength();
1267
1413
if (length == 0)
1268
1414
return(ABORT_SYM); // Names must be nonempty.
1269
1415
if ((tokval= find_keyword(lip, length,0)))
1271
1417
lip->yyUnget(); // Put back 'c'
1272
return(tokval); // Was keyword
1418
return(tokval); // Was keyword
1274
1420
yylval->lex_str=get_token(lip, 0, length);
1276
1422
lip->body_utf8_append(lip->m_cpp_text_start);
1278
lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
1424
lip->body_utf8_append_literal(thd, &yylval->lex_str, cs,
1425
lip->m_cpp_text_end);
1280
1427
return(result_state);
1434
Construct a copy of this object to be used for mysql_alter_table
1435
and mysql_create_table.
1437
Historically, these two functions modify their Alter_info
1438
arguments. This behaviour breaks re-execution of prepared
1439
statements and stored procedures and is compensated by always
1440
supplying a copy of Alter_info to these functions.
1442
@return You need to use check the error in THD for out
1443
of memory condition after calling this function.
1446
Alter_info::Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root)
1447
:drop_list(rhs.drop_list, mem_root),
1448
alter_list(rhs.alter_list, mem_root),
1449
key_list(rhs.key_list, mem_root),
1450
create_list(rhs.create_list, mem_root),
1452
keys_onoff(rhs.keys_onoff),
1453
tablespace_op(rhs.tablespace_op),
1454
no_parts(rhs.no_parts),
1455
build_method(rhs.build_method),
1456
datetime_field(rhs.datetime_field),
1457
error_if_not_empty(rhs.error_if_not_empty)
1460
Make deep copies of used objects.
1461
This is not a fully deep copy - clone() implementations
1462
of Alter_drop, Alter_column, Key, foreign_key, Key_part_spec
1463
do not copy string constants. At the same length the only
1464
reason we make a copy currently is that ALTER/CREATE TABLE
1465
code changes input Alter_info definitions, but string
1466
constants never change.
1468
list_copy_and_replace_each_value(drop_list, mem_root);
1469
list_copy_and_replace_each_value(alter_list, mem_root);
1470
list_copy_and_replace_each_value(key_list, mem_root);
1471
list_copy_and_replace_each_value(create_list, mem_root);
1285
1475
void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str)
1562
1765
next->prev= prev;
1566
* Mark all Select_Lex struct from this to 'last' as dependent
1568
* @param Pointer to last Select_Lex struct, before wich all
1569
* Select_Lex have to be marked as dependent
1570
* @note 'last' should be reachable from this Select_Lex_Node
1572
void Select_Lex::mark_as_dependent(Select_Lex *last)
1770
st_select_lex_node::mark_as_dependent mark all st_select_lex struct from
1771
this to 'last' as dependent
1774
last - pointer to last st_select_lex struct, before wich all
1775
st_select_lex have to be marked as dependent
1778
'last' should be reachable from this st_select_lex_node
1781
void st_select_lex::mark_as_dependent(st_select_lex *last)
1575
1784
Mark all selects from resolved to 1 before select where was
1576
1785
found table as depended (of select where was found table)
1578
for (Select_Lex *s= this;
1787
for (SELECT_LEX *s= this;
1579
1788
s && s != last;
1580
1789
s= s->outer_select())
1582
if (! (s->uncacheable.test(UNCACHEABLE_DEPENDENT)))
1791
if (!(s->uncacheable & UNCACHEABLE_DEPENDENT))
1584
1793
// Select is dependent of outer select
1585
s->uncacheable.set(UNCACHEABLE_DEPENDENT);
1586
s->uncacheable.set(UNCACHEABLE_UNITED);
1587
Select_Lex_Unit *munit= s->master_unit();
1588
munit->uncacheable.set(UNCACHEABLE_UNITED);
1589
munit->uncacheable.set(UNCACHEABLE_DEPENDENT);
1590
for (Select_Lex *sl= munit->first_select(); sl ; sl= sl->next_select())
1794
s->uncacheable= (s->uncacheable & ~UNCACHEABLE_UNITED) |
1795
UNCACHEABLE_DEPENDENT;
1796
SELECT_LEX_UNIT *munit= s->master_unit();
1797
munit->uncacheable= (munit->uncacheable & ~UNCACHEABLE_UNITED) |
1798
UNCACHEABLE_DEPENDENT;
1799
for (SELECT_LEX *sl= munit->first_select(); sl ; sl= sl->next_select())
1593
! (sl->uncacheable.test(UNCACHEABLE_DEPENDENT) && sl->uncacheable.test(UNCACHEABLE_UNITED)))
1594
sl->uncacheable.set(UNCACHEABLE_UNITED);
1802
!(sl->uncacheable & (UNCACHEABLE_DEPENDENT | UNCACHEABLE_UNITED)))
1803
sl->uncacheable|= UNCACHEABLE_UNITED;
1597
1806
s->is_correlated= true;
1604
bool Select_Lex_Node::set_braces(bool)
1607
bool Select_Lex_Node::inc_in_sum_expr()
1610
uint32_t Select_Lex_Node::get_in_sum_expr()
1613
TableList* Select_Lex_Node::get_table_list()
1616
List<Item>* Select_Lex_Node::get_item_list()
1619
TableList *Select_Lex_Node::add_table_to_list(Session *,
1622
const bitset<NUM_OF_TABLE_OPTIONS>&,
1813
bool st_select_lex_node::set_braces(bool value __attribute__((unused)))
1815
bool st_select_lex_node::inc_in_sum_expr() { return 1; }
1816
uint st_select_lex_node::get_in_sum_expr() { return 0; }
1817
TableList* st_select_lex_node::get_table_list() { return 0; }
1818
List<Item>* st_select_lex_node::get_item_list() { return 0; }
1819
TableList *st_select_lex_node::add_table_to_list (THD *thd __attribute__((unused)),
1820
Table_ident *table __attribute__((unused)),
1821
LEX_STRING *alias __attribute__((unused)),
1822
uint32_t table_join_options __attribute__((unused)),
1823
thr_lock_type flags __attribute__((unused)),
1824
List<Index_hint> *hints __attribute__((unused)),
1825
LEX_STRING *option __attribute__((unused)))
1829
uint32_t st_select_lex_node::get_table_join_options()
1632
1835
prohibit using LIMIT clause
1634
bool Select_Lex::test_limit()
1837
bool st_select_lex::test_limit()
1636
1839
if (select_limit != 0)
1638
1841
my_error(ER_NOT_SUPPORTED_YET, MYF(0),
1639
1842
"LIMIT & IN/ALL/ANY/SOME subquery");
1645
Select_Lex_Unit* Select_Lex_Unit::master_unit()
1650
Select_Lex* Select_Lex_Unit::outer_select()
1652
return (Select_Lex*) master;
1655
bool Select_Lex::add_order_to_list(Session *session, Item *item, bool asc)
1657
return add_to_list(session, order_list, item, asc);
1660
bool Select_Lex::add_item_to_list(Session *, Item *item)
1849
st_select_lex_unit* st_select_lex_unit::master_unit()
1855
st_select_lex* st_select_lex_unit::outer_select()
1857
return (st_select_lex*) master;
1861
bool st_select_lex::add_order_to_list(THD *thd, Item *item, bool asc)
1863
return add_to_list(thd, order_list, item, asc);
1867
bool st_select_lex::add_item_to_list(THD *thd __attribute__((unused)),
1662
1870
return(item_list.push_back(item));
1665
bool Select_Lex::add_group_to_list(Session *session, Item *item, bool asc)
1667
return add_to_list(session, group_list, item, asc);
1670
Select_Lex_Unit* Select_Lex::master_unit()
1672
return (Select_Lex_Unit*) master;
1675
Select_Lex* Select_Lex::outer_select()
1677
return (Select_Lex*) master->get_master();
1680
bool Select_Lex::set_braces(bool value)
1874
bool st_select_lex::add_group_to_list(THD *thd, Item *item, bool asc)
1876
return add_to_list(thd, group_list, item, asc);
1880
st_select_lex_unit* st_select_lex::master_unit()
1882
return (st_select_lex_unit*) master;
1886
st_select_lex* st_select_lex::outer_select()
1888
return (st_select_lex*) master->get_master();
1892
bool st_select_lex::set_braces(bool value)
1686
bool Select_Lex::inc_in_sum_expr()
1899
bool st_select_lex::inc_in_sum_expr()
1692
uint32_t Select_Lex::get_in_sum_expr()
1906
uint st_select_lex::get_in_sum_expr()
1694
1908
return in_sum_expr;
1697
TableList* Select_Lex::get_table_list()
1912
TableList* st_select_lex::get_table_list()
1699
1914
return (TableList*) table_list.first;
1702
List<Item>* Select_Lex::get_item_list()
1917
List<Item>* st_select_lex::get_item_list()
1704
1919
return &item_list;
1708
bool Select_Lex::setup_ref_array(Session *session, uint32_t order_group_num)
1922
uint32_t st_select_lex::get_table_join_options()
1924
return table_join_options;
1928
bool st_select_lex::setup_ref_array(THD *thd, uint order_group_num)
1710
1930
if (ref_pointer_array)
1934
We have to create array in prepared statement memory if it is
1937
Query_arena *arena= thd->stmt_arena;
1713
1938
return (ref_pointer_array=
1714
(Item **)session->getMemRoot()->allocate(sizeof(Item*) * (n_child_sum_items +
1939
(Item **)arena->alloc(sizeof(Item*) * (n_child_sum_items +
1715
1940
item_list.elements +
1716
1941
select_n_having_items +
1717
1942
select_n_where_fields +
1718
1943
order_group_num)*5)) == 0;
1721
void Select_Lex_Unit::print(String *str, enum_query_type query_type)
1947
void st_select_lex_unit::print(String *str, enum_query_type query_type)
1723
1949
bool union_all= !union_distinct;
1724
for (Select_Lex *sl= first_select(); sl; sl= sl->next_select())
1950
for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select())
1726
1952
if (sl != first_select())
1848
2089
query_tables= 0;
1849
2090
query_tables_last= &query_tables;
1850
2091
query_tables_own_last= 0;
2095
We delay real initialization of hash (and therefore related
2096
memory allocation) until first insertion into this hash.
2098
hash_clear(&sroutines);
2100
else if (sroutines.records)
2102
/* Non-zero sroutines.records means that hash was initialized. */
2103
my_hash_reset(&sroutines);
2105
sroutines_list.empty();
2106
sroutines_list_own_last= sroutines_list.next;
2107
sroutines_list_own_elements= 0;
2108
binlog_stmt_flags= 0;
2113
Destroy Query_tables_list object with freeing all resources used by it.
2116
destroy_query_tables_list()
2119
void Query_tables_list::destroy_query_tables_list()
2121
hash_free(&sroutines);
1854
2126
Initialize LEX object.
1860
2132
LEX object initialized with this constructor can be used as part of
1861
Session object for which one can safely call open_tables(), lock_tables()
2133
THD object for which one can safely call open_tables(), lock_tables()
1862
2134
and close_thread_tables() functions. But it is not yet ready for
1863
2135
statement parsing. On should use lex_start() function to prepare LEX
1873
sql_command(SQLCOM_END),
1875
option_type(OPT_DEFAULT),
1878
sum_expr_used(false),
1879
_create_table(NULL),
1880
_create_field(NULL),
2140
:result(0), yacc_yyss(0), yacc_yyvs(0),
2141
sql_command(SQLCOM_END), option_type(OPT_DEFAULT), is_lex_started(0)
2144
my_init_dynamic_array2(&plugins, sizeof(plugin_ref),
2145
plugins_static_buffer,
2146
INITIAL_LEX_PLUGIN_LIST_SIZE,
2147
INITIAL_LEX_PLUGIN_LIST_SIZE);
1883
2148
reset_query_tables_list(true);
2153
Check whether the merging algorithm can be used on this VIEW
2156
st_lex::can_be_merged()
2159
We can apply merge algorithm if it is single SELECT view with
2160
subqueries only in WHERE clause (we do not count SELECTs of underlying
2161
views, and second level subqueries) and we have not grpouping, ordering,
2162
HAVING clause, aggregate functions, DISTINCT clause, LIMIT clause and
2163
several underlying tables.
2166
false - only temporary table algorithm can be used
2167
true - merge algorithm can be used
2170
bool st_lex::can_be_merged()
2172
// TODO: do not forget implement case when select_lex.table_list.elements==0
2174
/* find non VIEW subqueries/unions */
2175
bool selects_allow_merge= select_lex.next_select() == 0;
2176
if (selects_allow_merge)
2178
for (SELECT_LEX_UNIT *tmp_unit= select_lex.first_inner_unit();
2180
tmp_unit= tmp_unit->next_unit())
2182
if (tmp_unit->first_select()->parent_lex == this &&
2183
(tmp_unit->item == 0 ||
2184
(tmp_unit->item->place() != IN_WHERE &&
2185
tmp_unit->item->place() != IN_ON)))
2187
selects_allow_merge= 0;
2193
return (selects_allow_merge &&
2194
select_lex.group_list.elements == 0 &&
2195
select_lex.having == 0 &&
2196
select_lex.with_sum_func == 0 &&
2197
select_lex.table_list.elements >= 1 &&
2198
!(select_lex.options & SELECT_DISTINCT) &&
2199
select_lex.select_limit == 0);
2204
check if command can use VIEW with MERGE algorithm (for top VIEWs)
2207
st_lex::can_use_merged()
2210
Only listed here commands can use merge algorithm in top level
2211
SELECT_LEX (for subqueries will be used merge algorithm if
2212
st_lex::can_not_use_merged() is not true).
2215
false - command can't use merged VIEWs
2216
true - VIEWs with MERGE algorithms can be used
2219
bool st_lex::can_use_merged()
2221
switch (sql_command)
2224
case SQLCOM_CREATE_TABLE:
2226
case SQLCOM_UPDATE_MULTI:
2228
case SQLCOM_DELETE_MULTI:
2230
case SQLCOM_INSERT_SELECT:
2231
case SQLCOM_REPLACE:
2232
case SQLCOM_REPLACE_SELECT:
2241
Check if command can't use merged views in any part of command
2244
st_lex::can_not_use_merged()
2247
Temporary table algorithm will be used on all SELECT levels for queries
2248
listed here (see also st_lex::can_use_merged()).
2251
false - command can't use merged VIEWs
2252
true - VIEWs with MERGE algorithms can be used
2255
bool st_lex::can_not_use_merged()
2257
switch (sql_command)
2260
SQLCOM_SHOW_FIELDS is necessary to make
2261
information schema tables working correctly with views.
2262
see get_schema_tables_result function
2264
case SQLCOM_SHOW_FIELDS:
2272
Detect that we need only table structure of derived table/view
2275
only_view_structure()
2278
true yes, we need only structure
2279
false no, we need data
2282
bool st_lex::only_view_structure()
2284
switch (sql_command) {
2285
case SQLCOM_SHOW_CREATE:
2286
case SQLCOM_SHOW_TABLES:
2287
case SQLCOM_SHOW_FIELDS:
2296
Should Items_ident be printed correctly
2299
need_correct_ident()
2302
true yes, we need only structure
2303
false no, we need data
2307
bool st_lex::need_correct_ident()
2311
case SQLCOM_SHOW_CREATE:
2312
case SQLCOM_SHOW_TABLES:
1887
2321
This method should be called only during parsing.
1888
2322
It is aware of compound statements (stored routine bodies)
1889
2323
and will initialize the destination with the default
1890
2324
database of the stored routine, rather than the default
1891
2325
database of the connection it is parsed in.
1892
E.g. if one has no current database selected, or current database
2326
E.g. if one has no current database selected, or current database
1893
2327
set to 'bar' and then issues:
1895
2329
CREATE PROCEDURE foo.p1() BEGIN SELECT * FROM t1 END//
2094
There are Select_Lex::add_table_to_list &
2095
Select_Lex::set_lock_for_tables are in sql_parse.cc
2097
Select_Lex::print is in sql_select.cc
2099
Select_Lex_Unit::prepare, Select_Lex_Unit::exec,
2100
Select_Lex_Unit::cleanup, Select_Lex_Unit::reinit_exec_mechanism,
2101
Select_Lex_Unit::change_result
2543
Save current state of Query_tables_list for this LEX, and prepare it
2544
for processing of new statemnt.
2547
reset_n_backup_query_tables_list()
2548
backup Pointer to Query_tables_list instance to be used for backup
2551
void st_lex::reset_n_backup_query_tables_list(Query_tables_list *backup __attribute__((unused)))
2557
Restore state of Query_tables_list for this LEX from backup.
2560
restore_backup_query_tables_list()
2561
backup Pointer to Query_tables_list instance used for backup
2564
void st_lex::restore_backup_query_tables_list(Query_tables_list *backup __attribute__((unused)))
2570
Checks for usage of routines and/or tables in a parsed statement
2573
st_lex:table_or_sp_used()
2576
false No routines and tables used
2577
true Either or both routines and tables are used.
2580
bool st_lex::table_or_sp_used()
2582
if (sroutines.records || query_tables)
2590
Do end-of-prepare fixup for list of tables and their merge-VIEWed tables
2593
fix_prepare_info_in_table_list()
2595
tbl List of tables to process
2598
Perform end-end-of prepare fixup for list of tables, if any of the tables
2599
is a merge-algorithm VIEW, recursively fix up its underlying tables as
2604
static void fix_prepare_info_in_table_list(THD *thd, TableList *tbl)
2606
for (; tbl; tbl= tbl->next_local)
2610
tbl->prep_on_expr= tbl->on_expr;
2611
tbl->on_expr= tbl->on_expr->copy_andor_structure(thd);
2613
fix_prepare_info_in_table_list(thd, tbl->merge_underlying_list);
2619
There are st_select_lex::add_table_to_list &
2620
st_select_lex::set_lock_for_tables are in sql_parse.cc
2622
st_select_lex::print is in sql_select.cc
2624
st_select_lex_unit::prepare, st_select_lex_unit::exec,
2625
st_select_lex_unit::cleanup, st_select_lex_unit::reinit_exec_mechanism,
2626
st_select_lex_unit::change_result
2102
2627
are in sql_union.cc
2114
2639
Used in filling up the tagged hints list.
2115
This list is filled by first setting the kind of the hint as a
2640
This list is filled by first setting the kind of the hint as a
2116
2641
context variable and then adding hints of the current kind.
2117
2642
Then the context variable index_hint_type can be reset to the
2118
2643
next hint type.
2120
void Select_Lex::set_index_hint_type(enum index_hint_type type_arg, index_clause_map clause)
2645
void st_select_lex::set_index_hint_type(enum index_hint_type type_arg,
2646
index_clause_map clause)
2122
2648
current_index_hint_type= type_arg;
2123
2649
current_index_hint_clause= clause;
2127
2654
Makes an array to store index usage hints (ADD/FORCE/IGNORE INDEX).
2130
2657
alloc_index_hints()
2131
session current thread.
2133
void Select_Lex::alloc_index_hints (Session *session)
2135
index_hints= new (session->mem_root) List<Index_hint>();
2661
void st_select_lex::alloc_index_hints (THD *thd)
2663
index_hints= new (thd->mem_root) List<Index_hint>();
2139
adds an element to the array storing index usage hints
2669
adds an element to the array storing index usage hints
2140
2670
(ADD/FORCE/IGNORE INDEX).
2143
2673
add_index_hint()
2144
session current thread.
2145
2675
str name of the index.
2146
2676
length number of characters in str.
2149
2679
0 on success, non-zero otherwise
2151
bool Select_Lex::add_index_hint (Session *session, char *str, uint32_t length)
2681
bool st_select_lex::add_index_hint (THD *thd, char *str, uint length)
2153
return index_hints->push_front (new (session->mem_root)
2683
return index_hints->push_front (new (thd->mem_root)
2154
2684
Index_hint(current_index_hint_type,
2155
2685
current_index_hint_clause,
2159
bool check_for_sql_keyword(drizzled::lex_string_t const& string)
2161
if (sql_reserved_words::in_word_set(string.str, string.length))
2167
bool check_for_sql_keyword(drizzled::st_lex_symbol const& string)
2169
if (sql_reserved_words::in_word_set(string.str, string.length))
2176
} /* namespace drizzled */