作者
索引可以加快查詢的速度
一
create table test(id number(
insert into test values(
insert into test values(
insert into test values(
insert into test values(
insert into test values(
insert into test values(
commit;
alter table test add (constraint test_pk primary key (id));
column index_name format a
column monitoring format a
column used format a
column start_monitoring format a
column end_monitoring format a
select index_name
SQL> l
SQL> /
no rows selected
Elapsed:
SQL> alter index test_pk monitoring usage;
Index altered
Elapsed:
SQL> select index_name
INDEX_NAME MONITORING USED START_MONITORING END_MONITORING
TEST_PK YES NO
Elapsed:
SQL> set autotrace on explain
SQL> select * from test where id =
ID NAME
Elapsed:
Execution Plan
SQL> set autotrace off
SQL> /
ID NAME
Elapsed:
SQL>
從上我們可以看到確實使用了索引
SQL> select index_name
INDEX_NAME MONITORING USED START_MONITORING END_MONITORING
TEST_PK YES YES
Elapsed:
SQL> alter index test_pk nomonitoring usage;
Index altered
Elapsed:
SQL> select index_name
INDEX_NAME MONITORING USED START_MONITORING END_MONITORING
TEST_PK NO YES
Elapsed:
到此為止
二
從上面的例子中我們可以看出
CREATE OR REPLACE VIEW SYS
(
INDEX_NAME
TABLE_NAME
MONITORING
USED
START_MONITORING
END_MONITORING
)
AS
select io
decode(bitand(i
decode(bitand(ou
ou
ou
from sys
where io
and i
and io
and t
/
COMMENT ON TABLE SYS
/
GRANT SELECT ON SYS
/
下面是該視圖列的描述
INDEX_NAME: sys
TABLE_NAME: sys
MONITORING: YES (索引正在被監控)
USED: YES (索引已經被使用過)
START_MONITORING: 開始監控的時間
END_MONITORING: 結束監控的時間
所有被使用過至少一次的索引都可以被監控並顯示到這個視圖中
三
set heading off
set echo off
set feedback off
set pages
spool start_index_monitor
select
from dba_indexes
where owner in (
spool off
set heading on
set echo on
set feedback on
set heading off
set echo off
set feedback off
set pages
spool stop_index_monitor
select
from dba_indexes
where owner in (
spool off
set heading on
set echo on
set feedback on
在業務量比較多的一天上班時運行start_index_monitor
SQL> conn t/t
Connected
SQL> select index_name
INDEX_NAME TABLE_NAME USED
TEST_PK TEST NO
SQL>
你也許已經注意到
CREATE OR REPLACE VIEW SYS
(
OWNER
INDEX_NAME
TABLE_NAME
MONITORING
USED
START_MONITORING
END_MONITORING
)
AS
select u
decode(bitand(i
decode(bitand(ou
ou
From:http://tw.wingwit.com/Article/program/Oracle/201311/17521.html