Skip to content

Commit 62fd6aa

Browse files
author
malff/marcsql@weblab.(none)
committed
manual merge 5.0-runtime -> 5.1->runtime, with 25411 part I
1 parent 18d7ed6 commit 62fd6aa

18 files changed

+477
-298
lines changed

sql/event_data_objects.cc

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,14 @@ void
156156
Event_parse_data::init_body(THD *thd)
157157
{
158158
DBUG_ENTER("Event_parse_data::init_body");
159+
160+
/* This method is called from within the parser, from sql_yacc.yy */
161+
DBUG_ASSERT(thd->m_lip != NULL);
162+
159163
DBUG_PRINT("info", ("body: '%s' body_begin: 0x%lx end: 0x%lx", body_begin,
160-
(long) body_begin, (long) thd->lex->ptr));
164+
(long) body_begin, (long) thd->m_lip->ptr));
161165

162-
body.length= thd->lex->ptr - body_begin;
166+
body.length= thd->m_lip->ptr - body_begin;
163167
const char *body_end= body_begin + body.length - 1;
164168

165169
/* Trim nuls or close-comments ('*'+'/') or spaces at the end */
@@ -1912,15 +1916,20 @@ Event_job_data::execute(THD *thd, bool drop)
19121916
thd->query= sp_sql.c_ptr_safe();
19131917
thd->query_length= sp_sql.length();
19141918

1915-
lex_start(thd, thd->query, thd->query_length);
1916-
1917-
if (MYSQLparse(thd) || thd->is_fatal_error)
19181919
{
1919-
sql_print_error("Event Scheduler: "
1920-
"%serror during compilation of %s.%s",
1921-
thd->is_fatal_error ? "fatal " : "",
1922-
(const char *) dbname.str, (const char *) name.str);
1923-
goto end;
1920+
Lex_input_stream lip(thd, thd->query, thd->query_length);
1921+
thd->m_lip= &lip;
1922+
lex_start(thd);
1923+
int err= MYSQLparse(thd);
1924+
1925+
if (err || thd->is_fatal_error)
1926+
{
1927+
sql_print_error("Event Scheduler: "
1928+
"%serror during compilation of %s.%s",
1929+
thd->is_fatal_error ? "fatal " : "",
1930+
(const char *) dbname.str, (const char *) name.str);
1931+
goto end;
1932+
}
19241933
}
19251934

