Bug #47125 auto_increment start value is ignored if an index is created and engine=innodb

Submitted: 4 Sep 2009 8:15 Modified: 19 Jun 2010 17:52
Reporter: Bernt Marius Johnsen Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S2 (Serious)
Version:5.1.37, 5.1.39-bzr, 5.0.85 OS:Any
Assigned to: Satya B CPU Architecture:Any

[4 Sep 2009 8:15] Bernt Marius Johnsen
Description:
auto_increment start value is ignored if an index is created with CREATE INDEX and engine=innodb

The following SQL: 

drop table if exists t1;
create table t1 (
   pk integer auto_increment,
   i integer,
   primary key (pk)
)  auto_increment=10 engine=innodb;
create index ix on t1(i);

insert into t1 (i) values (0);
select * from t1;

Gives the result
+----+------+
| pk | i    |
+----+------+
|  1 |    0 |
+----+------+

drop table if exists t2;
create table t2 (
   pk integer auto_increment,
   i integer,
   primary key (pk),
   key(i)
)  auto_increment=10 engine=innodb;

insert into t2 (i) values (0);
select * from t2;

Gives the correct result:

+----+------+
| pk | i    |
+----+------+
| 10 |    0 |
+----+------+

While the following SQL:

How to repeat:
Run the following SQL:

drop table if exists t1;
create table t1 (
   pk integer auto_increment,
   i integer,
   primary key (pk)
)  auto_increment=10 engine=innodb;
create index ix on t1(i);

insert into t1 (i) values (0);
select * from t1;
[4 Sep 2009 8:20] Valeriy Kravchuk
Verified just as described.
[4 Sep 2009 8:24] Valeriy Kravchuk
Same with recent 5.1.39 from bzr on Linux:

openxs@suse:/home2/openxs/dbs/5.1> bin/mysql -uroot test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.39-debug Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> drop table if exists t1;
Query OK, 0 rows affected (0.02 sec)

mysql> create table t1 (
    ->    pk integer auto_increment,
    ->    i integer,
    ->    primary key (pk)
    -> )  auto_increment=10 engine=innodb;
Query OK, 0 rows affected (0.11 sec)

