0
如何在最少的處理時間內獲得分頁的總行數?如何在最少的處理時間內獲得分頁的總行數。
我在產品列表中選擇的SQL過於複雜,無法顯示分頁中的總頁數。我必須查詢沒有限制參數的SQL,這需要花費太多時間來處理。有沒有更好的方式來獲得全部記錄?
這是我的SQL:
SELECT DISTINCT
p.products_model,
p.products_image,
pd.products_name,
p.products_quantity,
p.products_id,
p.products_type,
p.master_categories_id,
p.manufacturers_id,
p.products_price,
products_price_market,
p.products_tax_class_id,
pd.products_description,
IF (pbs.products_id, 1, 0) pdsid,
IF (
s. STATUS = 1,
s.specials_new_products_price,
NULL
) AS specials_new_products_price,
IF (
s. STATUS = 1,
s.specials_new_products_price,
p.products_price
) AS final_price,
p.products_sort_order,
p.product_is_call,
p.product_is_always_free_shipping,
p.products_qty_box_status,
p.products_recommend,
p.products_in_stock
FROM
jy_products_description pd,
jy_products p
LEFT JOIN jy_products_best_selling pbs ON p.products_id = pbs.products_id
AND pbs.category_id = 77,
jy_products_to_categories p2c
LEFT JOIN jy_specials s ON p2c.products_id = s.products_id
AND s. STATUS = 1,
jy_products_attributes pa0
WHERE
p.products_status = 1
AND p.products_quantity > 0
AND p.products_id = p2c.products_id
AND pd.products_id = p2c.products_id
AND p.products_id = pa0.products_id
AND pd.language_id = 1
AND p2c.categories_id = 77
ORDER BY
pdsid DESC,
pbs.sort_by ASC,
p.products_ordered
需要多長時間?什麼索引? – 2013-07-09 03:28:14
您不需要對結果進行排序即可獲得總行數。我認爲,如果刪除,按子句排序,則count(*)的響應速度會快得多。另外,確保有適當的索引。 – Sumoanand