2010-03-26 77 views
2

这是怎么回事?顺便说一句,MySQL服务器版本:5.0.45-日志源分布。MySQL与Date()的结果不一致()select

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 
+0

没有,什么都没有改变。我可以继续尝试这两个查询,并重复获得相同的不一致结果。 – 2010-03-26 22:58:22

+0

请发布您的表格架构,并说出您正在使用的引擎和版本。 – MarkR 2010-03-26 23:04:04

+0

已发布。另外,我尝试倾销/导入表格,并开始获得一致的结果。它看起来像数据库已损坏。 – 2010-03-26 23:25:56

回答

0

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

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

我们不认为有必要立即作出反应这一情况,但我们将迁移到更高版本的MySQL的(无论是5.0.77+或5.1)

0

如果表很小,尝试倾销&重装在另一台新的服务器上(同一版本)。如果问题消失,则会出现一些内部损坏情况,您需要重新加载现有服务器上的表,或者从转储中重新整理整个数据库。

如果行为在一个干净的数据库上是可重现的,并且没有人能够解释它(在发布模式等之后),那么引发一个错误。

+0

当我尝试时,查询确实一致。我们正在使用主从复制(并且主服务器已损坏),那么重新加载此数据的最佳方式是什么? – 2010-03-26 23:36:26

+0

如果表很小,请尝试mysqldump并重新加载它(这会对服务的可用性产生一些影响)。如果表很大,请在您的测试系统上尝试各种选项,我发现mk-parallel-dump相当快,但仍然不快。 SELECT INTO OUTFILE后跟​​LOAD DATA INFILE也可以。在非生产系统上试验生产规模的数据。 – MarkR 2010-03-27 23:05:07