mysql> create index ix on t1(i);
Query OK, 0 rows affected (0.16 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql>
mysql> insert into t1 (i) values (0);
Query OK, 1 row affected (0.00 sec)

mysql> select * from t1;
+----+------+
| pk | i    |
+----+------+
|  1 |    0 |
+----+------+
1 row in set (0.01 sec)

mysql>
mysql> drop table if exists t2;
Query OK, 0 rows affected (0.00 sec)

mysql> create table t2 (
    ->    pk integer auto_increment,
    ->    i integer,
    ->    primary key (pk),
    ->    key(i)
    -> )  auto_increment=10 engine=innodb;
Query OK, 0 rows affected (0.02 sec)

mysql>
mysql> insert into t2 (i) values (0);
Query OK, 1 row affected (0.00 sec)

mysql> select * from t2;
+----+------+
| pk | i    |
+----+------+
| 10 |    0 |
+----+------+
1 row in set (0.00 sec)
[4 Sep 2009 8:27] Valeriy Kravchuk
MyISAM is not affected:

mysql> create table t1 (
    ->    pk integer auto_increment,
    ->    i integer,
    ->    primary key (pk)
    -> )  auto_increment=10 engine=MyISAM;
Query OK, 0 rows affected (0.08 sec)

mysql> create index ix on t1(i);
Query OK, 0 rows affected (0.13 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> insert into t1 (i) values (0);
Query OK, 1 row affected (0.06 sec)

mysql> select * from t1;
+----+------+
| pk | i    |
+----+------+
| 10 |    0 |
+----+------+
1 row in set (0.00 sec)
[17 Sep 2009 2:00] Sunny Bains
Works with the plugin:

mysql> create table t1 (pk integer auto_increment, i integer, primary key (pk) ) auto_increment=10 engine=innodb;
Query OK, 0 rows affected (0.02 sec)

mysql> create index ix on t1(i);
Query OK, 0 rows affected (0.03 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> insert into t1 (i) values (0);
Query OK, 1 row affected (10.48 sec)

mysql> select * from t1;
+----+------+
| pk | i    |
+----+------+
| 10 |    0 | 
+----+------+
1 row in set (0.00 sec)
[21 Sep 2009 23:48] Sunny Bains
CREATE INDEX I ON T(C); creates a new table, copies the data, drops the old table and then renames the new table to the old table name. We need to check for SQLCOM_CREATE_INDEX and copy the old autoinc value across to the new table too.
[4 Nov 2009 9:24] Bugs System
Pushed into 5.1.41 (revid:joro@sun.com-20091104092152-qz96bzlf2o1japwc) (version source revid:kristofer.pettersson@sun.com-20091103162305-08l4gkeuif2ozsoj) (merge vers: 5.1.41) (pib:13)
[11 Nov 2009 6:49] Bugs System
Pushed into 6.0.14-alpha (revid:alik@sun.com-20091110093407-rw5g8dys2baqkt67) (version source revid:alik@sun.com-20091109080109-7dxapd5y5pxlu08w) (merge vers: 6.0.14-alpha) (pib:13)
[11 Nov 2009 6:56] Bugs System
Pushed into 5.5.0-beta (revid:alik@sun.com-20091109115615-nuohp02h8mdrz8m2) (version source revid:svoj@sun.com-20091105122958-jyqjx9xus8v4e0yd) (merge vers: 5.5.0-beta) (pib:13)
[22 Nov 2009 0:31] Paul DuBois
Noted in 5.1.41, 5.5.0, 6.0.14 changelogs.

If an InnoDB table was created with the AUTO_INCREMENT table option
to specify an initial auto-increment value, and an index was added in
a separate operation later, the auto-increment value was lost
(subsequent inserts began at 1 rather than the specified value).
[18 Dec 2009 10:26] Bugs System
Pushed into 5.1.41-ndb-7.1.0 (revid:jonas@mysql.com-20091218102229-64tk47xonu3dv6r6) (version source revid:jonas@mysql.com-20091218095730-26gwjidfsdw45dto) (merge vers: 5.1.41-ndb-7.1.0) (pib:15)
[18 Dec 2009 10:42] Bugs System
Pushed into 5.1.41-ndb-6.2.19 (revid:jonas@mysql.com-20091218100224-vtzr0fahhsuhjsmt) (version source revid:jonas@mysql.com-20091217101452-qwzyaig50w74xmye) (merge vers: 5.1.41-ndb-6.2.19) (pib:15)
[18 Dec 2009 10:57] Bugs System
Pushed into 5.1.41-ndb-6.3.31 (revid:jonas@mysql.com-20091218100616-75d9tek96o6ob6k0) (version source revid:jonas@mysql.com-20091217154335-290no45qdins5bwo) (merge vers: 5.1.41-ndb-6.3.31) (pib:15)
[18 Dec 2009 11:12] Bugs System
Pushed into 5.1.41-ndb-7.0.11 (revid:jonas@mysql.com-20091218101303-ga32mrnr15jsa606) (version source revid:jonas@mysql.com-20091218064304-ezreonykd9f4kelk) (merge vers: 5.1.41-ndb-7.0.11) (pib:15)
[5 May 2010 15:02] Bugs System
Pushed into 5.1.47 (revid:joro@sun.com-20100505145753-ivlt4hclbrjy8eye) (version source revid:vasil.dimov@oracle.com-20100331130613-8ja7n0vh36a80457) (merge vers: 5.1.46) (pib:16)
[6 May 2010 17:39] Paul DuBois
Push resulted from incorporation of InnoDB tree. No changes pertinent to this bug.
Re-closing.
[28 May 2010 5:45] Bugs System
Pushed into mysql-next-mr (revid:alik@sun.com-20100524190136-egaq7e8zgkwb9aqi) (version source revid:vasil.dimov@oracle.com-20100331130613-8ja7n0vh36a80457) (pib:16)
[28 May 2010 6:15] Bugs System
Pushed into 6.0.14-alpha (revid:alik@sun.com-20100524190941-nuudpx60if25wsvx) (version source revid:vasil.dimov@oracle.com-20100331130613-8ja7n0vh36a80457) (merge vers: 5.1.46) (pib:16)
[28 May 2010 6:43] Bugs System
Pushed into 5.5.5-m3 (revid:alik@sun.com-20100524185725-c8k5q7v60i5nix3t) (version source revid:vasil.dimov@oracle.com-20100331130613-8ja7n0vh36a80457) (merge vers: 5.1.46) (pib:16)
[29 May 2010 22:41] Paul DuBois
Push resulted from incorporation of InnoDB tree. No changes pertinent to this bug.
Re-closing.
[15 Jun 2010 8:08] Bugs System
Pushed into 5.5.5-m3 (revid:alik@sun.com-20100615080459-smuswd9ooeywcxuc) (version source revid:mmakela@bk-internal.mysql.com-20100415070122-1nxji8ym4mao13ao) (merge vers: 5.1.47) (pib:16)
[15 Jun 2010 8:23] Bugs System
Pushed into mysql-next-mr (revid:alik@sun.com-20100615080558-cw01bzdqr1bdmmec) (version source revid:mmakela@bk-internal.mysql.com-20100415070122-1nxji8ym4mao13ao) (pib:16)
[17 Jun 2010 11:45] Bugs System
Pushed into 5.1.47-ndb-7.0.16 (revid:martin.skold@mysql.com-20100617114014-bva0dy24yyd67697) (version source revid:vasil.dimov@oracle.com-20100331130613-8ja7n0vh36a80457) (merge vers: 5.1.46) (pib:16)
[17 Jun 2010 12:23] Bugs System
Pushed into 5.1.47-ndb-6.2.19 (revid:martin.skold@mysql.com-20100617115448-idrbic6gbki37h1c) (version source revid:vasil.dimov@oracle.com-20100331130613-8ja7n0vh36a80457) (merge vers: 5.1.46) (pib:16)
[17 Jun 2010 13:10] Bugs System
Pushed into 5.1.47-ndb-6.3.35 (revid:martin.skold@mysql.com-20100617114611-61aqbb52j752y116) (version source revid:vasil.dimov@oracle.com-20100331130613-8ja7n0vh36a80457) (merge vers: 5.1.46) (pib:16)

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.082 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.