Commit bb5cdfb8 authored by evgen@sunlight.local's avatar evgen@sunlight.local

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.
parent 4ffcc4f2
......@@ -830,3 +830,15 @@ id prev_id join_id
3 2 0
4 3 0
DROP TABLE t1,t2;
#
# Bug#30384: Having SQL_BUFFER_RESULT option in the
# CREATE .. KEY(..) .. SELECT led to creating corrupted index.
#
create table t1(f1 int);
insert into t1 values(1),(2),(3);
create table t2 (key(f1)) engine=myisam select sql_buffer_result f1 from t1;
check table t2 extended;
Table Op Msg_type Msg_text
test.t2 check status OK
drop table t1,t2;
##################################################################
......@@ -385,3 +385,15 @@ INSERT INTO t1 (prev_id) SELECT id
SELECT * FROM t1;
DROP TABLE t1,t2;
--echo #
--echo # Bug#30384: Having SQL_BUFFER_RESULT option in the
--echo # CREATE .. KEY(..) .. SELECT led to creating corrupted index.
--echo #
create table t1(f1 int);
insert into t1 values(1),(2),(3);
create table t2 (key(f1)) engine=myisam select sql_buffer_result f1 from t1;
check table t2 extended;
drop table t1,t2;
--echo ##################################################################
......@@ -2029,7 +2029,7 @@ class select_insert :public select_result_interceptor {
ulonglong last_insert_id;
COPY_INFO info;
bool insert_into_view;
bool is_bulk_insert_mode;
select_insert(TABLE_LIST *table_list_par,
TABLE *table_par, List<Item> *fields_par,
List<Item> *update_fields, List<Item> *update_values,
......
......@@ -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 |
......
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