Bug #32824 DISABLE KEYS does not work
Submitted: 28 Nov 2007 17:55 Modified: 28 Nov 2007 20:50
Reporter: Michael Peters Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: DDL Severity:S2 (Serious)
Version:5.0.45 OS:Linux
Assigned to: CPU Architecture:Any

[28 Nov 2007 17:55] Michael Peters
Description:
I've created a table and disabled it's keys because I want to temporarily ignore unique key constraints inside of a transaction. But nothing I've tried seems to work. All of them result in a "Duplicate key" error message and SHOW INDEXES does not report that they are disabled.

I've tried this on 5.0.41 and it fails there too.

How to repeat:
mysql> CREATE TABLE foo (id int unsigned, bar varchar(255), PRIMARY KEY (id), UNIQUE KEY (bar));
Query OK, 0 rows affected (0.01 sec)

mysql> INSERT INTO foo (id, bar) VALUES (1, 'hello');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO foo (id, bar) VALUES (2, 'hello');
ERROR 1062 (23000): Duplicate entry 'hello' for key 2

So far so good.

mysql> ALTER TABLE foo DISABLE KEYS;
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO foo (id, bar) VALUES (1, 'hello2');
ERROR 1062 (23000): Duplicate entry '1' for key 1

That should have been allowed.
mysql> SHOW INDEXES FROM foo;
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| foo   |          0 | PRIMARY  |            1 | id          | A         |           2 |     NULL | NULL   |      | BTREE      |         | 
| foo   |          0 | bar      |            1 | bar         | A         |        NULL |     NULL | NULL   | YES  | BTREE      |         | 
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
2 rows in set (0.00 sec)
[28 Nov 2007 20:50] Valeriy Kravchuk
Thank you for a problem report. Looks like it is not a bug, though. Please, read the manual, http://dev.mysql.com/doc/refman/5.0/en/alter-table.html:

"ALTER TABLE ... DISABLE KEYS tells MySQL to stop updating non-unique indexes."