[20111214]汇总11GR2 Deferred Segment Creation一些相关信息.txt

11G R2引入了Deferred Segment Creation的新特性,在建立空表时并不分配空间.这样对于一些系统能节省许多空间。但是也可能遇到一些问题,我把这段时间看到关于这个方面的信息做一个汇总。

1.sys用户不受这个限制:

测试例子:
sqlplus sys as sysdba
SQL> create table t1 (a number);
Table created.
SQL> select  table_name ,segment_created from user_tables where table_name='T1';
TABLE_NAME                     SEG
------------------------------ ---
T1                             YES

SQL> select  segment_name ,segment_type ,bytes from user_segments where segment_name='T1' and segment_type='TABLE';
SEGMENT_NAME                                                                      SEGMENT_TYPE            BYTES
--------------------------------------------------------------------------------- ------------------ ----------
T1                                                                                TABLE                   65536
    可以发现,SYS用户建立的表不受限制!

2.导致使用exp/imp这些空表无法导入:
测试例子参考http://space.itpub.net/267265/viewspace-695835。

3.如果把表做一个move操作,将会建立相应的段。

测试例子
sqlplus scott/xxxx

SQL> create table t1 (a number);
Table created.
SQL> select  table_name ,segment_created from user_tables where table_name='T1';
TABLE_NAME                     SEG
------------------------------ ---
T1                             NO
SQL> select  segment_name ,segment_type ,bytes from user_segments where segment_name='T1' and segment_type='TABLE';
no rows selected

SQL> alter table scott.t1 move tablespace users;
Table altered.

SQL> select  table_name ,segment_created from user_tables where table_name='T1';
TABLE_NAME                     SEG
------------------------------ ---
T1                             YES

SQL> select  segment_name ,segment_type ,bytes from user_segments where segment_name='T1' and segment_type='TABLE';
SEGMENT_NAME                                                                      SEGMENT_TYPE            BYTES
--------------------------------------------------------------------------------- ------------------ ----------
T1                                                                                TABLE                   65536

    可以发现move后会建立相应的extent。

4.如果索引属性修改为unusable,该索引占用的段会消失。
SQL> drop table t1 purge;
SQL> create table t1 (a number);
Table created.
SQL> create index i_t1_a on t1(a);
Index created.

SQL> insert into t1 values (1);
1 row created.
SQL> commit ;
Commit complete.

SQL> select  table_name ,segment_created from user_indexes where table_name='T1';
TABLE_NAME                     SEG
------------------------------ ---
T1                             YES

SQL> select  segment_name ,segment_type ,bytes from user_segments where segment_name='I_T1_A' and segment_type='INDEX';
SEGMENT_NAME                                                                      SEGMENT_TYPE            BYTES
--------------------------------------------------------------------------------- ------------------ ----------
I_T1_A                                                                            INDEX                   65536

SQL> alter index i_t1_a unusable;
Index altered.

SQL> select  table_name ,segment_created from user_indexes where table_name='T1';
TABLE_NAME                     SEG
------------------------------ ---
T1                             NO

SQL> select  segment_name ,segment_type ,bytes from user_segments where segment_name='I_T1_A' and segment_type='INDEX';
no rows selected

利用这个特性,我们可以建立一些分区索引,保留我们自己需要的,不需要的索引修改为unusable.

这里有一个很好的例子
http://richardfoote.wordpress.com/2011/02/27/oracle11g-zero-sized-unusable-indexes-part-ii-nathan-adler/
[也许需要翻墙才能看!]

例子:
create table t2 (a number, b varchar2(10),status varchar2(1));
insert into t2 select rownum, 'test','1'from dual connect by level update t2 set status = '0' where a in (9990, 9992, 9994, 9996, 9998);
commit;

假设status的取值仅仅'1','0'. 查询正常业务仅仅查询='0'的情况,而且status='0'的值很少!正常如果建立索引status会随着记录的添加索引逐步变大,而实际上我们仅仅需要索引status='0'的情况,这个需要dba与开发人员协商好,程序员写的sql代码如下:

SQL> select * from t2 where decode(status,'1',NULL,status)='0';

         A B          S
---------- ---------- -
      9990 test       0
      9992 test       0
      9994 test       0
      9996 test       0
      9998 test       0

建立decode(status,'1',NULL,status)的函数索引。但是这个需要dba与程序员协商好!语句也要这样写。
create index scott.if_status on t2 (decode("status",'1',null,"status"));

