mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Bug#30384: Having SQL_BUFFER_RESULT option in the CREATE .. KEY(..) .. SELECT
led to creating corrupted index. While execution of the CREATE .. SELECT SQL_BUFFER_RESULT statement the engine->start_bulk_insert function was called twice. On the first call On the first call MyISAM disabled all non-unique indexes and on the second call it decides to not re-enable them because all indexes was disabled. Due to this no indexes was actually created during CREATE TABLE thus producing crashed table. Now the select_inset class has is_bulk_insert_mode flag which prevents calling the start_bulk_insert function twice. The flag is set in the select_create::prepare, select_insert::prepare2 functions and the select_insert class constructor. The flag is reset in the select_insert::send_eof function.
This commit is contained in:
@ -2647,7 +2647,8 @@ select_insert::select_insert(TABLE_LIST *table_list_par, TABLE *table_par,
|
||||
bool ignore_check_option_errors)
|
||||
:table_list(table_list_par), table(table_par), fields(fields_par),
|
||||
last_insert_id(0),
|
||||
insert_into_view(table_list_par && table_list_par->view != 0)
|
||||
insert_into_view(table_list_par && table_list_par->view != 0),
|
||||
is_bulk_insert_mode(FALSE)
|
||||
{
|
||||
bzero((char*) &info,sizeof(info));
|
||||
info.handle_duplicates= duplic;
|
||||
@ -2832,8 +2833,11 @@ int select_insert::prepare2(void)
|
||||
{
|
||||
DBUG_ENTER("select_insert::prepare2");
|
||||
if (thd->lex->current_select->options & OPTION_BUFFER_RESULT &&
|
||||
!thd->prelocked_mode)
|
||||
!thd->prelocked_mode && !is_bulk_insert_mode)
|
||||
{
|
||||
table->file->start_bulk_insert((ha_rows) 0);
|
||||
is_bulk_insert_mode= TRUE;
|
||||
}
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
|
||||
@ -2939,6 +2943,7 @@ bool select_insert::send_eof()
|
||||
DBUG_ENTER("select_insert::send_eof");
|
||||
|
||||
error= (!thd->prelocked_mode) ? table->file->end_bulk_insert():0;
|
||||
is_bulk_insert_mode= FALSE;
|
||||
table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
|
||||
table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
|
||||
|
||||
@ -3271,7 +3276,10 @@ select_create::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
|
||||
if (info.handle_duplicates == DUP_UPDATE)
|
||||
table->file->extra(HA_EXTRA_INSERT_WITH_UPDATE);
|
||||
if (!thd->prelocked_mode)
|
||||
{
|
||||
table->file->start_bulk_insert((ha_rows) 0);
|
||||
is_bulk_insert_mode= TRUE;
|
||||
}
|
||||
thd->abort_on_warning= (!info.ignore &&
|
||||
(thd->variables.sql_mode &
|
||||
(MODE_STRICT_TRANS_TABLES |
|
||||
|
Reference in New Issue
Block a user