[TYPO3-dev] Tip: use SQL function COUNT(*)

ries van Twisk typo3 at rvt.dds.nl
Fri Jul 18 19:09:09 CEST 2008


On Jul 18, 2008, at 10:57 AM, Ernesto Baschny [cron IT] wrote:

> ries van Twisk wrote: on 18.07.2008 16:35:
>>
>> On Jul 18, 2008, at 9:14 AM, Martin Kutschker wrote:
>> <snip>........
>>
>
> I don't think that mysql_num_rows will be processed "client side". The
> data sets won't even be retrieved if you just do a select followed by
> mysql_num_rows. It is probably more expensive than count(*), but I
> cannot imagine that it is *that* much faster.
>
> I recall that mysql has a shortcut in the special case "COUNT(*) FROM
> <table>" (without a "WHERE"), because it will consult the MYD headers
> for the amount of rows and not even load indexes to do the dirty work.
> So this is of course the easiest to do.
>
> But as in TYPO3 almost on all queries you will have to include
> enableFields, I figure that MySQL will have to touch indexes anyway so
> it shouldn't matter that much.
>
> Cheers,
> Ernesto
> _______________________________________________

Hey Ernesto,

 From reading the docs about mysql_num_rows : "Retrieves the number of  
rows from a result set."

That means that the result set was already transfered to PHP's API   
and there you lose performance because
of the data treansfer. You would properly really notice it with one  
query and a small table.
But one a buzy database with large record sets it can consume a lot of  
time.


Ries







More information about the TYPO3-dev mailing list