This is for the upcoming project. I have two tables - first, the tracks of photos are recorded, and the second tracks the rank of the photo
Photos: +-------+-----------+------------------+ | id | photo | current_rank | +-------+-----------+------------------+ | 1 | apple | 5 | | 2 | orange | 9 | +-------+-----------+------------------+
The rank of a photograph is constantly changing, and this is the table that tracks it:
Ranks: +-------+-----------+----------+-------------+ | id | photo_id | ranks | timestamp | +-------+-----------+----------+-------------+ | 1 | 1 | 8 | * | | 2 | 2 | 2 | * | | 3 | 1 | 3 | * | | 4 | 1 | 7 | * | | 5 | 1 | 5 | * | | 6 | 2 | 9 | * | +-------+-----------+----------+-------------+ * = current timestamp
Each rank is tracked for reporting / analysis purposes. [Change] Users will have access to statistics upon request.
I talked with someone who has experience in this area, and he told me that maintaining ranks like the above is the way to go. But I'm not sure yet.
The problem is data redundancy . There will be tens of thousands of photos. The photo rank changes on an hourly basis (many times over several minutes) for the latest photos, but less often for old photos. In this scenario, the table will have millions of records over several months. And since I do not have experience with large databases, this makes me a little nervous.
I thought about this:
Ranks: +-------+-----------+--------------------+ | id | photo_id | ranks | +-------+-----------+--------------------+ | 1 | 1 | 8:*,3:*,7:*,5:* | | 2 | 2 | 2:*,9:* | +-------+-----------+--------------------+ * = current timestamp
This means that some additional code in PHP shares the rank / time (and sort), but it looks good to me.
Is it right to optimize the table for performance? What would you recommend?
optimization database php mysql
Yeti
source share