当我添加从 JOINED 表派生的 ORDER BY 时,执行查询的时间从 0.008 秒上升到 0.50 秒,尽管 order by 字段上有一个索引。以下是查询:
SELECT a.productid
FROM products a
JOIN products_lng b FORCE INDEX (primary)
ON a.productid = b.productid
AND b.code = 'US'
JOIN pricing c
ON c.productid = a.productid
JOIN thumbnails d
ON d.productid = a.productid
JOIN bigthumbnails e
ON e.productid = a.productid
JOIN products_categories f
ON f.productid = a.productid
WHERE a.forsale = 'Y'
GROUP BY b.productid
ORDER BY b.product
解释计划:
b 具有以下索引:
CREATE TABLE `products_lng` (
`code` varchar(2) CHARACTER SET latin1 NOT NULL DEFAULT '',
`productid` int(11) NOT NULL DEFAULT '0',
`product` varchar(255) CHARACTER SET latin1 NOT NULL DEFAULT '',
`descr` varchar(512) CHARACTER SET latin1 NOT NULL,
`full_descr` varchar(1024) CHARACTER SET latin1 NOT NULL,
`processed` varchar(1) CHARACTER SET latin1 NOT NULL,
PRIMARY KEY (`code`,`productid`,`product`),
KEY `ad` (`code`,`productid`,`product`,`descr`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin