Re: counting rows

From: Volker Hetzer <>
Date: Fri, 31 Mar 2006 13:13:52 +0200
Message-ID: <e0j2tg$eoe$> schrieb:
> Consider the tables USERS and PICTURES. When retrieving the number of
> pictures from a user there are two ways:
> 1) I count them from pictures table.
> 2) I pick it directly from a field "numPictures" in table users.
> How are you used to do this? Which is better?
 From a software maintenance view, 1) is better. It's way more difficult to maintain the correct count than to simply put an index on the picture table and count.

If users have more than let's say ten thousand pictures, you got to use your particular database's special abilities like materialized views and so on. At that time, doing a very careful trigger implementation might become a serious contender too, depending on how poor your database is at real applications.

Lots of Greetings!
Volker Received on Fri Mar 31 2006 - 13:13:52 CEST

Original text of this message