错误的搜索查询正在使我们的网站崩溃。写这个的人计算了每个子类别,然后将它们加在一起以获得主要类别的总数。对于分页 Next、Last、Pages,然后使用 JOIN/INNER JOIN(该页面的所有产品)编写查询。它创建了太多的步骤,从而减慢了一切,直到超时。帮助!
查询摘要:
SELECT COUNT(DISTINCT node.nid) AS cnt FROM
content_type_product cp
LEFT JOIN node node ON node.nid = cp.nid
LEFT JOIN uc_products uc_products ON node.nid = uc_products.nid
LEFT JOIN users users ON users.uid = node.uid
LEFT JOIN files ON files.fid = cp.field_product_image_1_value
LEFT JOIN content_type_product_tags ct ON ct.field_product_product_id_value = cp.nid
WHERE
(
node.status <> N
)
AND
(
ct.field_product_tag_id_value = N
)
AND
(
cp.field_deleted_value <> N
)
AND
(
cp.field_stock_level_value > N
)
AND EXISTS
(
SELECT scp.nid FROM content_type_store scp
LEFT JOIN node snode ON snode.nid = scp.nid
LEFT JOIN users susers ON susers.uid = snode.uid
WHERE susers.name = users.name
AND scp.field_shop_activated_value = 'S'
AND scp.field_shop_suspended_value = 'S')
ORDER BY cp.field_product_last_changed_value DESC;
查询样本:
SELECT count(Distinct node.nid) as cnt
FROM content_type_product cp
LEFT JOIN node node ON node.nid = cp.nid
LEFT JOIN uc_products uc_products ON node.nid = uc_products.nid
LEFT JOIN users users ON users.uid = node.uid
LEFT JOIN files ON files.fid = cp.field_product_image_1_value
LEFT JOIN content_type_product_tags ct ON ct.field_product_product_id_value = cp.nid
WHERE
(
node.status <> 0
)
AND
(
ct.field_product_tag_id_value = 478
)
AND
(
cp.field_deleted_value <> 1
)
AND
(
cp.field_stock_level_value > 0
)
AND EXISTS
(
SELECT scp.nid FROM content_type_store scp
LEFT JOIN node snode on snode.nid = scp.nid
LEFT JOIN users susers on susers.uid = snode.uid
WHERE susers.name = users.name
AND scp.field_shop_activated_value = '1'
AND scp.field_shop_suspended_value = '0'
)
ORDER BY cp.field_product_last_changed_value DESC