Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
次のフィールドを持つテーブル製品があります:code-string、id-integer
私のテーブルには500万行以上あります。
モデルでは、次のコードを使用します。
find(:all, :conditions => ['code = ?', "#{search}"])
結果を見つけるのに2秒かかります。 検索時間を短縮する方法はありますか?
私はデータベースとしてrails3.2.11、ruby 1.9.3、sqlite3を使用しています
UPD 変更されたモデルコード
私は答えを見つけることができました。追加したばかり
add_index :products, :code
移行の変更に対応し、今では非常に高速に動作します。詳細はこちら