[英]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_id
, team
。 short_name
AS shortteamname
, team
. short_name
AS shortteamname
, team
。 url
AS team_url
, team
. url
AS team_url
, team
。 id
AS team_id
, league
. id
AS team_id
, league
。 id
AS league_id
, product
. id
AS league_id
, product
。 product_id
AS product_id
, product
. product_id
AS product_id
, product
。 product_status
AS product_status
, product
. product_status
AS product_status
, product
。 upload_image_l
AS upload_image_l
, dept
. upload_image_l
AS upload_image_l
, dept
。 name
AS department
, team
. name
AS department
, team
。 name
AS team
, league
. name
AS team
, league
。 name
AS league
, product
. name
AS league
, product
。 title
AS title
, cat_product
. title
AS title
, cat_product
。 product_url
AS product_url
, product
. product_url
AS product_url
, product
。 discount
AS discount
, product
. discount
AS discount
, product
。 discount_start_date
AS discount_start_date
, product
. discount_start_date
AS discount_start_date
, product
。 discount_end_date
AS discount_end_date
, product
. discount_end_date
AS discount_end_date
, product
。 extra_discount
AS extra_discount
, product
. extra_discount
AS extra_discount
, product
。 extra_discount_start_date
AS extra_discount_start_date
, product
. extra_discount_start_date
AS extra_discount_start_date
, product
。 extra_discount_end_date
AS extra_discount_end_date
, product
. extra_discount_end_date
AS extra_discount_end_date
, product
。 global_alt_tag
AS global_alt_tag
, product
. global_alt_tag
AS global_alt_tag
, product
。 msrp
AS msrp
, product
. msrp
AS msrp
, product
。 cost
AS cost
, product
. cost
AS cost
, product
。 vendor_id
AS vendor_id
,if(( cat_product
. is_default
> 0),1,0) AS is_default
, vendor_id
AS vendor_id
,如果(( cat_product
。 is_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( league
。 name
,_utf8 ' team
, name
,_utf8', dept
, name
,_utf8 '更换(更换(更换(更换( product
, title
, '$ leaguename', league
。 name
),' $ teamname ' team
。 name
), '$ shortteamname', team
。 short_name
), '$ DepartmentName的', dept
, name
),' ' product
。 sku_code
,_utf8',更换(更换(更换(更换( product
。 site_search_keyword
, '$ leaguename', league
。 name
), '$ teamname', team
。 name
), '$ shortteamname', team
。 short_name
), '$ DepartmentName的', dept
。 name
))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
在((( team
。 id
= dept
。 parent_id
)和( team
。 category_type
= _utf8'team'))))加入categories
league
上((( league
。 id
= team
。 parent_id
)和( league
。 category_type
= _utf8'league'))))加入category_products
cat_product
上(( cat_product
。 category_id
= dept
。 id
)))加入products
product
上(( product
。 product_id
= cat_product
。 product_id
)))其中,( dept
。 category_type
= _utf8'department')由顺序dept
。 id
desc; id
desc;
如果在要搜索的列上的“ v_prod_cat”表中添加索引,则这将有助于加快视图的速度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.