When I add an ORDER BY derived from a JOINED table, the time to execute the query goes up from 0.008 seconds to 0.50 seconds, this although there's an index on the order by field. The following is the query:
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
Explain plan:
b has the following indexes:
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