Wicked
конечно.
Запрос:
[sql]
SELECT `p` . *
FROM `shoppingcart_products` AS `p`
INNER JOIN (
SELECT `id`
FROM `shoppingcart_products`
ORDER BY `date` DESC
LIMIT 10
) AS `p2` ON ( `p`.`id` = `p2`.`id` )
LEFT JOIN `shoppingcart_products_data` AS `d` ON `p`.`id` = `d`.`itemid`
LEFT JOIN `shoppingcart_products_categories` AS `pc` ON `pc`.`pid` = `p`.`id`
LEFT JOIN `shoppingcart_categories` AS `cc` ON `cc`.`id` = `pc`.`cid`
LEFT JOIN `shoppingcart_currency` AS `cur` ON `cur`.`id` = `p`.`currency`
LEFT JOIN `shoppingcart_manufacturers_data` AS `m` ON `m`.`itemid` = `p`.`manufacturer`
LEFT JOIN `shoppingcart_users` AS `u` ON `u`.`id` = `p`.`added_by`
GROUP BY `p`.`id`
[/sql]
Explain:
Код:
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 10 Using temporary; Using filesort
1 PRIMARY p eq_ref PRIMARY PRIMARY 4 p2.id 1
1 PRIMARY d ref itemid itemid 4 mydb.p.id 2 Using index
1 PRIMARY pc ref PRIMARY PRIMARY 4 mydb.p.id 2 Using index
1 PRIMARY cc eq_ref PRIMARY PRIMARY 4 mydb.pc.cid 1 Using index
1 PRIMARY cur eq_ref PRIMARY PRIMARY 4 mydb.p.currency 1 Using index
1 PRIMARY m ref itemid itemid 4 mydb.p.manufacturer 1 Using index
1 PRIMARY u eq_ref PRIMARY PRIMARY 4 mydb.p.added_by 1 Using index
2 DERIVED elva_wsshoppingcart_products index NULL date 8 NULL 4655
-~{}~ 05.08.10 12:28:
Не смотря на опять печальный explain, запрос выполняется гораздо быстрее.
Первый вариант: 1.3057 sec
Второй вариант: 0.0108 sec
Обе выполнил с ключом SQL_NO_CACHE