请教关于mongodb聚合查询优化问题

wayne很忙 2014-10-11 12:21:45
期望:
想实现类似如下sql查询:select sum(col) from xxx where a=? and b=? and c=? and d in();
现状和问题:
目前查到的资料是使用mongodb的mapreduce和group by的查询。
但是当数据量过百万的时候,查询速度就巨慢。
求教:
慢得原因是否和group/mapreduce的查询方式有关?
mongodb能实现我期望的查询形式吗?
有何优化方案吗?
...全文
1648 19 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_32225113 2015-10-28
  • 打赏
  • 举报
回复
你好现在问题解决了么 查询效率怎样 现在我也遇到了同样问题
yihong2017 2014-10-14
  • 打赏
  • 举报
回复
说个题外话,为什么在中文论坛还要说英文。
eshujiushiwo 2014-10-13
  • 打赏
  • 举报
回复
引用 15 楼 micropentium6 的回复:
[quote=引用 14 楼 eshujiushiwo 的回复:] [quote=引用 13 楼 micropentium6 的回复:] [quote=引用 12 楼 eshujiushiwo 的回复:] [quote=引用 11 楼 micropentium6 的回复:] [quote=引用 10 楼 eshujiushiwo 的回复:] [quote=引用 8 楼 micropentium6 的回复:] [quote=引用 7 楼 eshujiushiwo 的回复:] [quote=引用 6 楼 micropentium6 的回复:] [quote=引用 5 楼 eshujiushiwo 的回复:] [quote=引用 4 楼 micropentium6 的回复:] [quote=引用 2 楼 eshujiushiwo 的回复:] 现在来补充, 我们是通过aggregate的方式来实现,速度比mapreduce是要快很多的。 问题1:mapreduce确实效率有限。 问题2:使用aggregate来实现。 问题3:使用aggregate来实现。
are u an employee of mongodb?[/quote] HI nope. 哈哈,不是的。是Mongodb中文文档翻译组的成员。[/quote] that's pretty cool! I guess I will probably have lots of questions for u, so thank you in advance! BTW, "Mongodb中文文档翻译组", is this a paid job or a voluntary effort?[/quote] It`s just a a voluntary effort. And u can get more information from the mongoing.com. [/quote] the website looks great! keep your good work and I am sure you will meet mongo users worldwide soon in the States![/quote] lol~[/quote] I am not kidding, u guys deserve it... I will be very disappointed if mongo doesn't offer it...[/quote] 我也希望呀~嘿嘿,借你吉言啦~ 目前我是打算先把上海用户组多多推广~ 人数够的时候,在上海组织次交流会嘛,请TJ哥来分享分享,自己也做点分享什么的~ [/quote] who's TJ? Does Mongo have an office in mainland China?[/quote] TJ 是MongoDB官方在大中华区的首席技术顾问,他的职责是为MongoDB的用户提供方案架构,性能优化,系统部署及扩展等方面的技术支持。在加入MongoDB之前, TJ在联邦快递新加坡担任首席技术架构师。 有的,应该是在深圳~[/quote] Great! looking forward to seeing his presentation![/quote] 我也很期待啊~
  • 打赏
  • 举报
回复
引用 14 楼 eshujiushiwo 的回复:
[quote=引用 13 楼 micropentium6 的回复:] [quote=引用 12 楼 eshujiushiwo 的回复:] [quote=引用 11 楼 micropentium6 的回复:] [quote=引用 10 楼 eshujiushiwo 的回复:] [quote=引用 8 楼 micropentium6 的回复:] [quote=引用 7 楼 eshujiushiwo 的回复:] [quote=引用 6 楼 micropentium6 的回复:] [quote=引用 5 楼 eshujiushiwo 的回复:] [quote=引用 4 楼 micropentium6 的回复:] [quote=引用 2 楼 eshujiushiwo 的回复:] 现在来补充, 我们是通过aggregate的方式来实现,速度比mapreduce是要快很多的。 问题1:mapreduce确实效率有限。 问题2:使用aggregate来实现。 问题3:使用aggregate来实现。
are u an employee of mongodb?[/quote] HI nope. 哈哈,不是的。是Mongodb中文文档翻译组的成员。[/quote] that's pretty cool! I guess I will probably have lots of questions for u, so thank you in advance! BTW, "Mongodb中文文档翻译组", is this a paid job or a voluntary effort?[/quote] It`s just a a voluntary effort. And u can get more information from the mongoing.com. [/quote] the website looks great! keep your good work and I am sure you will meet mongo users worldwide soon in the States![/quote] lol~[/quote] I am not kidding, u guys deserve it... I will be very disappointed if mongo doesn't offer it...[/quote] 我也希望呀~嘿嘿,借你吉言啦~ 目前我是打算先把上海用户组多多推广~ 人数够的时候,在上海组织次交流会嘛,请TJ哥来分享分享,自己也做点分享什么的~ [/quote] who's TJ? Does Mongo have an office in mainland China?[/quote] TJ 是MongoDB官方在大中华区的首席技术顾问,他的职责是为MongoDB的用户提供方案架构,性能优化,系统部署及扩展等方面的技术支持。在加入MongoDB之前, TJ在联邦快递新加坡担任首席技术架构师。 有的,应该是在深圳~[/quote] Great! looking forward to seeing his presentation!
eshujiushiwo 2014-10-13
  • 打赏
  • 举报
