-
unknown authored
or implicitly uses stored function gives "Table not locked" error' CREATE TABLE ... SELECT ... statement which was explicitly or implicitly (through view) using stored function gave "Table not locked" error. The actual bug resides in the current locking scheme of CREATE TABLE SELECT code, which first opens and locks tables of the SELECT statement itself, and then, having SELECT tables locked, creates the .FRM, opens the .FRM and acquires lock on it. This scheme opens a possibility for a deadlock, which was present and ignored since version 3.23 or earlier. This scheme also conflicts with the invariant of the prelocking algorithm -- no table can be open and locked while there are tables locked in prelocked mode. The patch makes an exception for this invariant when doing CREATE TABLE ... SELECT, thus extending the possibility of a deadlock to the prelocked mode. We can't supply a better fix in 5.0. mysql-test/r/sp.result: Added tests for bugs#12472/#15137 'CREATE TABLE ... SELECT ... which explicitly or implicitly uses stored function gives "Table not locked" error' mysql-test/t/sp.test: Added tests for bugs#12472/#15137 'CREATE TABLE ... SELECT ... which explicitly or implicitly uses stored function gives "Table not locked" error' sql/mysql_priv.h: Added flag which can be passed to open_table() routine in order to ignore set of locked tables and prelocked mode. We don't need declaration of create_table_from_items() any longer as it was moved into sql_insert.cc and made static. sql/sql_base.cc: open_table(): Added flag which allows open table ignoring set of locked tables and prelocked mode. sql/sql_insert.cc: Moved create_table_from_items() from sql_table.cc to sql_insert.cc as it was not used outside of sql_insert.cc and contains code which is specific for CREATE TABLE ... SELECT. Also now when we are executing CREATE TABLE ... SELECT ... statement which SELECT part requires execution in prelocked mode we ignore set of locked tables in order to get access to the table we just have created. We probably don't want to do this if we are under real LOCK TABLES since it will widen window for deadlock too much. sql/sql_table.cc: Moved create_table_from_items() routine into sql_insert.cc, since it was not used anywhere outside of this file and contains logic which is specific for CREATE TABLE ... SELECT statement.
4f15a043