我們的搜索非常緩慢。我們無法在視圖上定義索引..請幫助我們如何改進此操作。在查詢下方花了33.3993秒。mysql查詢查詢速度緩慢
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 算法=未定義VIEW v_prod_cat
AS 選擇 dept
。 id
AS dept_id
,team
。 short_name
AS shortteamname
,team
。 url
AS team_url
,team
。 id
AS team_id
,。 id
AS league_id
,product
。 product_id
AS product_id
,product
。 product_status
AS product_status
,product
。 upload_image_l
AS upload_image_l
,dept
。 name
AS department
,team
。 name
AS team
,。 name
AS ,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 discount_end_date
,product
。 extra_discount
AS 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
,如果((cat_product
。is_default
> 0),1,0)AS is_default
,
的concat(。name
,_utf8' 'team
。name
,_utf8' ',dept
。name
,_utf8' ' ,更換(更換(更換(更換(product
。title
, '$ leaguename',。name
), '$ teamname',team
。name
), '$ shortteamname',team
。short_name
), '$ DepartmentName的',dept
。 'product
。sku_code
,_utf8'',替換(替換(替換地點(product
。 site_search_keyword
,'$ leaguename',。 name
),'$ teamname',team
。 '$ shortteamname',team
。 short_name
),'$ departmentname',dept
。 name
))AS category_type
= _utf8'team'))))search_text
從 ((((categories
dept
加入關於categories
team
(((team
。id
= dept
。parent_id
)和(team
。加入categories
上(((。id
= team
。 parent_id
)和(。category_type
= _utf8'league'))))加入在((cat_product
。category_id
= dept
category_products
cat_product
。id
)))加入在((product
。product_id
= cat_product
products
product
。product_id
))),其中( dept
。category_type
= _utf8'department') order by dept
。 id
desc;
通常全文搜索是緩慢查詢和文本搜索的答案......否則,你不需要像'='des''那樣的可能嗎? – 2014-08-27 07:56:21
你是什麼意思「我們無法定義視圖索引」?你不能只在視圖引用的表上定義索引嗎? – Tim 2014-08-27 08:02:42
你好,謝謝你的回覆,引用表是innoDB,並且視圖中的字段「search_text」是從視圖中的多個連接操縱的。讓我知道怎樣才能在它們上定義索引..正如我解釋上面的查詢。 – 2014-08-27 11:13:09