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

Steffen Kamper steffen at sk-typo3.de
Fri Jul 18 14:13:43 CEST 2008


Martin Kutschker schrieb:
> Steffen Kamper schrieb:
>> Ingo Renner schrieb:
>>> Martin Kutschker wrote:
>>>
>>>> Anyway it's better to use this:
>>>>
>>>> $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('COUNT(*)', 'tx_table');
>>> $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('COUNT(uid)', 'tx_table');
>>>
>>> ;)
>>>
>>>
>> i tested this and it makes no difference
>> COUNT(*) or COUNT(field) is internally the same
> 
> Internally - where? Of course it makes no difference on the client side.
> 
> I'm not sure if it makes a difference for the server as COUNT(*) has -
> to me - the meaning "just count the rows". So I don't think that Mysql
> will try to do anything with the whole record and is optimized to
> retrieve the row count (probably using the primary key).
> 
> Masi

some time ago i did some benchmark. I wanted to figure out if a COUNT() 
could be optimized by calling a field COUNT(field)

It seems that MySQL makes no difference, the COUNT always counts rows.
How this is realized internally (and that means the MySQL-engine) i 
don't know, but i think it uses only the indizes.

vg Steffen




More information about the TYPO3-dev mailing list