diff --git a/ha/ha0ha.c b/ha/ha0ha.c index f0d80d69e88..78027d9785b 100644 --- a/ha/ha0ha.c +++ b/ha/ha0ha.c @@ -373,11 +373,20 @@ ha_print_info( FILE* file, /* in: file where to print */ hash_table_t* table) /* in: hash table */ { +#ifdef UNIV_DEBUG +/* Some of the code here is disabled for performance reasons in production +builds, see http://bugs.mysql.com/36941 */ +#define PRINT_USED_CELLS +#endif /* UNIV_DEBUG */ + +#ifdef PRINT_USED_CELLS hash_cell_t* cell; ulint cells = 0; - ulint n_bufs; ulint i; +#endif /* PRINT_USED_CELLS */ + ulint n_bufs; +#ifdef PRINT_USED_CELLS for (i = 0; i < hash_get_n_cells(table); i++) { cell = hash_get_nth_cell(table, i); @@ -387,10 +396,14 @@ ha_print_info( cells++; } } +#endif /* PRINT_USED_CELLS */ - fprintf(file, - "Hash table size %lu, used cells %lu", - (ulong) hash_get_n_cells(table), (ulong) cells); + fprintf(file, "Hash table size %lu", + (ulong) hash_get_n_cells(table)); + +#ifdef PRINT_USED_CELLS + fprintf(file, ", used cells %lu", (ulong) cells); +#endif /* PRINT_USED_CELLS */ if (table->heaps == NULL && table->heap != NULL) { diff --git a/handler/ha_innodb.cc b/handler/ha_innodb.cc index 5f66ca0bb2a..a04e0b44669 100644 --- a/handler/ha_innodb.cc +++ b/handler/ha_innodb.cc @@ -6641,6 +6641,14 @@ ha_innobase::info( if (thd_sql_command(user_thd) == SQLCOM_TRUNCATE) { n_rows = 0; + + /* We need to reset the prebuilt value too, otherwise + checks for values greater than the last value written + to the table will fail and the autoinc counter will + not be updated. This will force write_row() into + attempting an update of the table's AUTOINC counter. */ + + prebuilt->last_value = 0; } stats.records = (ha_rows)n_rows; diff --git a/lock/lock0lock.c b/lock/lock0lock.c index aac136cbbee..37ac19c3050 100644 --- a/lock/lock0lock.c +++ b/lock/lock0lock.c @@ -4264,6 +4264,15 @@ lock_rec_print( } #ifndef UNIV_HOTBACKUP + +#ifdef UNIV_DEBUG +/* Print the number of lock structs from lock_print_info_summary() only +in non-production builds for performance reasons, see +http://bugs.mysql.com/36942 */ +#define PRINT_NUM_OF_LOCK_STRUCTS +#endif /* UNIV_DEBUG */ + +#ifdef PRINT_NUM_OF_LOCK_STRUCTS /************************************************************************* Calculates the number of record lock structs in the record lock hash table. */ static @@ -4290,6 +4299,7 @@ lock_get_n_rec_locks(void) return(n_locks); } +#endif /* PRINT_NUM_OF_LOCK_STRUCTS */ /************************************************************************* Prints info of locks for all transactions. */ @@ -4331,9 +4341,11 @@ lock_print_info_summary( "History list length %lu\n", (ulong) trx_sys->rseg_history_len); +#ifdef PRINT_NUM_OF_LOCK_STRUCTS fprintf(file, "Total number of lock structs in row lock hash table %lu\n", (ulong) lock_get_n_rec_locks()); +#endif /* PRINT_NUM_OF_LOCK_STRUCTS */ } /************************************************************************* diff --git a/mysql-test/innodb-autoinc.result b/mysql-test/innodb-autoinc.result index 3078eadf4a5..e000f910772 100644 --- a/mysql-test/innodb-autoinc.result +++ b/mysql-test/innodb-autoinc.result @@ -87,3 +87,85 @@ SELECT * FROM t1; c1 c2 18446744073709551615 NULL DROP TABLE t1; +CREATE TABLE t1(c1 INT PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1), (2), (3); +INSERT INTO t1 VALUES (NULL), (NULL), (NULL); +SELECT c1 FROM t1; +c1 +1 +2 +3 +4 +5 +6 +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`c1`) +) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1 +TRUNCATE TABLE t1; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`c1`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES (1), (2), (3); +INSERT INTO t1 VALUES (NULL), (NULL), (NULL); +SELECT c1 FROM t1; +c1 +1 +2 +3 +4 +5 +6 +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`c1`) +) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1 +DROP TABLE t1; +CREATE TABLE t1(c1 INT PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1), (2), (3); +INSERT INTO t1 VALUES (NULL), (NULL), (NULL); +SELECT c1 FROM t1; +c1 +1 +2 +3 +4 +5 +6 +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`c1`) +) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1 +DELETE FROM t1; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`c1`) +) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES (1), (2), (3); +INSERT INTO t1 VALUES (NULL), (NULL), (NULL); +SELECT c1 FROM t1; +c1 +1 +2 +3 +7 +8 +9 +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`c1`) +) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1 +DROP TABLE t1; diff --git a/mysql-test/innodb-autoinc.test b/mysql-test/innodb-autoinc.test index b6bb9c6b0b7..aa464e42627 100644 --- a/mysql-test/innodb-autoinc.test +++ b/mysql-test/innodb-autoinc.test @@ -105,3 +105,37 @@ INSERT INTO t1 VALUES (18446744073709551615, null); INSERT INTO t1 (c2) VALUES ('innodb'); SELECT * FROM t1; DROP TABLE t1; + +# +# Bug 37531 +# After truncate, auto_increment behaves incorrectly for InnoDB +# +CREATE TABLE t1(c1 INT PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1), (2), (3); +INSERT INTO t1 VALUES (NULL), (NULL), (NULL); +SELECT c1 FROM t1; +SHOW CREATE TABLE t1; +TRUNCATE TABLE t1; +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (1), (2), (3); +INSERT INTO t1 VALUES (NULL), (NULL), (NULL); +SELECT c1 FROM t1; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +# +# Deleting all records should not reset the AUTOINC counter. +# +CREATE TABLE t1(c1 INT PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1), (2), (3); +INSERT INTO t1 VALUES (NULL), (NULL), (NULL); +SELECT c1 FROM t1; +SHOW CREATE TABLE t1; +DELETE FROM t1; +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (1), (2), (3); +INSERT INTO t1 VALUES (NULL), (NULL), (NULL); +SELECT c1 FROM t1; +SHOW CREATE TABLE t1; +DROP TABLE t1; + diff --git a/mysql-test/innodb-replace.result b/mysql-test/innodb-replace.result index 77e0aeb38fd..c926bb89a2e 100644 --- a/mysql-test/innodb-replace.result +++ b/mysql-test/innodb-replace.result @@ -3,11 +3,11 @@ create table t1 (c1 char(5) unique not null, c2 int, stamp timestamp) engine=inn select * from t1; c1 c2 stamp replace delayed into t1 (c1, c2) values ( "text1","11"); -ERROR HY000: Table storage engine for 't1' doesn't have this option +ERROR HY000: DELAYED option not supported for table 't1' select * from t1; c1 c2 stamp replace delayed into t1 (c1, c2) values ( "text1","12"); -ERROR HY000: Table storage engine for 't1' doesn't have this option +ERROR HY000: DELAYED option not supported for table 't1' select * from t1; c1 c2 stamp drop table t1; diff --git a/mysql-test/innodb-replace.test b/mysql-test/innodb-replace.test index d44ede65ce8..8c3aacde5e8 100644 --- a/mysql-test/innodb-replace.test +++ b/mysql-test/innodb-replace.test @@ -11,10 +11,10 @@ drop table if exists t1; # create table t1 (c1 char(5) unique not null, c2 int, stamp timestamp) engine=innodb; select * from t1; ---error 1031 +--error ER_DELAYED_NOT_SUPPORTED replace delayed into t1 (c1, c2) values ( "text1","11"); select * from t1; ---error 1031 +--error ER_DELAYED_NOT_SUPPORTED replace delayed into t1 (c1, c2) values ( "text1","12"); select * from t1; drop table t1;