NYCPHP Meetup

NYPHP.org

[nycphp-talk] Paging Strategies

Brent Baisley brenttech at gmail.com
Wed Oct 24 14:03:02 EDT 2007


My guess is that two queries would be faster if only the indexes
needed to be accessed. Meaning it would not need to read from the main
data file to determine the result set, just the index file. This would
be especially true of InnoDB based tables.

On 10/24/07, Rob Marscher <rmarscher at beaffinitive.com> wrote:
> On Oct 18, 2007, at 5:08 PM, Brent Baisley wrote:
> > You don't need to do an extra count query. If you are using MySQL,
> > just add SQL_CALC_FOUND_ROWS to your select query.
> > SELECT SQL_CALC_FOUND_ROWS * FROM ...
> > You can then run SELECT FOUND_ROWS() to get the total rows without any
> > limits. It's still 2 queries, but the second one is essentially free.
>
> If it's a relatively simple query that makes use of indexes, then
> it's going to be faster to do a separate count(0) query instead of
> SQL_CALC_FOUND_ROWS.  I confirmed with some gurus at the recent mysql
> camp that SQL_CAL_FOUND_ROWS is faster than count(0) if it's a
> complex search query (i.e. where clauses/joins on non-indexed columns).
>
> -Rob
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
>



More information about the talk mailing list