Creating table in Rails
When you create a table in rails, does the primary key default to :id?
I am trying to access a row in the table by :id, and it's taking over 3 seconds to return the result.
The table contains BLOBs on the order of 5-20Mb and whenever I directly reference a row using ModleName.find(:id), the operation tak开发者_StackOverflow中文版es a long time.
If anyone has suggestions on how to speed up this process I"m all ears
The primary key is the id
by default but it doesn't mean any index
has been created.
To achieve that simply add this kind of line in a migration
file:
add_index(table_name, column_names, options)
See doc here.
When you create a table in rails, does the primary key default to :id?
Yes
The table contains BLOBs on the order of 5-20Mb and whenever I directly reference a row using ModleName.find(:id), the operation takes a long time.
If anyone has suggestions on how to speed up this process I"m all ears
Don't store actual files in the database. You'll run into performance issues like you are right now.
Yes, Rails does the primary key default to :id
First make sure the select query runs up to the speed you wanted in the MySQL command line itself.
Because once I had an issue, where MySQL query itself is slow, as if the MySQL query is slow, there is nothing Rails can do about it.
Anyway as Chirs pointed out, never store files in the table, unless otherwise you have a very good reason to.
精彩评论