Description:
Using MySQL 5.1.30-log and InnoDB the following statement from documentation ist wrong:
(http://dev.mysql.com/doc/refman/5.1/en/information-functions.html)
"If you use INSERT IGNORE and the row is ignored, the AUTO_INCREMENT counter is not incremented and ...."
For MyISAM it works and also with InnoDB-tables on MySQL 5.0.
How to repeat:
mysql> CREATE TABLE `value2` (
-> `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
-> `value` varchar(255) NOT NULL DEFAULT '',
-> PRIMARY KEY (`id`),
-> UNIQUE KEY `value` (`value`)
-> ) ENGINE=myisam;
Query OK, 0 rows affected (0.03 sec)
mysql> show create table value2\G
*************************** 1. row ***************************
Table: value2
Create Table: CREATE TABLE `value2` (
`id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`value` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
UNIQUE KEY `value` (`value`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
mysql> INSERT IGNORE INTO value2 (value) values('11');
Query OK, 1 row affected (0.02 sec)
mysql> INSERT IGNORE INTO value2 (value) values('11');
Query OK, 0 rows affected (0.00 sec)
mysql> INSERT IGNORE INTO value2 (value) values('11');
Query OK, 0 rows affected (0.00 sec)
mysql> show create table value2\G
*************************** 1. row ***************************
Table: value2
Create Table: CREATE TABLE `value2` (
`id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`value` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
UNIQUE KEY `value` (`value`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
mysql> INSERT IGNORE INTO value2 (value) values('11');
Query OK, 0 rows affected (0.00 sec)
mysql> INSERT IGNORE INTO value2 (value) values('11');
Query OK, 0 rows affected (0.00 sec)
mysql> show create table value2\G
*************************** 1. row ***************************
Table: value2
Create Table: CREATE TABLE `value2` (
`id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`value` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
UNIQUE KEY `value` (`value`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
mysql> INSERT IGNORE INTO value2 (value) values('12');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT IGNORE INTO value2 (value) values('13');
Query OK, 1 row affected (0.00 sec)
mysql> show create table value2\G
*************************** 1. row ***************************
Table: value2
Create Table: CREATE TABLE `value2` (
`id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`value` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
UNIQUE KEY `value` (`value`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
mysql> select * from value2;
+----+-------+
| id | value |
+----+-------+
| 1 | 11 |
| 2 | 12 |
| 3 | 13 |
+----+-------+
3 rows in set (0.00 sec)
mysql> alter table value2 engine=innodb;
Query OK, 3 rows affected (0.15 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> show create table value2\G
*************************** 1. row ***************************
Table: value2
Create Table: CREATE TABLE `value2` (
`id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`value` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
UNIQUE KEY `value` (`value`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
mysql> INSERT IGNORE INTO value2 (value) values('11');
Query OK, 0 rows affected (0.03 sec)
mysql> INSERT IGNORE INTO value2 (value) values('11');
Query OK, 0 rows affected (0.04 sec)
mysql> INSERT IGNORE INTO value2 (value) values('11');
Query OK, 0 rows affected (0.03 sec)
mysql> INSERT IGNORE INTO value2 (value) values('11');
Query OK, 0 rows affected (0.03 sec)
mysql> show create table value2\G
*************************** 1. row ***************************
Table: value2
Create Table: CREATE TABLE `value2` (
`id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`value` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
UNIQUE KEY `value` (`value`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
mysql> select * from value2;
+----+-------+
| id | value |
+----+-------+
| 1 | 11 |
| 2 | 12 |
| 3 | 13 |
+----+-------+
3 rows in set (0.00 sec)
Suggested fix:
If no row is inserted when using INSERT IGNORE the AUTO_INCREMENT of the table shouldn't increment.