3

Possible Duplicate:
Storing vs calculating aggregate values

Say I have a table full of photos that each have an albumId that is a foreign key to an album table. To get the amount of photos in each album, I could simply do a Count() on the photo table where the albumId = the id from the album table. However, to accomplish this same task, I could keep a photoCount column in the album table. Is it worth keeping that extra column in the album table instead of using the Count() function?

joshholat
  • 131
  • 1

2 Answers2

1

You can also consider materialized views (not all RDMS support this feature though)

a1ex07
  • 9,060
  • 3
  • 27
  • 41
0

It depends on your application. If you use the number of your photos a lot, its better to keep the count so you don't have to run a query every time. But another things is if you add new photos with a high frequency, by storing the number of photos, you will have to update it every time.

AliBZ
  • 1,827
  • 5
  • 17
  • 27