A fix and test case for Bug#5985 ""prepare stmt from "select rand(?)"
crashes server." The fix makes Item_func_rand prepared-statements aware plus it fixes the case when RAND is used in prepared statements and replication is on (as well as several similar issues). Until now we did not reset THD before every execution of a prepared statement, so if some execution had set thd->time_zone_used or thd->rand_used they would not be reset until next mysql_parse. Some of post-review fixes done. mysql-test/r/ps.result: A test case for Bug#5985: test results fixed. mysql-test/t/ps.test: A test case for Bug#5985 "prepare stmt from "select rand(?)" crashes server." sql/item_func.cc: Actual fix for Bug#5985: Item_func_rand rewritten to be prepared statements aware. sql/item_func.h: Actual fix for Bug#5985: Item_func_rand rewritten to be prepared statements aware. sql/mysql_priv.h: We need a separate call to reset THD state before every execute of a prepared statement. Otherwise things like THD->user_var_events are never cleaned up and bloat binary log (as the list of events grows from execution to execution). sql/sql_class.cc: Statement::end_statement -> THD::end_statement() (a leftover from some design change which is not to pushed now, but the leftover is to be pushed). sql/sql_class.h: Statement::end_statement -> THD::end_statement() (a leftover from some design change which is not to pushed now, but the leftover is to be pushed). sql/sql_lex.cc: Move the part responsible for initializing LEX from mysql_init_query to lex_start. sql/sql_lex.h: All lex-related initialization is now in lex_start. Move thd->select_number to lex->select_number to be able to use it easily in lex_start. sql/sql_parse.cc: Split mysql_init_query into two functions: mysql_reset_thd_for_next_query, which is used in PS and conventional execution, and lex_start, used only when we want to parse something. Fix init_connect to use initialized THD. sql/sql_prepare.cc: Deploy mysql_reset_thd_for_next_query to reset THD state before execution of a prepared statement. Normally this should have been added to just one place, but we have to reset thd before assigning placeholders from variables, thus we can't do that in execute_stmt (yuck).
Showing
Please register or sign in to comment