日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Oracle表移動后必須做的事

概述

移動一張表實際上是一個重組過程,數(shù)據(jù)庫會將原來的數(shù)據(jù)復(fù)制到新的地方。但是如果你發(fā)現(xiàn)這個表在移動后性能下降了,可能是你的索引沒有重建。本文將指導(dǎo)您找到依賴索引并重建它們。

創(chuàng)新互聯(lián)是一家專業(yè)提供曹縣企業(yè)網(wǎng)站建設(shè),專注與網(wǎng)站設(shè)計制作、成都網(wǎng)站設(shè)計、H5場景定制、小程序制作等業(yè)務(wù)。10年已為曹縣眾多企業(yè)、政府機構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)的建站公司優(yōu)惠進行中。

將表從示例移動到用戶

SQL> select tablespace_name from dba_tables where owner = 'HR' and table_name = 'EMPLOYEES';

TABLESPACE_NAME
------------------------------
EXAMPLE

SQL> alter table hr.employees move tablespace users;

Table altered.

SQL> select tablespace_name from dba_tables where owner = 'HR' and table_name = 'EMPLOYEES';

TABLESPACE_NAME
------------------------------
USERS

查看哪些索引取決于此表

SQL> column index_name format a30;
SQL> column tablespace_name format a30;
SQL> column status format a10;
SQL> select index_name, tablespace_name, status from dba_indexes where owner = 'HR' and table_name = 'EMPLOYEES';

INDEX_NAME TABLESPACE_NAME STATUS
------------------------------ ------------------------------ ----------
EMP_JOB_IX EXAMPLE UNUSABLE
EMP_DEPARTMENT_IX EXAMPLE UNUSABLE
EMP_MANAGER_IX EXAMPLE UNUSABLE
EMP_NAME_IX EXAMPLE UNUSABLE
EMP_EMAIL_UK EXAMPLE UNUSABLE
EMP_EMP_ID_PK EXAMPLE UNUSABLE

6 rows selected.

如您所見,所有依賴索引都是UNUSABLE。這意味著,數(shù)據(jù)庫不會自動重建它們。你必須自己做。

編寫所有重建語句,然后執(zhí)行它們

SQL> select 'alter index ' || owner || '.' ||index_name || ' rebuild tablespace users;' as SQL_TO_BE_EXECUTED from dba_indexes where owner = 'HR' and table_name = 'EMPLOYEES';

SQL_TO_BE_EXECUTED
--------------------------------------------------------------------------------
alter index EMP_JOB_IX rebuild tablespace users;
alter index EMP_DEPARTMENT_IX rebuild tablespace users;
alter index EMP_MANAGER_IX rebuild tablespace users;
alter index EMP_NAME_IX rebuild tablespace users;
alter index EMP_EMAIL_UK rebuild tablespace users;
alter index EMP_EMP_ID_PK rebuild tablespace users;

6 rows selected.

或者您可以重建原始表空間的索引。

SQL> select 'alter index ' || owner || '.' ||index_name || ' rebuild tablespace ' || tablespace_name || ';' as SQL_TO_BE_EXECUTED from dba_indexes where owner = 'HR' and table_name = 'EMPLOYEES';

SQL_TO_BE_EXECUTED
--------------------------------------------------------------------------------
alter index HR.EMP_DEPARTMENT_IX rebuild tablespace EXAMPLE;
alter index HR.EMP_NAME_IX rebuild tablespace EXAMPLE;
alter index HR.EMP_MANAGER_IX rebuild tablespace EXAMPLE;
alter index HR.EMP_EMP_ID_PK rebuild tablespace EXAMPLE;
alter index HR.EMP_EMAIL_UK rebuild tablespace EXAMPLE;
alter index HR.EMP_JOB_IX rebuild tablespace EXAMPLE;

6 rows selected.

請注意,我們在新表空間USERS中重建索引。也就是說,對于索引,REBUILD相當于表中的MOVE

重建后檢查狀態(tài)

SQL> select index_name, tablespace_name, status from dba_indexes where owner = 'HR' and table_name = 'EMPLOYEES';

INDEX_NAME TABLESPACE_NAME STATUS
------------------------------ ------------------------------ ----------
EMP_JOB_IX USERS VALID
EMP_DEPARTMENT_IX USERS VALID
EMP_MANAGER_IX USERS VALID
EMP_NAME_IX USERS VALID
EMP_EMAIL_UK USERS VALID
EMP_EMP_ID_PK USERS VALID

6 rows selected.

所有索引都變?yōu)閂ALID,表明所重建的索引有效。


分享文章:Oracle表移動后必須做的事
本文網(wǎng)址:http://www.dlmjj.cn/article/djhisce.html