r/ProgrammerHumor • • Oct 05 '26

Meme [ Removed by moderator ]

/r/ProgrammerHumor/comments/1wydy0f/removed_by_moderator/

[removed] — view removed post

9.4k Upvotes

558 comments sorted by

View all comments

58

u/PyroCatt Oct 05 '26

If you are deleting records in a DB, you have bad design

27

u/amejin Oct 05 '26

Hmm.. I can't say I agree with you. Can you expand on your position a bit? What about systems that use heavy ephemeral data that can/should be purged regularly? Or data that ages out over time? There are also cases of massive volume and keeping records indefinitely would cause disk bloat...

6

u/joerdie Oct 05 '26

OP is advocating for soft deletes rather than hard ones. And they are right! Sort of. You shouldn't be hard deleting data most of the time. Even if it ages out. Instead, you should mark it deleted and a check for that bool in your selects. You can choose to delete data from time to time. But best practices USUALLY are to not hard delete. But Black and White thinking is USUALLY a bad choice as well. (As OP did.)

2

u/Named_after_color Oct 05 '26

I dunno my systems use a api front for all io with a changelog record and daily backups. Not your usecase, but I imagine having prescribed scripts saved in the backend for common operations might be sufficient.

does your tech stack not support automatic TTL? Maybe chose one with that feature. I dunno what kind of work requires hard database access that doesn't provide some ephemeral database management.

11

u/mynotell Oct 05 '26

" isDeleted = 1"

would be enough. right?

10

u/dotpoint7 Oct 05 '26

GDPR deletion request says hello.
And basically all other applications that are handling enough data to require deletion every few days.

-4

u/AdminClown Oct 05 '26

Proper anonymization says hello.

Are you all just larping here? Let me come up with another "Who is JSON" joke for you guys.

2

u/dotpoint7 Oct 05 '26

Nope, admittedly I have no experience about the first point and may have been wrong, though by my understanding (as a consumer) you do actually have to delete data, not just anonymize it?

The second one is more along the lines of what I'm doing (enterprise software for production planning systems).

3

u/amejin Oct 05 '26

Anonymization is equivalent to deletion when done right, but retains metadata that may be important such as "someone did something" we just don't know who, and their particular experience or actions may still hold informative or real value to the application.

→ More replies (2)

14

u/Sianic12 Oct 05 '26

If you allow users to do it, I agree. But it's totally fine to delete unused records as an admin, if those records are really no longer needed. If you don't clean up the marked-as-deleted records every now and then, your database is gonna bloat unnecessarily.

It goes without saying that this should be handled delicately, and never ever by an AI. Allowing indeterministic processes to alter your database is under no circumstances ever a good idea.

9

u/Weekly-Beginning-229 Oct 05 '26

Or it could be like it is for us where we are not allowed to delete any data within the last 10 years due to audits and stuff. We would love to archive or delete some data from our table with 50 million rows but we aren't allowed.

Thiis table doesn't even have indexes or proper foreign keys. Everything is nvarchar(max) because we don't have enough of a release window to update them (usually half an hour, and I reckon it would take at least 3 hours to add indexes, foreignkeys and max lengths to our 2 largest tables) 🥲

10

u/aetius476 Oct 05 '26

You don't delete data because you might get audited. I do delete data because we might get audited. We are not the same.

1

u/Weekly-Beginning-229 Oct 05 '26

Hahaha good one! Will use that one with the PO

1

u/SuperFLEB Oct 06 '26

The best time to delete the evidence was before you had any idea it was evidence. The second-best time to delete the evidence is today.

6

u/dotpoint7 Oct 05 '26

This does not spark joy.

4

u/Weekly-Beginning-229 Oct 05 '26

It does not! We took over this project and every table in the entire database where nullable, nvarchar (max), no indexes at all. And in the 4 years I've work with it ive finally fixed every table except the two big ones 🥲

But we have a plan to update the database on a Sunday, but bureaucracy has delayed us quite a bit

2

u/ClamPaste Oct 05 '26

It's gonna feel so good when it's done, though.

3

u/amlybon Oct 05 '26

Or it could be like it is for us where we are not allowed to delete any data within the last 10 years due to audits and stuff.

Here complete opposite, certain data HAS TO be deleted within 30 days after it's no longer needed for confidentiality reasons. There's a single table it can be stored in and it can never ever ever be stored in any other table, another db, another system, physically printed out, anything.

1

u/Sianic12 Oct 05 '26

That sounds absolutely atrocious. Do the tables have primary keys at least, or at timestamps? Do you have the storage capacity to create clones of those tables (with proper types, indexes, and FKs), and then copy all the data into them? How long does a simple select even take on tables like that?

1

u/Weekly-Beginning-229 Oct 05 '26

We have Primary keys and a clustered index for created at (not optimal but better than a Guid V4)

We have tried to push on having a table to archive data from those tables. We could have a scheduled task move data older than 30 days. We keep pushing for it because our argument is things will be way faster so hopefully next year we might grt this idea accepted

Well I would say it takes about 15-20 seconds to fetch a few rows of data in DEV so I can't imagine what it's like in PROD. We also fetch other data at the same time, luckily different endpoints. This table basically saves what the users selects as inputs in a dynamic form. So it could be a Label and radio buttons with different options. And every time they select something it gets added to the table. I tested running count on the table and updated after a few seconds and it keeps increasing every time I update

What's even worse is that the code fetching this data is the most legacy part of our code. So it doesn't just fetch the needed data, it fetches everything (with EF core in C# the best way to improve performance is to select the exact columns you need)

But we call this "The last boss of refactoring". One day we will figure out what is actually needed and improve the queries performance!

3

u/VirusLover69 Oct 05 '26

this, you do not want to be cleaning up a database that did not have any unused entries deleted in 25 years.. believe me, i've been there

3

u/_87- Oct 05 '26

I guess we can just disregard GDPR?

1

u/entropic Oct 05 '26

Hard disk drive manufacturers love this one weird trick