亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標題: 狀態(tài)為unusable的索引影響DML速度嗎? [打印本頁]

作者: fish617    時間: 2008-07-15 16:38
標題: 狀態(tài)為unusable的索引影響DML速度嗎?
如題
作者: fish617    時間: 2008-07-16 09:51
頂一下
這類一句話問題,大蝦請幫忙解答,謝謝!
作者: fusm    時間: 2008-07-16 10:25
不影響。
作者: blue_stone    時間: 2008-07-16 10:31
just try.
作者: fish617    時間: 2008-07-16 14:10
我這里有3個過程
1.drop n 個索引
2. 向幾張表內插入大量數(shù)據
3.create 1中那幾個索引
如果確定unusable不影響DML速度的話,我想把3個過程優(yōu)化下,改成下面方式.
1.set index為unusable
2.insert大量數(shù)據
3.rebuild索引
因rebuild比create要快,不用排序。
各位大蝦,我的想法可以嗎? 謝謝!
作者: dhhb    時間: 2008-07-16 17:09
記得不可以。unusable以后再insert會報錯.
作者: fish617    時間: 2008-07-16 18:27
設置index為unusable時,要修改參數(shù)skip_unusable_indexes為TRUE,否則用到該索引時會報錯.
作者: imtj    時間: 2008-07-16 22:27
如果確定unusable不影響DML速度的話,我想把3個過程優(yōu)化下,改成下面方式.
1.set index為unusable
2.insert大量數(shù)據
3.rebuild索引
因rebuild比create要快,不用排序。
各位大蝦,我的想法可以嗎? 謝謝!
這個應該更快,因為Rebuild肯定比create快
作者: fish617    時間: 2008-07-17 07:33
謝謝回復!
作者: fusm    時間: 2008-07-17 09:46
不錯的想法,不過rebuild index無論是走index ffs還是full table scan都是需要排序的呀,只不過前者排序量小一點罷了。

[ 本帖最后由 fusm 于 2008-7-17 09:49 編輯 ]
作者: 秋風No.1    時間: 2008-07-17 11:45
原帖由 fish617 于 2008-7-16 18:27 發(fā)表
設置index為unusable時,要修改參數(shù)skip_unusable_indexes為TRUE,否則用到該索引時會報錯.


如果index狀態(tài)為UNUSABLE,insert數(shù)據的時候,會報錯并拒絕,測試如下

show parameter skip

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
skip_unusable_indexes                boolean     TRUE


使index不可用

alter index pk_test unusable


查看index狀態(tài)
select index_name,status,table_name from user_indexes;

INDEX_NAME                     STATUS   TABLE_NAME
------------------------------ -------- ------------------------------
PK_TEST                        UNUSABLE TEST


開始insert
insert into test values(12,'asdf');
insert into test values(12,'asdf')
*
ERROR at line 1:
ORA-01502: index 'PRODUCT.PK_TEST' or partition of such index is in unusable
state


可見如果index狀態(tài)是unusable,insert可能是無法完成的,這種情況在分區(qū)表中比較常見,如果建index的時候,是global index,在維護分區(qū)的時候,可能就會使index 狀態(tài)為unusable

[ 本帖最后由 秋風No.1 于 2008-7-17 11:47 編輯 ]
作者: dhhb    時間: 2008-07-17 13:28
呵呵,老同事所見略同啊
作者: fish617    時間: 2008-07-17 13:55
原來如此,謝謝!原來被爛書給騙了,唉,盡信書不如無書!
作者: fusm    時間: 2008-07-17 14:35
靠,偶也叫書給騙了。
作者: 秋風No.1    時間: 2008-07-17 14:38
原帖由 dhhb 于 2008-7-17 13:28 發(fā)表
呵呵,老同事所見略同啊


作者: imtj    時間: 2008-07-17 17:54
10g中吧index 設置成為unusable可以插入的,9I沒有試過
作者: 秋風No.1    時間: 2008-07-18 00:05
原帖由 imtj 于 2008-7-17 17:54 發(fā)表
10g中吧index 設置成為unusable可以插入的,9I沒有試過

我測試的環(huán)境就是10G,你是用什么方法insert的?給大家共享一下吧
作者: fusm    時間: 2008-07-18 10:57
這個問題有必要仔細研究綜合一下,說不定oracle自己都不明確呢。
作者: imtj    時間: 2008-07-19 14:04
SQL> drop table test_part1;

Table dropped

SQL>
SQL> create table test_part1 (id number(4),hire_date date)
  2  partition by range (id)
  3  (
  4  partition testpart1_1 values less than (100) tablespace part1,
  5  partition testpart1_2 values less than (200) tablespace part2,
  6  partition testpart1_3 values less than (300) tablespace part3,
  7  partition testpart1_4 values less than (maxvalue)
  8  );

Table created

SQL>
SQL> declare
  2  i int;
  3  begin
  4  for i in 1..600 loop
  5  insert into test_part1 values (i,sysdate);
  6  end loop;
  7  end;
  8  /

PL/SQL procedure successfully completed

SQL> create index test_part1_indx on test_part1(id)
  2  /

Index created

SQL> alter index test_part1_indx unusable;

Index altered

SQL>
SQL> declare
  2  i int;
  3  begin
  4  for i in 1..600 loop
  5  insert into test_part1 values (i,sysdate);
  6  end loop;
  7  end;
  8  /

PL/SQL procedure successfully completed

SQL> commit;

Commit complete
作者: 秋風No.1    時間: 2008-07-20 00:37
這個問題看似矛盾,是因為這個索引字段是否未主鍵約束或唯一約束,當對某個字段建主鍵或者唯一約束時,會自動創(chuàng)建一個索引,這樣將該index改為unusable時,約束還是enable狀態(tài),當有數(shù)據插入時,檢查數(shù)據完整性時候,這個約束會去使用這個index,而這個index是unusable狀態(tài),就會報錯。具體測試如下

創(chuàng)建主鍵約束索引,insert失敗
SQL> create table test(id number,name varchar2(10));

Table created.

SQL> alter table test add constraint pk_test primary key(id);

Table altered.

SQL> select index_name,status from user_indexes;

INDEX_NAME                     STATUS
------------------------------ --------
PK_TEST                        VALID

SQL> select index_name,status from user_indexes;

INDEX_NAME                     STATUS
------------------------------ --------
PK_TEST                        VALID

SQL>  insert into test  values (1,'sdfs');

1 row created.

SQL> commit;

Commit complete.

SQL> alter index PK_TEST unusable;

Index altered.

SQL> select index_name,status from user_indexes;

INDEX_NAME                     STATUS
------------------------------ --------
PK_TEST                        UNUSABLE

SQL>  insert into test  values (2,'asdf');
insert into test  values (2,'asdf')
*
ERROR at line 1:
ORA-01502: index 'PRODUCT.PK_TEST' or partition of such index is in unusable state



創(chuàng)建不帶約束的索引,insert成功
SQL> drop table test purge;

Table dropped.

SQL> create table test(id number,name varchar2(10));

Table created.

SQL> create index pk_test on test(id);

Index created.

SQL>  select index_name,status from user_indexes;

INDEX_NAME                     STATUS
------------------------------ --------
PK_TEST                        VALID

SQL>  insert into test  values (2,'asdf');

1 row created.

SQL> alter index PK_TEST unusable;

Index altered.

SQL>  select index_name,status from user_indexes;

INDEX_NAME                     STATUS
------------------------------ --------
PK_TEST                        UNUSABLE

SQL>  insert into test  values (3,'dddffd');

1 row created



創(chuàng)建唯一約束索引,insert失敗,這個時候,可以看一下約束的狀態(tài),是enable
SQL> create table test(id number,name varchar2(10));

Table created.

SQL> alter table test add constraint pk_test unique (id);

Table altered.

SQL> select index_name,status from user_indexes;

INDEX_NAME                     STATUS
------------------------------ --------
PK_TEST                        VALID

SQL> insert into test  values (1,'sdfs');

1 row created.

SQL> commit;

Commit complete.

SQL> alter index PK_TEST unusable;

Index altered.

SQL> select index_name,status from user_indexes;

INDEX_NAME                     STATUS
------------------------------ --------
PK_TEST                        UNUSABLE

SQL> insert into test  values (2,'asdf');
insert into test  values (2,'asdf')
*
ERROR at line 1:
ORA-01502: index 'PRODUCT.PK_TEST' or partition of such index is in unusable
state


select CONSTRAINT_NAME,CONSTRAINT_TYPE,TABLE_NAME,STATUS from  user_constraints;

CONSTRAINT_NAME                C TABLE_NAME                     STATUS
------------------------------ - ------------------------------ --------
PK_TEST                        U TEST                           ENABLED


創(chuàng)建唯一約束索引,insert時,將約束關閉,insert成功

SQL> drop table test purge;

Table dropped.

SQL> create table test(id number,name varchar2(10));

Table created.

SQL> alter table test add constraint pk_test unique (id);

Table altered.

SQL> alter index PK_TEST unusable;

Index altered.

SQL> insert into test  values (2,'asdf');
insert into test  values (2,'asdf')
*
ERROR at line 1:
ORA-01502: index 'PRODUCT.PK_TEST' or partition of such index is in unusable
state


SQL> alter table test disable constraint pk_test;

Table altered.

SQL> insert into test  values (2,'asdf');

1 row created.

SQL> select CONSTRAINT_NAME,CONSTRAINT_TYPE,TABLE_NAME,STATUS from  user_constraints;

CONSTRAINT_NAME                C TABLE_NAME                     STATUS
------------------------------ - ------------------------------ --------
PK_TEST                        U TEST                           DISABLED





歡迎光臨 Chinaunix (http://www.72891.cn/) Powered by Discuz! X3.2