gpt4 book ai didi

mysql - 如何按总和排序(:field) without using temp filesort

转载 作者:行者123 更新时间:2023-11-29 11:30:25 25 4
gpt4 key购买 nike

因此,我们希望通过用户操作(评论、图片上传等)获得最多积分的对象。每个 Action 都存储有其分值和目标。

select sum(points) as points, target_type,target_id from user_actions where target_type="Modification" group by target_id order by points DESC limit 100

显示第 0 - 99 行(总共 100 行,查询耗时 200.7865 秒。)

表大小 4M 行。

关于target_typetarget_id的索引。

如果我解释查询,它会说它正在使用临时文件排序。这显然正在扼杀它。

问题

我有机会加快这个查询吗?

最佳答案

您可以添加另一个索引,或者更改现有索引(如果其他地方未使用该索引)。

Points 列未编入索引,如果有的话,应该会显着提高您的性能:

CREATE INDEX user_actions_indx 
ON user_actions (target_type,target_id,points);

关于mysql - 如何按总和排序(:field) without using temp filesort,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37519738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com