Table 引數總結 (ZT)
關於Oracle Tables 的一些基礎知識:
Ref:
[@more@]1.BUFFER POOL SQL> CREATE TABLE wwm_test(ID NUMBER(9)) STORAGE (BUFFER_POOL DEFAULT);Table created.
1* SELECT TABLE_NAME,BUFFER_POOL FROM USER_TABLES WHERE TABLE_NAME='WWM_TEST'
SQL> /
TABLE_NAME BUFFER_
------------------------------ -------
WWM_TEST DEFAULT
SQL> ALTER TABLE WWM_TEST STORAGE(BUFFER_POOL RECYCLE);
Table altered.
SQL> SELECT TABLE_NAME,BUFFER_POOL FROM USER_TABLES WHERE TABLE_NAME='WWM_TEST';
TABLE_NAME BUFFER_
------------------------------ -------
WWM_TEST RECYCLE
SQL> ALTER TABLE WWM_TEST STORAGE(BUFFER_POOL KEEP);
Table altered.
SQL> SELECT TABLE_NAME,BUFFER_POOL FROM USER_TABLES WHERE TABLE_NAME='WWM_TEST';
TABLE_NAME BUFFER_
------------------------------ -------
WWM_TEST KEEP
2. CACHE
index-organized table不能被這樣CACHE。
SQL> CREATE TABLE WWM_TEST2(ID NUMBER(10)) CACHE;
Table created.
SQL> SELECT TABLE_NAME,CACHE FROM USER_TABLES WHERE TABLE_NAME='WWM_TEST2';
TABLE_NAME CACHE
------------------------------ ----------
WWM_TEST2 Y
SQL> ALTER TABLE WWM_TEST2 NOCACHE;
Table altered.
SQL> SELECT TABLE_NAME,CACHE FROM USER_TABLES WHERE TABLE_NAME='WWM_TEST2';
TABLE_NAME CACHE
- ----------------------------- ----------
WWM_TEST2 N
3. COMPRESS
COMPRESS常用在資料倉儲裡,插入更新不頻繁,能節省儲存空間。
建立NOCOMPRESS的TABLE 和INDEX
SQL> create table nocompress_wwm as select * from all_objects;
Table created.
SQL> create index ind_nocompress_wwm_object_id on nocompress_wwm(objecT_id);
Index created.
建立COMPRESS的TABLE和INDEX
1* create table compress_wwm compress as select * from all_objects
SQL> /
Table created.
SQL> create index ind_compress_wwm_object_id on compress_wwm(object_id);
Index created.
統計資訊以便比較
SQL> EXEC DBMS_STATS.GATHER_SCHEMA_STATS (OWNNAME=>'SYSTEM',CASCADE=>TRUE);
PL/SQL procedure successfully completed.
SQL> SELECT TABLE_NAME,BLOCKS FROM USER_TABLES WHERE TABLE_NAME LIKE '%COMPRESS%';
TABLE_NAME BLOCKS
------------------------------ ----------
COMPRESS_WWM 420
NOCOMPRESS_WWM 809
可見所用BLOCK少了很多
1* SELECT INDEX_NAME,LEAF_BLOCKS FROM USER_INDEXES WHERE INDEX_NAME LIKE '%COMPRE%'
SQL> /
INDEX_NAME LEAF_BLOCKS
------------------------------ -----------
IND_COMPRESS_WWM_OBJECT_ID 130
IND_NOCOMPRESS_WWM_OBJECT_ID 130
但索引還是一樣
4. LOGGING
SQL> create table wwm_log_test (id number(10));
Table created.
1* select table_name,logging from user_tables where table_name='WWM_LOG_TEST'
SQL> /
TABLE_NAME LOG
------------------------------ ---
WWM_LOG_TEST YES
SQL> alter table wwm_log_test nologging;
Table altered.
SQL> select table_name,logging from user_tables where table_name='WWM_LOG_TEST'
2 /
TABLE_NAME LOG
------------------------------ ---
WWM_LOG_TEST NO
5.PARALLEL
與PARALLEL_THREADS_PER_CPU 初始化引數相關
SQL> create table wwm_parallel_test (id number(10)) parallel(degree 4);
Table created.
SQL> select table_name,degree from user_tables where table_name='WWM_PARALLEL_TEST';
TABLE_NAME DEGREE
------------------------------ --------------------
WWM_PARALLEL_TEST 4
也可以寫成
1* create table wwm_parallel_test1(id number(10)) parallel 4
SQL> /
Table created.
SQL> select table_name,degree from user_tables where table_name='WWM_PARALLEL_TEST';
TABLE_NAME DEGREE
------------------------------ --------------------
WWM_PARALLEL_TEST 4
修改
SQL> alter table wwm_parallel_test1 parallel 2;
Table altered.
SQL> select table_name,degree from user_tables where table_name like ' WWM_PARALLEL%';
TABLE_NAME DEGREE
------------------------------ --------------------
WWM_PARALLEL_TEST 4
WWM_PARALLEL_TEST1 2
6. TABLE LOCK
可以防止DDL
SQL> create table wwm_lock(id number(10));
Table created.
SQL> alter table wwm_lock disable table lock;
Table altered.
SQL> alter table wwm_lock add (name varchar2(10));
alter table wwm_lock add (name varchar2(10))
*
ERROR at line 1:
ORA-00069: cannot acquire lock -- table locks disabled for WWM_LOCK
很神奇吧,想想能用在什麼地方呢?
使表不能LOCK,但是現在還是可以DML的。
SQL> insert into wwm_lock values(111);
1 row created.
SQL> commit;
Commit complete.
使表能LOCK
SQL> alter table wwm_lock enable table lock;
Table altered.
SQL> alter table wwm_lock add (name varchar2(10));
Table altered.
SQL> desc wwm_lock
Name Null? Type
----------------------------------------- -------- ---------------
ID NUMBER(10)
NAME VARCHAR2(10)
7. global temporary table
不能指定表空間,只能建立在TEMP表空間上,
這裡用on commit delete rows表示在COMMIT的時候清空。
SQL> create global temporary table wwm_temp(id number(10)) on commit delete rows;
Table created.
SQL> insert into wwm_temp values (111);
1 row created.
SQL> select * from wwm_temp;
ID
----------
111
SQL> commit;
Commit complete.
檢查是否清空了
SQL> select * from wwm_temp;
no rows selected
SQL> insert into wwm_temp values (222);
1 row created.
TRUNCATE可以用嗎?
SQL> truncate table wwm_temp;
Table truncated.
SQL> select * from wwm_temp;
no rows selected
global temporary table 本身是NOLOG的
SQL> select table_name,logging from user_tables where table_name='WWM_TEMP';
TABLE_NAME LOG
------------------------------ ---
WWM_TEMP NO
這裡看看ON COMMIT PRESERVER ROWS,這種情況在SESSION結束的時候會清空.
1* create global temporary table wwm_temp_reserve (id number(10)) on commit preserve rows
SQL> /
Table created.
SQL> insert into wwm_temp_reserve values (111);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from wwm_temp_reserve;
ID
----------
111
結束SESSION
SQL> connect user/pass
Connected.
SQL> select * from wwm_temp_reserve;
no rows selected
8. comment
不多解釋了
SQL> comment on table wwm2 is 'MY TEST TABLE';
Comment created.
1* select table_name,comments from user_tab_comments where table_name='WWM2'
SQL> /
TABLE_NAME
------------------------------
COMMENTS
-------------------------------------------------------------------------------
WWM2
MY TEST TABLE
在列上作COMMENT
SQL> comment on column wwm2.id is 'id column of wwm2,it is the sequence'
2 /
Comment created.
SQL> select table_name,column_name ,comments from user_col_comments where table_name='WWM2';
TABLE_NAME COLUMN_NAME
------------------------------ ------------------------------
COMMENTS
--------------------------------------------------------------------------------
WWM2 ID
id column of wwm2,it is the sequence
WWM2 NAME
可見TABLE裡的所有欄位都在USER_COL_COMMENTS裡存在,只是有的有COMMENT
9. EXTENT ALLOCATE AND DEALLOCATE
SQL> create table wwm_allo(id number(10));
Table created.
實驗表佔1個EXTENTS
SQL> select segment_name,extents from user_segments where segment_name='WWM_ALLO';
SEGMENT_NAME
--------------------------------------------------------------------------------
EXTENTS
----------
WWM_ALLO
1
使表擴充套件
SQL> alter table wwm_allo allocate extent;
Table altered.
擴充套件後佔2個EXTENT
SQL> select segment_name,extents from user_segments where segment_name='WWM_ALLO';
SEGMENT_NAME
--------------------------------------------------------------------------------
EXTENTS
----------
WWM_ALLO
2
回收相臨的EXTENT
SQL> alter table wwm_allo deallocate unused;
Table altered.
SQL> select segment_name,extents from user_segments where segment_name='WWM_ALLO';
SEGMENT_NAME
--------------------------------------------------------------------------------
EXTENTS
----------
WWM_ALLO
1
10. 不相臨EXTENT如何合併
建立測試表
SQL> create table wwm_ext (id number(6),name varchar2(20));
Table created.
SQL> select block_num,count(*) from (
2 select dbms_rowid.rowid_block_number(rowid) block_num from wwm_ext)
3 group by block_num
4 /
no rows selected
插入測試資料
1 begin
2 for n in 1..100000
3 loop
4 insert into wwm_ext (id,name)
5 values (n,'asdfghjklqwertyuiopz');
6 end loop;
7 commit;
8* end;
SQL> /
PL/SQL procedure successfully completed.
查其佔用情況
select block_num,count(*) from (
select dbms_rowid.rowid_block_number(rowid) block_num from wwm_ext)
group by block_num
BLOCK_NUM COUNT(*)
---------- ----------
89452 115
89453 115
89454 115
89455 115
89456 115
............................
89458 115
89459 115
89460 71
867 rows selected.
人工製造碎片
SQL> delete from wwm_ext where mod (id,2)=1;
50000 rows deleted.
SQL> commit;
Commit complete.
查其佔用情況
select block_num,count(*) from (
select dbms_rowid.rowid_block_number(rowid) block_num from wwm_ext)
group by block_num
BLOCK_NUM COUNT(*)
---------- ----------
89452 58
89453 57
89454 58
89455 57
...............................
89457 57
89458 58
89459 57
89460 36
867 rows selected.
ALTER TABLE WWM_EXT DEALLOCATE UNUSED;對這種情況是沒有任何作用的
10G 提供了ALTER TABLE TABLE_NAME SHRINK SPACE COMPACT CASCADE;的語法可以解決碎片問題,但要求表是ENABLE ROW MOVEMENT的。
9I最有效的解決方法只有EXT/IMP或MOVE 了。
1* alter table wwm_ext move tablespace users
SQL> /
Table altered.
select block_num,count(*) from (
select dbms_rowid.rowid_block_number(rowid) block_num from wwm_ext)
group by block_num
BLOCK_NUM COUNT(*)
---------- ----------
468 114
469 114
470 114
471 114
...................................
473 114
474 114
475 114
476 11
438 rows selected.
11. 其他
ALTER TABLE wwm DROP COLUMN id CHECKPOINT 10000;
ALTER TABLE wwm SET UNUSED COLUMN id;
SELECT * FROM user_unused_col_tabs;
ALTER TABLE wwm DROP UNUSED COLUMNS;
ALTER TABLE wwm DROP UNUSED COLUMNS CHECKPOINT 250;
DROP TABLE wwm CASCADE CONSTRAINTS;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/271283/viewspace-1002970/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SYBASE優化總結(zt)優化
- parallel rollback引數總結Parallel
- Mybatis引數處理總結MyBatis
- Python函式引數總結Python函式
- Bootstrap-Table 總結boot
- Flink常用的配置引數總結
- Oracle Table建立引數說明Oracle
- openai GPT引數(入參)使用總結OpenAIGPT
- consul配置引數大全、詳解、總結
- 引數彙總
- ocfs2檔案系統問題總結(zt)
- (4)caffe總結之視覺層及引數視覺
- (6)caffe總結之其它常用層及引數
- JVM調優引數、方法、工具以及案例總結JVM
- MySQL中Redo Log相關的重要引數總結MySql
- sklearn與XGBoost庫xgboost演算法引數總結演算法
- layUI Table自定義工具欄和搜尋引數UI
- MySQL儲存過程in、out、inout引數示例與總結MySql儲存過程
- TensorFlow卷積網路常用函式引數詳細總結卷積函式
- C技巧:結構體引數轉成不定引數結構體
- 12C關於CDB、PDB引數的區別和總結
- 2.5萬字長文簡單總結SpringMVC請求引數接收SpringMVC
- Grails中如何繫結引數AI
- InceptionResnetV1引數結構
- 計數題總結
- 總結Sass 變數變數
- 熬夜總結vue3中setUp函式的2個引數詳解Vue函式
- 檢視作業系統位數(zt)作業系統
- HTML table表格結構HTML
- 數論總結——更新ing
- 《沉默的大多數》總結
- 日誌損壞時,加入隱含引數開啟資料庫的總結資料庫
- sp_sysmon效能診斷結果分析(zt)
- MySQL效能最佳化之Open_Table配置引數的合理配置建議MySql
- 【工作篇】再次熟悉 SpringMVC 引數繫結SpringMVC
- INSTEAD OF(zt)
- lsof(zt)
- ElasticSearch7.3學習(二十六)----搜尋(Search)引數總結、結果跳躍(bouncing results)問題解析Elasticsearch
- 資料統計與視覺化複習總結(二):非引數檢驗、生存分析視覺化