1 message in com.mysql.lists.mysqlUNION, LIMIT, and FOUND_ROWS()
FromSent OnAttachments
Homam S.A.28 Mar 2005 18:56 
Subject:UNION, LIMIT, and FOUND_ROWS()
From:Homam S.A. (homa@yahoo.com)
Date:03/28/2005 06:56:21 PM
List:com.mysql.lists.mysql

If I use the LIMIT clause without using SQL_CALC_FOUND_ROWS in a non-UNION statement, MySQL returns the number of rows found up to the LIMIT. Using SQL_CALC_FOUND_ROWS forces MySQL to keep going on checking all hits, and that affects performance.

However, if I use the LIMIT clause at the end of a UNION query, MySQL returns the number of all matches even if I don't use SQL_CALC_FOUND_ROWS!

This is causing performance problems because I want MySQL to stop counting all the matches as soon as it finds hits matching the limit.

How do I force MySQL quit calculating all the hits and stick to the LIMIT clause in UNION queries?

In other words, how do I force my SQL to execute the UNION statement the same way it executes a non-UNION statement with a LIMIT clause but no SQL_CALC_FOUND_ROWS?

I appreciate your help.

Homam