My application writes to a table core; this name is immutable. It’s gotten very large (millions of rows) and so its size make INSERTs into it slower than they need be. My solution is to only hold one week’s worth of data in core. So I’ve constructed a table core_archive to put everything older than one week into at scheduled intervals.
At schedule intervals a script gets all the new values in core, operates on them and puts them into a third table core_details. The schema is such that core_details has a foreign key constraint to the PK in core.
My problem is that because of this foreign key constraint (between core_detail and core), I cannot delete any rows from core. So what should I do?
Options:
- Do an ALTER TABLE to point the old foreign key constraints at
core_archive. This really shouldn’t and maybe can’t be done safely on a large production database, though. - ? [I have no other viable ideas…any thoughts StackO?]
You’ll have to create a
core_details_archivetable as well and archive the rows ofcore_archivethat point to rows ofcorethat are scheduled to be archived. Depending on your data structure, this approach may need to be extended to any number of tables.