[英]Fetch filter properties from mysql innodb table (about 1.5m rows)
我有一個產品表,上面有150萬行。 我想獲取產品並對其進行過濾(關於其類別,品牌等)
我這樣做是這樣的:(場景是:我輸入ID為35的類別,我想獲取其及其子產品)
SELECT distinct r_category as r_category,brand as brand,price as price,offer_id FROM Product where Product.status = 1 and Product.r_category IN (35,279,280,274,276,278,277,275,39,294,295,296,38,292,293,290,291,289,34,271,272,273,36,283,282,284,281,37,285,286,288,287,350,351,348,349,4)
這段代碼告訴我他們有哪些類別,品牌和價格。
我得到的產品大約為0.049秒,但是當我運行此代碼時,它的速度提高到7秒。
0.14223003387451 first query (with limit 20)
7.0965619087219 last query time ( about 957895 rows)
(我的表是innodb,並且我有索引r_category,品牌,價格等)
謝謝大家
要減少查詢時間,您可以執行以下操作:
FORCE INDEX(r_category)
-> SELECT distinct r_category as r_category,brand as brand,price as price,offer_id FROM Product FORCE INDEX(r_category) where Product.status = 1 and Product.r_category IN (35,279,280,274,276,278,277,275,39,294,295,296,38,292,293,290,291,289,34,271,272,273,36,283,282,284,281,37,285,286,288,287,350,351,348,349,4)
如果可能,通過限制和偏移量對查詢分頁。 當您從PHP的數據庫中收到957895行時,會有很多內存分配。 當您使用較少的內存時,腳本將運行得更快。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.