多層巢狀同義詞
在Oracle的管理員手冊上,說明可以為表、檢視、物化檢視、過程、函式、包、物件和序列建立同義詞。雖然Oracle並沒有明確說明,但是同樣可以為同義詞建立同義詞。
有些時候建立指向同義詞的同義詞是有意義的。由於同義詞本身功能之一就是實現物理結構和物理位置的透明性,因此使用者在建立同義詞的時候並不會太關係當前指向的物件是否是同義詞還是其他物件。
Oracle處理指向同義詞的同義詞只是在解析物件的時候存在很小的代價,其他並沒有太多的影響。
當然如果同義詞巢狀的層數過多,也不是很好的設計方式,使用者在確定要訪問真正的物件是會很麻煩,Oracle在分析物件的時候同樣也要花費時間:
SQL> create synonym s1 for t;
同義詞已建立。
SQL> create synonym s2 for s1;
同義詞已建立。
對於同義詞S2來說,就是一個巢狀同義詞,指向了同義詞S1。如果這種巢狀的層數太多,也會影響分析的效能。比如,一個巢狀了10000層的同義詞:
SQL> begin
2 for i in 2..10000 loop
3 execute immediate 'create synonym s' || (i+1) || ' for s' || i;
4 end loop;
5 end;
6 /
PL/SQL 過程已成功完成。
SQL> set timing on
SQL> set autot on
SQL> select * from t;
未選定行
已用時間: 00: 00: 00.02
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT ptimizer=CHOOSE
1 0 TABLE ACCESS (FULL) OF 'T'
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
267 bytes sent via SQL*Net to client
460 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed
SQL> select * from s1;
未選定行
已用時間: 00: 00: 00.02
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT ptimizer=CHOOSE
1 0 TABLE ACCESS (FULL) OF 'T'
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
267 bytes sent via SQL*Net to client
460 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed
SQL> select * from s2;
未選定行
已用時間: 00: 00: 00.02
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT ptimizer=CHOOSE
1 0 TABLE ACCESS (FULL) OF 'T'
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
267 bytes sent via SQL*Net to client
460 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed
SQL> select * from s100;
未選定行
已用時間: 00: 00: 00.03
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT ptimizer=CHOOSE
1 0 TABLE ACCESS (FULL) OF 'T'
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
267 bytes sent via SQL*Net to client
460 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed
SQL> select * from s1000;
未選定行
已用時間: 00: 00: 00.11
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT ptimizer=CHOOSE
1 0 TABLE ACCESS (FULL) OF 'T'
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
267 bytes sent via SQL*Net to client
460 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed
SQL> select * from s10000;
未選定行
已用時間: 00: 00: 01.20
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT ptimizer=CHOOSE
1 0 TABLE ACCESS (FULL) OF 'T'
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
267 bytes sent via SQL*Net to client
460 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed
SQL> select * from s10000;
未選定行
已用時間: 00: 00: 00.01
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT ptimizer=CHOOSE
1 0 TABLE ACCESS (FULL) OF 'T'
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
267 bytes sent via SQL*Net to client
460 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed
可以看到,同義詞巢狀層數越多,Oracle就要花費越多的分析的時間來確定要訪問的物件。當然這個分析的結果是儲存在共享池內的,下次再次執行相同的查詢,就不需要重新分析了。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/4227/viewspace-613451/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 集合框架-集合的巢狀遍歷(多層巢狀)框架巢狀
- 微信小程式自定義tab,多層tab巢狀實現微信小程式巢狀
- 多層巢狀表型別語法巢狀型別
- vue elementUI 表單校驗(多層巢狀)VueUI巢狀
- iOS開發·runtime+KVC實現多層字典模型轉換(多層資料:模型巢狀模型,模型巢狀陣列,陣列巢狀模型)iOS模型巢狀陣列
- 【Oracle】-【同義詞】-public與非public同義詞Oracle
- 多層 UIScrollView 巢狀滾動解決方案UIView巢狀
- 漫談 React 元件庫開發(一):多層巢狀彈層元件React元件巢狀
- 物件、同義詞和公有同義詞順序選取物件
- 多層巢狀後的 Fragment 懶載入實現巢狀Fragment
- Python的if語句多層巢狀怎麼使用Python巢狀
- c# saf 框架欄位屬性多層巢狀示例C#框架巢狀
- 封裝多型巢狀封裝多型巢狀
- 授權與同義詞
- ORACLE公有/私有同義詞Oracle
- 詳解同義詞(synonym)
- 微信小程式如何阻止多層巢狀元件的點選事件冒泡微信小程式巢狀元件事件
- 中考常見同義詞和同義短語總結
- Android實現雙層ViewPager巢狀AndroidViewpager巢狀
- 匯出oracle公有同義詞Oracle
- Oracle中的同義詞SYNONYMOracle
- Oracle同義詞建立方法Oracle
- Oracle同義詞 kingsql作品OracleSQL
- 官檔同義詞學習
- 基於複製的多層巢狀快速重新整理物化檢視巢狀
- 匯出Oracle中的同義詞Oracle
- SYS查詢不到的同義詞
- 資料庫鏈與同義詞資料庫
- Oracle同義詞建立方法(轉)Oracle
- element-ui的----el-form表單校驗巢狀表單校驗(表單多層巢狀)+el-table和el-form巢狀使用表單校驗UIORM巢狀
- 059.Define 巨集定義的巢狀巢狀
- jquery div為巢狀,更改了外層,不會改裡層jQuery巢狀
- python 利用 for ... else 跳出雙層巢狀迴圈Python巢狀
- 利用索引提示減少分頁的巢狀層數索引巢狀
- 6.5. 常用物件——6.5.4. 同義詞物件
- Oracle資料庫開發——同義詞Oracle資料庫
- 用Java的方式模擬Flutter的Widget的實現(多層括號巢狀)JavaFlutter巢狀
- 微信小程式入門教程--列表渲染多層巢狀迴圈及wx:key的使用微信小程式巢狀