Likes are always slow if you must do a suffix match ( "%something" ),
as no index can handle that. But if you're doing a prefix match (
"something%" ) it won't be that bad.

And there's no "how big is big". You can have a slow app with a
thousand rows and a hundred queries per second, and you can have a
fast one with a million rows and a query per second. It all depends on
what you're doing.

Get a book on database optimization, all big databases have one, then
you'll undertand what's fast and what's slow about your database.

-
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en)



On Fri, Mar 13, 2009 at 3:11 PM, Mike C <[email protected]> wrote:
>
> 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?
>
> 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