【问题标题】:mysql Query slow on view for searchmysql查询查看搜索速度慢
【发布时间】:2014-10-20 17:12:24
【问题描述】:

我们的搜索速度很慢。我们无法在视图上定义索引..请帮助我们如何改进..下面的查询花费了 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 使用索引;使用临时的;使用文件排序 1 SIMPLE dept eq_ref PRIMARY PRIMARY 4 newdhf.cat_product.category_id 1 使用 where 1 SIMPLE 团队 eq_ref PRIMARY PRIMARY 4 newdhf.dept.parent_id 1 使用 where 1 SIMPLE League eq_ref PRIMARY PRIMARY 4 newdhf.team.parent_id 1 使用 where 1 简单产品 eq_ref PRIMARY PRIMARY 4 newdhf.cat_product.product_id 1 使用 where

创建 算法=未定义视图v_prod_cat AS 选择 deptid AS dept_idteamshort_name AS shortteamnameteamurl AS team_urlteamid AS team_idleague.id AS league_id,product.product_id AS product_id,product.product_status AS product_status,@98765434@44@.upload_image_lAS @9876454345.,@9876 name AS departmentteamname AS teamleaguename AS leagueproducttitle AS titlecat_productproduct_url AS product_url,product.discount AS discount,product.discount_start_date AS discount_start_date,product.discount_end_date AS @9876454371@,@9876 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 msrp,product.cost AS cost,product.vendor_id AS vendor_id,if((cat_product.is_default > 0),1,0) AS is_default,

concat(league.name,_utf8' ',team.name,_utf8' ',dept.name,_utf8' ',replace(replace(replace(replace(@ 987654401@.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',@ 987654415@.name),'$teamname',team.name),'$shortteamname',team.short_name),'$departmentname',dept.name))作为search_text

来自 ((((categoriesdept加入categoriesteam on(((team.id=dept.parent_id)和(team.category_type) ')))) 加入categoriesleague on(((league.id = team.parent_id) 和 (league.category_type = _utf8'league'))))加入category_productscat_product on((cat_product.category_id = dept.id))) 加入productsproduct on((product.@9876544@2@51=. product_id))) 其中 (dept.category_type = _utf8'department') 订购 dept.id desc;

【问题讨论】:

  • 通常全文搜索是慢查询和文本搜索的答案......否则你不需要像可能而不是= 'des'吗?
  • “我们不能在视图上定义索引”是什么意思?你不能只定义视图引用的表上的索引吗?
  • 嗨,蒂姆,感谢您的回复,引用表是 innoDB,视图“search_text”中的字段是从视图中的多个连接操作的。让我知道如何在它们上定义索引。正如我解释上面的查询..

标签: mysql sql


【解决方案1】:

如果您在要搜索的列上为“v_prod_cat”表添加索引,那么这应该有助于加快您的查看速度。

【讨论】:

  • 'v_prod_cat' 这实际上是一个视图,我们不能定义索引@Simon
  • 'v_prod_cat' 这实际上是一个视图,我们无法定义索引@Lajos Veres
  • 因为这是一个视图,所以在该视图中使用的表可能没有应用最佳索引。尝试遍历此视图中的所有表,看看它们是否已正确设置。
  • 过去我在一些查询中也注意到了一些事情,当您在查询中转换值的排序规则(例如,使用 _utf8 设置字符串的排序规则)时,它可能会变慢它下降了一点。你能改变你传递的表格或文本的排序规则吗?
猜你喜欢
  • 2021-07-23
  • 1970-01-01
  • 1970-01-01
  • 2016-06-08
  • 2016-08-28
  • 1970-01-01
  • 2016-01-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多