Live data from Hacker News

DELETEs Are Difficult

notso.boringsql.com

81–90 of 121 posts

Re: DELETEs Are Difficult

#81
post #66

Earlier quoted context omitted.

I have long day-dreamed of what a “use it (soon) or loose it” runtime would mean. Allocated blocks would just expire after a set time.

So kind of like browsers work now with the tab unloading and Android killing apps? Personally I find it really obnoxious and disruptive.

You would prefer something a little more persistent?

Re: DELETEs Are Difficult

#82
post #10

DELETE FROM films; I'm surprised databases makes it so easy to just delete an entire table. I think the command should be DELETE FROM films YES-I-KNOW-WHAT-I-AM-DOING;

MySQL has this as default as far as I recall. But then I never delete, I just set "deleted" to yes.

You're probably thinking of the --safe-updates option [1] for the `mysql` CLI, also available as the memorable alias --i-am-a-dummy. This requires UPDATE and DELETE to have either a WHERE clause or a LIMIT clause. Under the hood, the command-line client option just manipulates the sql_safe_updates session variable [2] to enforce the UPDATE and DELETE requirement, as well as a couple other unrelated variables to prevent overly-huge SELECTs.

It's not enabled by default out of the box, but some companies do override their configuration to enable it for new sessions, iirc Facebook did this.

[1] https://dev.mysql.com/doc/refman/8.4/en/mysql-tips.html#safe...

[2] https://dev.mysql.com/doc/refman/8.4/en/server-system-variab...

Re: DELETEs Are Difficult

#83
post #44
post #23

Earlier quoted context omitted.

I think garbage collection memory management can be thought of a delete optimized database.

Runtimes with garbage collectors typically optimize for allocation, not deletion.

Generational GC optimizes for both. They assume that most objects die young, so choose to relocate live objects and just mark the entire region that was evacuated as empty. So this is a very efficient way to delete data.

Re: DELETEs Are Difficult

#84

DELETE is expensive at a deep fundamental level that we don’t think about much in computer science because we are more worried about losing data. The article is about Postgres but it generalizes. We don’t actually have any computer science for DELETE optimized databases. I’ve idly looked into delete-optimization in databases as thought experiments, since there isn’t much in the way of literature on it, and it is far…

What about LSM trees? Something like RocksDB is very efficient at deleting. A delete operation is a tiny write (a tombstone) and then the actual deletion is done via compaction in the background with entire tablets being freed at once when the live data is evacuated. It's actually most efficient when deleting large ranges - when just replacing data it's not so efficient due to the write amplification.

That said, I agree with you in general. An under-used technique is to simply encrypt everything and then use a key store that is guaranteed capable of deleting data. This makes it easy to comply with legal deletion requests even across backups, though of course, you need to manage the keys very carefully and ensure that they are also backed up.

Re: DELETEs Are Difficult

#85

DELETE is expensive at a deep fundamental level that we don’t think about much in computer science because we are more worried about losing data. The article is about Postgres but it generalizes. We don’t actually have any computer science for DELETE optimized databases. I’ve idly looked into delete-optimization in databases as thought experiments, since there isn’t much in the way of literature on it, and it is far…

It's absolutely true that we don't think about it much. When I was first taught balanced binary trees, deletion wasn't even a topic that needed to be learned. Same thing later when I was taught balanced binary trees. Then again in hash tables. It's an operation that's overlooked in CS education.

Re: DELETEs Are Difficult

#86
post #81
post #66

Earlier quoted context omitted.

So kind of like browsers work now with the tab unloading and Android killing apps? Personally I find it really obnoxious and disruptive.

You would prefer something a little more persistent?

I would prefer a 48 hour day, so that I could get everything done that needs to be done.

Or maybe a 72 hour day, so I'd have time for things that I'd just enjoy.

Re: DELETEs Are Difficult

#87
post #43

Earlier quoted context omitted.

I think that gp’s comment can be reinterpreted as: why should this landmine exist when databases could notify a reader of its manual about this issue in an explicit way, for example: DELETE FROM t WHERE … BATCH 100 Which would simulate batched queries when called outside of transaction. This would remove the need of a client to be connected (or at least active) for a duration of this lenghty operation. If DELETE is s…

Rather than batching, I would want a "NO ROLLBACK DELETE" sort of command. The real expensive part of the delete is rewriting the records into the transaction log so that a cancel or crash can undo the delete. If you've gone to the effort of batching things, you are still writing out those records, you are just giving the db a chance to delete them from the log. I'd like to save my ssds that heartache and instead all…

Yes the commercial databases make it easier to handle this.

One simple way in Oracle is to take a table lock, copy the data you want to preserve out to a temporary table, truncate the target table, copy the data back in.

Re: DELETEs Are Difficult

#88
post #30

> For example, deleting 1 million rows in a single transaction is a textbook case of what not to do. Instead, splitting the operation into smaller batches, such as deleting 10,000 rows across 100 iterations, is far more effective. Why do I as a user have to do that? Why can't the database implement batching internally and automatically transform my 1-million-rows query into an appropriate list of batched queries? (Ed…

Admin panels may do that. Say for example deleting a bucket with a million rows. In that case I'd fire off a job and tell the user, yeah sure the delete is successful. But check the logs to be sure.

I show these as pending.

No message (other than an INFO log message) when the operation completes successfully, but failures are handled and notified properly.

Re: DELETEs Are Difficult

#89

One solution for performance degradation with soft deletes is to partition the table by some field like `created` monthly. Queries will need to include `created` in the query is the main downside.

I've only heard of this trick being employed on OLAP scenarios. Is this kind of partitioning also advisable for OLTP workloads?

Re: DELETEs Are Difficult

#90

If data isn’t actually removed until vacuuming, then are systems that perform SQL DELETES actually GDPR compliant? Because technically the private data is still there on disk and could be recovered. “Until the autovacuum process or a manual VACUUM operation reclaims the space, the “deleted” data remains.”

Even vacuuming wouldn't actually destroy the data right? Because filesystems don't guarantee they will overwrite or wipe any particular disk blocks. And even if they did, SSDs still wouldn't promise that the blocks aren't remapped instead of being wiped & reused.

> Because filesystems don't guarantee they will overwrite or wipe any particular disk blocks.

Some filesystems have a richer interface to the underlying storage device, allowing them to invoke commands such as ATA TRIM or SCSI UNMAP - either incrementally as blocks are freed, or on demand - which request that the underlying storage device forget the block contents.

So the necessary interfaces exist and are widely available, and even if imperfect they improve the situation.

Post reply on HN