Saturday, March 9, 2019

Unique constraints in the database guard against excessive insertions from the application

I'd been wondering for a while why my app was seeming slower than it used to be. Today I was looking around its database for unrelated reasons when I noticed that one table that was used by every request had ~170,000 rows, the vast majority of which were duplicates. It looks like the application has concurrency issues that sometimes led to it inserting another row inappropriately. The relevant column of the table was missing an index, so the query really hurt performance as the size grew. And as queries took longer, it looks like the concurrency problem was exacerbated, compounding the issue. I purged the extra entries and added a unique constraint. The app is now much faster!

No comments:

Post a Comment