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

Martin Kutschker masi-no at spam-typo3.org
Fri Jul 18 12:54:04 CEST 2008


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




More information about the TYPO3-dev mailing list