SELECT MAX( CAST( auction_price.Auctionprice AS SIGNED ) ) AS `max_auction_price`
FROM auction_detail
LEFT JOIN auction_price ON auction_detail.auction_id = auction_price.auction_id
WHERE auction_detail.season = '2011'
AND auction_detail.sale_no = '26'
AND auction_detail.area LIKE '%Mumbai%'
AND auction_detail.broker_code LIKE '%PAP%'
AND auction_detail.category LIKE '%CTC%'
AND auction_detail.tea_type LIKE '%BEST%'
上面的查询需要大约49秒运行,所以我真的需要优化它以提高性能。有什么建议吗?
答案 0 :(得分:1)
在mysql中运行前缀为explain的命令,它会显示查询中使用了哪些索引,需要一些时间来学习如何读取输出,但这并不太难。
EXPLAIN SELECT MAX( CAST( auction_price.Auctionprice AS SIGNED ) ) AS `max_auction_price`
FROM auction_detail
LEFT JOIN auction_price ON auction_detail.auction_id = auction_price.auction_id
WHERE auction_detail.season = '2011'
AND auction_detail.sale_no = '26'
AND auction_detail.area LIKE '%Mumbai%'
AND auction_detail.broker_code LIKE '%PAP%'
AND auction_detail.category LIKE '%CTC%'
AND auction_detail.tea_type LIKE '%BEST%'
答案 1 :(得分:0)
LIKE关键词是否总是独立存在(而不是字符串的部分)? (Mumbai
,PAP
,CTC
,BEST
)
如果是这样,请尝试full-text search。正确索引的全文搜索可能比LIKE更快。
答案 2 :(得分:0)
创建索引。
例如
auction_detail.sale_no
和auction_price.auction_id
。OR
auction_detail.area
和auction_price.auction_id
上进行查询
例如'Mumbai%'
(即没有%)答案 3 :(得分:0)
sale_no, season
)。