0

次のクエリがある場合、高速化するためにどのインデックスを作成できますか?

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

参考までに、このクエリは Rails によって生成されているため、作成方法を完全に制御することはできません。

EXPLAIN を使用すると、次の結果が得られます。

ID = 1

select_type = シンプル

テーブル = 住宅

タイプ = 範囲

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 = 6

参照 = ヌル

行 = 209272

Extra = where の使用

4

2 に答える 2

2

試しましたか :

EXPLAIN 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
于 2012-03-08T16:10:57.947 に答える
0

インデックスにとって非常に重要な列の順序は、次のことを試してください。

is_active, created_at, modified, list_price, square_feet, property_type 
于 2012-03-08T19:00:18.060 に答える