Em 06-12-2011 03:31, Jon Jensen escreveu:
On Nov 28, 11:50 am, Rodrigo Rosenfeld Rosas<[email protected]>
wrote:
Also if creating the foreign key won't
automatically create an index to it for some databases, such statement
should also take care of creating the index too.
Postgres does not automatically create indexes for foreign keys, and
for good reason. Consider a "categories" table with an id, name, and
several other columns. It has only 5 rows. Then you have an "items"
table with a million rows. It has a category_id, and you make it a
foreign key. Adding an index with such a low cardinality is a Bad
Idea™ because 1. it will likely never be used by the query planner 2.
it will always slow down all writes to that table.
Yes, I was referring exactly to PostgreSQL. Don't you think that for
most associations we would want an index?
I'm proposing creating one unless specified not to. For example:
t.references :category, create_index: false
Don't you think 'true' should be default for :create_index?
--
You received this message because you are subscribed to the Google Groups "Ruby on
Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.