Commit 177e99f3 authored by unknown's avatar unknown
Browse files

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 c0af1e3c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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,
+28 −0
Original line number Diff line number Diff line
@@ -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.
+5 −1
Original line number Diff line number Diff line
@@ -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);
  }