oracle内存表与临时表,Oracle 临时表之临时表空间组(TTG)
環境:
sys@ORCL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE? ? 10.2.0.1.0? ? ? Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
在Oracle中,temp猶如win下的虛擬內存和unix下的swap分區
TTG是10g引入的概念,目的就是為了減少IO競爭
只有臨時表空間可以定組,普通的表空間無法定組
對待TTG就像對待單個臨時表空間一樣,無甚區別
TTG本身不能被創建,它隨著temp的加入而創建,temp的脫離而刪除
alter tablespace temp tablespace group '';
我們知道一個用戶只能使用一個臨時表空間,而一個臨時表空間中只存在一個臨時段
當一個session在使用臨時段時,其他session再請求臨時段時需要等到擁有該臨時段的session使用完畢之后才能使用
而臨時表空間組的出現大大改善了同一用戶并發session對臨時段的爭奪
因為臨時表空間組的出現使用戶能夠使用多個臨時表空間了
下面作個簡單測試
sys@ORCL> create temporary tablespace temp1 tempfile size 20M tablespace group tempg;
Tablespace created.
sys@ORCL> create temporary tablespace temp2 tempfile size 20M tablespace group tempg;
Tablespace created.
sys@ORCL> create temporary tablespace temp3 tempfile size 20M tablespace group tempg;
Tablespace created.
sys@ORCL> alter database default temporary tablespace tempg;
Database altered.
sys@ORCL> drop tablespace temp;
Tablespace dropped.
sys@ORCL> select * from dba_tablespace_groups;
GROUP_NAME? ? ? ? ? ? ? ? ? ? TABLESPACE_NAME
------------------------------ ------------------------------
TEMPG? ? ? ? ? ? ? ? ? ? ? ? ? TEMP1
TEMPG? ? ? ? ? ? ? ? ? ? ? ? ? TEMP2
TEMPG? ? ? ? ? ? ? ? ? ? ? ? ? TEMP3
sys@ORCL> alter user hr temporary tablespace tempg;
User altered.
sys@ORCL> conn hr/hr
Connected.
hr@ORCL> create table t as select * from dba_objects;
Table created.
hr@ORCL> begin
2? ? ? ? for i in 1..4
3? ? ? ? loop
4? ? ? ? ? insert into t select * from t;
5? ? ? ? end loop;
6? ? ? ? commit;
7? ? ? end;
8? /
PL/SQL procedure successfully completed.
hr@ORCL> create table tt as select * from t;
Table created.
分別打開兩個session以用戶hr登錄對表t和tt同時進行排序,之后通過如下查詢監視對臨時表空間的使用情況
sys@ORCL> select operation_type ,sql_id , tablespace,tempseg_size,number_passes from v$sql_workarea_active;
OPERATION_ SQL_ID? ? ? ? TABLESPACE? ? ? ? ? ? ? ? ? ? TEMPSEG_SIZE NUMBER_PASSES
---------- ------------- ------------------------------ ------------ -------------
SORT (v2)? b7q3tuybvatbt? ? temp1? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0
SORT (v2)? cn7ucn092pg8s? ? temp3? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0
sys@ORCL> select sql_text from v$sql where sql_id in (select sql_id from v$sql_workarea_active);
SQL_TEXT
---------------------------------------------
select object_id from t order by object_id desc
select object_id from tt order by object_id desc
發現來自同一用戶hr的不同session同時排序時使用了同一臨時表空間組內的不同臨時表空間
這樣大大減少了之前同一用戶只能使用一個臨時表空間而產生的請求臨時段的等待時間
總結
以上是生活随笔為你收集整理的oracle内存表与临时表,Oracle 临时表之临时表空间组(TTG)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: TeeChart替代品,MFC下好用的高
- 下一篇: 函数的作用域以及预编译