(12R1)
--データ準備
set time on
set timing on
drop table tab1 purge;
create table tab1(col1 int,col2 int,col3 int);
alter table tab1 add constraint tab1p primary key (col1);
declare
begin
for i in 1..1000000 loop
insert into tab1 values(i,i,i);
commit;
end loop;
end;
/
--1.インデックス使用カラム更新中のインデックス作成
--session1から実行
update tab1 set col2 = col2+1;
--session2から実行
create index ind2 on tab1(col2);
→ORA-00054: リソース・ビジー。NOWAITが指定されているか、タイムアウトしました
create index ind2 on tab1(col2) online;
→commitされるまで待ちになる
--2.インデックス使用外カラム更新中のインデックス作成
--session1から実行
update tab1 set col2 = col2+1;
--session2から実行
create index ind3 on tab1(col3);
→ORA-00054: リソース・ビジー。NOWAITが指定されているか、タイムアウトしました
create index ind3 on tab1(col3) online;
→commitされるまで待ちになる
--3.インデックス使用カラム更新中のインデックスリビルド
--session1から実行
update tab1 set col2 = col2+1;
--session2から実行
alter index ind2 rebuild;
→ORA-00054: リソース・ビジー。NOWAITが指定されているか、タイムアウトしました
alter index ind2 rebuild online;
→commitされるまで待ちになる
--4.インデックス使用外カラム更新中のインデックスリビルド
--session1から実行
update tab1 set col2 = col2+1;
--session2から実行
alter index ind3 rebuild;
→ORA-00054: リソース・ビジー。NOWAITが指定されているか、タイムアウトしました
alter index ind3 rebuild online;
→commitされるまで待ちになる
----------------------------------------------------
--データ準備
set time on
set timing on
drop table tab1 purge;
create table tab1(col1 int,col2 int,col3 int);
alter table tab1 add constraint tab1p primary key (col1);
declare
begin
for i in 1..10000000 loop
insert into tab1 values(i,i,i);
commit;
end loop;
end;
/
--5.インデックス作成中のインデックス使用カラム更新
--session1から実行
create index ind2 on tab1(col2);
create index ind2 on tab1(col2) online;
--session2から実行
update tab1 set col2 = col2+1 where col1 = floor(dbms_random.value(1, 10000001));
→待ちになる
※インデックス作成時にonlineオプションを付与すると待ちにならない
--6.インデックス作成中のインデックス使用外カラム更新
--session1から実行
create index ind3 on tab1(col3);
create index ind3 on tab1(col3) online;
--session2から実行
update tab1 set col2 = col2+1 where col1 = floor(dbms_random.value(1, 10000001));
→待ちになる
※インデックス作成時にonlineオプションを付与すると待ちにならない
--7.インデックスリビルド中のインデックス使用カラム更新
--session1から実行
alter index ind2 rebuild;
alter index ind2 rebuild online;
--session2から実行
update tab1 set col2 = col2+1 where col1 = floor(dbms_random.value(1, 10000001));
→待ちになる
※インデックスリビルド時にonlineオプションを付与すると待ちにならない
--8.インデックスリビルド中のインデックス使用外カラム更新
--session1から実行
alter index ind3 rebuild;
alter index ind3 rebuild online;
--session2から実行
update tab1 set col2 = col2+1 where col1 = floor(dbms_random.value(1, 10000001));
→待ちになる
※インデックスリビルド時にonlineオプションを付与すると待ちにならない
(5.6)
--データ準備
drop table tab1;
create table tab1(col1 int,col2 int,col3 int);
alter table tab1 add constraint tab1p primary key(col1);
drop procedure proc1;
delimiter //
create procedure proc1()
begin
declare i int;
set i = 1;
while i <= 1000000 do
insert into tab1 values(i,i,i);
set i = i + 1;
end while;
end
//
delimiter ;
call proc1();
--1.インデックス使用カラム更新中のインデックス作成
--session1から実行
start transaction;
update tab1 set col2 = col2+1;
--session2から実行
create index ind2 on tab1(col2);
→commitされるまで待ちになる
--2.インデックス使用外カラム更新中のインデックス作成
--session1から実行
start transaction;
update tab1 set col2 = col2+1;
--session2から実行
create index ind3 on tab1(col3);
→commitされるまで待ちになる
--3.インデックス使用カラム更新中のインデックスリビルド
--session1から実行
start transaction;
update tab1 set col2 = col2+1;
--session2から実行
alter table tab1 engine innodb;
→commitされるまで待ちになる
----------------------------------------------------
--データ準備
drop table tab1;
create table tab1(col1 int,col2 int,col3 int);
alter table tab1 add constraint tab1p primary key(col1);
drop procedure proc1;
delimiter //
create procedure proc1()
begin
declare i int;
set i = 1;
while i <= 10000000 do
insert into tab1 values(i,i,i);
set i = i + 1;
end while;
end
//
delimiter ;
call proc1();
--5.インデックス作成中のインデックス使用カラム更新
--session1から実行
create index ind2 on tab1(col2);
--session2から実行
start transaction;
update tab1 set col2 = col2+1 where col1 = floor(rand() * 10000000)+1;
→待ちにならない
--6.インデックス作成中のインデックス使用外カラム更新
--session1から実行
create index ind3 on tab1(col3);
--session2から実行
start transaction;
update tab1 set col2 = col2+1 where col1 = floor(rand() * 10000000)+1;
→待ちにならない
--7.インデックスリビルド中のインデックス使用カラム更新
--session1から実行
alter table tab1 engine innodb;
--session2から実行
start transaction;
update tab1 set col2 = col2+1 where col1 = floor(rand() * 10000000)+1;
→待ちにならない
(9.4)
--データ準備
\timing
drop table tab1;
create table tab1(col1 int,col2 int,col3 int);
create unique index ind1 on tab1(col1);
alter table tab1 add constraint tab1p primary key using index ind1;
insert into tab1 select generate_series(1,1000000),generate_series(1,1000000),generate_series(1,1000000);
--1.インデックス使用カラム更新中のインデックス作成
--session1から実行
start transaction;
update tab1 set col2 = col2+1;
--session2から実行
create index ind2 on tab1(col2);
→commitされるまで待ちになる
create index concurrently ind2 on tab1(col2);
→commitされるまで待ちになる
--2.インデックス使用外カラム更新中のインデックス作成
--session1から実行
start transaction;
update tab1 set col2 = col2+1;
--session2から実行
create index ind3 on tab1(col3);
→commitされるまで待ちになる
create index concurrently ind3 on tab1(col3);
→commitされるまで待ちになる
--3.インデックス使用カラム更新中のインデックスリビルド
--session1から実行
start transaction;
update tab1 set col2 = col2+1;
--session2から実行
time /usr/pgsql-9.4/bin/pg_repack -d test -i ind2
→commitされるまで待ちになる
--4.インデックス使用外カラム更新中のインデックスリビルド
--session1から実行
start transaction;
update tab1 set col2 = col2+1;
--session2から実行
time /usr/pgsql-9.4/bin/pg_repack -d test -i ind3
→commitされるまで待ちになる
----------------------------------------------------
--データ準備
\timing
drop table tab1;
create table tab1(col1 int,col2 int,col3 int);
create unique index ind1 on tab1(col1);
alter table tab1 add constraint tab1p primary key using index ind1;
insert into tab1 select generate_series(1,10000000),generate_series(1,10000000),generate_series(1,10000000);
--5.インデックス作成中のインデックス使用カラム更新
--session1から実行
create index ind2 on tab1(col2);
create index concurrently ind2 on tab1(col2);
--session2から実行
start transaction;
update tab1 set col2 = col2+1 where col1 = floor(random() * 10000000)+1;
→待ちになる
※インデックス作成時にCONCURRENTLYオプションを付与するとインデックス作成を待たなくなる
--6.インデックス作成中のインデックス使用外カラム更新
--session1から実行
create index ind3 on tab1(col3);
create index concurrently ind3 on tab1(col3);
--session2から実行
start transaction;
update tab1 set col2 = col2+1 where col1 = floor(random() * 10000000)+1;
→待ちになる
※インデックス作成時にCONCURRENTLYオプションを付与するとインデックス作成を待たなくなる
--7.インデックスリビルド中のインデックス使用カラム更新
--session1から実行
time /usr/pgsql-9.4/bin/pg_repack -d test -i ind2
--session2から実行
start transaction;
update tab1 set col2 = col2+1 where col1 = floor(random() * 10000000)+1;
→待ちにならない
--8.インデックスリビルド中のインデックス使用外カラム更新
--session1から実行
time /usr/pgsql-9.4/bin/pg_repack -d test -i ind3
--session2から実行
start transaction;
update tab1 set col2 = col2+1 where col1 = floor(random() * 10000000)+1;
→待ちにならない
(2014)
SET STATISTICS TIME ON
--データ準備
drop table tab1;
create table tab1(col1 int not null,col2 int,col3 int);
alter table tab1 add constraint tab1p primary key(col1);
DECLARE @i integer;
SET @i = 1;
WHILE @i <= 10000000
BEGIN
insert into tab1 values(@i,@i,@i);
SET @i = @i + 1;
END
--1.インデックス使用カラム更新中のインデックス作成
--session1から実行
begin transaction;
update tab1 set col2 = col2+1;
--session2から実行
create index ind2 on tab1(col2);
→commitされるまで待ちになる
create index ind2 on tab1(col2) with ( online = on );
→commitされるまで待ちになる
--2.インデックス使用外カラム更新中のインデックス作成
--session1から実行
begin transaction;
update tab1 set col2 = col2+1;
--session2から実行
create index ind3 on tab1(col3);
→commitされるまで待ちになる
create index ind3 on tab1(col3) with ( online = on );
→commitされるまで待ちになる
--3.インデックス使用カラム更新中のインデックスリビルド
--session1から実行
begin transaction;
update tab1 set col2 = col2+1 where col1 = floor(rand() * 10000000)+1;
--session2から実行
alter index ind2 on tab1 rebuild;
→commitされるまで待ちになる
alter index ind2 on tab1 rebuild with ( online = on );
→commitされるまで待ちになる
--4.インデックス使用外カラム更新中のインデックスリビルド
--session1から実行
begin transaction;
update tab1 set col2 = col2+1 where col1 = floor(rand() * 10000000)+1;
--session2から実行
alter index ind3 on tab1 rebuild;
→commitされるまで待ちになる
alter index ind3 on tab1 rebuild with ( online = on );
→commitされるまで待ちになる
----------------------------------------------------
--5.インデックス作成中のインデックス使用カラム更新
--session1から実行
create index ind2 on tab1(col2);
create index ind2 on tab1(col2) with ( online = on );
--session2から実行
begin transaction;
update tab1 set col2 = col2+1 where col1 = floor(rand() * 10000000)+1;
→待ちになる
※インデックス作成時にwith( online = on )オプションを付与すると待ちにならない
--6.インデックス作成中のインデックス使用外カラム更新
--session1から実行
create index ind3 on tab1(col3);
create index ind3 on tab1(col3) with ( online = on );
--session2から実行
begin transaction;
update tab1 set col2 = col2+1 where col1 = floor(rand() * 10000000)+1;
→待ちになる
※インデックス作成時にwith( online = on )オプションを付与すると待ちにならない
--7.インデックスリビルド中のインデックス使用カラム更新
--session1から実行
alter index ind2 on tab1 rebuild;
alter index ind2 on tab1 rebuild with ( online = on );
--session2から実行
begin transaction;
update tab1 set col2 = col2+1 where col1 = floor(rand() * 10000000)+1;
→待ちになる
※インデックスリビルド時にwith( online = on )オプションを付与すると待ちにならない
--8.インデックスリビルド中のインデックス使用外カラム更新
--session1から実行
alter index ind3 on tab1 rebuild;
alter index ind3 on tab1 rebuild with ( online = on );
--session2から実行
begin transaction;
update tab1 set col2 = col2+1 where col1 = floor(rand() * 10000000)+1;
→待ちになる
※インデックスリビルド時にwith( online = on )オプションを付与すると待ちにならない