> Thanks, that makes things clearer. But how big is big? I don't plan on
> my app being hugely popular, but would thousands of entries be ok? Is
> there an area where LIKE starts to be really slow?

If it's a blog, I wouldn't think twice about using LIKE.  That is, I  
can't see a blog being big enough for it to become a problem.   
However, as other folks have said it definitely can be the source of  
problems down the road.

At that point you should look at one of the full text search engines  
like ferret, sphinx, solr, etc.

Also, just so you're aware LIKE in mysql is case-INSENSITIVE.  LIKE in  
PostgreSQL is case-SENSITIVE.

So when you're searching for names and are happy doing a LIKE '%ill%'  
to find those names below, keep in mind that won't work in  
PostgreSQL.  PostgreSQL has an ILIKE for that, but then that's not  
supported by MySQL.  PostgreSQL also has some regex pattern matching  
functions that are faster, but again I believe are postgres only.

Anyway, just something to keep in mind if you think your app might be  
run with different backends.

-philip




> On Mar 13, 11:06 am, Charles Johnson <[email protected]> wrote:
>> 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