回复
引用 13 楼 micropentium6 的回复:
[quote=引用 12 楼 eshujiushiwo 的回复:] [quote=引用 11 楼 micropentium6 的回复:] [quote=引用 10 楼 eshujiushiwo 的回复:] [quote=引用 8 楼 micropentium6 的回复:] [quote=引用 7 楼 eshujiushiwo 的回复:] [quote=引用 6 楼 micropentium6 的回复:] [quote=引用 5 楼 eshujiushiwo 的回复:] [quote=引用 4 楼 micropentium6 的回复:] [quote=引用 2 楼 eshujiushiwo 的回复:] 现在来补充, 我们是通过aggregate的方式来实现,速度比mapreduce是要快很多的。 问题1:mapreduce确实效率有限。 问题2:使用aggregate来实现。 问题3:使用aggregate来实现。
are u an employee of mongodb?[/quote] HI nope. 哈哈,不是的。是Mongodb中文文档翻译组的成员。[/quote] that's pretty cool! I guess I will probably have lots of questions for u, so thank you in advance! BTW, "Mongodb中文文档翻译组", is this a paid job or a voluntary effort?[/quote] It`s just a a voluntary effort. And u can get more information from the mongoing.com. [/quote] the website looks great! keep your good work and I am sure you will meet mongo users worldwide soon in the States![/quote] lol~[/quote] I am not kidding, u guys deserve it... I will be very disappointed if mongo doesn't offer it...[/quote] 我也希望呀~嘿嘿,借你吉言啦~ 目前我是打算先把上海用户组多多推广~ 人数够的时候,在上海组织次交流会嘛,请TJ哥来分享分享,自己也做点分享什么的~ [/quote] who's TJ? Does Mongo have an office in mainland China?[/quote] TJ 是MongoDB官方在大中华区的首席技术顾问,他的职责是为MongoDB的用户提供方案架构,性能优化,系统部署及扩展等方面的技术支持。在加入MongoDB之前, TJ在联邦快递新加坡担任首席技术架构师。 有的,应该是在深圳~
  • 打赏
  • 举报
回复
引用 12 楼 eshujiushiwo 的回复:
[quote=引用 11 楼 micropentium6 的回复:] [quote=引用 10 楼 eshujiushiwo 的回复:] [quote=引用 8 楼 micropentium6 的回复:] [quote=引用 7 楼 eshujiushiwo 的回复:] [quote=引用 6 楼 micropentium6 的回复:] [quote=引用 5 楼 eshujiushiwo 的回复:] [quote=引用 4 楼 micropentium6 的回复:] [quote=引用 2 楼 eshujiushiwo 的回复:] 现在来补充, 我们是通过aggregate的方式来实现,速度比mapreduce是要快很多的。 问题1:mapreduce确实效率有限。 问题2:使用aggregate来实现。 问题3:使用aggregate来实现。
are u an employee of mongodb?[/quote] HI nope. 哈哈,不是的。是Mongodb中文文档翻译组的成员。[/quote] that's pretty cool! I guess I will probably have lots of questions for u, so thank you in advance! BTW, "Mongodb中文文档翻译组", is this a paid job or a voluntary effort?[/quote] It`s just a a voluntary effort. And u can get more information from the mongoing.com. [/quote] the website looks great! keep your good work and I am sure you will meet mongo users worldwide soon in the States![/quote] lol~[/quote] I am not kidding, u guys deserve it... I will be very disappointed if mongo doesn't offer it...[/quote] 我也希望呀~嘿嘿,借你吉言啦~ 目前我是打算先把上海用户组多多推广~ 人数够的时候,在上海组织次交流会嘛,请TJ哥来分享分享,自己也做点分享什么的~ [/quote] who's TJ? Does Mongo have an office in mainland China?
eshujiushiwo 2014-10-13
  • 打赏
  • 举报
