'Twas brillig, and Dennis Becker at 26/01/09 10:54 did gyre and gimble:
This is slower in comparison with a 2nd "SELCT COUNT(PRIMARY_KEY_COLUMN)
FROM blah" - look
at http://www.mysqlperformanceblog.com/2007/08/28/to-sql_calc_found_rows-or-not-to-sql_calc_found_rows/
An interesting, if not always accurate (according to the comments) analysis.
In some cases tho', due to the kind of select statement your running
you'd have to do:
$select->reset(Zend_Db_Select::COLUMNS);
$select->reset(Zend_Db_Select::GROUP);
$select->reset(Zend_Db_Select::ORDER);
$select->columns(new Zend_Db_Expr('COUNT(DISTINCT
table.pri_key_col)'));
Depending on the use case, it could be faster/slower than the
calc_found_rows technique. I always heard that with innodb that select
count(*)'s were pretty inefficient anyway, but perhaps that no longer
holds true.
Either way, it's actually very simple to support this in Zend_Db_Select
(I've already coded it up in an extended class), so I'll submit the
patch upstream for inclusion in a future ZF release anyway.
Cheers
Col
--
Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/
Day Job:
Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
Mandriva Linux Contributor [http://www.mandriva.com/]
PulseAudio Hacker [http://www.pulseaudio.org/]
Trac Hacker [http://trac.edgewall.org/]