I have a query which takes about 6 secs to execute.
SELECT * FROM
(SELECT ord.ID, op.name AS prodName, op.code, ord.date, ord.email, op.total, stat.ID AS statusID, stat.value AS status, user.firstname, user.lastname, op.ID AS prouctOrderID, sp.ID AS productID, user.userID
FROM table_orders_1_products AS op
LEFT JOIN table_orders_1 AS ord ON ord.ID=op.orderID
LEFT JOIN cms_user_aditional AS USER ON ord.userAdditional=USER.ID
LEFT JOIN table_status AS stat ON stat.ID=op.statusID
LEFT JOIN table_product_1 AS sp ON op.productID=sp.ID
LEFT JOIN table_partners AS spp ON sp.supplier=spp.ID
WHERE op.statusID!='0'
ORDER BY ord.ID DESC LIMIT 1000) AS allO
ORDER BY allO.ID DESC
If I remove the "bolded" order by statement it takes only 40ms.
Is there any work around to fix this issue?
Create table for test_orders_1
CREATE TABLE `com_shop_orders_1` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`date` int(11) NOT NULL,
`email` text NOT NULL,
`name` text,
`userID` int(11) DEFAULT NULL,
`status` int(3) NOT NULL DEFAULT '1',
`productsTotal` double NOT NULL,
`total` double NOT NULL,
`tax` double NOT NULL,
`discount` double NOT NULL,
`shippingID` int(3) NOT NULL,
`shippingPrice` double NOT NULL,
`paymentID` int(3) NOT NULL,
`userAdditional` int(11) NOT NULL,
`transacitonID` text NOT NULL,
`paymentPrice` double NOT NULL,
PRIMARY KEY (`ID`),
KEY `userID` (`userID`),
KEY `shippingID` (`shippingID`),
KEY `paymentID` (`paymentID`),
KEY `ID_index` (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=208180 DEFAULT CHARSET=latin1;