回复
引用 11 楼 micropentium6 的回复:
[quote=引用 10 楼 eshujiushiwo 的回复:] [quote=引用 8 楼 micropentium6 的回复:] [quote=引用 7 楼 eshujiushiwo 的回复:] [quote=引用 6 楼 micropentium6 的回复:] [quote=引用 5 楼 eshujiushiwo 的回复:] [quote=引用 4 楼 micropentium6 的回复:] [quote=引用 2 楼 eshujiushiwo 的回复:] 现在来补充, 我们是通过aggregate的方式来实现,速度比mapreduce是要快很多的。 问题1:mapreduce确实效率有限。 问题2:使用aggregate来实现。 问题3:使用aggregate来实现。
are u an employee of mongodb?[/quote] HI nope. 哈哈,不是的。是Mongodb中文文档翻译组的成员。[/quote] that's pretty cool! I guess I will probably have lots of questions for u, so thank you in advance! BTW, "Mongodb中文文档翻译组", is this a paid job or a voluntary effort?[/quote] It`s just a a voluntary effort. And u can get more information from the mongoing.com. [/quote] the website looks great! keep your good work and I am sure you will meet mongo users worldwide soon in the States![/quote] lol~[/quote] I am not kidding, u guys deserve it... I will be very disappointed if mongo doesn't offer it...[/quote] 我也希望呀~嘿嘿,借你吉言啦~ 目前我是打算先把上海用户组多多推广~ 人数够的时候,在上海组织次交流会嘛,请TJ哥来分享分享,自己也做点分享什么的~
  • 打赏
  • 举报
回复
引用 10 楼 eshujiushiwo 的回复:
[quote=引用 8 楼 micropentium6 的回复:] [quote=引用 7 楼 eshujiushiwo 的回复:] [quote=引用 6 楼 micropentium6 的回复:] [quote=引用 5 楼 eshujiushiwo 的回复:] [quote=引用 4 楼 micropentium6 的回复:] [quote=引用 2 楼 eshujiushiwo 的回复:] 现在来补充, 我们是通过aggregate的方式来实现,速度比mapreduce是要快很多的。 问题1:mapreduce确实效率有限。 问题2:使用aggregate来实现。 问题3:使用aggregate来实现。
are u an employee of mongodb?[/quote] HI nope. 哈哈,不是的。是Mongodb中文文档翻译组的成员。[/quote] that's pretty cool! I guess I will probably have lots of questions for u, so thank you in advance! BTW, "Mongodb中文文档翻译组", is this a paid job or a voluntary effort?[/quote] It`s just a a voluntary effort. And u can get more information from the mongoing.com. [/quote] the website looks great! keep your good work and I am sure you will meet mongo users worldwide soon in the States![/quote] lol~[/quote] I am not kidding, u guys deserve it... I will be very disappointed if mongo doesn't offer it...
eshujiushiwo 2014-10-13
  • 打赏
  • 举报
回复
引用 8 楼 micropentium6 的回复:
[quote=引用 7 楼 eshujiushiwo 的回复:] [quote=引用 6 楼 micropentium6 的回复:] [quote=引用 5 楼 eshujiushiwo 的回复:] [quote=引用 4 楼 micropentium6 的回复:] [quote=引用 2 楼 eshujiushiwo 的回复:] 现在来补充, 我们是通过aggregate的方式来实现,速度比mapreduce是要快很多的。 问题1:mapreduce确实效率有限。 问题2:使用aggregate来实现。 问题3:使用aggregate来实现。
are u an employee of mongodb?[/quote] HI nope. 哈哈,不是的。是Mongodb中文文档翻译组的成员。[/quote] that's pretty cool! I guess I will probably have lots of questions for u, so thank you in advance! BTW, "Mongodb中文文档翻译组", is this a paid job or a voluntary effort?[/quote] It`s just a a voluntary effort. And u can get more information from the mongoing.com. [/quote] the website looks great! keep your good work and I am sure you will meet mongo users worldwide soon in the States![/quote] lol~
eshujiushiwo 2014-10-13
  • 打赏
  • 举报
回复
引用 3 楼 haoxiaoliang 的回复:
[quote=引用 2 楼 eshujiushiwo 的回复:]
现在来补充,
我们是通过aggregate的方式来实现,速度比mapreduce是要快很多的。
问题1:mapreduce确实效率有限。
问题2:使用aggregate来实现。
问题3:使用aggregate来实现。


测试过了,确实快了很多,300万数据时间大概缩短了4/5。原先reduce大概36秒,优化后将近7秒。
但是还有个问题想请教:
因为优化后的时间我也不是很满意,故我在查询条件上加上了个组合索引,再次查询却发现速度没有降,反而有小幅度的上升,稳定在了7秒多点。
我猜测大概是我索引的选择度不是很高造成的,但是目前是可能存在这种查询条件的。

我想问下,如果想进一步优化,除了加索引还可以怎么做[/quote]
HI 楼主
很高兴能帮助到你。

aggregate的过程可以通过上图看出,先进行查询,然后对查询后的数据进行再次处理。
很多时候我们的时间消耗在了再次处理的过程中。
BTW
这样sql的需求是什么呢?看看能否从别的方面来进行优化。
  • 打赏
  • 举报