select * from t2 where decode(status,'1',NULL,status)='0';
PLAN_TABLE_OUTPUT
--------------------------------------
SQL_ID  4nsvdy41fymmr, child number 1
-------------------------------------
select * from t2 where decode(status,'1',NULL,status)='0'
Plan hash value: 1171039187
----------------------------------------------------------
| Id  | Operation                   | Name      | E-Rows |
----------------------------------------------------------
|   0 | SELECT STATEMENT            |           |        |
|   1 |  TABLE ACCESS BY INDEX ROWID| T2        |      5 |
|*  2 |   INDEX RANGE SCAN          | IF_STATUS |      5 |
----------------------------------------------------------

SQL> create index I_T2_STATUS on T2(STATUS) global partition by range (STATUS) (
  partition STATUS0 values less than ('1'),
  partition STATUS_OTHER values less than (MAXVALUE)
) unusable;
Index created.

SQL> select  table_name ,segment_created from user_indexes where table_name='T2';
TABLE_NAME                     SEG
------------------------------ ---
T1                             N/A
SQL> select  segment_name,partition_name,segment_type ,bytes from user_segments where segment_name='I_T2_STATUS' ;
no rows selected

--建立索引,仅仅rebuild我们需要的哪部分.
SQL> alter index i_t2_status rebuild partition status0;
Index altered.

SQL> select  table_name ,segment_created from user_indexes where table_name='T2';
TABLE_NAME                     SEG
------------------------------ ---
T2                             N/A

SQL> select  segment_name ,PARTITION_NAME,segment_type ,bytes from user_segments where segment_name='I_T2_STATUS' ;
SEGMENT_NAME    PARTITION_NAME                 SEGMENT_TYPE            BYTES
--------------- ------------------------------ ------------------ ----------
I_T2_STATUS     STATUS0                        INDEX PARTITION         65536

   可以发现仅仅status=0的分区索引,占用空间明显减少!

SQL> select * from t2 where status='0';
PLAN_TABLE_OUTPUT
--------------------------------------
SQL_ID  36k4a41s20ac8, child number 0
-------------------------------------
 select * from t2 where status='0'
Plan hash value: 4122182659
-------------------------------------------------------------
| Id  | Operation                    | Name        | E-Rows |
-------------------------------------------------------------
|   0 | SELECT STATEMENT             |             |        |
|   1 |  PARTITION RANGE SINGLE      |             |   5000 |
|   2 |   TABLE ACCESS BY INDEX ROWID| T2          |   5000 |
|*  3 |    INDEX RANGE SCAN          | I_T2_STATUS |   5000 |
-------------------------------------------------------------

统计信息不准,重新分析,Cascade=>false,:

BEGIN
  SYS.DBMS_STATS.GATHER_TABLE_STATS (
      OwnName        => 'SCOTT'
     ,TabName        => 'T2'
    ,Estimate_Percent  => SYS.DBMS_STATS.AUTO_SAMPLE_SIZE
    ,Method_Opt        => 'FOR ALL COLUMNS SIZE auto '
    ,Degree            => 1
    ,Cascade           => false
    ,No_Invalidate     => TRUE);
END;
/

Execution Plan
----------------------------------------------------------
Plan hash value: 4122182659
------------------------------------------------------------------------------------------------------------
| Id  | Operation                    | Name        | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT             |             |     5 |    55 |     1   (0)| 00:00:01 |       |       |
|   1 |  PARTITION RANGE SINGLE      |             |     5 |    55 |     1   (0)| 00:00:01 |     1 |     1 |
|   2 |   TABLE ACCESS BY INDEX ROWID| T2          |     5 |    55 |     1   (0)| 00:00:01 |       |       |
|*  3 |    INDEX RANGE SCAN          | I_T2_STATUS |     5 |       |     1   (0)| 00:00:01 |     1 |     1 |
------------------------------------------------------------------------------------------------------------

5.配额问题(quotas):
  因为建立空表以及索引是并没有分配空间,这样建立的表以及索引没有配额问题,但是一旦插入数据就可能报错!

SQL> create user test identified by 1234  default tablespace users  temporary tablespace temp  profile default  account unlock;
SQL> grant create session to test;
SQL> grant create table to test;

sqlplus  test/1234

SQL> create table t3 ( a number) ;
Table created.
SQL> insert into t3 values (100);
insert into t3 values (100)
            *
ERROR at line 1:
ORA-01536: space quota exceeded for tablespace 'USERS'

可以发现建立表没有问题,这时不占用空间,一旦有数据插入,问题才会暴露出来!

