Indexing of association

Dear

Which table do we index when we have many_to_many relations on rails?
since the foreign key is not in any of the main tables;

when I query, i use eager loading. However, the performance is kind of
slow, because I am confused which table to index

Thanks

ok guys

another question

if i have this

select * from users order by name desc

in order to increase the performance, is it possible to index the
column ‘name’
or it will not help

indexing is a bit confusing me, any idea
thanks

On 13 Aug 2008, at 11:35, Shuaib85 wrote:

in order to increase the performance, is it possible to index the
column ‘name’
or it will not help

This sort of thing is ultimately database dependant, so check the docs
for your database.
Most should on something like this. (and you can always use EXPLAIN to
see whether the database is using your index)

Fred

I have added the index to the column name,

i did the following queries, it seems that order by name uses the
index, if not is there any other way

thanks

mysql> explain select * from products;
±—±------------±--------±-----±--------------±-----±--------
±-----±-----±------+
| id | select_type | table | type | possible_keys | key | key_len |
ref | rows | Extra |
±—±------------±--------±-----±--------------±-----±--------
±-----±-----±------+
| 1 | SIMPLE | products | ALL | NULL | NULL | NULL
| NULL | 129 | |
±—±------------±--------±-----±--------------±-----±--------
±-----±-----±------+
1 row in set (0.00 sec)

mysql> explain select * from products order by name;
±—±------------±--------±------±--------------
±----------------------±--------±-----±-----±------+
| id | select_type | table | type | possible_keys |
key | key_len | ref | rows | Extra |
±—±------------±--------±------±--------------
±----------------------±--------±-----±-----±------+
| 1 | SIMPLE | products | index | NULL |
index_products_on_name | 258 | NULL | 129 | |
±—±------------±--------±------±--------------
±----------------------±--------±-----±-----±------+
1 row in set (0.00 sec)

On Aug 13, 6:41 pm, Frederick C. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs