MySQL与Date()选择结果不一致

时间:2010-03-26 21:24:43

标签: mysql

这里发生了什么? BTW,MySQL服务器版本:5.0.45-log源代码分发。

mysql> select count(*) 
       from notes 
      where date(updated_at) > date('2010-03-25');
+----------+
| count(*) |
+----------+
|        0 | 
+----------+
1 row in set (0.59 sec)

mysql> select count(*) 
         from notes 
        where message like'%***%' 
          and date(updated_at) > date('2010-03-25');
+----------+
| count(*) |
+----------+
|       26 | 
+----------+
1 row in set (1.30 sec)

mysql> explain select count(*) 
      from notes 
      where date(updated_at) > date('2010-03-25');
+----+-------------+-------+------+---------------+------+---------+------+--------+-------------+
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows   | Extra       |
+----+-------------+-------+------+---------------+------+---------+------+--------+-------------+
|  1 | SIMPLE      | notes | ALL  | NULL          | NULL | NULL    | NULL | 588106 | Using where | 
+----+-------------+-------+------+---------------+------+---------+------+--------+-------------+
1 row in set (0.07 sec)

mysql> explain select updated_at 
         from notes 
        where message like'%***%' 
          and date(updated_at) > date('2010-03-25');
+----+-------------+-------+------+---------------+------+---------+------+--------+-------------+
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows   | Extra       |
+----+-------------+-------+------+---------------+------+---------+------+--------+-------------+
|  1 | SIMPLE      | notes | ALL  | NULL          | NULL | NULL    | NULL | 588106 | Using where | 
+----+-------------+-------+------+---------------+------+---------+------+--------+-------------+
1 row in set (0.09 sec)

mysql> 

这是表架构。

CREATE TABLE `notes` (
 `id` int(11) NOT NULL auto_increment,
 `status` varchar(255) default NULL,
 `message` text,
 `noteable_id` int(11) default NULL,
 `noteable_type` varchar(255) default NULL,
 `deleted_at` datetime default NULL,
 `creator_id` int(11) default NULL,
 `updater_id` int(11) default NULL,
 `deleter_id` int(11) default NULL,
 `created_at` datetime default NULL,
 `updated_at` datetime default NULL,
 `public` tinyint(1) default '0',
 `forced` tinyint(1) default '0',
 `agent_created_at` datetime default NULL,
 PRIMARY KEY  (`id`),
 KEY `noteable_id` (`noteable_id`),
 KEY `deleted_at` (`deleted_at`),
 KEY `noteable_type` (`noteable_type`(10)),
 KEY `creator_id` (`creator_id`),
 KEY `status` (`status`),
 KEY `created_at` (`created_at`)
) ENGINE=InnoDB AUTO_INCREMENT=613168 DEFAULT CHARSET=latin1 

2 个答案:

答案 0 :(得分:0)

如果表格很小,请尝试转储&在另一个盒子(具有相同版本)的新服务器上重新加载。如果问题消失,则存在一些内部损坏,您需要在现有服务器上重新加载表,或者从转储重新启动整个数据库。

如果行为在干净的数据库上是可重现的,并且没人能解释它(在发布架构之后),那么就提出一个错误。

答案 1 :(得分:0)

事实证明,这个特定实例不是由数据库损坏引起的,而是MySQL版本5.0.45(+?)的Date函数中的错误。

http://bugs.mysql.com/bug.php?id=32159

我们认为不需要立即对此情况作出反应,但我们将迁移到更高版本的MySQL(5.0.77+或5.1)