다음 쿼리가 있으면 속도를 높이기 위해 어떤 인덱스를 만들 수 있습니까?이 MySQL 쿼리에 대해 어떤 인덱스를 생성해야합니까?
SELECT `residentials`.*
FROM `residentials`
WHERE
(is_active = 1) AND
(
(created_at > '2012-02-20 20:51:56' OR modified > '2012-02-20 20:51:56') AND
list_price >= 229000 AND
list_price <= 311000 AND
square_feet >= '1223' AND
square_feet <= '1654' AND
property_type IN ('commercial','condo','detached','house','multi','rowtownhouse','semidetached') AND
(zip LIKE '%19147%')
)
ORDER BY list_price DESC
참고 :이 쿼리는 레일스에 의해 생성되었으므로 작성 방법을 완전히 제어 할 수 없습니다. 다음 수율 EXPLAIN 사용
:
ID = 1
SELECT_TYPE = SIMPLE
테이블 = residentials
형
= 범위이 possible_keys = index_residentials_on_list_price, index_residentials_on_property_style, index_residentials_on_square_feet, index_residentials_on_modified, index_residentials_ on_is_active, index_residentials_on_is_active_and_board_id는 index_residentials_is_active_board_id_list_price_property_type는 index_residentials_on_is_active_and_created_at_and_modified, dates_and_type는 dates_type_price는 board_price_type_zip는 board_price_type_zip_mls
키 = index_residentials_on_list_price
있는 key_len = 209,272
추가 = 사용 6
심판 = NULL
행 어디
012 당신은 시도 3,516,
속도에 대한 제안의 커플 (도움을 확인하려면 다음과 같이 EXPLAIN 사용) - > 및 <조건에 BETWEEN을 사용해보십시오. 또한 지퍼'LIKE'는 성능이 무거울 것입니다. 나는 그것의 유무에 관계없이 그리고 zip에 대한 인덱스가 있거나없이 쿼리를 시도 할 것이다. –