【发布时间】: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
选择
dept。id AS dept_id,team。short_name AS shortteamname,team。url AS team_url,team。id AS team_id,league.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 department,team。name AS team,league。name AS league,product。title AS title,cat_product。product_url AS product_url,product.discount AS discount,product.discount_start_date AS discount_start_date,product.discount_end_date AS @9876454371@,@9876 extra_discount,product。extra_discount_start_date AS extra_discount_start_date,product。extra_discount_end_date AS extra_discount_end_date,product。global_alt_tag AS global_alt_tag,product。msrp 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”中的字段是从视图中的多个连接操作的。让我知道如何在它们上定义索引。正如我解释上面的查询..