sql - 为什么数据库在更新行时执行删除和插入操作?

标签 sql sql-server database oracle

如果我知道错了请指正。当我们命令更新一行时,数据库会执行删除和插入操作。谁能告诉我原因或建议我读一篇文章?

最佳答案

某些数据库将使用删除和插入来实现更新,并且将具有日志结构的文件系统,因此对行的更新会将旧的已删除行保留在其原始位置,并将该行的新副本写入其他位置.

参见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:

  1. Although the original Berkeley DB uses a fairly standard architecture, the Java port, BDB-JE uses all of the components we just described.

  2. 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.

  3. PostgreSQL uses MVCC, and its writeahead logs are structured so as to permit the incremental backup approach we described.

  4. 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/

相关文章:

python - SQL 错误 1054, "Unknown column ' xxxxx' in 'field list' “在带有占位符的 Python 中

c# - SQL Server本地数据库无法插入新表中的数据

php - 如何使用文本文件创建SQL表条目?

mysql - 使用子字符串作为 WHERE 条件的 select 语句

mysql - 查询 : Find customers who have made purchase of every type of flower offered by shop

sql-server - 频繁设置和拆除 SQL Server 复制

sql - 防止重复记录,创建新记录之前进行查询

SQL连接2个有日期差异的表

mysql - 将所有数据库 - 表,存储过程复制到一个文件中并保存在闪存盘上

sql-server - ROW_NUMBER 与 COUNT(1) 个?