oralce 壓縮表與heap表儲存空間與查詢效能比較
首先來看一下test表
SQL> set autot trace exp stat
SQL> SELECT COUNT(*) FROM test;
SQL> set autot trace exp stat
SQL> SELECT COUNT(*) FROM test;
已用時間: 00: 00: 03.42
執行計劃
----------------------------------------------------------
Plan hash value: 3187697131
----------------------------------------------------------
Plan hash value: 3187697131
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 9479 (4)| 00:01:54 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | INDEX FAST FULL SCAN| IDX_TIME | 15M| 9479 (4)| 00:01:54 |
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 9479 (4)| 00:01:54 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | INDEX FAST FULL SCAN| IDX_TIME | 15M| 9479 (4)| 00:01:54 |
--------------------------------------------------------------------------
統計資訊
----------------------------------------------------------
0 recursive calls
0 db block gets
42926 consistent gets
42900 physical reads
0 redo size
416 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> SELECT COUNT(*) FROM test;
已用時間: 00: 00: 03.29
執行計劃
----------------------------------------------------------
Plan hash value: 3187697131
----------------------------------------------------------
Plan hash value: 3187697131
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 9479 (4)| 00:01:54 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | INDEX FAST FULL SCAN| IDX_TIME | 15M| 9479 (4)| 00:01:54 |
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 9479 (4)| 00:01:54 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | INDEX FAST FULL SCAN| IDX_TIME | 15M| 9479 (4)| 00:01:54 |
--------------------------------------------------------------------------
統計資訊
----------------------------------------------------------
0 recursive calls
0 db block gets
42926 consistent gets
42900 physical reads
0 redo size
416 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
將buffer_cache記憶體中cache的資料清空
SQL> alter system flush buffer_cache;
SQL> alter system flush buffer_cache;
系統已更改。
已用時間: 00: 00: 00.03
SQL> SELECT COUNT(*) FROM test;
SQL> SELECT COUNT(*) FROM test;
已用時間: 00: 00: 03.39
執行計劃
----------------------------------------------------------
Plan hash value: 3187697131
----------------------------------------------------------
Plan hash value: 3187697131
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 9479 (4)| 00:01:54 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | INDEX FAST FULL SCAN| IDX_TIME | 15M| 9479 (4)| 00:01:54 |
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 9479 (4)| 00:01:54 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | INDEX FAST FULL SCAN| IDX_TIME | 15M| 9479 (4)| 00:01:54 |
--------------------------------------------------------------------------
統計資訊
----------------------------------------------------------
0 recursive calls
0 db block gets
42926 consistent gets
42901 physical reads
0 redo size
416 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
將此表資料cache到記憶體後終於,查詢的效率提高了
SQL> SELECT COUNT(*) FROM test;
SQL> SELECT COUNT(*) FROM test;
已用時間: 00: 00: 00.60
執行計劃
----------------------------------------------------------
Plan hash value: 3187697131
----------------------------------------------------------
Plan hash value: 3187697131
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 9479 (4)| 00:01:54 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | INDEX FAST FULL SCAN| IDX_TIME | 15M| 9479 (4)| 00:01:54 |
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 9479 (4)| 00:01:54 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | INDEX FAST FULL SCAN| IDX_TIME | 15M| 9479 (4)| 00:01:54 |
--------------------------------------------------------------------------
統計資訊
----------------------------------------------------------
0 recursive calls
0 db block gets
42926 consistent gets
0 physical reads
0 redo size
416 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
以下建立壓縮表和普通表,對比儲存和查詢效能
SQL> create table test2
2 as
3 select * from test;
SQL> create table test2
2 as
3 select * from test;
表已建立。
已用時間: 00: 01: 31.29
SQL> create table test3 compress
2 as
3 select * from test;
SQL> create table test3 compress
2 as
3 select * from test;
表已建立。
已用時間: 00: 01: 25.39
SQL> SELECT COUNT(*) FROM test2;
已用時間: 00: 00: 10.46
執行計劃
----------------------------------------------------------
Plan hash value: 634289536
----------------------------------------------------------
Plan hash value: 634289536
--------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
--------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 33818 (2)| 00:06:46 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | TABLE ACCESS FULL| TEST2 | 15M| 33818 (2)| 00:06:46 |
--------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
--------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 33818 (2)| 00:06:46 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | TABLE ACCESS FULL| TEST2 | 15M| 33818 (2)| 00:06:46 |
--------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement
-----
- dynamic sampling used for this statement
統計資訊
----------------------------------------------------------
146 recursive calls
0 db block gets
152084 consistent gets
152017 physical reads
0 redo size
416 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
2 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> SELECT COUNT(*) FROM test3;
已用時間: 00: 00: 07.78
執行計劃
----------------------------------------------------------
Plan hash value: 1832809687
----------------------------------------------------------
Plan hash value: 1832809687
--------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
--------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 24779 (3)| 00:04:58 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | TABLE ACCESS FULL| TEST3 | 16M| 24779 (3)| 00:04:58 |
--------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
--------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 24779 (3)| 00:04:58 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | TABLE ACCESS FULL| TEST3 | 16M| 24779 (3)| 00:04:58 |
--------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement
-----
- dynamic sampling used for this statement
統計資訊
----------------------------------------------------------
28 recursive calls
0 db block gets
110776 consistent gets
110719 physical reads
0 redo size
416 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> SET AUTOT OFF
SQL> col owner format a15
SQL> col segment_name format a15
SQL> select owner,segment_name,bytes/1024/1024 m from dba_segments where segment_name='TEST2';
SQL> col owner format a15
SQL> col segment_name format a15
SQL> select owner,segment_name,bytes/1024/1024 m from dba_segments where segment_name='TEST2';
OWNER SEGMENT_NAME M
--------------- --------------- ----------
SYS TEST2 1216
--------------- --------------- ----------
SYS TEST2 1216
已用時間: 00: 00: 00.06
SQL> select owner,segment_name,bytes/1024/1024 m from dba_segments where segment_name='TEST3';
SQL> select owner,segment_name,bytes/1024/1024 m from dba_segments where segment_name='TEST3';
OWNER SEGMENT_NAME M
--------------- --------------- ----------
SYS TEST3 872
--------------- --------------- ----------
SYS TEST3 872
已用時間: 00: 00: 00.06
SQL> show parameter db_block
SQL> show parameter db_block
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_block_buffers integer 0
db_block_checking string FALSE
db_block_checksum string TRUE
db_block_size integer 8192
SQL>
------------------------------------ ----------- ------------------------------
db_block_buffers integer 0
db_block_checking string FALSE
db_block_checksum string TRUE
db_block_size integer 8192
SQL>
test2表與test3表相比:
1: 儲存test2表比test3多了1216-872=344M
2: 查詢效能:test2表比test3多掃描344*1024/8=44032個資料庫,故查詢時間也多出10.46-07.78=2.68秒
1: 儲存test2表比test3多了1216-872=344M
2: 查詢效能:test2表比test3多掃描344*1024/8=44032個資料庫,故查詢時間也多出10.46-07.78=2.68秒
但是載入壓縮表資料比載入普通表時間將近多2倍
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/16400082/viewspace-742794/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 測試表的空間壓縮與表空間的關係
- oracle 壓縮備份與普通備份從空間,時間,CPU效能的比較Oracle
- HybridDBforPostgreSQL列存表(AO表)的膨脹、垃圾檢查與空間收縮SQL
- oracle表空間查詢Oracle
- 表空間大小查詢
- 表空間查詢資訊
- 【表壓縮】使用表壓縮技術將表所佔用空間降低到最小
- 【儲存管理】表空間概念
- 表空間查詢和管理
- 表空間相關查詢
- oracle 表空間,臨時表空間使用率查詢Oracle
- 【儲存管理】建立永久表空間
- innodb表空間儲存結構
- 表空間中有資料也可以壓縮表空間(資料檔案)大小
- 表在表空間中的儲存情況
- Oracle查詢表佔磁碟空間大小及移動表空間Oracle
- 表空間使用量查詢
- 查詢表空間使用情況
- Oracle的表空間的儲存管理與最佳化技術Oracle
- 大資料中批次壓縮與獨立壓縮的比較 - Bozho大資料
- 分析表空間空閒率並收縮表空間
- oracle查詢表空間的空間佔用情況Oracle
- oracle 修改表空間儲存路徑Oracle
- 臨時表空間和回滾表空間使用率查詢
- Linux壓縮工具的效能比較Linux
- [DB2]表空間之DMS、自動儲存的DMS表空間DB2
- Oracle 查詢表大小以及表空間使用率Oracle
- oracle表空間使用率查詢Oracle
- Oracle 表空間查詢相關sqlOracleSQL
- Oracle查詢表空間使用情況Oracle
- 查詢表空間的使用率
- 臨時表空間的空間使用情況查詢
- Oracle 查詢各個 “表空間/資料檔案” 的空間使用比情況Oracle
- Oracle效能優化:收縮臨時表空間Oracle優化
- Oracle 查詢表與表之間的 主外來鍵關係Oracle
- 查詢表的大小及表空間的使用情況
- 【儲存管理】建立臨時表空間組、建立臨時表空間組及使用
- ORACLE查詢所有表空間使用情況Oracle