summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <guilhem@mysql.com>2004-08-23 16:15:57 +0200
committerunknown <guilhem@mysql.com>2004-08-23 16:15:57 +0200
commite9c25d9336c8d1266254df5f795366e7d280de85 (patch)
tree473c7951f1ebf8ee281da1848e8cadc3e2cf68e1
parent38b8c98543e68b3185a491b3cb9fb9d48662ef14 (diff)
downloadmariadb-git-e9c25d9336c8d1266254df5f795366e7d280de85.tar.gz
Fix for BUG#5033 "When using temporary tables truncate does NOT reset the auto_increment counter"
(ok'd by CTO to fix it in 4.0). Fix to make mysql-test-run work with all Valgrind versions. mysql-test/mysql-test-run.sh: fixing mysql-test-run.sh so that it works indifferently with Valgrind 1.x, 2.x (versions <= 2.0.0 refuse --tool option; versions >=2.1.2 require it; 2.1.0 accepts it). I hope the shell code is portable enough; anyway Valgrind only runs on Linux... I tested it with 2.0.0, 2.1.0, 2.1.2. mysql-test/r/truncate.result: result update mysql-test/t/truncate.test: testing if TRUNCATE resets autoinc counter for temp tables (BUG#5033); testing difference with DELETE FROM. sql/sql_delete.cc: in mysql_truncate(), always reset the autoinc counter, as manual says (even if it's a temp table, which was BUG#5033).
-rw-r--r--mysql-test/mysql-test-run.sh4
-rw-r--r--mysql-test/r/truncate.result21
-rw-r--r--mysql-test/t/truncate.test16
-rw-r--r--sql/sql_delete.cc5
4 files changed, 40 insertions, 6 deletions
diff --git a/mysql-test/mysql-test-run.sh b/mysql-test/mysql-test-run.sh
index cd6c331687f..d47560fe7a6 100644
--- a/mysql-test/mysql-test-run.sh
+++ b/mysql-test/mysql-test-run.sh
@@ -349,9 +349,11 @@ while test $# -gt 0; do
VALGRIND=`which valgrind` # this will print an error if not found
# Give good warning to the user and stop
if [ -z "$VALGRIND" ] ; then
- $ECHO "You need to have the 'valgrind' program in your PATH to run mysql-test-run with option --valgrind. Valgrind's home page is http://developer.kde.org/~sewardj ."
+ $ECHO "You need to have the 'valgrind' program in your PATH to run mysql-test-run with option --valgrind. Valgrind's home page is http://valgrind.kde.org ."
exit 1
fi
+ # >=2.1.2 requires the --tool option, some versions write to stdout, some to stderr
+ valgrind --help 2>&1 | grep "\-\-tool" > /dev/null && VALGRIND="$VALGRIND --tool=memcheck"
VALGRIND="$VALGRIND --alignment=8 --leak-check=yes --num-callers=16"
EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --skip-safemalloc --skip-bdb"
EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --skip-safemalloc --skip-bdb"
diff --git a/mysql-test/r/truncate.result b/mysql-test/r/truncate.result
index 1b387214292..fef15533738 100644
--- a/mysql-test/r/truncate.result
+++ b/mysql-test/r/truncate.result
@@ -31,4 +31,25 @@ SELECT * from t1;
a
1
2
+delete from t1;
+insert into t1 (a) values (NULL),(NULL);
+SELECT * from t1;
+a
+3
+4
+drop table t1;
+create temporary table t1 (a integer auto_increment primary key);
+insert into t1 (a) values (NULL),(NULL);
+truncate table t1;
+insert into t1 (a) values (NULL),(NULL);
+SELECT * from t1;
+a
+1
+2
+delete from t1;
+insert into t1 (a) values (NULL),(NULL);
+SELECT * from t1;
+a
+3
+4
drop table t1;
diff --git a/mysql-test/t/truncate.test b/mysql-test/t/truncate.test
index 3acab9f56de..f92e92fbc97 100644
--- a/mysql-test/t/truncate.test
+++ b/mysql-test/t/truncate.test
@@ -23,7 +23,7 @@ drop table t1;
truncate non_existing_table;
#
-# test autoincrement with TRUNCATE
+# test autoincrement with TRUNCATE; verifying difference with DELETE
#
create table t1 (a integer auto_increment primary key);
@@ -31,5 +31,19 @@ insert into t1 (a) values (NULL),(NULL);
truncate table t1;
insert into t1 (a) values (NULL),(NULL);
SELECT * from t1;
+delete from t1;
+insert into t1 (a) values (NULL),(NULL);
+SELECT * from t1;
drop table t1;
+# Verifying that temp tables are handled the same way
+
+create temporary table t1 (a integer auto_increment primary key);
+insert into t1 (a) values (NULL),(NULL);
+truncate table t1;
+insert into t1 (a) values (NULL),(NULL);
+SELECT * from t1;
+delete from t1;
+insert into t1 (a) values (NULL),(NULL);
+SELECT * from t1;
+drop table t1;
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index b568166a766..555e63b9e32 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -545,15 +545,13 @@ int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
int error;
DBUG_ENTER("mysql_truncate");
+ bzero((char*) &create_info,sizeof(create_info));
/* If it is a temporary table, close and regenerate it */
if (!dont_send_ok && (table_ptr=find_temporary_table(thd,table_list->db,
table_list->real_name)))
{
TABLE *table= *table_ptr;
- HA_CREATE_INFO create_info;
table->file->info(HA_STATUS_AUTO | HA_STATUS_NO_LOCK);
- bzero((char*) &create_info,sizeof(create_info));
- create_info.auto_increment_value= table->file->auto_increment_value;
db_type table_type=table->db_type;
strmov(path,table->path);
@@ -596,7 +594,6 @@ int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
DBUG_RETURN(-1);
}
- bzero((char*) &create_info,sizeof(create_info));
*fn_ext(path)=0; // Remove the .frm extension
error= ha_create_table(path,&create_info,1) ? -1 : 0;
query_cache_invalidate3(thd, table_list, 0);