2014-08-27 170 views
0

我們的搜索非常緩慢。我們無法在視圖上定義索引..請幫助我們如何改進此操作。在查詢下方花了33.3993秒。mysql查詢查詢速度緩慢

SELECT 
    `v_cat_pro`.`product_id`, `v_cat_pro`.`msrp`, 
FROM 
    `v_prod_cat` AS `v_cat_pro` 
WHERE 
    (product_status="1" and msrp >0 AND (search_text = 'de')) 
ORDER BY 
    `msrp` ASC LIMIT 50 

解釋查詢結果

 
id select_type  table type possible_keys key  key_len  ref  rows Extra 
1 SIMPLE cat_product  index catproducts_product_id,category_product_index category_product_index 8 NULL 941343 Using index; Using temporary; Using filesort 
1 SIMPLE dept eq_ref PRIMARY  PRIMARY  4 newdhf.cat_product.category_id 1 Using where 
1 SIMPLE team eq_ref PRIMARY  PRIMARY  4 newdhf.dept.parent_id 1 Using where 
1 SIMPLE league eq_ref PRIMARY  PRIMARY  4 newdhf.team.parent_id 1 Using where 
1 SIMPLE product  eq_ref PRIMARY  PRIMARY  4 newdhf.cat_product.product_id 1 Using where 

CREATE 算法=未定義VIEW v_prod_cat AS 選擇 deptid AS dept_idteamshort_name AS shortteamnameteamurl AS team_urlteamid AS team_id,。 id AS league_idproductproduct_id AS product_idproductproduct_status AS product_statusproductupload_image_l AS upload_image_ldeptname AS departmentteamname AS team,。 name AS ,producttitle AS titlecat_productproduct_url AS product_urlproductdiscount AS discountproductdiscount_start_date AS discount_start_dateproductdiscount_end_date AS discount_end_dateproductextra_discount AS extra_discountproductextra_discount_start_date AS extra_discount_start_dateproductextra_discount_end_date AS extra_discount_end_dateproductglobal_alt_tag AS global_alt_tagproductmsrp AS msrpproductcost AS costproductvendor_id AS vendor_id,如果((cat_productis_default> 0),1,0)AS is_default

的concat(。name,_utf8' 'teamname,_utf8' ',deptname,_utf8' ' ,更換(更換(更換(更換(producttitle, '$ leaguename',。name), '$ teamname',teamname), '$ shortteamname',teamshort_name), '$ DepartmentName的',dept。 'productsku_code,_utf8'',替換(替換(替換地點(productsite_search_keyword,'$ leaguename',。 name),'$ teamname',team。 '$ shortteamname',teamshort_name),'$ departmentname',deptname))AS category_type = _utf8'team'))))search_text

從 ((((categoriesdept加入關於categoriesteam(((teamid = deptparent_id)和(team。加入categories 上(((。id = teamparent_id)和(。category_type = _utf8'league'))))加入在((cat_productcategory_id = deptcategory_productscat_productid)))加入在((productproduct_id = cat_productproductsproductproduct_id))),其中( deptcategory_type = _utf8'department') order by deptid desc;

+0

通常全文搜索是緩慢查詢和文本搜索的答案......否則,你不需要像'='des''那樣的可能嗎? – 2014-08-27 07:56:21

+0

你是什麼意思「我們無法定義視圖索引」?你不能只在視圖引用的表上定義索引嗎? – Tim 2014-08-27 08:02:42

+0

你好,謝謝你的回覆,引用表是innoDB,並且視圖中的字段「search_text」是從視圖中的多個連接操縱的。讓我知道怎樣才能在它們上定義索引..正如我解釋上面的查詢。 – 2014-08-27 11:13:09

回答

0

如果您在正在搜索的列上的'v_prod_cat'表中添加索引,那麼這應該有助於加快視圖的速度。

+0

'v_prod_cat'這實際上是一個視圖,我們不能定義索引@Simon – 2014-08-27 11:41:03

+0

'v_prod_cat'這實際上是一個視圖,我們不能定義索引@Lajos Veres – 2014-08-27 11:52:08

+0

因爲這是一個視圖,所以使用的表在該視圖內可能沒有適用的最佳索引。嘗試遍歷該視圖中的所有表格以查看它們是否已正確設置。 – Simon 2014-08-28 08:11:19