我有一個超慢的查詢,我在這裏發佈:http://pastebin.com/E5sdRi7e。當我做了一個解釋,我得到以下內容:超慢MySQL - 需要幫助!
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 5 Using filesort
2 DERIVED Workflow ALL PRIMARY NULL NULL NULL 9 Using temporary; Using filesort
2 DERIVED <derived3> ALL NULL NULL NULL NULL 141 Using where; Using join buffer
2 DERIVED DataSource ALL PRIMARY NULL NULL NULL 1310 Using where; Using join buffer
2 DERIVED <derived4> ALL NULL NULL NULL NULL 1310 Using where; Using join buffer
2 DERIVED User eq_ref PRIMARY PRIMARY 4 LatestDataSourceActivityLog.UserId 1
4 DERIVED t1 ALL NULL NULL NULL NULL 5400 Using where; Using temporary; Using filesort
5 DEPENDENT SUBQUERY t2 ref DataSourceId DataSourceId 4 companyname_db.t1.DataSourceId 4
3 DERIVED DataSource range PRIMARY PRIMARY 4 NULL 142 Using where
上表是什麼告訴我的?它能幫助我確定哪些字段應該被編入索引嗎?
任何幫助,非常感謝。
查詢
SELECT WrappedData.*
FROM (SELECT ParentLeafNodeDataSource.Id,
LatestDataSourceActivityLog.UserId,
DataSource.Status AS StatusCode,
(CASE
WHEN User.Name IS NULL THEN 'CompanyName'
ELSE User.Name
END) AS `Username`,
Workflow.Name AS WorkflowName,
LatestDataSourceActivityLog.Timestamp
FROM DataSource,
Workflow,
(SELECT *
FROM DataSource
WHERE DataSource.Id IN (0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 10, 11,
12, 13, 16, 21,
22, 23, 24, 25,
26, 27, 28, 29,
30, 31, 32, 33,
34, 35, 36, 37,
38, 39, 40, 41,
42, 43, 44, 45,
46, 47, 48, 49,
50, 51, 52, 53,
54, 55, 56, 57,
58, 59, 60, 61,
62, 63, 64, 65,
66, 67, 68, 69,
70, 71, 72, 73,
74, 75, 76, 77,
78, 79, 80, 81,
83, 84, 85, 86,
87, 88, 89, 90,
91, 92, 93, 94,
95, 96, 97, 98,
99, 100, 101, 102,
103, 104, 105, 106,
107, 108, 109, 110,
111, 112, 113, 114,
115, 116, 117, 118,
119, 120, 142, 1293,
1294, 1295, 1296, 1297,
1298, 1299, 143, 1300,
1301, 1302, 1303, 1304,
1305, 1306, 144, 146,
145, 1307, 1308, 1309,
1310, 147, 149, 148,
150, 151)) AS ParentLeafNodeDataSource,
(SELECT t1.*
FROM DataSourceActivityLog AS t1
WHERE Timestamp = (SELECT Max(t2.Timestamp)
FROM DataSourceActivityLog AS t2
WHERE t1.DataSourceId = t2.DataSourceId)
GROUP BY t1.DataSourceId) AS LatestDataSourceActivityLog
LEFT JOIN User
ON User.Id = LatestDataSourceActivityLog.UserId
WHERE ParentLeafNodeDataSource.Status = '203'
OR ParentLeafNodeDataSource.Status = '204'
AND Workflow.Id = ParentLeafNodeDataSource.WorkflowId
AND LatestDataSourceActivityLog.DataSourceId = ParentLeafNodeDataSource.Id
AND DataSource.Id = LatestDataSourceActivityLog.DataSourceId
AND LatestDataSourceActivityLog.UserId = 1
GROUP BY ParentLeafNodeDataSource.Id) AS WrappedData
ORDER BY WrappedData.`Timestamp` DESC
你可以粘貼到問題的查詢?趨勢科技阻止pastebin。 – 2010-09-19 12:08:57
對不起,但這個查詢只是讓我的一天:) CodeSOD(thedailywtf.com) – 2010-09-19 12:09:37
@Martin:聽起來像一個軟件遲鈍的一塊。最好擺脫它。 – 2010-09-19 12:11:19