On 20 Dec 2008, at 07:11, Marnen Laibow-Koser wrote:

>
>
> On Dec 20, 1:01 am, Jeff Pritchard <[email protected]>
> wrote:
>> Hi,
>> I don't quite understand the syntax for database indexes and/or how  
>> the
>> work to help speed up specific database searches.  Can somebody  
>> suggest
>> a set of indexs that would make this set of queries go faster?
> [...]
>
> Very simple: you can profit by indexing on almost anything you're
> going to be doing a lot of searching on.  In this case, that means
> that you should consider building indices on your foreign key fields
> (such as contacts.user_id), since they're what you're searching on in
> these queries.  But before you do that, you might want to try EXPLAIN
> SELECT on the queries you're interested in, and see what mySQL tells
> you about where the bottlenecks are.
>
All of the above is good. To explain a little more if you do

SELECT * from contacts where contacts.user_id = 2356

and there is no index then the database must examine every single row  
in the contacts table to see if it has the right user_id whereas if it  
has an index it can go straight there. (similar to how if you have a  
phone book and you're looking for all entries 'Michael smith' you  
don't have to read the entire phone book, you can jump to the  
appropriate page very quickly)

Fred
> Best,
> --
> Marnen Laibow-Koser
> [email protected]
> http://www.marnen.org
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" 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-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to