Performance
MariaDB 執行緩慢
不確定這是否可以在沒有 UNION 的情況下完成。我認為是 UNION 讓它變慢了。這兩個部分本身就相當快,但結合 UNION,此程式碼需要 > 5 秒才能完成。可以優化嗎?
SELECT rl.Updated, c.CultureName, "CollectionName" as CollectionName, k.KeyName , rl.Value , s.StatusName , rl.Comment , rl.Comment as ActionInfo, a.ActionName, u.UserName FROM ResourceLog rl INNER JOIN `Status` s ON rl.StatusId = s.StatusId INNER JOIN Culture c ON rl.CultureId = c.CultureId INNER JOIN `Key` k ON rl.KeyId = k.KeyId LEFT JOIN `Action` a ON rl.ActionId = a.ActionId LEFT JOIN `User` u ON rl.UserId = u.UserId UNION SELECT imp.Created as Updated, "Imported" as CultureName, "None" as CollectionName, "Imported" as KeyName, "Imported" as Value, "Imported" as StatusName, "Imported" as Comment, "ActionInfo" as ActionInfo, "Imported" as ActionName, UserId FROM Import imp ORDER BY Updated DESC, KeyName, CultureName limit 50
我懷疑組合查詢沒有做你認為它正在做的事情。
添加括號以明確第二個是
ORDER BY
屬於第二個SELECT
還是屬於UNION
. 同上LIMIT
。( SELECT ... ) UNION ( SELECT ... -- Do the ORDER BY and LIMIT belong here? ) -- Or here (for the UNION)?
如需進一步討論,請提供
EXPLAIN ... SHOW CREATE TABLE ... how big are the tables