| Two general MySQL questions.. [message #522] |
Tue, 02 January 2007 10:17  |
oordopjes Messages: 15 Registered: January 2007 |
Junior Member |
|
|
Hi,
1. When using SQL_CALC_FOUND_ROWS combined with a LIMIT and an ORDER BY. Does MySQL stop ordering after the LIMIT is reached? Or are all results ordered by MySQL while getting the SQL_CALC_FOUND_ROWS?
If this is the case it probably is faster to do a SELECT COUNT(*) instead..without an ORDER BY.
2. When MySQL (regular INNER??) JOINs two tables.. Does it first do a SELECT on table1 and a SELECT on table2 and then combine the results? Or does it do a SELECT on table1, join it.. and do another select?
Thanks!
|
|
|
| Re: Two general MySQL questions.. [message #525 is a reply to message #522 ] |
Tue, 02 January 2007 18:51   |
Peter Messages: 405 Registered: August 2006 |
Senior Member Super Guru |
|
|
1) Good question. I'm not 100% sure but I would assume it does not, note even if you use LIMIT without SQL_CALC_FOUND_ROWS MySQL can only stop sorting on very last pass, so most work is performed anyway.
2) SELECT is SQL lever operation so it is neither, what happens it performs scan/lookup in the first table and for each row it performs lookup in the second table. EXPLAIN can be used to see what kind of lookup is used in both cases.
Peter Zaitsev, MySQL Performance Expert
MySQL Performance Blog - http://www.mysqlperformanceblog.com
MySQL Consulting http://www.mysqlperformanceblog.com/mysql-consulting/
|
|
|
|
|
| Re: Two general MySQL questions.. [message #555 is a reply to message #553 ] |
Tue, 09 January 2007 05:40  |
Peter Messages: 405 Registered: August 2006 |
Senior Member Super Guru |
|
|
Ryan,
You're right Sort with Limit can be done way better
There are also numerous other sort optimizations which can be implemented, for example
KEY(A)
ORDER BY A,B
One can still use index based sort and only reorder values for constant A
Order with Join also can be improved to use the index or only partial sort rather than filesort in many cases.
Peter Zaitsev, MySQL Performance Expert
MySQL Performance Blog - http://www.mysqlperformanceblog.com
MySQL Consulting http://www.mysqlperformanceblog.com/mysql-consulting/
|
|
|