假设我有一个表和一个索引
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/