Re: Mysql strategy

From: Date: Wed, 15 Nov 2006 12:15:45 +0000
Subject: Re: Mysql strategy
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-244658@lists.php.net to get a copy of this message
Chris wrote:
David Tulloh wrote:
Dotan Cohen wrote:
If I have to perform 30 LIKE searches for different keywords in a varchar field, which strategy would be recommended: 1) 30 searches, one for each keyword 2) To select the varchar field from all the rows, and search through them with php's array functions?
It's not going to make a great deal of difference if you do the processing in the MySQL or the PHP, in this case it's basically the same operation in each. I suspect that efficiently recreating the LIKE functionality in PHP wouldn't be trivial to do, if you are just doing straight comparisons the MySQL STRCMP function should be faster.
I'd say there will be a big difference. Pulling in 10,000 entries from the database and then sorting them in php will take a lot of memory (and database time to retrieve all of the entries). Getting the database to restrict that number of entries will take a little time but it doesn't have to return all entries, your php memory won't blow out and it won't have bugs in it.
Yes, of course, much better to run it in the database, my bad. I was concentrating far too much on the processing complexity.

« previous php.general (#244658) next »