r/programminghorror • • Feb 23 '26

SQL DB with 2241 tables

Post image

I can't even fathom what led someone to do this. I got this database to refactor as part of my job. Basically, every client has their own table named "Client_[their ID]," which contains only one row with all the client data in JSON format (wtf).
If the website using this database wants to filter out some users, it queries all the tables, resulting in a load of 2,000+ SQL queries for a single search.
On top of that, for some reason, the date of birth is stored as the number of days since birth, with a CRON script that updates this in each table every day at 3 AM.
I don't even have to mention that none of the data follows the rules of database normalization...
I honestly don't know where to start with fixing this mess.

1.5k Upvotes

134 comments sorted by

View all comments

Show parent comment

1

u/DeGandalf Feb 27 '26

because they added a table containing a summary of all users added in the past three years. The backend first checks this summary table, and if it doesn't find what it’s looking for, it starts scanning through all the individual tables

in case there is actually that much data that you also need something like this in the end take a look at what a bloom filter is. It's basically a data structure exactly for this usecase.

Edit: just realized you actually mean that there is actual data in that table, too, wtf