Improve SQL strategy - denormalize in object-children-images case

Posted by fesja on Stack Overflow See other posts from Stack Overflow or by fesja
Published on 2010-04-22T23:52:02Z Indexed on 2010/04/22 23:53 UTC
Read the original article Hit count: 163

Filed under:
|
|

Hi,

I have a Tour object which has many Place objects. For the list of tours, I want to show some info of the tour, the number of places of the tour, and three Place's images. Right one my SQL queries are (i'm using Doctrine with Symfony on MySQL)

get Tour
get Tour 1 places
get Tour 2 places
get Tour 3 places
...
get Tour n places

If I have a three Tour list, it's not so bad; but I'm sure it can get bad if I do a 10-20 tour-list. So, thinking on how to improve the queries I've thought of several measures:

  1. Having a place count cache
  2. Storing the urls of three images on a new tour field.

The problem with 2. is that if I change the image, I have to check all the tours to update that image for another one.

What solution do you think is best to scale the system in a near future? Any other suggestion.

thanks!

© Stack Overflow or respective owner

Related posts about sql

Related posts about scalability