Есть вот такой вот кусок запроса
p.quantity > 0 as nalichie
который реплейсится вот таким
SELECT GREATEST(p.quantity, COALESCE((SELECT max(p1.quantity) FROM " . DB_PREFIX . "product p1 WHERE p1.product_id IN (SELECT pl.product_id FROM hpmodel_links pl WHERE pl.parent_id = p.product_id)), 0))) > 0 as nalichie
на выходе..
$sql = "SELECT DISTINCT ps.product_id, p.price, (SELECT GREATEST(p.quantity, COALESCE((SELECT max(p1.quantity) FROM " . DB_PREFIX . "product p1 WHERE p1.product_id IN (SELECT pl.product_id FROM hpmodel_links pl WHERE pl.parent_id = p.product_id)), 0))) > 0 as nalichie, p.price > 0 as nalichie2, (SELECT AVG(rating) FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = ps.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating FROM " . DB_PREFIX . "product_special ps LEFT JOIN " . DB_PREFIX . "product p ON (ps.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "hpmodel_product_hidden kph ON (p.product_id = kph.pid) WHERE kph.pid IS NULL AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ps.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) GROUP BY ps.product_id";
но.. в итоге получаем 4,2сек..
у кого какие идеи..?
3.209 сек.
SELECT p.product_id, p.price,
(SELECT GREATEST(p.quantity, COALESCE((SELECT max(p1.quantity)
FROM product p1
WHERE
p1.product_id IN (SELECT pl.product_id
FROM hpmodel_links pl
WHERE
pl.parent_id = p.product_id)), 0))) > 0 as nalichie, p.price > 0 as nalichie2, (SELECT AVG(rating)
AS total
FROM review r1
WHERE
r1.product_id = p.product_id AND
r1.status = '1'
GROUP BY r1.product_id) AS rating,
(SELECT price
FROM product_discount pd2
WHERE
pd2.product_id = p.product_id AND
pd2.customer_group_id = '1' AND
pd2.quantity = '1' AND
((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND
(pd2.date_end = '0000-00-00' OR pd2.date_end > NOW()))
ORDER BY pd2.priority ASC, pd2.price ASC
LIMIT 1)
AS discount,
(SELECT price
FROM product_special ps
WHERE
ps.product_id = p.product_id AND
ps.customer_group_id = '1' AND
((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND
(ps.date_end = '0000-00-00' OR ps.date_end > NOW()))
ORDER BY ps.priority ASC, ps.price ASC
LIMIT 1)
AS special
FROM product_to_category p2c
LEFT JOIN product p ON (p2c.product_id = p.product_id)
LEFT JOIN product_description pd ON (p.product_id = pd.product_id)
LEFT JOIN product_to_store p2s ON (p.product_id = p2s.product_id)
LEFT JOIN hpmodel_product_hidden kph ON (p.product_id = kph.pid)
WHERE
kph.pid IS NULL AND
pd.language_id = '1' AND
p.status = '1' AND
p.date_available <= NOW() AND
p2s.store_id = '0' AND
p2c.category_id = '93' AND
(p.stock_status_id <> 9) OR (p.quantity > 0 AND
p.stock_status_id = 9)
GROUP BY p.product_id
ORDER BY nalichie2 DESC, p.sort_order ASC, LCASE(pd.name) ASC
LIMIT 0,24