douyingtai6662 2016-03-03 13:06
浏览 43

优化与MySQL查询的慢速匹配

My MyISAM table has 315,000 rows. I have a fulltext index on product_name. Cardinality is 0.

query_cache_size = 20M
query_cache_type = 1
query_cache_limit =  2M

My query is:

select `id`,`product_name`,`description`,`price`,`image`,`colour` 
from table 
where MATCH (`product_name`) AGAINST (:search) 
AND `price` BETWEEN :mincost 
AND :maxcost 
ORDER BY `price` ASC LIMIT :start, :limit

Sometimes I will try a search and it will take around 20-40 seconds, usually the first time I try or when I havnt tried a search for 10+ minutes. Other times it will return the results in about 2 seconds or less. Im guessing this is to do with caching? Something similar to Query taking very long the first time it runs

Lets say my search variable was 'test', does MySQL cache the query with the variable 'test'? So that the next time I search for 'test' the results would return quickly.

Or does it cache the actual search query regardless of what the search variable is so that whatever is searched for will return quickly?

EXPLAIN:

1 SIMPLE table fulltext price,FULLTEXT_product_name FULLTEXT_product_name 0 NULL 1 Using where; Using filesort

  • 写回答

1条回答 默认 最新

  • donglu3087 2016-03-03 13:18
    关注

    Try this with SQL_CACHE

    select SQL_CACHE id,product_name,description,price,image,colour from table where MATCH (product_name) AGAINST (:search) AND price BETWEEN :mincost AND :maxcost ORDER BY price ASC LIMIT :start, :limit

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度