summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <monty@mashka.mysql.fi>2002-09-18 21:04:49 +0300
committerunknown <monty@mashka.mysql.fi>2002-09-18 21:04:49 +0300
commit83fc12f21653f1e6fc12c61791f4e6f2dd87be96 (patch)
tree83f34b98c4e43e4f23f9b941d93676b65ef1b657
parentaef675029f198c61a1a1c46dbb68890f705d40db (diff)
downloadmariadb-git-83fc12f21653f1e6fc12c61791f4e6f2dd87be96.tar.gz
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. Docs/manual.texi: Changelog include/my_base.h: Added code to flush a bulk_insert index myisam/mi_extra.c: Added code to flush a bulk_insert index mysql-test/r/insert.result: test of auto_increment and bulk_insert mysql-test/t/insert.test: test of auto_increment and bulk_insert sql/ha_myisam.cc: Added code to flush a bulk_insert index sql/sql_insert.cc: Mark that bulk_insert is used sql/sql_load.cc: Mark that bulk_insert is used Remove duplicated call to initialize bulk insert sql/table.h: Mark that bulk_insert is used vio/viosslfactories.c: Remove compiler warning
-rw-r--r--Docs/manual.texi6
-rw-r--r--include/my_base.h1
-rw-r--r--myisam/mi_extra.c12
-rw-r--r--mysql-test/r/insert.result8
-rw-r--r--mysql-test/t/insert.test9
-rw-r--r--sql/ha_myisam.cc20
-rw-r--r--sql/sql_insert.cc2
-rw-r--r--sql/sql_load.cc3
-rw-r--r--sql/table.h2
-rw-r--r--vio/viosslfactories.c2
10 files changed, 59 insertions, 6 deletions
diff --git a/Docs/manual.texi b/Docs/manual.texi
index 331589a0674..0e51a2d7acb 100644
--- a/Docs/manual.texi
+++ b/Docs/manual.texi
@@ -50442,6 +50442,12 @@ each individual 4.0.x release.
@itemize @bullet
@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
@item
@code{--skip-ssl} can now be used to disable SSL in the MySQL clients,
diff --git a/include/my_base.h b/include/my_base.h
index ae8fc2204d5..7d7e296ead3 100644
--- a/include/my_base.h
+++ b/include/my_base.h
@@ -107,6 +107,7 @@ enum ha_extra_function {
HA_EXTRA_NO_IGNORE_DUP_KEY,
HA_EXTRA_DONT_USE_CURSOR_TO_UPDATE, /* Cursor will not be used for update */
HA_EXTRA_BULK_INSERT_BEGIN,
+ HA_EXTRA_BULK_INSERT_FLUSH, /* Flush one index */
HA_EXTRA_BULK_INSERT_END,
HA_EXTRA_PREPARE_FOR_DELETE
};
diff --git a/myisam/mi_extra.c b/myisam/mi_extra.c
index 519cc5bc2b8..39eb4b0bd99 100644
--- a/myisam/mi_extra.c
+++ b/myisam/mi_extra.c
@@ -34,7 +34,9 @@
HA_EXTRA_WRITE_CACHE
HA_EXTRA_CACHE
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
0 ok
*/
@@ -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 :
myisam_bulk_insert_tree_size));
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:
if (info->bulk_insert)
{
diff --git a/mysql-test/r/insert.result b/mysql-test/r/insert.result
index b27cbb46210..2ffa9d88618 100644
--- a/mysql-test/r/insert.result
+++ b/mysql-test/r/insert.result
@@ -41,6 +41,14 @@ a t>0 c i
5 0 a NULL
6 1 hello NULL
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;
create database foo;
use foo;
diff --git a/mysql-test/t/insert.test b/mysql-test/t/insert.test
index 2c912d94c70..0bca8dc5890 100644
--- a/mysql-test/t/insert.test
+++ b/mysql-test/t/insert.test
@@ -40,6 +40,15 @@ select a,t>0,c,i from 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
#
diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc
index bae455cbb3c..cc1e4c3f45c 100644
--- a/sql/ha_myisam.cc
+++ b/sql/ha_myisam.cc
@@ -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)
{
@@ -670,9 +678,12 @@ void ha_myisam::deactivate_non_unique_index(ha_rows rows)
mi_extra(file, HA_EXTRA_NO_KEYS, 0);
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,
current_thd->variables.bulk_insert_buff_size);
+ table->bulk_insert= 1;
}
}
enable_activate_all_index=1;
@@ -690,6 +701,7 @@ bool ha_myisam::activate_all_index(THD *thd)
DBUG_ENTER("activate_all_index");
mi_extra(file, HA_EXTRA_BULK_INSERT_END, 0);
+ table->bulk_insert= 0;
if (enable_activate_all_index &&
share->state.key_map != set_bits(ulonglong, share->base.keys))
{
@@ -1194,6 +1206,10 @@ longlong ha_myisam::get_auto_increment()
return auto_increment_value;
}
+ if (table->bulk_insert)
+ mi_extra(file, HA_EXTRA_BULK_INSERT_FLUSH,
+ (void*) &table->next_number_index);
+
longlong nr;
int error;
byte key[MI_MAX_KEY_LENGTH];
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 9b6e6a549c9..de2e15cd29d 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -202,6 +202,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, List<Item> &fields,
thd->variables.read_buff_size);
table->file->extra_opt(HA_EXTRA_BULK_INSERT_BEGIN,
thd->variables.bulk_insert_buff_size);
+ table->bulk_insert= 1;
}
while ((values= its++))
@@ -290,6 +291,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, List<Item> &fields,
error=1;
}
}
+ table->bulk_insert= 0;
}
if (id && values_list.elements != 1)
thd->insert_id(id); // For update log
diff --git a/sql/sql_load.cc b/sql/sql_load.cc
index 50e0ea9d5c8..8881c79eba4 100644
--- a/sql/sql_load.cc
+++ b/sql/sql_load.cc
@@ -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;
VOID(table->file->extra_opt(HA_EXTRA_WRITE_CACHE,
thd->variables.read_buff_size));
- VOID(table->file->extra_opt(HA_EXTRA_BULK_INSERT_BEGIN,
- thd->variables.bulk_insert_buff_size));
+ table->bulk_insert= 1;
if (handle_duplicates == DUP_IGNORE ||
handle_duplicates == DUP_REPLACE)
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
diff --git a/sql/table.h b/sql/table.h
index 229d41a2df7..2c9a1b2c16a 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -91,7 +91,7 @@ struct st_table {
my_bool null_row; /* All columns are null */
my_bool maybe_null,outer_join; /* Used with OUTER JOIN */
my_bool distinct,const_table,no_rows;
- my_bool key_read;
+ my_bool key_read, bulk_insert;
my_bool crypted;
my_bool db_low_byte_first; /* Portable row format */
my_bool locked_by_flush;
diff --git a/vio/viosslfactories.c b/vio/viosslfactories.c
index 23a35f540f6..9e7a1475951 100644
--- a/vio/viosslfactories.c
+++ b/vio/viosslfactories.c
@@ -71,9 +71,11 @@ report_errors()
while ((l=ERR_get_error_line_data(&file,&line,&data,&flags)) != 0)
{
+#ifndef DBUG_OFF /* Avoid warning */
char buf[200];
DBUG_PRINT("error", ("OpenSSL: %s:%s:%d:%s\n", ERR_error_string(l,buf),
file,line,(flags & ERR_TXT_STRING) ? data : "")) ;
+#endif
}
DBUG_VOID_RETURN;
}