database - RDBMS 如何处理表更新?

标签 database oracle algorithm indexing

假设我有一个表和一个索引

original simple table A
------------------------
rowid  |  id   name
123    |  1    A
124    |  4    G
125    |  2    R
126    |  3    P

index on A.id
-------------
id  rowid
1   123
2   125
3   126
4   124

此时,我执行这条DML语句

UPDATE A SET id = 5 WHERE id = 4

执行这条语句时到底发生了什么?

一)

BEGIN
go to index
search for `id == 4` (B tree index generally)
find that `rowid = 124`
go to that location
update id in the table
come back (? I am not sure)
update the index
END

二)

BEGIN
go to index
search for `id == 4` (B tree index generally)
update the id value in index
find that `rowid = 124`
go to that location
update id in the table
END

c) 其他事情完全发生了

由于这可能取决于数据库本身,它在 Oracle 中是如何发生的?

最佳答案

发件人:http://jonathanlewis.wordpress.com/2006/11/22/tuning-updates/

"If Oracle uses a (B-tree) index to find the data to be updated, it postpones any (B-tree) index updates needed until the end of the update, then sorts the index keys (with their rowids) for the before and after values before applying bulk updates to the indexes"

如果您进行了详细跟踪,等待事件会显示 IO 的文件/ block 详细信息。从那里应该可以确定对象(使用 DBA_EXTENTS)以及访问事物的顺序。

也就是说,它非常学术,不应影响您编写代码的方式。

关于database - RDBMS 如何处理表更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3442268/

相关文章:

java - 如何连接 Android Studio 和 SQL Server 数据库?

php - 从具有每个用户限制的同一个表中获取记录

python - 动画网络图以显示算法的进度

c# - 最小边界四叉树节点

java - 在 SQL 语句中实现动态变量时,是否有比字符串连接更好的方法

用户 'NT AUTHORITY\NETWORK SERVICE' 的 ASP.NET 登录失败

oracle - dbext 无法识别 dbi/oracle 设置的语句终止符

java - 启动 SQL Developer 时出错

sql - Oracle 中的第 N 个最高工资

algorithm - 这是 walking 1 算法的替代方案吗?