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