I have a SQL table called "EVENT" and a copy table called "PAST_EVENT". The EVENT table has a foreign key to it's corresponding PAST_EVENT. Given that:
- Any update made to the EVENT table is also made to the PAST_EVENT table. They are "duplicates".
- The EVENT table is written and read to extremely frequently.
- The PAST_EVENT table is read to extremely frequently.
- When an event in the EVENT table ends, it is deleted from the EVENT table. Thus every event created will eventually only exist in the PAST_EVENT table.
I decided to have a duplicate of information in the EVENT table in the PAST_EVENT table because my application is looking for data about current and ongoing events (only needing to read from the EVENT table), OR it is looking for events that have ended (only needing to read from the PAST_EVENT table). But never both. My rationale is that making SQL queries on a subset of events is quicker than the alternative.
Alternative:
What if instead, I consolidate both tables into one table called EVENT. I would then add a database indexed boolean field, "hasEnded", in order to query for ongoing or ended events.
Which of the aforementioned strategies is more performant?
More Info (update):
- Many EVENTs are created each day. Simultaneously, many EVENT rows are being pruned daily because they have ended. Events get deleted from the EVENT table by a chron job that runs every 12 hours and prunes events that have ended.
- One EVENT row does not spawn many PAST_EVENTs. Just one (which will be maintained an exact replica of the present state of its corresponding EVENT row).
- The primary keys are auto-inc. In addition, when an EVENT is created, a PAST_EVENT is created with the same primary key id for my personal satisfaction.