【发布时间】:2013-07-31 02:18:50
【问题描述】:
我还是 sql 新手,我的代码运行时间太长。
这是我的代码
SELECT SUM(b.matchusertime)
FROM(
SELECT fulldate, realmatchid, isclanmatch
FROM go_int.int_match
WHERE (fulldate BETWEEN '2013-06-30' AND '2013-07-27') AND isclanmatch = 0
GROUP BY realmatchid)a
INNER JOIN go_int.int_match_user b
ON b.realmatchid = a.realmatchid
WHERE (b.fulldate BETWEEN '2013-06-30' AND '2013-07-27')
我正在尝试做的是从匹配表中获取不在氏族匹配中的用户 ID,并将其匹配到 match_user 表中,以找出非氏族匹配的总持续时间。
但每次我运行查询时,都需要 45 分钟或更长时间,并且由于超时问题等原因没有返回结果。
【问题讨论】:
-
桌子有多大?你用的是什么数据库?你有什么索引?
-
表格很大,超过 500,000 行。 match 可能有很多列,大约 8 列。对于 match 用户,它有大约 15 列。
-
在不知道您当前的索引是什么、您正在使用的数据库以及您的查询的查询计划的情况下,任何有关性能的提示都只是猜测。
标签: sql join long-integer