Bug #32361 Strange behaviour in counting rows
Submitted: 14 Nov 2007 9:37 Modified: 14 Nov 2007 10:22
Reporter: Anton Dischner Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:5.0.45 OS:Linux (SLES9 SP3)
Assigned to: CPU Architecture:Any
Tags: count, null

[14 Nov 2007 9:37] Anton Dischner
Description:
Hi all, 

i have a table: t_pdat which i get from my production table by: 

mysql> create table t_pdat as select lbefudat, zst from pdat; 

+----------+----------+------+-----+---------+-------+ 
| Field | Type | Null | Key | Default | Extra | 
+----------+----------+------+-----+---------+-------+ 
| lbefudat | datetime | YES | | NULL | | 
| zst | datetime | NO | | | | 
+----------+----------+------+-----+---------+-------+ 

When i do a "select count(*)" i get 0 rows which is -not- correct. 

mysql> select count(*) from t_pdat where date(lbefudat) = date('2007-04-27'); 

+----------+ 
| count(*) | 
+----------+ 
| 0 | 
+----------+ 
1 row in set (2,87 sec) 

Proof: 

mysql> select count(*) from t_pdat where date_format(lbefudat, '%Y-%m-%d') = '2007-04-27'; 
+----------+ 
| count(*) | 
+----------+ 
| 588 | 
+----------+ 
1 row in set (3,02 sec) 

then i do a 

drop table t_pdat1; 
create table t_pdat1 as select * from t_pdat where lbefudat is null; 

Query OK, 1334912 rows affected (24,55 sec) 
Records: 1334912 Duplicates: 0 Warnings: 0 

delete from t_pdat where lbefudat is null; 
Query OK, 1334912 rows affected (13,83 sec) 

select count(*) from t_pdat where date(lbefudat) = date('2007-04-27'); 

+----------+ 
| count(*) | 
+----------+ 
| 588 | 
+----------+ 
1 row in set (1,38 sec) 

insert into t_pdat select * from t_pdat1; 

Query OK, 1334912 rows affected (19,83 sec) 
Records: 1334912 Duplicates: 0 Warnings: 0 

mysql> 
mysql> select count(*) from t_pdat where date(lbefudat) = date('2007-04-27'); 
+----------+ 
| count(*) | 
+----------+ 
| 588 | 
+----------+ 

Any clues to this strange behaviour or is this a bug? 

kind regards, 

Toni

How to repeat:
I tried to make a testcase with data but i cannot reproduce thirs error.

Sometimes it is working correct and sometimes it show the error obove.
[14 Nov 2007 10:22] Sveta Smirnova
Thank you for the report.

I can not repeat described behaviour with current development sources although bug is repeatable with version 5.0.45. Please wait next release.