warehouse icon indicating copy to clipboard operation
warehouse copied to clipboard

Release Descriptions contains orphaned records

Open miketheman opened this issue 2 years ago • 2 comments

Something about our Release Descriptions tables is causing orphaned records.

This was discovered in #14788 when fixing the backref to back_populates relationship flags.

This SQL query will expose the orphaned records.

select count(d.id) from release_descriptions d
left join releases r on d.id = r.description_id
where r.description_id is null;

As of this writing, the count is 621643, and had increased by two in ~4 minutes. I had thought that the changes over there would prevent records from being orphaned, so something is still causing these records to not be removed.

Since the Descriptions model doesn't maintain a foreign key to it's parent Release, rather the parent Release retains a reference to the current Description, it's not super simple to back-trace these records. We can probably use the raw text column to find similar records, but that's no guarantee since many Releases use a pretty similar Description, but it's one idea.

miketheman avatar Oct 30 '23 13:10 miketheman

The count today is 666275. There's been changes to the db models since this was observed.

If the number remains stable, then we can entertain a simple DELETE for these records. Otherwise we need to find out how release_description rows are being orphaned.

miketheman avatar Jul 31 '24 16:07 miketheman

Looks like it's still in flux:

warehouse=> select count(d.id) from release_descriptions d
left join releases r on d.id = r.description_id
where r.description_id is null;
 count
--------
 666374
(1 row)

di avatar Aug 01 '24 19:08 di