[Q]怎么样创建使用虚拟索引 [A]可以使用nosegment选项,如 create index virtual_index_name on table_name(col_name) nosegment; 如果在哪个session需要测试虚拟索引,可以利用隐含参数来处理 alter session set "_use_nosegment_indexes" = true; 就可以利用explain plan for select ……来看虚拟索引的效果 利用@$ORACLE_HOME/rdbms/admin/utlxpls查看执行计划 最后,根据需要,我们可以删除虚拟索引,如普通索引一样 drop index virtual_index_name; 注意:虚拟索引并不是物理存在的,所以虚拟索引并不等同于物理索引,不要用自动跟踪去测试虚拟索引,因为那是实际执行的效果,是用不到虚拟索引的。
[Q]怎样监控无用的索引 [A]Oracle 9i以上,可以监控索引的使用情况,如果一段时间内没有使用的索引,一般就是无用的索引 语法为: 开始监控:alter index index_name monitoring usage; 检查使用状态:select * from v$object_usage; 停止监控:alter index index_name nomonitoring usage; 当然,如果想监控整个用户下的索引,可以采用如下的脚本: set heading off set echo off set feedback off set pages 10000 spool start_index_monitor.sql SELECT 'alter index '||owner||'.'||index_name||' monitoring usage;' FROM dba_indexes WHERE owner = USER; spool off set heading on set echo on set feedback on ------------------------------------------------ set heading off set echo off set feedback off set pages 10000 spool stop_index_monitor.sql SELECT 'alter index '||owner||'.'||index_name||' nomonitoring usage;' FROM dba_indexes WHERE owner = USER; spool off set heading on set echo on set feedback on