-3

我正在将 testlink 用于我们的内部存储系统进行测试。以下查询耗时近 80 秒,并返回约 11k 行数据。有什么可以改进的地方吗?我假设瓶颈是两个左外连接。

现在的速度:

(11,002 total, Query took 82.8888 sec)

这是查询:

SELECT UA.build_id AS build_id, 
   UA.feature_id AS feature_id,
   UA.user_id as user_id,   
   TPTCV.testplan_id AS testplan_id,
   TPTCV.tcversion_id AS tcversion_id,
   TPTCV.platform_id AS platform_id,       
   E.status AS status,
   E.id as execution_id,
   E.tester_id as tester_id
FROM user_assignments UA  
LEFT OUTER JOIN testplan_tcversions TPTCV ON UA.feature_id = TPTCV.id  
LEFT OUTER JOIN executions E ON TPTCV.tcversion_id = E.tcversion_id
AND UA.build_id = E.build_id
AND TPTCV.platform_id = E.platform_id
WHERE UA.type = 1 AND UA.build_id = 10
ORDER BY E.id DESC
4

2 回答 2

3

你在外键列上有索引吗?你需要它们。如果可能,在所有连接列上。同时生成执行计划并查看输出,这对性能分析非常有帮助。如果您不明白,请在此处发布。

http://dev.mysql.com/doc/refman/5.1/en/execution-plan-information.html

您的 ORDER BY 子句也可能非常昂贵。躲开它。如果可能的话,在别处排序。

于 2012-12-11T19:07:13.937 回答
0

考虑添加覆盖索引,这样查询就可以完全从索引块满足,而不需要引用表块。

例如

... ON user_assignments (build_id, type, feature_id, user_id)

... ON testplan_tcversions (id, testplan_id, tcversion_id, platform_id)

... ON executions (tcversion_id, platform_id, build_id,  status, tester_id, id)

您还可以尝试在没有 ORDER BY 的情况下运行查询,以消除对排序操作的需要。

于 2012-12-11T20:16:47.823 回答