Commit 4c43672a authored by unknown's avatar unknown

Fix bug in INSERT DELAYED with prepared statements

The bug was that if you have two TL_WRITE_DELAYED at the same time,
mi_lock_databases() could be done in the wrong order and we could write the wrong header to the MyISAM index file.


sql/mysql_priv.h:
  Fix bug in insert delayed with prepared statements
sql/sql_base.cc:
  Fix bug in insert delayed with prepared statements
sql/sql_prepare.cc:
  Fix bug in insert delayed with prepared statements
  The bug was that if you have two TL_WRITE_DELAYED at the same time,
  mi_lock_databases() could be done in the wrong order and we could write the wrong header to the MyISAM index file.
parent 2d54c8cd
......@@ -725,6 +725,7 @@ void wait_for_refresh(THD *thd);
int open_tables(THD *thd, TABLE_LIST *tables, uint *counter);
int simple_open_n_lock_tables(THD *thd,TABLE_LIST *tables);
int open_and_lock_tables(THD *thd,TABLE_LIST *tables);
int open_normal_and_derived_tables(THD *thd, TABLE_LIST *tables);
void relink_tables_for_derived(THD *thd);
int lock_tables(THD *thd, TABLE_LIST *tables, uint counter);
TABLE *open_temporary_table(THD *thd, const char *path, const char *db,
......
......@@ -1702,6 +1702,34 @@ int open_and_lock_tables(THD *thd, TABLE_LIST *tables)
}
/*
Open all tables in list and process derived tables
SYNOPSIS
open_normal_and_derived_tables
thd - thread handler
tables - list of tables for open&locking
RETURN
FALSE - ok
TRUE - error
NOTE
This is to be used on prepare stage when you don't read any
data from the tables.
*/
int open_normal_and_derived_tables(THD *thd, TABLE_LIST *tables)
{
uint counter;
DBUG_ENTER("open_normal_and_derived_tables");
if (open_tables(thd, tables, &counter))
DBUG_RETURN(-1); /* purecov: inspected */
relink_tables_for_derived(thd);
DBUG_RETURN(mysql_handle_derived(thd->lex));
}
/*
Let us propagate pointers to open tables from global table list
to table lists in particular selects if needed.
......
......@@ -897,8 +897,12 @@ static int mysql_test_insert(Prepared_statement *stmt,
/*
open temporary memory pool for temporary data allocated by derived
tables & preparation procedure
Note that this is done without locks (should not be needed as we will not
access any data here)
If we would use locks, then we have to ensure we are not using
TL_WRITE_DELAYED as having two such locks can cause table corruption.
*/
if (open_and_lock_tables(thd, table_list))
if (open_normal_and_derived_tables(thd, table_list))
{
DBUG_RETURN(-1);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment