简体   繁体   English

mysql查询查看慢

[英]mysql Query slow on view for search

Our search is very slow on view. 我们的搜索很慢。 we can't define index on view.. Please help how we can improve this .. Below Query took 33.3993 sec. 我们无法在视图上定义索引。.请帮助我们改善此方法.. Query下面花费了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

Explain query result 说明查询结果

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 ALGORITHM=UNDEFINED VIEW v_prod_cat AS select dept . CREATE ALGORITHM =未定义视图v_prod_cat AS select dept id AS dept_id , team . id AS dept_idteam short_name AS shortteamname , team . short_name AS shortteamnameteam url AS team_url , team . url AS team_urlteam id AS team_id , league . id AS team_idleague id AS league_id , product . id AS league_idproduct product_id AS product_id , product . product_id AS product_idproduct product_status AS product_status , product . product_status AS product_statusproduct upload_image_l AS upload_image_l , dept . upload_image_l AS upload_image_ldept name AS department , team . name AS departmentteam name AS team , league . name AS teamleague name AS league , product . name AS leagueproduct title AS title , cat_product . title AS titlecat_product product_url AS product_url , product . product_url AS product_urlproduct discount AS discount , product . discount AS discountproduct discount_start_date AS discount_start_date , product . discount_start_date AS discount_start_dateproduct discount_end_date AS discount_end_date , product . discount_end_date AS discount_end_dateproduct extra_discount AS extra_discount , product . extra_discount AS extra_discountproduct extra_discount_start_date AS extra_discount_start_date , product . extra_discount_start_date AS extra_discount_start_dateproduct extra_discount_end_date AS extra_discount_end_date , product . extra_discount_end_date AS extra_discount_end_dateproduct global_alt_tag AS global_alt_tag , product . global_alt_tag AS global_alt_tagproduct msrp AS msrp , product . msrp AS msrpproduct cost AS cost , product . cost AS costproduct vendor_id AS vendor_id ,if(( cat_product . is_default > 0),1,0) AS is_default , vendor_id AS vendor_id ,如果(( cat_productis_default > 0),1,0)AS is_default

concat( league . name ,_utf8' ', team . name ,_utf8' ', dept . name ,_utf8' ',replace(replace(replace(replace( product . title ,'$leaguename', league . name ),'$teamname', team . name ),'$shortteamname', team . short_name ),'$departmentname', dept . name ),' ', product . sku_code ,_utf8' ',replace(replace(replace(replace( product . site_search_keyword ,'$leaguename', league . name ),'$teamname', team . name ),'$shortteamname', team . short_name ),'$departmentname', dept . name )) AS search_text CONCAT( leaguename ,_utf8 ' teamname ,_utf8', deptname ,_utf8 '更换(更换(更换(更换( producttitle , '$ leaguename', leaguename ),' $ teamname ' teamname ), '$ shortteamname', teamshort_name ), '$ DepartmentName的', deptname ),' ' productsku_code ,_utf8',更换(更换(更换(更换( productsite_search_keyword , '$ leaguename', leaguename ), '$ teamname', teamname ), '$ shortteamname', teamshort_name ), '$ DepartmentName的', deptname ))AS search_text

from (((( categories dept join categories team on((( team . id = dept . parent_id ) and ( team . category_type = _utf8'team')))) join categories league on((( league . id = team . parent_id ) and ( league . category_type = _utf8'league')))) join category_products cat_product on(( cat_product . category_id = dept . id ))) join products product on(( product . product_id = cat_product . product_id ))) where ( dept . category_type = _utf8'department') order by dept . 从(((( categories dept参加categories team在((( teamid = deptparent_id )和( teamcategory_type = _utf8'team'))))加入categories league上((( leagueid = teamparent_id )和( leaguecategory_type = _utf8'league'))))加入category_products cat_product上(( cat_productcategory_id = deptid )))加入products product上(( productproduct_id = cat_productproduct_id )))其中,( deptcategory_type = _utf8'department')由顺序dept id desc; id desc;

如果在要搜索的列上的“ v_prod_cat”表中添加索引,则这将有助于加快视图的速度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM