這是怎麼回事?順便說一句,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
沒有,什麼都沒有改變。我可以繼續嘗試這兩個查詢,並重復獲得相同的不一致結果。 – 2010-03-26 22:58:22
請發佈您的表格架構,並說出您正在使用的引擎和版本。 – MarkR 2010-03-26 23:04:04
已發佈。另外,我嘗試傾銷/導入表格,並開始獲得一致的結果。它看起來像數據庫已損壞。 – 2010-03-26 23:25:56