0
我有以下查詢。我使用的MySQL數據庫使用索引優化mySql查詢性能
Explain
SELECT
a.ProductID,
a.ProductName,
b.ShelfID,
b.SCode,
c.CompanyID,
c.CompanyName,
d.CategoryName,
ProdCategoryID
FROM tblProduct a
LEFT OUTER JOIN tblShelfComp b
ON a.ProductSID = b.ShelfID
INNER JOIN tblCompany c
ON a.ProductCompId = c.CompId
LEFT OUTER JOIN tclCategory d
ON a.CategoryID = d.CategoryID
ORDER BY a.ProductName
給出O/P
id Select_type table type Possible_keys Key Key_len ref rows Extra
1 SIMPLE a ALL (NULL) (NULL) (NULL) (NULL) 45850 Using where; Using filesort
1 SIMPLE b Eq_ref PRIMARY PRIMARY 34 a. ProductSID 1 (NULL)
1 SIMPLE c Eq_ref PRIMARY PRIMARY 34 a. ProductCompId 1 (NULL)
1 SIMPLE d Eq_ref PRIMARY PRIMARY 34 a. CategoryID 1 (NULL)
這個查詢需要一段時間來執行。所以我使用解釋來了解它是如何運作的。但我無法確定如何處理這個結果。我需要採取哪些步驟來優化性能?
您的查詢需要多少結果行? – Seb
需要將近20秒才能執行。返回45k行 –
唯一引起關注的是用於連接的主鍵字段的長度。建議他們不是整數字段。整數往往對連接更有效率。 – Kickstart