加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

database – 如何通过RDBMS处理表UPDATE?

发布时间:2020-12-12 13:14:21 所属栏目:百科 来源:网络整理
导读:假设我有一个表和一个索引 original simple table A------------------------rowid | id name123 | 1 A124 | 4 G125 | 2 R126 | 3 Pindex on A.id-------------id rowid1 1232 1253 1264 124 此时,我执行此DML语句 UPDATE A SET id = 5 WHERE id = 4 执行此
假设我有一个表和一个索引

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

b)

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的文件/块详细信息.从那里应该可以确定对象(使用DBA_EXTENTS)以及访问事物的顺序.

也就是说,这是相当学术性的,不应该影响你编码的方式.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读