- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
出于某种原因,当我按 DESC 对查询进行排序时,速度非常快,但如果按 ASC 排序,则速度非常慢。
这大约需要 150 毫秒:
SELECT posts.id
FROM posts USE INDEX (published)
WHERE posts.feed_id IN ( 4953,622,1,1852,4952,76,623,624,10 )
ORDER BY posts.published DESC
LIMIT 0, 50;
这大约需要 32 秒:
SELECT posts.id
FROM posts USE INDEX (published)
WHERE posts.feed_id IN ( 4953,622,1,1852,4952,76,623,624,10 )
ORDER BY posts.published ASC
LIMIT 0, 50;
两个查询的 EXPLAIN 相同。
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE posts index NULL published 5 NULL 50 Using where
我已将其追踪到“USE INDEX(已发布)”。如果我把它去掉,那么两种方式的表现都是一样的。但是 EXPLAIN 显示查询总体上效率较低。
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE posts range feed_id feed_id 4 \N 759 Using where; Using filesort
这是表格。
CREATE TABLE `posts` (
`id` int(20) NOT NULL AUTO_INCREMENT,
`feed_id` int(11) NOT NULL,
`post_url` varchar(255) NOT NULL,
`title` varchar(255) NOT NULL,
`content` blob,
`author` varchar(255) DEFAULT NULL,
`published` int(12) DEFAULT NULL,
`updated` datetime NOT NULL,
`created` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `post_url` (`post_url`,`feed_id`),
KEY `feed_id` (`feed_id`),
KEY `published` (`published`)
) ENGINE=InnoDB AUTO_INCREMENT=196530 DEFAULT CHARSET=latin1;
有解决办法吗?
最佳答案
你的索引是降序排列的,所以当你要求升序时,它需要做更多的工作才能把它恢复到那个顺序
关于MySQL ORDER BY DESC 很快,但 ASC 很慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2886575/
我知道如果一个函数被标记为final,那么它就不能在子类中被覆盖。但是如果一个类中的属性被标记为最终的呢?我试了一下,发现可以在子类中给它赋一个新值。 最佳答案 属性上的 Final 意味着子类不能修
我正在制作一个名为“fullWidthContainer”的容器,用于放置我所有的文章和废话。它需要与顶部页眉和底部页脚隔开,所以我在顶部和底部给了它 40px 的边距。 HTML代码: ...
在this talk by Sutter在 1:15:26 出现了如下代码, class employee{ std::string name_; public: template, std::st
我有多年使用数据库相关代码的经验,但有一个问题我总是问自己。基于 Java 的 Hazelcast(内存中)如何比任何其他非基于 Java 的数据库更快?例如,内存中的 Redis 和 Memcach
我一直在尝试以下内容,并注意到此处定义的无分支“if”(现在用 &-!! 替换 *!!)可以加快速度使用 clang 在 64 位 Intel 目标上将某些瓶颈代码提高(几乎)2 倍: // Prod
我正在 github.io 上阅读 Facebook 的 React 文档。这里写的是react的事件委托(delegate)比原生javascript的事件委托(delegate)要快,因为有一些映
我正在运行 Hibernate 4.1,并在 Oracle 12c 之上的 Hikari 池之上运行 Javassist 运行时检测。 JDK 是 1.7。 我有一个查询在数据库上运行得非常快,并在
我目前正在尝试使用 swift 制作音乐应用程序。这是我的第一个应用程序(不包括一些教程内容)。我一直在查看一些示例代码,包括 Apple 的 addMusic 示例,并且我遇到了以下将 object
我和一个 friend 正在开发一个简单的 iOS 应用程序,并尝试实现一些 Firebase 功能,例如登录/注册功能。我的 friend 设置了我们的 firebase 帐户并编写了如下所示的代码
我有一个问题: Update users set Numreviews = 1 where userID = 12345 “numreviews”和“userID”这两个字段都有索引,可以帮助不相关的
通过具有高延迟的网络将数据从 Windows 计算机发送到 Windows 或 Linux 使用了 10% 的链路容量。同时,从 Linux 通过同一网络发送相同数据的速度几乎快了十倍。即使仅通过延迟
我们有 18 个表连接,这对于 ERP 系统来说是典型的。连接是通过 LINQ over Entity Framework 完成的。 随着加入的加入越来越多,加入变得越来越慢。返回结果集很小(15 条
背景 我想制作一些整数大小的 struct s(即 32 位和 64 位)可以轻松转换为相同大小的原始非托管类型(即 Int32 和 UInt32,特别是对于 32 位大小的结构)。 然后,这些结构将
出于某种原因,当我按 DESC 对查询进行排序时,速度非常快,但如果按 ASC 排序,则速度非常慢。 这大约需要 150 毫秒: SELECT posts.id FROM posts USE INDE
我有一个中型 Angular 应用程序,它使用 angular-1.2.10 和 ui-router-0.2.8。当我转换到特定状态时,无论我是在 ng-show 上使用 $animate 还是手动设
我看到一些非常奇怪的性能,与使用 Entity Framework Code-First 和 .NET Framework 版本 4 的非常简单的查询相关。LINQ2Entities 查询如下所示:
我有两个表,都有大约 200,000 条记录。我想在 KEY 上加入他们,这是一个字符串。 两个表都有一个索引KEY,VALUE。当我运行时: SELECT vpn, t1_sku, t2_sk
几个月来,我一直在 Windows CMD 提示符下使用 Cygwin 命令,没有出现任何问题。在过去的几天里,每次我调用 Cygwin 命令(例如 ls)时,该命令在实际运行之前都需要几秒钟的时间来
好的,我正在开发一个新网站。它是一个社交网络类型的网站,并且具有很多 jquery 交互性。 当我尝试使用 JQuery.live() 实现鼠标悬停效果时出现问题。它在 Chrome 和 Safari
我对以下简单 ReactJS 示例的性能感到非常失望。单击项目时,标签(计数)会相应更新。不幸的是,更新大约需要 0.5-1 秒。这主要是由于“重新呈现”了整个待办事项列表。 我的理解是 React
我是一名优秀的程序员,十分优秀!