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.

-- 
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.

Reply via email to