Re: MySQL query length
| From: | CC Zona | Date: | Tue, 28 Aug 2001 07:07:01 +0000 |
| Subject: | Re: MySQL query length | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-64739@lists.php.net to get a copy of this message | ||
In article <NPEFKEPHNLKEPEOLHPKNKEIFCDAA.niklas.lampen@publico.fi>,
niklas.lampen@publico.fi (Niklas lampén) wrote:
> Can it cause any problems if mySQL query is very long? I have to compare
> many words to many fields in my DB and I've done it like
> "....Field LIKE '%searchword%' || Field LIKE '%searchword%' || Field
> LIKE
> '%searchword%'.....". Query is build by a function, so I don't know the
> exact length but it is VERY long. I also have to compare several words to
> one field so I've done many of those "Field LIKE '%blah%'" for those
> too.
> Is there any smarter way to do this?
Depending on what you need the comparison to do and how bit the range of
possible searchwords is, querying against either a "fulltext" index, an
"enum" field, or a "set" field might work out better for you. (See the
*MySQL* manual for more info.)
As for the where clause, AFAIK[*] the length of the query should be less of
a concern than the fact that MySQL is not being allowed to use an index
(because of the leading "%"). It has to do row-by-row comparisons, slowing
down execution.
[*] Double-check that with the folks on the MySQL.com support list, though.
It's a question better asked of them anyway...
--
CC