效果不错!从3降到了1!
但是,为了使用到索引,在视图定义中使用了” where dummy='X'”的条件(哈哈,注意,dummy为not null时不要条件也能使用到索引)。这会给我们的程序带来一定风险。能否避免它呢?当然可以!建立索引组织表试试:
SQL> set autot off
SQL> drop synonym DUAL;
Synonym dropped.
SQL> connect sys/sys as sysdba
Connected.
SQL>
SQL> drop view x_$dual;
那还能不能做进一步优化,把consistent gets降到0呢?试试把对象cache到keep pool中去(当然必须保证keep pool最少大于0)!
SQL> set autot off
SQL> drop synonym DUAL;
Synonym dropped.
SQL> connect sys/sys as sysdba
Connected.
SQL> drop view x_$dual;
View dropped.
SQL> show parameter cache
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
... ...
db_cache_size big integer 25165824
db_keep_cache_size big integer 0
... ...
SQL> alter system set db_keep_cache_size=1M;
alter system set db_keep_cache_size=1M
*
ERROR at line 1:
ORA-02097: parameter cannot be modified because specified value is invalid
ORA-00384: Insufficient memory to grow cache
SQL> alter system set db_cache_size=20M;
System altered.
SQL> alter system set db_keep_cache_size=1M;
System altered.
SQL> show parameter cache;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
... ...
db_cache_size big integer 20971520
db_keep_cache_size big integer 4194304
... ...
上面过程中有一些有趣的事件发生,不知道你留意到了没有(最少2处)?这里就不做解释了(卖个关子吧)。
SQL> create view x_$dual as select * from x$dual;
View created.
SQL> grant select on x_$dual to public;
Grant succeeded.
SQL> alter table dual cache storage(buffer_pool keep);
Table altered.
SQL> connect demo/demo
Connected.
SQL> create synonym DUAL for sys.x_$dual;
Synonym created.
看看结果:
SQL> set autot trace
SQL> select sysdate from dual;
Execution Plan
----------------------------------------------------------
ERROR:
ORA-01039: insufficient privileges on underlying objects of the view