oracle10g自带的公共同义词,10g ALL_SYNONYMS同义词查询性能下降
在10g中,由于解決了9I ALL_SYNONYMS的bug,導致查詢ALL_SYNONYMS性能下降。
上一篇介紹了9i中,如果創建一個指向同義詞的同義詞,則在ALL_SYNONYMS視圖中可能看不到這個同義詞。10g中則解決了這個問題。可以看到,9i和10g的ALL_SYNONYMS視圖的定義發生了變化:
SQL> select
dbms_metadata.get_ddl('VIEW', 'ALL_SYNONYMS') from dual;
DBMS_METADATA.GET_DDL('VIEW','ALL_SYNONYMS')
--------------------------------------------------------------------------------
CREATE OR REPLACE FORCE VIEW
"SYS"."ALL_SYNONYMS" ("OWNER",
"SYNONYM_NAME", "TABLE_OWNER", "TABLE_NAME",
"DB_LINK") A
S
select u.name, o.name, s.owner, s.name, s.node
from sys.user$ u, sys.syn$ s, sys.obj$ o
where o.obj# = s.obj#
and o.type# = 5
and o.owner# = u.user#
and (
o.owner# in (USERENV('SCHEMAID'), 1 /* PUBLIC */) /* user's private, any public
*/
or /* user has any privs on base object */
exists
(select null from sys.objauth$ ba, sys.obj$ bo, sys.user$ bu
where bu.name = s.owner
and bo.name = s.name
and bu.user# = bo.owner#
and ba.obj# = bo.obj#
and ( ba.grantee# in (select kzsrorol from x$kzsro)
or ba.grantor# = USERENV('SCHEMAID')
)
)
or /* user has system privileges */
exists (select null from v$enabledprivs
where priv_number in (-45 /* LOCK ANY TABLE */,
-47 /* SELECT ANY TABLE */,
-48 /* INSERT ANY TABLE */,
-49 /* UPDATE ANY TABLE */,
-50 /* DELETE ANY TABLE */)
)
)
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
PL/SQL Release 9.2.0.4.0 - Production
CORE 9.2.0.3.0 Production
TNS for Linux: Version 9.2.0.4.0 - Production
NLSRTL Version 9.2.0.4.0 - Production
而10g在9i的基礎上添加了新的部分:
SQL> select
dbms_metadata.get_ddl('VIEW', 'ALL_SYNONYMS') from dual;
DBMS_METADATA.GET_DDL('VIEW','ALL_SYNONYMS')
--------------------------------------------------------------------------------
CREATE OR REPLACE FORCE VIEW
"SYS"."ALL_SYNONYMS" ("OWNER",
"SYNONYM_NAME", "TABLE_OWNER", "TABLE_NAME",
"DB_LINK") A
S
select u.name, o.name, s.owner, s.name, s.node
from sys.user$ u, sys.syn$ s, sys.obj$ o
where o.obj# = s.obj#
and o.type# = 5
and o.owner# = u.user#
and (
o.owner# in (USERENV('SCHEMAID'), 1 /* PUBLIC */) /* user's private, any public
*/
or /* user has any privs on base object in local database */
exists
(select null
from sys.objauth$ ba, sys.obj$ bo, sys.user$ bu
where s.node is null /* don't know accessibility if syn for db link */
and bu.name = s.owner
and bo.name = s.name
and bu.user# = bo.owner#
and ba.obj# = bo.obj#
and ( ba.grantee# in (select kzsrorol from x$kzsro)
or ba.grantor# = USERENV('SCHEMAID')
)
)
or /* local object, and user has system privileges */
(s.node is null /* don't know accessibility if syn is for db link */
and exists (select null from v$enabledprivs
where priv_number in (-45 /* LOCK ANY TABLE */,
-47 /* SELECT ANY TABLE */,
-48 /* INSERT ANY TABLE */,
-49 /* UPDATE ANY TABLE */,
-50 /* DELETE ANY TABLE */)
)
)
)
union
select u.name, o.name, s.owner, s.name, s.node
from sys.user$ u, sys.syn$ s, sys.obj$ o, sys."_ALL_SYNONYMS_TREE" st
where o.obj# = s.obj#
and o.type# = 5
and o.owner# = u.user#
and o.obj# = st.syn_id /* syn is in tree pointing to accessible base obj */
and s.obj# = st.syn_id /* syn is in tree pointing to accessible base obj */
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for Linux: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
正是增加的這部分UNION語句,解決了9i中bug的同時,也帶來了性能影響。
問題是不僅僅是用戶訪問ALL_SYNONYMS同義詞變慢,而很多工具會導致系統遞歸調用中訪問ALL_SYNONYMS視圖,從而導致系統整體性能下降。
對于用戶訪問這個視圖的性能下降,最簡單的辦法是仿照9i的語法,在當前用戶建立一個視圖,比如ALL_SYNONYMS_V92,然后創建一個當前用戶下的同義詞ALL_SYNONYMS指向當前用戶的ALL_SYNONYMS_V92視圖。由于用戶下的同義詞優先級高于PUBLIC SYNONYMS,用戶在訪問的時候就會訪問用戶下的ALL_SYNONYMS_V92視圖,不過9i中指向同義詞的同義詞就可能在ALL_SYNONYMS中無法訪問。
不過這種方式對于一些系統調用或者工具產生的調用無效,因為這些SQL可能訪問的并不是PUBLIC同義詞,而是SYS.ALL_SYNONYMS對象,這就導致了用戶創建的同義詞無效。如果是這種情況,那么為了解決性能問題,只要仿照9i的語法重建10g的ALL_SYNONYMS視圖,同樣9i中的bug就會在10g中再次出現。
Oracle在文檔ID 377037.1詳細描述了這個問題。看來有的時候正確性和性能很難完全兼顧。
總結
以上是生活随笔為你收集整理的oracle10g自带的公共同义词,10g ALL_SYNONYMS同义词查询性能下降的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: oracle每天自增长,oracle的自
- 下一篇: 农村可以做什么加工厂2022 可以考虑