首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MySQL与Date() select的结果不一致

MySQL与Date() select的结果不一致
EN

Stack Overflow用户
提问于 2010-03-27 05:24:43
回答 2查看 197关注 0票数 2

这里发生了什么事?顺便说一句,MySQL服务器版本:5.0.45-记录源分发。

代码语言:javascript
复制
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> 

这是表模式。

代码语言:javascript
复制
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 
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-03-31 10:31:39

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

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

我们认为没有必要立即对这种情况做出反应,但我们将迁移到更高版本的MySQL ( 5.0.77+或5.1)

票数 0
EN

Stack Overflow用户

发布于 2010-03-27 07:27:12

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2526858

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档