Bug #37788 InnoDB Plugin: AUTO_INCREMENT wrong for compressed tables
Submitted: 1 Jul 2008 22:28 Modified: 19 Jun 2010 0:28
Reporter: Justin Tolmer Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: InnoDB Plugin storage engine Severity:S2 (Serious)
Version:5.1.23.rc OS:Linux
Assigned to: Satya B CPU Architecture:Any
Triage: Triaged: D2 (Serious)

[1 Jul 2008 22:28] Justin Tolmer
Description:
When using the InnoDB plugin and doing an alter table to compress a table, AUTO_INCREMENT sometimes changes to an incorrect value.

How to repeat:
Edit my.cnf to include:

innodb_file_per_table
innodb_file_format=Barracuda

Run:

DROP TABLE IF EXISTS test.t1;
CREATE TABLE test.t1 (MyId int NOT NULL AUTO_INCREMENT, MyName varchar(128) NOT NULL DEFAULT '', PRIMARY KEY (MyId)) ENGINE=InnoDB;
INSERT INTO test.t1 values (-1, 'test'), (1, 'test'), (2, 'test');
SHOW CREATE TABLE test.t1;

Note that AUTO_INCREMENT=3 is displayed. Run:

DROP TABLE IF EXISTS test.t1;
CREATE TABLE test.t1 (MyId int NOT NULL AUTO_INCREMENT, MyName varchar(128) NOT NULL DEFAULT '', PRIMARY KEY (MyId)) ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8;
INSERT INTO test.t1 values (-1, 'test'), (1, 'test'), (2, 'test');
SHOW CREATE TABLE test.t1;

AUTO_INCREMENT=3 again. Run:

DROP TABLE IF EXISTS test.t1;
CREATE TABLE test.t1 (MyId int NOT NULL AUTO_INCREMENT, MyName varchar(128) NOT NULL DEFAULT '', PRIMARY KEY (MyId)) ENGINE=InnoDB;
INSERT INTO test.t1 values (-1, 'test'), (1, 'test'), (2, 'test');
SHOW CREATE TABLE test.t1;

Still =3. Finally:

ALTER TABLE test.t1 ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8;
SHOW CREATE TABLE test.t1;

Result: AUTO_INCREMENT=18446744073709551615, which isn't correct.
[2 Jul 2008 6:49] Shane Bester
I saw similar behaviour, but can't remember how i got there :)
http://forums.innodb.com/read.php?3,31,31#msg-31
[2 Jul 2008 9:51] Sunny Bains
1. Using -ve values for auto-increment is undefined behavior.

2. The problem is that when we go to ha_innobase::write_row and do
   a auto_inc = table->next_number_field->val_int() in order to update
   the table max autoinc value the -1 gets converted to an uint64. This
   value is the one that you see in the SHOW CREATE TABLE.

Fix: Determine the sign of the autoinc column and coerce the value accordingly.
[6 Oct 2008 7:48] Vasil Dimov
This has been fixed and will be shipped in the next plugin release 1.0.2.
[26 May 2009 20:00] Paul Dubois
Noted in 5.1.31, 6.0.10 changelogs.

When using ALTER TABLE on an InnoDB table, the AUTO_INCREMENT value 
could be changed to an incorrect value.
[5 May 2010 15:17] 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 15:57] Paul Dubois
Push resulted from incorporation of InnoDB tree. No changes pertinent to this bug.
Re-closing.
[28 May 2010 5:57] 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:25] 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:53] 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)
[30 May 2010 0:14] Paul Dubois
Push resulted from incorporation of InnoDB tree. No changes pertinent to this bug.
Re-closing.
[15 Jun 2010 8:16] 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:33] 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:58] 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:38] 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:24] 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)