2010-03-26 121 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