MongoDB执行优化的问题

影子传说_Hades 2013-11-25 04:13:31
When you have a sequence with $sort followed by a
$skip followed by a $limit, an optimization occurs that moves the $limit operator before the $skip operator.
For example, if the pipeline consists of the following stages:
{ $sort: { age : -1 } },
{ $skip: 10 },
{ $limit: 5 }
During the optimization phase, the optimizer transforms the sequence to the following:
{ $sort: { age : -1 } },
{ $limit: 15 }
{ $skip: 10 }


上面为什么要把$limit放在$skip前就能起优化作用呢?
...全文
210 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
有点发红 2013-11-26
  • 打赏
  • 举报
回复
速度可能差不多快 但是第二种的空间效率明显更优
rucypli 2013-11-26
  • 打赏
  • 举报
回复
你测出来哪个快一些

1,798

社区成员

发帖
与我相关
我的任务
社区描述
MongoDB相关内容讨论区
社区管理员
  • MongoDB社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