我在下面查询。我正在使用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)
该查询需要一段时间才能执行。因此,我正在使用解释来了解其功能。但是我无法确定如何处理此结果。我需要采取哪些步骤来优化性能?
如果您不使用“ ORDER BY”,运行查询需要多长时间?如果这大约是相同的时间,则您的查询没有优化的潜力。(也许投资更好的硬件/更快的磁盘-或调整您的mysql服务器值以进行优化?)
如果速度快得多,则可以尝试在tblProduct.ProductName上创建索引。不过,如果有帮助,请不要犹豫。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句