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>
20
#include <drizzled/server_includes.h>
26
21
#include <drizzled/item/num.h>
27
22
#include <drizzled/error.h>
28
23
#include <drizzled/session.h>
29
24
#include <drizzled/sql_base.h>
30
25
#include <drizzled/lookup_symbol.h>
31
#include <drizzled/index_hint.h>
32
#include <drizzled/select_result.h>
39
29
using namespace std;
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.
32
static int lex_one_token(void *arg, void *yysession);
36
We are using pointer to this variable for distinguishing between assignment
37
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);
40
sys_var *trg_new_row_fake_var= (sys_var*) 0x01;
71
43
LEX_STRING constant for null-string to be used in parser and other places.
73
45
const LEX_STRING null_lex_str= {NULL, 0};
49
Names of the index hints (for error messages). Keep in sync with
53
const char * index_hint_type_name[] =
63
st_parsing_options::reset()
65
allows_select_procedure= true;
75
68
Lex_input_stream::Lex_input_stream(Session *session,
76
69
const char* buffer,
77
unsigned int length) :
196
194
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,
198
void Lex_input_stream::body_utf8_append_literal(Session *session,
199
const LEX_STRING *txt,
200
const CHARSET_INFO * const txt_cs,
200
201
const char *end_ptr)
202
203
if (!m_cpp_utf8_processed_ptr)
208
if (!my_charset_same(txt_cs, &my_charset_utf8_general_ci))
210
session->convert_string(&utf_txt,
211
&my_charset_utf8_general_ci,
212
txt->str, txt->length,
217
utf_txt.str= txt->str;
218
utf_txt.length= txt->length;
205
221
/* 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;
223
memcpy(m_body_utf8_ptr, utf_txt.str, utf_txt.length);
224
m_body_utf8_ptr += utf_txt.length;
209
225
*m_body_utf8_ptr= 0;
211
227
m_cpp_utf8_processed_ptr= end_ptr;
215
232
This is called before every query that is to be parsed.
216
233
Because of this, it's critical to not do too much things here.
217
234
(We already do too much here)
219
void LEX::start(Session *arg)
224
237
void lex_start(Session *session)
226
LEX *lex= session->getLex();
239
LEX *lex= session->lex;
228
241
lex->session= lex->unit.session= session;
230
lex->context_stack.clear();
243
lex->context_stack.empty();
231
244
lex->unit.init_query();
232
245
lex->unit.init_select();
233
246
/* 'parent_lex' is used in init_query() so it must be before it. */
234
247
lex->select_lex.parent_lex= lex;
235
248
lex->select_lex.init_query();
236
lex->value_list.clear();
237
lex->update_list.clear();
238
lex->auxiliary_table_list.clear();
249
lex->value_list.empty();
250
lex->update_list.empty();
251
lex->param_list.empty();
252
lex->auxiliary_table_list.empty();
239
253
lex->unit.next= lex->unit.master=
240
254
lex->unit.link_next= lex->unit.return_to= 0;
241
255
lex->unit.prev= lex->unit.link_prev= 0;
247
261
lex->select_lex.link_prev= (Select_Lex_Node**)&(lex->all_selects_list);
248
262
lex->select_lex.options= 0;
249
263
lex->select_lex.init_order();
250
lex->select_lex.group_list.clear();
264
lex->select_lex.group_list.empty();
251
265
lex->describe= 0;
266
lex->subqueries= false;
252
267
lex->derived_tables= 0;
253
268
lex->lock_option= TL_READ;
254
269
lex->leaf_tables_insert= 0;
255
lex->var_list.clear();
270
lex->parsing_options.reset();
256
271
lex->select_lex.select_number= 1;
258
273
lex->select_lex.in_sum_expr=0;
259
lex->select_lex.group_list.clear();
260
lex->select_lex.order_list.clear();
274
lex->select_lex.ftfunc_list_alloc.empty();
275
lex->select_lex.ftfunc_list= &lex->select_lex.ftfunc_list_alloc;
276
lex->select_lex.group_list.empty();
277
lex->select_lex.order_list.empty();
261
278
lex->sql_command= SQLCOM_END;
262
279
lex->duplicates= DUP_ERROR;
281
lex->proc_list.first= 0;
264
282
lex->escape_used= false;
265
283
lex->query_tables= 0;
266
284
lex->reset_query_tables_list(false);
267
285
lex->expr_allows_subselect= true;
268
286
lex->use_only_table_context= false;
287
lex->parse_vcol_expr= false;
270
289
lex->name.str= 0;
271
290
lex->name.length= 0;
272
291
lex->nest_level=0 ;
273
292
lex->allow_sum_func= 0;
274
293
lex->in_sum_func= NULL;
277
295
lex->is_lex_started= true;
278
lex->statement= NULL;
280
lex->is_cross= false;
298
void lex_end(LEX *lex)
302
free(lex->yacc_yyss);
303
free(lex->yacc_yyvs);
295
safe_delete(_create_table);
302
safe_delete(statement);
305
313
static int find_keyword(Lex_input_stream *lip, uint32_t len, bool function)
307
315
/* Plenty of memory for the largest lex symbol we have */
432
445
str= lip->get_tok_start();
433
446
end= lip->get_ptr();
434
447
/* Extract the text from the token */
437
450
assert(end >= str);
439
if (!(start= (char*) lip->m_session->getMemRoot()->allocate((uint32_t) (end-str)+1)))
440
return (char*) ""; // memory::SqlAlloc has set error flag
452
if (!(start= (char*) lip->m_session->alloc((uint32_t) (end-str)+1)))
453
return (char*) ""; // Sql_alloc has set error flag
442
455
lip->m_cpp_text_start= lip->get_cpp_tok_start() + pre_skip;
443
456
lip->m_cpp_text_end= lip->get_cpp_ptr() - post_skip;
447
lip->yytoklen= (uint32_t) (end-str);
448
memcpy(start, str, lip->yytoklen);
449
start[lip->yytoklen]= 0;
460
lip->yytoklen=(uint32_t) (end-str);
461
memcpy(start,str,lip->yytoklen);
462
start[lip->yytoklen]=0;
455
for (to= start; str != end; str++)
459
int l= my_ismbchar(cs, str, end);
468
if (*str == '\\' && (str + 1) != end)
484
*to++= 0; // Ascii null
486
case 'Z': // ^Z must be escaped on Win32
491
*to++= '\\'; // remember prefix for wildcard
468
for (to=start ; str != end ; str++)
473
(l = my_ismbchar(cs, str, end))) {
480
if (*str == '\\' && str+1 != end)
496
*to++= 0; // Ascii null
498
case 'Z': // ^Z must be escaped on Win32
503
*to++= '\\'; // remember prefix for wildcard
498
else if (*str == sep)
499
*to++= *str++; // Two ' or "
504
lip->yytoklen= (uint32_t) (to - start);
510
else if (*str == sep)
511
*to++= *str++; // Two ' or "
516
lip->yytoklen=(uint32_t) (to-start);
518
530
** is done with int64_t or double.
521
static const char *long_str= "2147483647";
522
static const uint32_t long_len= 10;
523
static const char *signed_long_str= "-2147483648";
524
static const char *int64_t_str= "9223372036854775807";
525
static const uint32_t int64_t_len= 19;
526
static const char *signed_int64_t_str= "-9223372036854775808";
527
static const uint32_t signed_int64_t_len= 19;
528
static const char *unsigned_int64_t_str= "18446744073709551615";
529
static const uint32_t unsigned_int64_t_len= 20;
533
static const char *long_str="2147483647";
534
static const uint32_t long_len=10;
535
static const char *signed_long_str="-2147483648";
536
static const char *int64_t_str="9223372036854775807";
537
static const uint32_t int64_t_len=19;
538
static const char *signed_int64_t_str="-9223372036854775808";
539
static const uint32_t signed_int64_t_len=19;
540
static const char *unsigned_int64_t_str="18446744073709551615";
541
static const uint32_t unsigned_int64_t_len=20;
531
543
static inline uint32_t int_token(const char *str,uint32_t length)
600
612
return ((unsigned char) str[-1] <= (unsigned char) cmp[-1]) ? smaller : bigger;
603
} /* namespace drizzled */
605
base_sql_lex remember the following states from the following sql_baselex()
617
DRIZZLElex remember the following states from the following DRIZZLElex()
607
619
- MY_LEX_EOQ Found end of query
608
620
- MY_LEX_OPERATOR_OR_IDENT Last state was an ident, text or number
609
621
(which can't be followed by a signed number)
611
int base_sql_lex(union ParserType *yylval, drizzled::Session *session)
624
int DRIZZLElex(void *arg, void *yysession)
613
drizzled::Lex_input_stream *lip= session->m_lip;
626
Session *session= (Session *)yysession;
627
Lex_input_stream *lip= session->m_lip;
628
YYSTYPE *yylval=(YYSTYPE*) arg;
616
631
if (lip->lookahead_token != END_OF_INPUT)
665
int lex_one_token(ParserType *yylval, drizzled::Session *session)
667
unsigned char c= 0; /* Just set to shutup GCC */
677
int lex_one_token(void *arg, void *yysession)
679
register unsigned char c= 0; /* Just set to shutup GCC */
668
680
bool comment_closed;
669
681
int tokval, result_state;
670
682
unsigned int length;
671
683
enum my_lex_states state;
684
Session *session= (Session *)yysession;
672
685
Lex_input_stream *lip= session->m_lip;
673
LEX *lex= session->getLex();
686
LEX *lex= session->lex;
687
YYSTYPE *yylval=(YYSTYPE*) arg;
674
688
const CHARSET_INFO * const cs= session->charset();
675
689
unsigned char *state_map= cs->state_map;
676
690
unsigned char *ident_map= cs->ident_map;
791
809
for (; state_map[c] == MY_LEX_SKIP ; c= lip->yyGet()) {};
793
811
if (start == lip->get_ptr() && c == '.' && ident_map[(uint8_t)lip->yyPeek()])
794
lip->next_state=MY_LEX_IDENT_SEP;
812
lip->next_state=MY_LEX_IDENT_SEP;
796
814
{ // '(' must follow directly if function
798
if ((tokval = find_keyword(lip, length, c == '(')))
800
lip->next_state= MY_LEX_START; // Allow signed numbers
801
return(tokval); // Was keyword
816
if ((tokval = find_keyword(lip, length, c == '(')))
818
lip->next_state= MY_LEX_START; // Allow signed numbers
819
return(tokval); // Was keyword
803
821
lip->yySkip(); // next state does a unget
805
823
yylval->lex_str=get_token(lip, 0, length);
807
825
lip->body_utf8_append(lip->m_cpp_text_start);
809
lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
827
lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
828
lip->m_cpp_text_end);
811
830
return(result_state); // IDENT or IDENT_QUOTED
855
874
while (my_isdigit(cs, (c = lip->yyGet()))) ;
856
875
if (!ident_map[c])
857
876
{ // Can't be identifier
858
state=MY_LEX_INT_OR_REAL;
877
state=MY_LEX_INT_OR_REAL;
861
880
if (c == 'e' || c == 'E')
863
// The following test is written this way to allow numbers of type 1e1
882
// The following test is written this way to allow numbers of type 1e1
864
883
if (my_isdigit(cs,lip->yyPeek()) ||
865
884
(c=(lip->yyGet())) == '+' || c == '-')
867
886
if (my_isdigit(cs,lip->yyPeek())) // Number must have digit after sign
870
889
while (my_isdigit(cs,lip->yyGet())) ;
871
890
yylval->lex_str=get_token(lip, 0, lip->yyLength());
878
897
case MY_LEX_IDENT_START: // We come here after '.'
879
898
result_state= IDENT;
899
#if defined(USE_MB) && defined(USE_MB_IDENT)
882
result_state= IDENT_QUOTED;
902
result_state= IDENT_QUOTED;
883
903
while (ident_map[c=lip->yyGet()])
885
905
if (my_mbcharlen(cs, c) > 1)
887
int l= my_ismbchar(cs, lip->get_ptr() -1, lip->get_end_of_query());
908
if ((l = my_ismbchar(cs,
910
lip->get_end_of_query())) == 0)
890
912
lip->skip_binary(l-1);
896
919
for (result_state=0; ident_map[c= lip->yyGet()]; result_state|= c) {};
897
920
/* If there were non-ASCII characters, mark that we must convert */
898
921
result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
900
923
if (c == '.' && ident_map[(uint8_t)lip->yyPeek()])
901
lip->next_state=MY_LEX_IDENT_SEP;// Next is '.'
924
lip->next_state=MY_LEX_IDENT_SEP;// Next is '.'
903
926
yylval->lex_str= get_token(lip, 0, lip->yyLength());
905
928
lip->body_utf8_append(lip->m_cpp_text_start);
907
lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
930
lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
931
lip->m_cpp_text_end);
909
933
return(result_state);
914
938
char quote_char= c; // Used char
915
939
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)
942
if ((var_length= my_mbcharlen(cs, c)) == 1)
946
if (lip->yyPeek() != quote_char)
954
else if (var_length < 1)
931
956
lip->skip_binary(var_length-1);
933
959
if (double_quotes)
934
yylval->lex_str=get_quoted_token(lip, 1, lip->yyLength() - double_quotes -1, quote_char);
960
yylval->lex_str=get_quoted_token(lip, 1,
961
lip->yyLength() - double_quotes -1,
936
964
yylval->lex_str=get_token(lip, 1, lip->yyLength() -1);
937
965
if (c == quote_char)
938
966
lip->yySkip(); // Skip end `
939
967
lip->next_state= MY_LEX_START;
940
969
lip->body_utf8_append(lip->m_cpp_text_start);
941
lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
971
lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
972
lip->m_cpp_text_end);
942
974
return(IDENT_QUOTED);
944
976
case MY_LEX_INT_OR_REAL: // Complete int or incomplete real
946
978
{ // Found complete integer number.
947
979
yylval->lex_str=get_token(lip, 0, lip->yyLength());
948
return int_token(yylval->lex_str.str,yylval->lex_str.length);
980
return int_token(yylval->lex_str.str,yylval->lex_str.length);
951
983
case MY_LEX_REAL: // Incomplete real number
954
986
if (c == 'e' || c == 'E')
956
988
c = lip->yyGet();
957
if (c == '-' || c == '+')
958
c = lip->yyGet(); // Skip sign
959
if (!my_isdigit(cs,c))
960
{ // No digit after sign
989
if (c == '-' || c == '+')
990
c = lip->yyGet(); // Skip sign
991
if (!my_isdigit(cs,c))
992
{ // No digit after sign
964
996
while (my_isdigit(cs,lip->yyGet())) ;
965
997
yylval->lex_str=get_token(lip, 0, lip->yyLength());
968
1000
yylval->lex_str=get_token(lip, 0, lip->yyLength());
969
1001
return(DECIMAL_NUM);
1043
1075
case MY_LEX_STRING: // Incomplete text string
1044
1076
if (!(yylval->lex_str.str = get_text(lip, 1, 1)))
1046
state= MY_LEX_CHAR; // Read char by char
1078
state= MY_LEX_CHAR; // Read char by char
1049
1081
yylval->lex_str.length=lip->yytoklen;
1051
1083
lip->body_utf8_append(lip->m_cpp_text_start);
1053
lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
1085
lip->body_utf8_append_literal(session, &yylval->lex_str,
1086
lip->m_underscore_cs ? lip->m_underscore_cs : cs,
1087
lip->m_cpp_text_end);
1089
lip->m_underscore_cs= NULL;
1055
1091
lex->text_string_is_7bit= (lip->tok_bitmap & 0x80) ? 0 : 1;
1056
1092
return(TEXT_STRING);
1172
1208
state=MY_LEX_START;
1175
state=MY_LEX_CHAR; // Return '*'
1211
state=MY_LEX_CHAR; // Return '*'
1177
1213
case MY_LEX_SET_VAR: // Check if ':='
1178
1214
if (lip->yyPeek() != '=')
1180
state=MY_LEX_CHAR; // Return ':'
1216
state=MY_LEX_CHAR; // Return ':'
1184
1220
return (SET_VAR);
1185
1221
case MY_LEX_SEMICOLON: // optional line terminator
1186
1222
if (lip->yyPeek())
1224
if ((session->client_capabilities & CLIENT_MULTI_STATEMENTS))
1226
lip->found_semicolon= lip->get_ptr();
1227
session->server_status|= SERVER_MORE_RESULTS_EXISTS;
1228
lip->next_state= MY_LEX_END;
1229
lip->set_echo(true);
1230
return (END_OF_INPUT);
1188
1232
state= MY_LEX_CHAR; // Return ';'
1191
1235
lip->next_state=MY_LEX_END; // Mark for next loop
1192
1236
return(END_OF_INPUT);
1208
1252
case MY_LEX_END:
1209
1253
lip->next_state=MY_LEX_END;
1210
return false; // We found end of input last time
1254
return(0); // We found end of input last time
1212
1256
/* Actually real shouldn't start with . but allow them anyhow */
1213
1257
case MY_LEX_REAL_OR_POINT:
1214
1258
if (my_isdigit(cs,lip->yyPeek()))
1215
state= MY_LEX_REAL; // Real
1259
state = MY_LEX_REAL; // Real
1218
state= MY_LEX_IDENT_SEP; // return '.'
1262
state= MY_LEX_IDENT_SEP; // return '.'
1219
1263
lip->yyUnget(); // Put back '.'
1224
1268
case MY_LEX_STRING:
1225
1269
case MY_LEX_USER_VARIABLE_DELIMITER:
1226
1270
case MY_LEX_STRING_OR_DELIMITER:
1228
1272
case MY_LEX_USER_END:
1229
lip->next_state=MY_LEX_SYSTEM_VAR;
1273
lip->next_state=MY_LEX_SYSTEM_VAR;
1232
lip->next_state=MY_LEX_HOSTNAME;
1276
lip->next_state=MY_LEX_HOSTNAME;
1235
1279
yylval->lex_str.str=(char*) lip->get_ptr();
1236
1280
yylval->lex_str.length=1;
1237
1281
return((int) '@');
1238
1282
case MY_LEX_HOSTNAME: // end '@' of user@hostname
1239
1283
for (c=lip->yyGet() ;
1240
my_isalnum(cs,c) || c == '.' || c == '_' || c == '$';
1284
my_isalnum(cs,c) || c == '.' || c == '_' || c == '$';
1241
1285
c= lip->yyGet()) ;
1242
1286
yylval->lex_str=get_token(lip, 0, lip->yyLength());
1243
1287
return(LEX_HOSTNAME);
1252
1296
return((int) '@');
1253
1297
case MY_LEX_IDENT_OR_KEYWORD:
1255
We come here when we have found two '@' in a row.
1256
We should now be able to handle:
1257
[(global | local | session) .]variable_name
1299
We come here when we have found two '@' in a row.
1300
We should now be able to handle:
1301
[(global | local | session) .]variable_name
1260
1304
for (result_state= 0; ident_map[c= lip->yyGet()]; result_state|= c) {};
1262
1306
result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
1265
lip->next_state=MY_LEX_IDENT_SEP;
1309
lip->next_state=MY_LEX_IDENT_SEP;
1266
1310
length= lip->yyLength();
1267
1311
if (length == 0)
1268
1312
return(ABORT_SYM); // Names must be nonempty.
1269
1313
if ((tokval= find_keyword(lip, length,0)))
1271
1315
lip->yyUnget(); // Put back 'c'
1272
return(tokval); // Was keyword
1316
return(tokval); // Was keyword
1274
1318
yylval->lex_str=get_token(lip, 0, length);
1276
1320
lip->body_utf8_append(lip->m_cpp_text_start);
1278
lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
1322
lip->body_utf8_append_literal(session, &yylval->lex_str, cs,
1323
lip->m_cpp_text_end);
1280
1325
return(result_state);
1332
Construct a copy of this object to be used for mysql_alter_table
1333
and mysql_create_table.
1335
Historically, these two functions modify their Alter_info
1336
arguments. This behaviour breaks re-execution of prepared
1337
statements and stored procedures and is compensated by always
1338
supplying a copy of Alter_info to these functions.
1340
@return You need to use check the error in Session for out
1341
of memory condition after calling this function.
1344
Alter_info::Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root)
1345
:drop_list(rhs.drop_list, mem_root),
1346
alter_list(rhs.alter_list, mem_root),
1347
key_list(rhs.key_list, mem_root),
1348
create_list(rhs.create_list, mem_root),
1350
keys_onoff(rhs.keys_onoff),
1351
tablespace_op(rhs.tablespace_op),
1352
no_parts(rhs.no_parts),
1353
build_method(rhs.build_method),
1354
datetime_field(rhs.datetime_field),
1355
error_if_not_empty(rhs.error_if_not_empty)
1358
Make deep copies of used objects.
1359
This is not a fully deep copy - clone() implementations
1360
of Alter_drop, Alter_column, Key, foreign_key, Key_part_spec
1361
do not copy string constants. At the same length the only
1362
reason we make a copy currently is that ALTER/CREATE TABLE
1363
code changes input Alter_info definitions, but string
1364
constants never change.
1366
list_copy_and_replace_each_value(drop_list, mem_root);
1367
list_copy_and_replace_each_value(alter_list, mem_root);
1368
list_copy_and_replace_each_value(key_list, mem_root);
1369
list_copy_and_replace_each_value(create_list, mem_root);
1285
1373
void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str)
1562
1660
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
1665
Select_Lex_Node::mark_as_dependent mark all Select_Lex struct from
1666
this to 'last' as dependent
1669
last - pointer to last Select_Lex struct, before wich all
1670
Select_Lex have to be marked as dependent
1673
'last' should be reachable from this Select_Lex_Node
1572
1676
void Select_Lex::mark_as_dependent(Select_Lex *last)
1579
1683
s && s != last;
1580
1684
s= s->outer_select())
1582
if (! (s->uncacheable.test(UNCACHEABLE_DEPENDENT)))
1686
if (!(s->uncacheable & UNCACHEABLE_DEPENDENT))
1584
1688
// Select is dependent of outer select
1585
s->uncacheable.set(UNCACHEABLE_DEPENDENT);
1586
s->uncacheable.set(UNCACHEABLE_UNITED);
1689
s->uncacheable= (s->uncacheable & ~UNCACHEABLE_UNITED) |
1690
UNCACHEABLE_DEPENDENT;
1587
1691
Select_Lex_Unit *munit= s->master_unit();
1588
munit->uncacheable.set(UNCACHEABLE_UNITED);
1589
munit->uncacheable.set(UNCACHEABLE_DEPENDENT);
1692
munit->uncacheable= (munit->uncacheable & ~UNCACHEABLE_UNITED) |
1693
UNCACHEABLE_DEPENDENT;
1590
1694
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);
1697
!(sl->uncacheable & (UNCACHEABLE_DEPENDENT | UNCACHEABLE_UNITED)))
1698
sl->uncacheable|= UNCACHEABLE_UNITED;
1597
1701
s->is_correlated= true;
1604
1708
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>&,
1710
bool Select_Lex_Node::inc_in_sum_expr() { return 1; }
1711
uint32_t Select_Lex_Node::get_in_sum_expr() { return 0; }
1712
TableList* Select_Lex_Node::get_table_list() { return 0; }
1713
List<Item>* Select_Lex_Node::get_item_list() { return 0; }
1714
TableList *Select_Lex_Node::add_table_to_list (Session *, Table_ident *, LEX_STRING *, uint32_t,
1715
thr_lock_type, List<Index_hint> *, LEX_STRING *)
1719
uint32_t Select_Lex_Node::get_table_join_options()
1632
1725
prohibit using LIMIT clause
1638
1731
my_error(ER_NOT_SUPPORTED_YET, MYF(0),
1639
1732
"LIMIT & IN/ALL/ANY/SOME subquery");
1645
1739
Select_Lex_Unit* Select_Lex_Unit::master_unit()
1650
1745
Select_Lex* Select_Lex_Unit::outer_select()
1652
1747
return (Select_Lex*) master;
1655
1751
bool Select_Lex::add_order_to_list(Session *session, Item *item, bool asc)
1657
1753
return add_to_list(session, order_list, item, asc);
1660
1757
bool Select_Lex::add_item_to_list(Session *, Item *item)
1662
1759
return(item_list.push_back(item));
1665
1763
bool Select_Lex::add_group_to_list(Session *session, Item *item, bool asc)
1667
1765
return add_to_list(session, group_list, item, asc);
1670
1769
Select_Lex_Unit* Select_Lex::master_unit()
1672
1771
return (Select_Lex_Unit*) master;
1675
1775
Select_Lex* Select_Lex::outer_select()
1677
1777
return (Select_Lex*) master->get_master();
1680
1781
bool Select_Lex::set_braces(bool value)
1686
1788
bool Select_Lex::inc_in_sum_expr()
1692
1795
uint32_t Select_Lex::get_in_sum_expr()
1694
1797
return in_sum_expr;
1697
1801
TableList* Select_Lex::get_table_list()
1699
1803
return (TableList*) table_list.first;
1704
1808
return &item_list;
1811
uint32_t Select_Lex::get_table_join_options()
1813
return table_join_options;
1708
1817
bool Select_Lex::setup_ref_array(Session *session, uint32_t order_group_num)
1710
1819
if (ref_pointer_array)
1713
1822
return (ref_pointer_array=
1714
(Item **)session->getMemRoot()->allocate(sizeof(Item*) * (n_child_sum_items +
1823
(Item **)session->alloc(sizeof(Item*) * (n_child_sum_items +
1715
1824
item_list.elements +
1716
1825
select_n_having_items +
1717
1826
select_n_where_fields +
1718
1827
order_group_num)*5)) == 0;
1721
1831
void Select_Lex_Unit::print(String *str, enum_query_type query_type)
1723
1833
bool union_all= !union_distinct;
1744
1854
str->append(STRING_WITH_LEN(" order by "));
1745
1855
fake_select_lex->print_order(
1747
(Order *) fake_select_lex->order_list.first,
1857
(order_st *) fake_select_lex->order_list.first,
1750
1860
fake_select_lex->print_limit(session, str, query_type);
1754
1865
void Select_Lex::print_order(String *str,
1756
1867
enum_query_type query_type)
1758
1869
for (; order; order= order->next)
1927
@brief Restore the LEX and Session in case of a parse error.
1929
This is a clean up call that is invoked by the Bison generated
1930
parser before returning an error from DRIZZLEparse. If your
1931
semantic actions manipulate with the global thread state (which
1932
is a very bad practice and should not normally be employed) and
1933
need a clean-up in case of error, and you can not use %destructor
1934
rule in the grammar file itself, this function should be used
1935
to implement the clean up.
1938
void LEX::cleanup_lex_after_parse_error(Session *)
1816
delete _create_table;
1863
2000
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),
2005
:result(0), yacc_yyss(0), yacc_yyvs(0),
2006
sql_command(SQLCOM_END), option_type(OPT_DEFAULT), is_lex_started(0)
1883
2009
reset_query_tables_list(true);
2013
Detect that we need only table structure of derived table/view
2016
only_view_structure()
2019
true yes, we need only structure
2020
false no, we need data
2023
bool LEX::only_view_structure()
2025
switch (sql_command) {
2026
case SQLCOM_SHOW_CREATE:
2027
case SQLCOM_SHOW_TABLES:
2028
case SQLCOM_SHOW_FIELDS:
2037
Should Items_ident be printed correctly
2040
need_correct_ident()
2043
true yes, we need only structure
2044
false no, we need data
2048
bool LEX::need_correct_ident()
2052
case SQLCOM_SHOW_CREATE:
2053
case SQLCOM_SHOW_TABLES:
1887
2062
This method should be called only during parsing.
1888
2063
It is aware of compound statements (stored routine bodies)
2065
2251
derived tables state. To rollback changes in Query_tables_list one has
2066
2252
to call Query_tables_list::reset_query_tables_list(false).
2068
2255
void LEX::cleanup_after_one_table_open()
2071
session->getLex()->derived_tables & additional units may be set if we open
2072
a view. It is necessary to clear session->getLex()->derived_tables flag
2073
to prevent processing of derived tables during next openTablesLock
2258
session->lex->derived_tables & additional units may be set if we open
2259
a view. It is necessary to clear session->lex->derived_tables flag
2260
to prevent processing of derived tables during next open_and_lock_tables
2074
2261
if next table is a real table and cleanup & remove underlying units
2075
NOTE: all units will be connected to session->getLex()->select_lex, because we
2262
NOTE: all units will be connected to session->lex->select_lex, because we
2076
2263
have not UNION on most upper level.
2078
2265
if (all_selects_list != &select_lex)
2282
Do end-of-prepare fixup for list of tables and their merge-VIEWed tables
2285
fix_prepare_info_in_table_list()
2286
session Thread handle
2287
tbl List of tables to process
2290
Perform end-end-of prepare fixup for list of tables, if any of the tables
2291
is a merge-algorithm VIEW, recursively fix up its underlying tables as
2296
static void fix_prepare_info_in_table_list(Session *session, TableList *tbl)
2298
for (; tbl; tbl= tbl->next_local)
2302
tbl->prep_on_expr= tbl->on_expr;
2303
tbl->on_expr= tbl->on_expr->copy_andor_structure(session);
2305
fix_prepare_info_in_table_list(session, tbl->merge_underlying_list);
2094
2311
There are Select_Lex::add_table_to_list &
2095
2312
Select_Lex::set_lock_for_tables are in sql_parse.cc