回复
引用 7 楼 eshujiushiwo 的回复:
[quote=引用 6 楼 micropentium6 的回复:] [quote=引用 5 楼 eshujiushiwo 的回复:] [quote=引用 4 楼 micropentium6 的回复:] [quote=引用 2 楼 eshujiushiwo 的回复:] 现在来补充, 我们是通过aggregate的方式来实现,速度比mapreduce是要快很多的。 问题1:mapreduce确实效率有限。 问题2:使用aggregate来实现。 问题3:使用aggregate来实现。
are u an employee of mongodb?[/quote] HI nope. 哈哈,不是的。是Mongodb中文文档翻译组的成员。[/quote] that's pretty cool! I guess I will probably have lots of questions for u, so thank you in advance! BTW, "Mongodb中文文档翻译组", is this a paid job or a voluntary effort?[/quote] It`s just a a voluntary effort. And u can get more information from the mongoing.com. [/quote] the website looks great! keep your good work and I am sure you will meet mongo users worldwide soon in the States!
eshujiushiwo 2014-10-13
  • 打赏
  • 举报
回复
引用 6 楼 micropentium6 的回复:
[quote=引用 5 楼 eshujiushiwo 的回复:] [quote=引用 4 楼 micropentium6 的回复:] [quote=引用 2 楼 eshujiushiwo 的回复:] 现在来补充, 我们是通过aggregate的方式来实现,速度比mapreduce是要快很多的。 问题1:mapreduce确实效率有限。 问题2:使用aggregate来实现。 问题3:使用aggregate来实现。
are u an employee of mongodb?[/quote] HI nope. 哈哈,不是的。是Mongodb中文文档翻译组的成员。[/quote] that's pretty cool! I guess I will probably have lots of questions for u, so thank you in advance! BTW, "Mongodb中文文档翻译组", is this a paid job or a voluntary effort?[/quote] It`s just a a voluntary effort. And u can get more information from the mongoing.com.
  • 打赏
  • 举报
回复
引用 5 楼 eshujiushiwo 的回复:
[quote=引用 4 楼 micropentium6 的回复:] [quote=引用 2 楼 eshujiushiwo 的回复:] 现在来补充, 我们是通过aggregate的方式来实现,速度比mapreduce是要快很多的。 问题1:mapreduce确实效率有限。 问题2:使用aggregate来实现。 问题3:使用aggregate来实现。
are u an employee of mongodb?[/quote] HI nope. 哈哈,不是的。是Mongodb中文文档翻译组的成员。[/quote] that's pretty cool! I guess I will probably have lots of questions for u, so thank you in advance! BTW, "Mongodb中文文档翻译组", is this a paid job or a voluntary effort?
eshujiushiwo 2014-10-13
  • 打赏
  • 举报
回复
引用 4 楼 micropentium6 的回复:
[quote=引用 2 楼 eshujiushiwo 的回复:] 现在来补充, 我们是通过aggregate的方式来实现,速度比mapreduce是要快很多的。 问题1:mapreduce确实效率有限。 问题2:使用aggregate来实现。 问题3:使用aggregate来实现。
are u an employee of mongodb?[/quote] HI nope. 哈哈,不是的。是Mongodb中文文档翻译组的成员。
  • 打赏
  • 举报
回复
引用 2 楼 eshujiushiwo 的回复:
现在来补充, 我们是通过aggregate的方式来实现,速度比mapreduce是要快很多的。 问题1:mapreduce确实效率有限。 问题2:使用aggregate来实现。 问题3:使用aggregate来实现。
are u an employee of mongodb?
wayne很忙 2014-10-11
  • 打赏
  • 举报
回复
引用 2 楼 eshujiushiwo 的回复:
现在来补充, 我们是通过aggregate的方式来实现,速度比mapreduce是要快很多的。 问题1:mapreduce确实效率有限。 问题2:使用aggregate来实现。 问题3:使用aggregate来实现。
测试过了,确实快了很多,300万数据时间大概缩短了4/5。原先reduce大概36秒,优化后将近7秒。 但是还有个问题想请教: 因为优化后的时间我也不是很满意,故我在查询条件上加上了个组合索引,再次查询却发现速度没有降,反而有小幅度的上升,稳定在了7秒多点。 我猜测大概是我索引的选择度不是很高造成的,但是目前是可能存在这种查询条件的。 我想问下,如果想进一步优化,除了加索引还可以怎么做
eshujiushiwo 2014-10-11
  • 打赏
  • 举报
回复
现在来补充, 我们是通过aggregate的方式来实现,速度比mapreduce是要快很多的。 问题1:mapreduce确实效率有限。 问题2:使用aggregate来实现。 问题3:使用aggregate来实现。
eshujiushiwo 2014-10-11
  • 打赏
  • 举报
回复
楼主你好~
我先来回答你的需求。

1,798

社区成员

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

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