[英]Ruby on rails, the ways to speed up search in database
I have the table products with following fields: code - string, id - integer 我的表产品具有以下字段:代码-字符串,id-整数
My table has over 5 million rows. 我的表有超过500万行。
In the model I use code: 在模型中,我使用代码:
find(:all, :conditions => ['code = ?', "#{search}"])
It takes 2 seconds to find the result. 需要2秒钟才能找到结果。
Is there any way to reduce search time? 有什么办法可以减少搜索时间?
I'm using rails 3.2.11, ruby 1.9.3 and sqlite3 as db 我正在使用Rails 3.2.11,ruby 1.9.3和sqlite3作为数据库
UPD UPD
Changed model code 更改型号代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.