On Fri, Mar 13, 2009 at 12:42 PM, Mike C <[email protected]> wrote:

>
> I've heard that using LIKE is very slow, but I see it being used a lot
> in examples, blogs etc. Is it really that bad? Since Rails doesn't
> directly support Fulltext search, this is the easiest way to get
> searching done, right? Or are there any other easier ways? I'm using
> acts_as_indexed right now, but it still doesn't do what LIKE does.

The problem with the sql "LIKE" is that it can render the use of an
index impossible. Imagine a search like:

@users = User.find(:all, :conditions => "first_name like '%ILL%'")

The database will have to find BILL, GILL, JILL, JILLIAN, etc. If you have a
few hundred or a few thousand users that may not be such an issue. Millions
of users makes this a different issue altogether. A full table scan is
needed, and what will you do with all those rows?

The point is this, when you are tempted to use LIKE be sure the data set
searched and returned are small and that you try to other ways to constrain
the search.

Cheers--

Charles

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