19261935
{

sql/ha_ndbcluster.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6564,7 +6564,7 @@ int ndb_create_table_from_engine(THD *thd, const char *db,
65646564
LEX *old_lex= thd->lex, newlex;
65656565
thd->lex= &newlex;
65666566
newlex.current_select= NULL;
6567-
lex_start(thd, "", 0);
6567+
lex_start(thd);
65686568
int res= ha_create_table_from_engine(thd, db, table_name);
65696569
thd->lex= old_lex;
65706570
return res;

sql/ha_ndbcluster_binlog.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ static void run_query(THD *thd, char *buf, char *end,
230230
ulonglong save_thd_options= thd->options;
231231
DBUG_ASSERT(sizeof(save_thd_options) == sizeof(thd->options));
232232
NET save_net= thd->net;
233+
const char* found_semicolon= NULL;
233234

234235
bzero((char*) &thd->net, sizeof(NET));
235236
thd->query_length= end - buf;
@@ -239,7 +240,7 @@ static void run_query(THD *thd, char *buf, char *end,
239240
thd->options&= ~OPTION_BIN_LOG;
240241

241242
DBUG_PRINT("query", ("%s", thd->query));
242-
mysql_parse(thd, thd->query, thd->query_length);
243+
mysql_parse(thd, thd->query, thd->query_length, &found_semicolon);
243244

244245
if (print_error && thd->query_error)
245246
{

sql/log_event.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5863,7 +5863,7 @@ int Rows_log_event::do_apply_event(RELAY_LOG_INFO const *rli)
58635863
Table_map_log_event::do_apply_event() we don't call
58645864
mysql_init_query() as that may reset the binlog format.
58655865
*/
5866-
lex_start(thd, NULL, 0);
5866+
lex_start(thd);
58675867

58685868
while ((error= lock_tables(thd, rli->tables_to_lock,
58695869
rli->tables_to_lock_count, &need_reopen)))
@@ -6513,7 +6513,8 @@ int Table_map_log_event::do_apply_event(RELAY_LOG_INFO const *rli)
65136513
initialized, so we should call lex_start(); to be even safer, we
65146514
call mysql_init_query() which does a more complete set of inits.
65156515
*/
6516-
mysql_init_query(thd, NULL, 0);
6516+
lex_start(thd);
6517+
mysql_reset_thd_for_next_command(thd);
65176518
/*
65186519
Check if the slave is set to use SBR. If so, it should switch
65196520
to using RBR until the end of the "statement", i.e., next

sql/mysql_priv.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,13 +838,15 @@ bool do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db,
838838
bool skip_error);
839839
bool mysql_change_db(THD *thd, const LEX_STRING *new_db_name,
840840
bool force_switch);
841-
void mysql_parse(THD *thd,char *inBuf,uint length);
841+
842+
void mysql_parse(THD *thd, const char *inBuf, uint length,
843+
const char ** semicolon);
844+
842845
bool mysql_test_parse_for_slave(THD *thd,char *inBuf,uint length);
843846
bool is_update_query(enum enum_sql_command command);
844847
bool alloc_query(THD *thd, const char *packet, uint packet_length);
845848
void mysql_init_select(LEX *lex);
846849
void mysql_reset_thd_for_next_command(THD *thd);
847-
void mysql_init_query(THD *thd, const char *buf, uint length);
848850
bool mysql_new_select(LEX *lex, bool move_down);
849851
void create_select_for_variable(const char *var_name);
850852
void mysql_init_multi_delete(LEX *lex);

sql/slave.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,7 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db,
923923
handler *file;
924924
ulonglong save_options;
925925
NET *net= &mysql->net;
926+
const char *found_semicolon= NULL;
926927
DBUG_ENTER("create_table_from_dump");
927928

928929
packet_len= my_net_read(net); // read create table statement
@@ -974,7 +975,7 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db,
974975
thd->db = (char*)db;
975976
DBUG_ASSERT(thd->db != 0);
976977
thd->db_length= strlen(thd->db);
977-
mysql_parse(thd, thd->query, packet_len); // run create table
978+
mysql_parse(thd, thd->query, packet_len, &found_semicolon); // run create table
978979
thd->db = save_db; // leave things the way the were before
979980
thd->db_length= save_db_length;
980981
thd->options = save_options;

sql/sp.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,15 @@ db_load_routine(THD *thd, int type, sp_name *name, sp_head **sphp,
384384
if ((ret= sp_use_new_db(thd, name->m_db, &old_db, 1, &dbchanged)))
385385
goto end;
386386

387-
lex_start(thd, defstr.c_ptr(), defstr.length());
387+
{
388+
Lex_input_stream lip(thd, defstr.c_ptr(), defstr.length());
389+
thd->m_lip= &lip;
390+
lex_start(thd);
391+
ret= MYSQLparse(thd);
392+
}
388393

389394
thd->spcont= 0;
390-
if (MYSQLparse(thd) || thd->is_fatal_error || newlex.sphead == NULL)
395+
if (ret || thd->is_fatal_error || newlex.sphead == NULL)
391396
{
392397
sp_head *sp= newlex.sphead;
393398

sql/sp_head.cc

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ sp_head::init_strings(THD *thd, LEX *lex)
557557
const char *endp; /* Used to trim the end */
558558
/* During parsing, we must use thd->mem_root */
559559
MEM_ROOT *root= thd->mem_root;
560+
Lex_input_stream *lip=thd->m_lip;
560561

561562
if (m_param_begin && m_param_end)
562563
{
@@ -565,7 +566,7 @@ sp_head::init_strings(THD *thd, LEX *lex)
565566
}
566567

567568
/* If ptr has overrun end_of_query then end_of_query is the end */
568-
endp= (lex->ptr > lex->end_of_query ? lex->end_of_query : lex->ptr);
569+
endp= (lip->ptr > lip->end_of_query ? lip->end_of_query : lip->ptr);
569570
/*
570571
Trim "garbage" at the end. This is sometimes needed with the
571572
"/ * ! VERSION... * /" wrapper in dump files.
@@ -574,8 +575,8 @@ sp_head::init_strings(THD *thd, LEX *lex)
574575

575576
m_body.length= endp - m_body_begin;
576577
m_body.str= strmake_root(root, m_body_begin, m_body.length);
577-
m_defstr.length= endp - lex->buf;
578-
m_defstr.str= strmake_root(root, lex->buf, m_defstr.length);
578+
m_defstr.length= endp - lip->buf;
579+
m_defstr.str= strmake_root(root, lip->buf, m_defstr.length);
579580
DBUG_VOID_RETURN;
580581
}
581582

@@ -1815,25 +1816,13 @@ sp_head::reset_lex(THD *thd)
18151816
DBUG_ENTER("sp_head::reset_lex");
18161817
LEX *sublex;
18171818
LEX *oldlex= thd->lex;
1818-
my_lex_states org_next_state= oldlex->next_state;
18191819

18201820
(void)m_lex.push_front(oldlex);
18211821
thd->lex= sublex= new st_lex;
18221822

1823-
/* Reset most stuff. The length arguments doesn't matter here. */
1824-
lex_start(thd, oldlex->buf, (ulong) (oldlex->end_of_query - oldlex->ptr));
1823+
/* Reset most stuff. */
1824+
lex_start(thd);
18251825

1826-
/*
1827-
next_state is normally the same (0), but it happens that we swap lex in
1828-
"mid-sentence", so we must restore it.
1829-
*/
1830-
sublex->next_state= org_next_state;
1831-
/* We must reset ptr and end_of_query again */
1832-
sublex->ptr= oldlex->ptr;
1833-
sublex->end_of_query= oldlex->end_of_query;
1834-
sublex->tok_start= oldlex->tok_start;
1835-
sublex->tok_end= oldlex->tok_end;
1836-
sublex->yylineno= oldlex->yylineno;
18371826
/* And keep the SP stuff too */
18381827
sublex->sphead= oldlex->sphead;
18391828
sublex->spcont= oldlex->spcont;
@@ -1866,10 +1855,6 @@ sp_head::restore_lex(THD *thd)
18661855
if (! oldlex)
18671856
return; // Nothing to restore
18681857

1869-
// Update some state in the old one first
1870-
oldlex->ptr= sublex->ptr;
1871-
oldlex->tok_end= sublex->tok_end;
1872-
oldlex->next_state= sublex->next_state;
18731858
oldlex->trg_table_fields.push_back(&sublex->trg_table_fields);
18741859

18751860
/*

sql/sp_head.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ class sp_head :private Query_arena
176176
*/
177177
HASH m_sroutines;
178178
// Pointers set during parsing
179-
const char *m_param_begin, *m_param_end, *m_body_begin;
179+
const char *m_param_begin;
180+
const char *m_param_end;
181+
const char *m_body_begin;
180182

181183
/*
182184
Security context for stored routine which should be run under

sql/sql_class.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class Load_log_event;
3131
class Slave_log_event;
3232
class sp_rcontext;
3333
class sp_cache;
34+
class Lex_input_stream;
3435
class Rows_log_event;
3536

3637
enum enum_enable_or_disable { LEAVE_AS_IS, ENABLE, DISABLE };
@@ -1423,6 +1424,16 @@ class THD :public Statement,
14231424
*/
14241425
query_id_t first_query_id;
14251426
} binlog_evt_union;
1427+
1428+
/**
1429+
Character input stream consumed by the lexical analyser,
1430+
used during parsing.
1431+
Note that since the parser is not re-entrant, we keep only one input
1432+
stream here. This member is valid only when executing code during parsing,
1433+
and may point to invalid memory after that.
1434+
*/
1435+
Lex_input_stream *m_lip;
1436+
14261437
#ifdef WITH_PARTITION_STORAGE_ENGINE
14271438
partition_info *work_part_info;
14281439
#endif

0 commit comments

Comments
 (0)