Sebastian wrote:

Ah.. OK. I'll give that a shot instead..
Also, now that i am doing some thinking on optimizing... should the $cat clause be present first in the where clause? since it decides if it should get results or not. for example:

WHERE MATCH(...) AGAINST(... IN BOOLEAN MODE) AND ('$cat' = 'news' OR @cat = '')

or:

WHERE ('$cat' = 'news' OR '$cat' = '') AND MATCH(...) AGAINST(... IN BOOLEAN MODE)

does it matter in terms of performance?

I'm not sure. In every case, the $cat clause is either impossible or certain, so it can be optimized away (taking the whole query with it in the impossible case). Hence, there will be no difference in the processing of tables once the execution plan has been chosen. The only possible difference would be determined by how much time the optimizer wastes on other parts of the WHERE clause before noticing an impossible $cat part. I don't know precisely how the optimizer does this, so I don't know if order makes a difference, nor which order would be best if it does. You could try it both ways, but I doubt you'd detect any difference in a single query. If I had to guess, though, I'd guess that if it makes any difference, then you are right that first is best.

Also, for completeness, note that if there is any more to your WHERE clause than just the MATCH AGAINST, you may need to use parentheses around the entire rest of the WHERE clause, aside from the $cat part. For example, AND is higher precedence than OR, so

  WHERE ('$cat' = 'news' OR '$cat' = '') AND cond1 OR cond2

wouldn't work the way you want. To guard against that, I'd suggest always adding the parentheses around the rest of the conditions:

  WHERE ('$cat' = 'news' OR '$cat' = '') AND (other conditions)

Michael

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to