mysql查询视图搜索速度慢

时间:2014-08-27 07:53:18

标签: mysql sql

我们的搜索速度很慢。我们无法在视图上定义索引..请帮助我们如何改进这个..下面的查询花了33.3993秒。

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      算法=未定义的视图v_prod_cat AS 选择     deptid AS dept_idteamshort_name AS shortteamnameteamurl AS {{ 1}},team_urlteam AS idteam_idleague AS idleague_id。{{1} } AS productproduct_idproduct_id AS productproduct_statusproduct_status AS productupload_image_lupload_image_l AS deptnamedepartment AS teamnameteam AS league,{{ 1}}。name AS leagueproducttitle AS titlecat_productproduct_url AS {{1} },product_urlproduct AS discountdiscountproduct AS discount_start_datediscount_start_dateproduct AS discount_end_datediscount_end_dateproduct AS extra_discountextra_discountproduct AS extra_discount_start_dateextra_discount_start_date。{{ 1}} AS productextra_discount_end_dateextra_discount_end_date AS productglobal_alt_tagglobal_alt_tag AS product,{{1} }。msrp AS msrp,if((productcost> 0),1,0)AS cost

concat(productvendor_id,_ utf8'',vendor_idcat_product,_ utf8'',is_defaultis_default,_ utf8 '',替换(替换(替换(替换(leaguename,'$ leaguename',teamname),'$ teamname',{{1} }。dept),'$ shortteamname',nameproduct),'$ departmentname',titleleague),'',{{ 1}}。name,_ utf8'',替换(替换(替换(替换(teamname,'$ leaguename',teamshort_name ), '$ teamname',deptname), '$ shortteamname',productsku_code), '$ DepartmentName的',product。{ {1}}))AS site_search_keyword

这    (((league name加入team name on(({teamshort_name = dept。{{1 }}和(namesearch_text = _utf8'team'))))加入categories dept on((categories。{{1} } = teamteam)和(iddept = _utf8'league'))))加入parent_id team(() category_typecategories = leagueleague)))加入id team on(parent_id。{{1} } = leaguecategory_type)))其中(category_productscat_product = _utf8'department') 订购       cat_productcategory_id desc;

1 个答案:

答案 0 :(得分:0)

如果您为' v_prod_cat'添加索引。您正在搜索的列上的表格,这将有助于加快您的观看速度。