create index時對錶加的什麼鎖

2021-04-12 16:20:13 字數 4213 閱讀 8634

sql> create index idx_1 on a02 (owner, object_name, subobject_name);

index created

sql> select sid from v$mystat where rownum<2;

sid----------

16select rpad(oracle_username, 10) o_name,

session_id sid,

decode(locked_mode,

0,'none',

1,'null',

2,'row share',

3,'row exclusive',

4,'share',

5,'share row exclusive',

6,'exclusive') lock_type,

object_name,

xidusn,

xidslot,

xidsqn

from v$locked_object, all_objects

where v$locked_object.object_id = all_objects.object_id;

o_name sid lock_type object_name xidusn xidslot xidsqn

test 16 share a02 7 30 84

test 16 row exclusive obj$ 7 30 84

select sid,

type,

id1,

id2,

decode(lmode,

0,'none',

1,'null',

2,'row share',

3,'row exclusive',

4,'share',

5,'share row exclusive',

6,'exclusive') lock_type,

request,

ctime,

block

from v$lock

where type in ('tx', 'tm');

sid type id1 id2 lock_type request ctime block

16 tx 458782 84 exclusive 0 6 0

16 tm 18 0 row exclusive 0 6 0

16 tm 6319 0 share 0 6 0

select owner,object_name,object_id from all_objects where object_id in (18,6319)

test a02 6319

sys obj$ 18

可見在create index時會在a02表上加tm為share的鎖,在sys.obj$上加tm為row exclusive的鎖,tx為exclusive的鎖。

如果在create index時a02上有dml,會首先在a02上加tm為row exclusive的鎖,其與存在在a02上的tm為share的鎖不相容,所以會發生等待。

insert into a02 select * from a02 where rownum<2(sid=15)

select rpad(oracle_username, 10) o_name,

session_id sid,

decode(locked_mode,

0,'none',

1,'null',

2,'row share',

3,'row exclusive',

4,'share',

5,'share row exclusive',

6,'exclusive') lock_type,

object_name,

xidusn,

xidslot,

xidsqn

from v$locked_object, all_objects

where v$locked_object.object_id = all_objects.object_id;

o_name sid lock_type object_name xidusn xidslot xidsqn

test 15 none a02 0 0 0

test 16 share a02 7 30 84

test 16 row exclusive obj$ 7 30 84

select sid,

type,

id1,

id2,

decode(lmode,

0,'none',

1,'null',

2,'row share',

3,'row exclusive',

4,'share',

5,'share row exclusive',

6,'exclusive') lock_type,

request,

ctime,

block

from v$lock

where type in ('tx', 'tm');

sid type id1 id2 lock_type request ctime block

15 tm 6319 0 none 3 4 0

16 tx 458782 84 exclusive 0 6 0

16 tm 18 0 row exclusive 0 6 0

16 tm 6319 0 share 0 6 1

同樣,如果table上有dml操作,這時進行create index,會報錯ora-00054: resource busy and acquire with nowait specified。

因為dml會在a02上加tm為row exclusive的鎖,會阻塞create index時對a02加tm為share的鎖。

那為什麼create index online不會阻塞dml呢?

sql> drop index idx_1;

index dropped

sql> create index idx_1 on a02 (owner, object_name, subobject_name) online;

select rpad(oracle_username, 10) o_name,

session_id sid,

decode(locked_mode,

0,'none',

1,'null',

2,'row share',

3,'row exclusive',

4,'share',

5,'share row exclusive',

6,'exclusive') lock_type,

object_name,

xidusn,

xidslot,

xidsqn

from v$locked_object, all_objects

where v$locked_object.object_id = all_objects.object_id;

test 16 row share a02 1 23 89

test 16 share sys_journal_6391 1 23 89

select sid,

type,

id1,

id2,

decode(lmode,

0,'none',

1,'null',

2,'row share',

3,'row exclusive',

4,'share',

5,'share row exclusive',

6,'exclusive') lock_type,

request,

ctime,

block

from v$lock

where type in ('tx', 'tm');

16 tx 65559 89 exclusive 0 4 0

16 tm 6392 0 share 0 4 0

16 tm 6319 0 row share 0 4 0

可見在create index online時對a02加的是tm為row share的鎖,其與row exclusive是相容的。同時對sys.obj$的鎖消失。會產生乙個sys_journal_6391的表,用於create index online時dml操作產生的索引維護。

solr 搜尋時加空格沒有結果

使用solr搜尋時候常會出現以下問題,比如搜尋 茶油 可以搜尋到結果,但是 茶和油之間加個空格就沒有結果了 首先你要了解產生這個原因的原理。schema.xml name solrconfig.xml name select class solr.searchhandler name default...

寫DLL 時,加與不加 Extern C 區別

翻閱筆記系列 加與不加的區別,我們可以過depends工具來檢視 extern c方式匯出的函式,在 dll 中函式名就是我們定義的名字 在c 中,不使用exern c方式匯出,在 dll 中函式名字已經不是我們定義時的名字了。新增了一些特殊符號。如果不注意這點,有時會dll 呼叫失敗還不明其原因。...

mysql查詢時加不加引號的問題

一 如果字段本身是int型別,如果查詢條件中加了引號,比如select from user where id 4 這時候可以查出id 4的使用者資訊,但是使用select from user where id 4abc 同樣可以查出這條資訊。網上說是mysql進行了隱式處理,後面的字元變成了0和前面...