Commit f638ee6d authored by monty@mashka.mysql.fi's avatar monty@mashka.mysql.fi

Added code to flush a bulk_insert index.

This fixes a bug when doing multi-row inserts on table with an auto_increment key that is not in the first key segment.
parent dfd0f82b
...@@ -50442,6 +50442,12 @@ each individual 4.0.x release. ...@@ -50442,6 +50442,12 @@ each individual 4.0.x release.
@itemize @bullet @itemize @bullet
@item @item
Fixed bug when doing a multi-line insert on a table with an
auto_increment key which was not in the first part of the key.
@item
Changed @code{LOAD DATA INFILE} to not recreate index if the table had
rows from before.
@item
Fixed overrun bug when calling @code{AES_DECRYPT()} with wrong arguments Fixed overrun bug when calling @code{AES_DECRYPT()} with wrong arguments
@item @item
@code{--skip-ssl} can now be used to disable SSL in the MySQL clients, @code{--skip-ssl} can now be used to disable SSL in the MySQL clients,
...@@ -107,6 +107,7 @@ enum ha_extra_function { ...@@ -107,6 +107,7 @@ enum ha_extra_function {
HA_EXTRA_NO_IGNORE_DUP_KEY, HA_EXTRA_NO_IGNORE_DUP_KEY,
HA_EXTRA_DONT_USE_CURSOR_TO_UPDATE, /* Cursor will not be used for update */ HA_EXTRA_DONT_USE_CURSOR_TO_UPDATE, /* Cursor will not be used for update */
HA_EXTRA_BULK_INSERT_BEGIN, HA_EXTRA_BULK_INSERT_BEGIN,
HA_EXTRA_BULK_INSERT_FLUSH, /* Flush one index */
HA_EXTRA_BULK_INSERT_END, HA_EXTRA_BULK_INSERT_END,
HA_EXTRA_PREPARE_FOR_DELETE HA_EXTRA_PREPARE_FOR_DELETE
}; };
......
...@@ -34,7 +34,9 @@ ...@@ -34,7 +34,9 @@
HA_EXTRA_WRITE_CACHE HA_EXTRA_WRITE_CACHE
HA_EXTRA_CACHE HA_EXTRA_CACHE
HA_EXTRA_BULK_INSERT_BEGIN HA_EXTRA_BULK_INSERT_BEGIN
If extra_arg is 0, then the default cache size is used. If extra_arg is 0, then the default cache size is used.
HA_EXTRA_BULK_INSERT_FLUSH
extra_arg is a a pointer to which index to flush (uint*)
RETURN VALUES RETURN VALUES
0 ok 0 ok
*/ */
...@@ -356,6 +358,14 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg) ...@@ -356,6 +358,14 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg)
error=_mi_init_bulk_insert(info, (extra_arg ? *(ulong*) extra_arg : error=_mi_init_bulk_insert(info, (extra_arg ? *(ulong*) extra_arg :
myisam_bulk_insert_tree_size)); myisam_bulk_insert_tree_size));
break; break;
case HA_EXTRA_BULK_INSERT_FLUSH:
if (info->bulk_insert)
{
uint index_to_flush= *(uint*) extra_arg;
if (is_tree_inited(&info->bulk_insert[index_to_flush]))
reset_tree(&info->bulk_insert[index_to_flush]);
}
break;
case HA_EXTRA_BULK_INSERT_END: case HA_EXTRA_BULK_INSERT_END:
if (info->bulk_insert) if (info->bulk_insert)
{ {
......
...@@ -41,6 +41,14 @@ a t>0 c i ...@@ -41,6 +41,14 @@ a t>0 c i
5 0 a NULL 5 0 a NULL
6 1 hello NULL 6 1 hello NULL
drop table t1; drop table t1;
create table t1 (sid char(20), id int(2) NOT NULL auto_increment, key(sid, id));
insert into t1 values ('skr',NULL),('skr',NULL),('test',NULL);
select * from t1;
sid id
skr 1
skr 2
test 1
drop table t1;
drop database if exists foo; drop database if exists foo;
create database foo; create database foo;
use foo; use foo;
......
...@@ -39,6 +39,15 @@ insert into t1 set a=default,t=default,c=default,i=default; ...@@ -39,6 +39,15 @@ insert into t1 set a=default,t=default,c=default,i=default;
select a,t>0,c,i from t1; select a,t>0,c,i from t1;
drop table t1; drop table t1;
#
# Test problem with bulk insert and auto_increment on second part keys
#
create table t1 (sid char(20), id int(2) NOT NULL auto_increment, key(sid, id));
insert into t1 values ('skr',NULL),('skr',NULL),('test',NULL);
select * from t1;
drop table t1;
# #
# Test of mysqld crash with fully qualified column names # Test of mysqld crash with fully qualified column names
# #
......
...@@ -657,7 +657,15 @@ int ha_myisam::repair(THD *thd, MI_CHECK &param, bool optimize) ...@@ -657,7 +657,15 @@ int ha_myisam::repair(THD *thd, MI_CHECK &param, bool optimize)
} }
/* Deactive all not unique index that can be recreated fast */ /*
Deactive all not unique index that can be recreated fast
SYNOPSIS
deactivate_non_unique_index()
rows Rows to be inserted
0 if we don't know
HA_POS_ERROR if we want to disable all keys
*/
void ha_myisam::deactivate_non_unique_index(ha_rows rows) void ha_myisam::deactivate_non_unique_index(ha_rows rows)
{ {
...@@ -670,9 +678,12 @@ void ha_myisam::deactivate_non_unique_index(ha_rows rows) ...@@ -670,9 +678,12 @@ void ha_myisam::deactivate_non_unique_index(ha_rows rows)
mi_extra(file, HA_EXTRA_NO_KEYS, 0); mi_extra(file, HA_EXTRA_NO_KEYS, 0);
else else
{ {
mi_disable_non_unique_index(file,rows); /* Only disable old index if the table was empty */
if (file->state->records == 0)
mi_disable_non_unique_index(file,rows);
ha_myisam::extra_opt(HA_EXTRA_BULK_INSERT_BEGIN, ha_myisam::extra_opt(HA_EXTRA_BULK_INSERT_BEGIN,
current_thd->variables.bulk_insert_buff_size); current_thd->variables.bulk_insert_buff_size);
table->bulk_insert= 1;
} }
} }
enable_activate_all_index=1; enable_activate_all_index=1;
...@@ -690,6 +701,7 @@ bool ha_myisam::activate_all_index(THD *thd) ...@@ -690,6 +701,7 @@ bool ha_myisam::activate_all_index(THD *thd)
DBUG_ENTER("activate_all_index"); DBUG_ENTER("activate_all_index");
mi_extra(file, HA_EXTRA_BULK_INSERT_END, 0); mi_extra(file, HA_EXTRA_BULK_INSERT_END, 0);
table->bulk_insert= 0;
if (enable_activate_all_index && if (enable_activate_all_index &&
share->state.key_map != set_bits(ulonglong, share->base.keys)) share->state.key_map != set_bits(ulonglong, share->base.keys))
{ {
...@@ -1194,6 +1206,10 @@ longlong ha_myisam::get_auto_increment() ...@@ -1194,6 +1206,10 @@ longlong ha_myisam::get_auto_increment()
return auto_increment_value; return auto_increment_value;
} }
if (table->bulk_insert)
mi_extra(file, HA_EXTRA_BULK_INSERT_FLUSH,
(void*) &table->next_number_index);
longlong nr; longlong nr;
int error; int error;
byte key[MI_MAX_KEY_LENGTH]; byte key[MI_MAX_KEY_LENGTH];
......
...@@ -202,6 +202,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, List<Item> &fields, ...@@ -202,6 +202,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, List<Item> &fields,
thd->variables.read_buff_size); thd->variables.read_buff_size);
table->file->extra_opt(HA_EXTRA_BULK_INSERT_BEGIN, table->file->extra_opt(HA_EXTRA_BULK_INSERT_BEGIN,
thd->variables.bulk_insert_buff_size); thd->variables.bulk_insert_buff_size);
table->bulk_insert= 1;
} }
while ((values= its++)) while ((values= its++))
...@@ -290,6 +291,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, List<Item> &fields, ...@@ -290,6 +291,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, List<Item> &fields,
error=1; error=1;
} }
} }
table->bulk_insert= 0;
} }
if (id && values_list.elements != 1) if (id && values_list.elements != 1)
thd->insert_id(id); // For update log thd->insert_id(id); // For update log
......
...@@ -248,8 +248,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, ...@@ -248,8 +248,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
table->next_number_field=table->found_next_number_field; table->next_number_field=table->found_next_number_field;
VOID(table->file->extra_opt(HA_EXTRA_WRITE_CACHE, VOID(table->file->extra_opt(HA_EXTRA_WRITE_CACHE,
thd->variables.read_buff_size)); thd->variables.read_buff_size));
VOID(table->file->extra_opt(HA_EXTRA_BULK_INSERT_BEGIN, table->bulk_insert= 1;
thd->variables.bulk_insert_buff_size));
if (handle_duplicates == DUP_IGNORE || if (handle_duplicates == DUP_IGNORE ||
handle_duplicates == DUP_REPLACE) handle_duplicates == DUP_REPLACE)
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY); table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
......
...@@ -91,7 +91,7 @@ struct st_table { ...@@ -91,7 +91,7 @@ struct st_table {
my_bool null_row; /* All columns are null */ my_bool null_row; /* All columns are null */
my_bool maybe_null,outer_join; /* Used with OUTER JOIN */ my_bool maybe_null,outer_join; /* Used with OUTER JOIN */
my_bool distinct,const_table,no_rows; my_bool distinct,const_table,no_rows;
my_bool key_read; my_bool key_read, bulk_insert;
my_bool crypted; my_bool crypted;
my_bool db_low_byte_first; /* Portable row format */ my_bool db_low_byte_first; /* Portable row format */
my_bool locked_by_flush; my_bool locked_by_flush;
......
...@@ -71,9 +71,11 @@ report_errors() ...@@ -71,9 +71,11 @@ report_errors()
while ((l=ERR_get_error_line_data(&file,&line,&data,&flags)) != 0) while ((l=ERR_get_error_line_data(&file,&line,&data,&flags)) != 0)
{ {
#ifndef DBUG_OFF /* Avoid warning */
char buf[200]; char buf[200];
DBUG_PRINT("error", ("OpenSSL: %s:%s:%d:%s\n", ERR_error_string(l,buf), DBUG_PRINT("error", ("OpenSSL: %s:%s:%d:%s\n", ERR_error_string(l,buf),
file,line,(flags & ERR_TXT_STRING) ? data : "")) ; file,line,(flags & ERR_TXT_STRING) ? data : "")) ;
#endif
} }
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
......
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