Bug #55659 Negative count(*)
Submitted: 31 Jul 2010 11:39
Reporter: Sveta Smirnova Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: MyISAM storage engine Severity:S3 (Non-critical)
Version:5.1 bzr OS:Any
Assigned to: CPU Architecture:Any

[31 Jul 2010 11:39] Sveta Smirnova
Description:
I do:

1. CREATE TABLE `t2` (
  `f1` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8
2. Insert 2 rows.
3. Run insert into t2 select * from t2; insert into t2 select * from t2; insert into t2 select * from t2; insert into t2 select * from t2; insert into t2 select * from t2; insert into t2 select * from t2; insert into t2 select * from t2; insert into t2 select * from t2; insert into t2 select * from t2; insert into t2 select * from t2; insert into t2 select * from t2; insert into t2 select * from t2; insert into t2 select * from t2; insert into t2 select * from t2; insert into t2 select * from t2; insert into t2 select * from t2; insert into t2 select * from t2; insert into t2 select * from t2; insert into t2 select * from t2; insert into t2 select * from t2; insert into t2 select * from t2; insert into t2 select * from t2; insert into t2 select * from t2;
4. kill this query in middle
5. delete all rows except 2
6. Run bunch of inserts again
7. In middle of query server is stopped by cron process which does rebuild
8. After server restarted I run count(*) query and get negative result.

How to repeat:
See description, then run query:

mysql> select count(*) from t2;
+----------+
| count(*) |
+----------+
| -2097150 |
+----------+
1 row in set (0.00 sec)

Suggested fix:
I understand table is most likely corrupted (archive with frm, MYD and MYI will be attached), but why count(*) returns such value anyway?
[31 Jul 2010 11:49] Sveta Smirnova
File named bug55659.tar.gz uploaded to MySQL ftp server.

Workaround: REPAIR TABLE