由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Utah版 - 有懂SQL的筒子么?
相关主题
再请教各位一个报税的问题你们说要不要上去帮忙?
Jr. asp.net developer in salt lake area from a recruiter (转载)多谢panys筒子请饭。 :-)
是不是筒子们很失望请参加活动的筒子进来吃包子
筒子们说说几天没来,版上这么热闹了.
Jazz Game night请参与讨论的筒子吃点包子消消火
请xubest筒子回奔看了开幕式直播的筒子们说说
筒子们xlfang筒子开个钓鱼俱乐部吧
这个周末还搞活动吗?食为天
相关话题的讨论汇总
话题: query话题: count话题: join话题: sql话题: table
进入Utah版参与讨论
1 (共1页)
e*******e
发帖数: 1837
1
最近开始学MySQL,发现包含COUNT()的query非常的慢.
我的query(两个table和要用到的column都已经index过了):
SELECT COUNT(*) FROM table_name AS t
INNER JOIN samples AS s ON t.ID = s.ID
GROUP BY s.group
在一个25,000 row 的表里运行这个query居然要20秒.大虾给看看有没有办法加快点?
多谢!
p*****n
发帖数: 43
2
本来以为自己还懂一点,看了你的问题才知道自己什么都不懂:P

【在 e*******e 的大作中提到】
: 最近开始学MySQL,发现包含COUNT()的query非常的慢.
: 我的query(两个table和要用到的column都已经index过了):
: SELECT COUNT(*) FROM table_name AS t
: INNER JOIN samples AS s ON t.ID = s.ID
: GROUP BY s.group
: 在一个25,000 row 的表里运行这个query居然要20秒.大虾给看看有没有办法加快点?
: 多谢!

s*****w
发帖数: 2065
3
me too.
but I guess the problem is not "count".
whenever you use "inner join", it will become very slow.
try to avoid that.
e*******e
发帖数: 1837
4
Thanks! I just found that's the problem as well. it's about 200 times faster
if i don't have to join the two tables. However, it took me 5 mins to
update the table with the column I'm grouping with. :-(
My query is:
UPDATE table_name AS t, sample AS s
SET t.group = s.group
WHERE t.ID = s.ID
Is there anyway to speed this up?

【在 s*****w 的大作中提到】
: me too.
: but I guess the problem is not "count".
: whenever you use "inner join", it will become very slow.
: try to avoid that.

s*****w
发帖数: 2065
5
没太看明白你的程序
应该是有办法的,不过我实在是忘了,两年没碰了
你尝试一下更新表格,在里面加列,这样就不用inner join了
然后再执行查询

faster

【在 e*******e 的大作中提到】
: Thanks! I just found that's the problem as well. it's about 200 times faster
: if i don't have to join the two tables. However, it took me 5 mins to
: update the table with the column I'm grouping with. :-(
: My query is:
: UPDATE table_name AS t, sample AS s
: SET t.group = s.group
: WHERE t.ID = s.ID
: Is there anyway to speed this up?

1 (共1页)
进入Utah版参与讨论
相关主题
食为天Jazz Game night
各位回国的筒子,有空一定要买一份Shanghai Daily看看请xubest筒子回奔
UU的筒子看过来筒子们
求助:有没有人知道babysit的相关信息?这个周末还搞活动吗?
再请教各位一个报税的问题你们说要不要上去帮忙?
Jr. asp.net developer in salt lake area from a recruiter (转载)多谢panys筒子请饭。 :-)
是不是筒子们很失望请参加活动的筒子进来吃包子
筒子们说说几天没来,版上这么热闹了.
相关话题的讨论汇总
话题: query话题: count话题: join话题: sql话题: table