[Rails] Re: Foreign Key (Mysql/Rails)

2009-06-10 Thread Frederick Cheung
On Jun 10, 2:52 am, Robert Walker wrote: > > Of course, there is no index in the foreign key so MySQL has no way to > optimize. When you add a foreign key mysql implicitly adds an index. > > > Ironically, when I do EXPLAIN SELECT * from products where category_id > > IN (1,2); It uses type-rang

[Rails] Re: Foreign Key (Mysql/Rails)

2009-06-09 Thread Robert Walker
Youyou Semsem wrote: > Hi, > > I am using a Mysql table products which has a foreign key category_id on > the categories table > > the foreign key constraint is defined (Innodb engine). The constraint matters not, for performance. What is important is that the foreign key is indexed. > I noti

[Rails] Re: Foreign Key (Mysql/Rails)

2009-06-09 Thread Perry Smith
I happen to be reading about this last night except I was reading about it in the PostgreSQL manual. In the case of PostgreSQL, the planner searches for the least expensive plan and uses different plans based upon the "selectivity" of the constraint. The PostgreSQL doc may give you a clue wha