0

I have the table products with following fields: code - string, id - integer

My table has over 5 million rows.

In the model I use code:

find(:all, :conditions => ['code = ?', "#{search}"])

It takes 2 seconds to find the result.
Is there any way to reduce search time?

I'm using rails 3.2.11, ruby 1.9.3 and sqlite3 as db

UPD
Changed model code

BoredT
  • 1,590
  • 15
  • 19

1 Answers1

0

I've managed to find answer. Just added

add_index :products, :code

to migration change and now it works really fast. You will find more information here

BoredT
  • 1,590
  • 15
  • 19