标签:
普通表
grant all on dba_objects to swat; grant all on v_$statname to swat; grant all on v_$mystat to swat; grant create any view to swat; conn swat/swat SELECT a.name, b.value from v$statname a, v$mystat b where a.statistic#=b.statistic# and a.name=‘redo size‘; create or replace view v_redo as SELECT a.name, b.value from v$statname a, v$mystat b where a.statistic#=b.statistic# and a.name=‘redo size‘; create table t as select * from dba_objects; NAME VALUE ---------------------------------------------------------------- ---------- redo size 12204 SQL> delete from t; 72493 rows deleted. SQL> select * from v_redo; NAME VALUE ---------------------------------------------------------------- ---------- redo size 28869556 SQL> select (28869556-12204)/1024/1024||‘M‘ redo from dual; REDO --------------------- 27.52051544189453125M SQL> insert into t select * from dba_objects; 72494 rows created. SQL> select * from v_redo; NAME VALUE ---------------------------------------------------------------- ---------- redo size 37166892 SQL> select (37166892-28869556)/1024/1024||‘M‘ redo from dual; REDO -------------------- 7.91295623779296875M SQL> update t set object_id=rownum; 72494 rows updated. SQL> select * from v_redo; NAME VALUE ---------------------------------------------------------------- ---------- redo size 57257080 SQL> select (57257080-37166892)/1024/1024||‘M‘ redo from dual; REDO ---------------------- 19.159496307373046875M 对72494条记录删除产生27.5M > 更新产生19.2M > 插入产生7.9M。 对于全局临时表来说这个数字分别是:22.8m 12.8M 0.43M
在sys用户下运行: @$ORACLE_HOME/sqlplus/admin/plustrce.sql grant plustrace to swat; conn swat/swat set autotrace on select count(*) from t;
Statistics
----------------------------------------------------------
1037 consistent gets
delete from t;
select count(*) from t;
Statistics
----------------------------------------------------------
1037 consistent gets
truncate table t;
select count(*) from t;
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 2 (0)| 00:00:01 | ---上两次选择cost均为288.时间为4秒
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | TABLE ACCESS FULL| T | 1 | 2 (0)| 00:00:01 |
Statistics
----------------------------------------------------------
20 recursive calls
1 db block gets --上面两次select语句以上项是0,所以没有拷贝过来
10 consistent gets
select * from t where object_id<=10; 4 consistent gets
----------------------------------------------------------------------------------------- | Id | Operation | Name | Rows| Bytes | Cost (%CPU)| Time | ----------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 9 | 1863 | 2 (0)| 00:00:01 | | 1 | TABLE ACCESS BY INDEX ROWID |T | 9 | 1863 | 2 (0)| 00:00:01 | |* 2 | INDEX RANGE SCAN | IDX_T_OID | 9 | | 1 (0)| 00:00:01 | ----------------------------------------------------------------------------------------- select object_id from t where object_id<=10; 2 consistent gets
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 9 | 117 | 1 (0)| 00:00:01 | |* 1 | INDEX RANGE SCAN| IDX_T_OID | 9 | 117 | 1 (0)| 00:00:01 |
全局临时表:应用场景:为了数据安全和数据保护的目的,对表的日志是不可避免;然而,实际情况中有些应用对于某些操作是不要求恢复的,如:运算中的临时中间结果集。
会话级别的全局临时表 create global temporary table t on COMMIT PRESERVE ROWS as select * from dba_objects where 1=2; select table_name,temporary,duration from user_tables where table_name=‘T‘; select * from v_redo; insert into t select * from dba_objects; select * from v_redo; 产生redo 0.43M; update t set object_id=rownum; 产生redo 12.8M; delete from t; 产生redo 22.8M; 提交,退出sql,然后重新进入:可以看到全部数据被删除。 SQL> conn swat/swat Connected. SQL> select count(*) from t; COUNT(*) ---------- 0 事务级别的全局临时表 create global temporary table tt on COMMIT DELETE ROWS as select * from dba_objects where 1=2; select table_name,temporary,duration from user_tables where table_name=‘TT‘; insert into tt select * from dba_objects; 产生0.43M redo update tt set object_id=rownum; 产生redo 12.8M; delete from tt; 产生redo 22.8M; 提交以后清零 SQL> select count(*) from tt; COUNT(*) ---------- 72495 SQL> commit; Commit complete. SQL> select count(*) from tt; COUNT(*) ---------- 0
分区表
create table range_pt(id number,month date,code number,contents varchar2(4000)) PARTITION BY RANGE(month)(partition p1 values less than (TO_DATE(‘2012-02-01‘,‘YYYY-MM-DD‘)), --partition by range是关键字 partition p2 values less than (TO_DATE(‘2012-03-01‘,‘YYYY-MM-DD‘)), partition p3 values less than (TO_DATE(‘2012-04-01‘,‘YYYY-MM-DD‘)), partition p4 values less than (TO_DATE(‘2012-05-01‘,‘YYYY-MM-DD‘)), partition p5 values less than (TO_DATE(‘2012-06-01‘,‘YYYY-MM-DD‘)), partition p6 values less than (TO_DATE(‘2012-07-01‘,‘YYYY-MM-DD‘)), partition p7 values less than (TO_DATE(‘2012-08-01‘,‘YYYY-MM-DD‘)), partition p8 values less than (TO_DATE(‘2012-09-01‘,‘YYYY-MM-DD‘)), partition p9 values less than (TO_DATE(‘2012-10-01‘,‘YYYY-MM-DD‘)), partition p10 values less than (TO_DATE(‘2012-11-01‘,‘YYYY-MM-DD‘)), partition p11 values less than (TO_DATE(‘2012-12-01‘,‘YYYY-MM-DD‘)), partition p12 values less than (TO_DATE(‘2013-01-01‘,‘YYYY-MM-DD‘)), partition p_max VALUES LESS THAN (MAXVALUE) --所有不属于上面12个区的全部落这个区,避免出错。 ) ; insert into range_pt (id,month,code,contents) select rownum, to_date(to_char(sysdate-365,‘J‘)+TRUNC(DBMS_RANDOM.VALUE(0,365)),‘J‘), ceil(dbms_random.value(590,599)), rpad(‘*‘,400,‘*‘) from dual connect by rownum <=100000; commit;
create table list_pt (id number,month date,code number,contents varchar2(4000)) PARTITION BY LIST (CODE) --这里指明这是一个list分区表以列值分区 ( PARTITION P_591 VALUES (591), --这里并不是说取值只能写一个,也可以写多个如:(591,592,593) PARTITION P_592 VALUES (592), --分区可以落在不同的表空间,如果不写就是默认表空间。 PARTITION P_593 VALUES (593), PARTITION P_594 VALUES (594), PARTITION P_595 VALUES (595), PARTITION P_596 VALUES (596), PARTITION P_597 VALUES (597), PARTITION P_598 VALUES (598), PARTITION P_599 VALUES (599), PARTITION P_other VALUES (DEFAULT) --表示剩下的数据全部落入这个分区。 ) ; insert into list_pt(id,month,code,contents) select rownum, to_date(to_char(sysdate-365,‘J‘)+TRUNC(dbms_random.value(0,365)),‘J‘), ceil(dbms_random.value(590,599)), rpad(‘*‘,400,‘*‘) from dual connect by rownum<=100000;
commit;
create table hash_pt (id number,month date,code number,contents varchar2(4000)) partition by hash(month) partitions 12; --没有指定表分区名,只指定了个数。这个个数尽量是偶数。可以指定表空间:store in (ts1,ts2…ts12) insert into hash_pt(id,month,code,contents) select rownum, to_date(to_char(sysdate-365,‘J‘)+trunc(dbms_random.value(0,365)),‘J‘), ceil(dbms_random.value(590,599)), rpad(‘*‘,400,‘*‘) from dual connect by rownum<=100000; commit;
索引组织表
簇表
标签:
原文地址:http://www.cnblogs.com/alexweng/p/4417695.html