自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Oracle 表移動(dòng)后必須做的事

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

概述

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

將表從示例移動(dòng)到用戶

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.

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

編寫所有重建語(yǔ)句,然后執(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.

請(qǐng)注意,我們?cè)谛卤砜臻gUSERS中重建索引。也就是說(shuō),對(duì)于索引,REBUILD相當(dāng)于表中的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,表明所重建的索引有效。

責(zé)任編輯:趙寧寧 來(lái)源: 今日頭條
相關(guān)推薦

2013-01-14 17:11:24

2013移動(dòng)開(kāi)發(fā)者開(kāi)發(fā)者

2010-07-27 11:29:43

Flex

2013-11-08 10:42:31

Ubuntu 13.1

2011-04-27 09:22:44

Ubuntu 11.0

2017-11-14 07:05:26

物聯(lián)網(wǎng)IT高管數(shù)字化

2013-12-05 17:07:29

openSUSEopenSUSE 13安裝

2013-07-11 10:07:46

Fedora 19

2010-03-24 09:42:12

Oracle數(shù)據(jù)庫(kù)

2010-04-12 14:58:56

Meego開(kāi)發(fā)

2020-12-29 09:50:23

大數(shù)據(jù)大數(shù)據(jù)技術(shù)

2012-08-30 09:41:23

移動(dòng)應(yīng)用開(kāi)發(fā)

2010-04-26 13:38:34

Oracle dele

2010-08-12 14:13:01

Flex開(kāi)發(fā)者

2011-08-04 08:54:31

2022-11-21 10:43:55

首席信息官IT 領(lǐng)導(dǎo)者

2015-11-11 09:12:47

2011-02-15 13:50:01

FreeBSDports

2013-01-06 10:51:56

2012-02-23 13:01:12

JavaPlay Framew

2022-02-28 15:28:43

開(kāi)源云時(shí)代軟件
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)