如果我知道错了请指正。当我们命令更新一行时,数据库会执行删除和插入操作。谁能告诉我原因或建议我读一篇文章?
最佳答案
某些数据库将使用删除和插入来实现更新,并且将具有日志结构的文件系统,因此对行的更新会将旧的已删除行保留在其原始位置,并将该行的新副本写入其他位置.
参见http://blog.notdot.net/2009/12/Damn-Cool-Algorithms-Log-structured-storage讨论一般用途和数据库的日志结构文件系统。
就哪些系统使用它而言,上面的引用文献提到:
With me singing its praises so loudly, you may be wondering what systems already use this algorithm. There are surprisingly few that I'm aware of, but here's a few notable ones:
Although the original Berkeley DB uses a fairly standard architecture, the Java port, BDB-JE uses all of the components we just described.
CouchDB uses the system just described, except that instead of dividing logs into segments and garbage collecting them, it rewrites its entire database when enough stale data accumulates.
PostgreSQL uses MVCC, and its writeahead logs are structured so as to permit the incremental backup approach we described.
The App Engine datastore is based on Bigtable, which takes a different approach to on-disk storage, but the transactional layer uses optimistic concurrency.
http://blogs.justonedatabase.com/tag/update-in-place/还讨论了使用日志结构附加而不是就地更新的优点。其中提到:
When we append updates rather than overwrite data we are able to keep the old and consistent version of the data while the update is in progress and this affords a robust recovery mechanism should the update fail. We are able to easily watermark the updates and we can choose to move that watermark only when we know that the updates have been completed and successfully persisted in storage. Whereas with update-in-place semantics we would have to write and retain the old version in a separate log before the update took place to be able to guarantee recovery from a failed update (assuming that a full recovery from a database backup copy is a little too rudimentary for most people).
关于sql - 为什么数据库在更新行时执行删除和插入操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24675459/