总结:
    大概发现这些,也许还有许多特性与问题。

时间: 2024-08-01 10:05:30

[20111214]汇总11GR2 Deferred Segment Creation一些相关信息.txt的相关文章

Oracle 11gR2新特性--延迟段创建(Deferred Segment Creation)

Oracle 11gR2新特性--延迟段创建(Deferred Segment Creation) 真题1. 什么是延迟段创建(Deferred Segment Creation)? 答案:在Oracle 11.2中,当创建一个空表或者空分区时,为了加快创建速度,Oracle并不会立即分配初始段和空间,实际的表段(Table Segement)被延迟到第一行数据插入时创建.延迟段创建特性通过DEFERRED_SEGMENT_CREATION参数控制,默认为TRUE,表示开启该功能.延迟段创建可以

[20131109]deferred segment creation与12c的exp命令.txt

[20131109]deferred segment creation与12c的exp命令.txt 参考链接:http://space.itpub.net/267265/viewspace-713311 昨天想导出一些数据在自己的12c测试环境,发现具有段延迟建立特性的表使用exp也能导出. 例子如下: SCOTT@test01p> @ver BANNER                                                                       

[20130524]11G的Deferred segment creation的问题.txt

[20130524]11G的Deferred segment creation的问题.txt 11G的Deferred segment creation是一个非常好的特性,有这个特性也产生一些问题. 自己以前写的链接:http://space.itpub.net/267265/viewspace-716102http://space.itpub.net/267265/viewspace-695835http://space.itpub.net/267265/viewspace-713311htt

[20120927]deferred segment creation与system,sys用户.txt

[20120927]deferred segment creation与system,sys用户.txt 今天看了一篇blog,才知道sys,system用户不能使用deferred segment creation. http://blog.tanelpoder.com/2010/07/11/dropping-and-creating-tables-in-read-only-tablespaces-what/ 自己重复了测试: SQL> select * from v$version ; BA

php获取服务器操作系统相关信息的方法_php技巧

本文实例讲述了php获取服务器操作系统相关信息的方法.分享给大家供大家参考,具体如下: 下面是PHP获取当前服务器信息的基本语句. PHP程式版本: <?PHP echo PHP_VERSION; ?> ZEND版本: <?PHP echo zend_version(); ?> MYSQL支持: <?php echo function_exists (mysql_close)?"是":"否"; ?> MySQL数据库持续连接 :

[20130628]关于cursor pin S以及cursor pin S wait on X的相关问题.txt

[20130628]关于cursor pin S以及cursor pin S wait on X的相关问题.txt 生产系统最近一段时间总是出现cursor pin S wait on X,以前从来没有遇到,今天抽空看了一下.了解关于cursor pin S以及cursor pin S wait on X的相关问题,我看了一些链接: http://www.pythian.com/blog/cursor-pin-s-wait-on-x-in-the-top-5-wait-events/http:/

11gR2 新特性--待定的统计信息(Pending Statistic)

 11gR2 新特性--待定的统计信息(Pending Statistic) 11gr2开始,可以使用下面类型的操作来收集优化器统计信息:1.             自动发布收集的统计信息在收集操作结束以后(默认选项publish)2.             保存新的统计信息,并且待定(暂不发布pending) 这个特性可以将新收集的统计信息置为待定状态,所以可以先验证新统计信息的有效性然后再发布. 可以使用下面的命令来查看是否默认发布新的统计信息.sys@DAVID> SELECTDBMS

c++-本地电脑连接着设备,我想远程用C++编的控制软件控制这台设备,怎样才能获得这台设备的相关信息?

问题描述 本地电脑连接着设备,我想远程用C++编的控制软件控制这台设备,怎样才能获得这台设备的相关信息? 本地电脑连接着设备,我想远程用C++编的控制软件控制这台设备,怎样才能获得这台设备的相关信息? 解决方案 拿到设备相应的api接口即可,进行对应的编程控制. 解决方案二: http://blog.csdn.net/ouyang_linux007/article/details/7637141

通过runtime获取对象相关信息

通过runtime获取对象相关信息 在这里,本人给大家提供一个runtime关于NSObject的扩展,用来显示各种NSObject中的信息,这有助于你来分析类的组成:) 先准备以下类供测试: Model.h 与 Model.m // // Model.h // Runtime // // Copyright (c) 2014年 Y.X. All rights reserved. // #import <Foundation/Foundation.h> typedef enum : NSUIn