如何优化这个SQL查询更快?

时间:2015-02-19 08:04:25

标签: mysql query-optimization

这是我的SQL查询:

SELECT * FROM
    (SELECT * FROM ClassifiedAd
    WHERE city_id = :city
    AND currency = :currency
    AND price > 100) 

UNION DISTINCT

(SELECT c.* FROM 
ClassifiedAd c 
WHERE c.city_id = :city
AND c.currency = :currency
AND (c.price > 100 AND c.price < c.price_last))" 
) l,                    
ClassifiedAd a
LEFT JOIN Picture p ON a.id=p.classifiedAd_id
LEFT JOIN Business b ON b.id=a.business_id
WHERE a.id = l.id 
AND (a.price between :priceDown AND :priceUp) 
AND a.subCategory_id IN (:apartamentList) 
AND a.category_id = :category 
AND a.district_id = :district 
AND a.datePosted > :date 
AND b.status = :bStatus AND a.adStatus = :cStatus AND (b.premium OR b.businessPlus OR b.excellence )
ORDER BY -a.business_id DESC LIMIT :limit

我正在使用mysql和jdbcTemplate。 有一些方法可以使这个查询更快? 我感谢任何帮助。

0 个答案:

没有答案