Gary Doades wrote: > Jian Lin wrote: >> >> but it is still the same: it took 75 seconds... > > That's because it's still really the same code! > >> i wanted the length, which is the count of word because in the future i >> might want to do query such as "select * where length > 3" and so if i >> count the word by getting "s" first, then it will be really slow won't >> it? if length is stored and indexed, then "length > 3" can be super >> fast? > > Just because it has an index on it doesn't automatically make it super > fast. It depends largely on the selectivity of the length field. I > suspect that most of your phrases are larger than 3 characters and so > such a query will result in a full table scan anyway. In that case > making the table smaller by leaving out the length may actually make it > faster. However, selecting all the phrases where length < 5 would almost > certainly use the index and make it faster. Only you know what you are > likely to do in general here so you need to decide (and test) whether it > is better to have the index and length column or not. > > You can always do "select * from phrases where length(s) > 3" or > something like. > > Are you sure your overall run time is not limited by CPU rather than IO? > How much CPU time is used to run your code?
oh sorry i should have clarified... the length is actually the count of words... so length > 3 means 3 words at least. or i might do a query that is word > 5 or 7... so will having an column and an index make it fast if i do query such as length > 7? i intend for example to get back only 5% or 3% of all records so the index might make it fast. by the way, the 75 second is the time from the moment the Phrase.transaction do to the end of it... so... i think during that time it is mostly IO time... let me actually write up a test case with some dummy data to simulate it so that every one is on the same ground... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

