首页 > 代码库 > 表压缩及并行提高效率的测试

表压缩及并行提高效率的测试

1、制作测试表

create table t1 as select * from FW_T_GTXLOG

insert into t1 select * from t1;

create table t2 compress as select * from t1

create table t3 as select * from t1

2、查看测试表数据量

select count(*) from t1;

select count(*) from t2;

select count(*) from t3;

3、查看测试表物理大小

SQL> select t.bytes/1024/1024/1024,t.blocks from dba_segments t where t.segment_name=‘T1‘;

T.BYTES/1024/1024/1024    BLOCKS

---------------------- ----------

    16.8876953G   2213504

Elapsed: 00:00:00.14

SQL> select t.bytes/1024/1024/1024,t.blocks from dba_segments t where t.segment_name=‘T2‘;

T.BYTES/1024/1024/1024    BLOCKS

---------------------- ----------

       13.0625G   1712128

Elapsed: 00:00:00.10

SQL> select t.bytes/1024/1024/1024,t.blocks from dba_segments t where t.segment_name=‘T3‘;

T.BYTES/1024/1024/1024    BLOCKS

---------------------- ----------

    16.8359375G   2206720

Elapsed: 00:00:00.09

4、查看测试表索引大小

SQL> select t.bytes/1024/1024/1024,t.blocks*8192 from dba_segments t where t.segment_name=‘IND_GUID_1‘;

T.BYTES/1024/1024/1024 T.BLOCKS*8192

---------------------- -------------

3.125   3355443200

Elapsed: 00:00:00.10

SQL> select t.bytes/1024/1024/1024,t.blocks*8192 from dba_segments t where t.segment_name=‘IND_GUID_2‘;

T.BYTES/1024/1024/1024 T.BLOCKS*8192

---------------------- -------------

      .5390625    578813952

Elapsed: 00:00:00.09

SQL> select t.bytes/1024/1024/1024,t.blocks*8192 from dba_segments t where t.segment_name=‘IND_GUID_3‘;

T.BYTES/1024/1024/1024 T.BLOCKS*8192

---------------------- -------------

      .5390625    578813952

Elapsed: 00:00:00.10

5、查看测试表定义语句

-- Create table T1

create table T1

(

GUID NVARCHAR2(32) not null,

  GTXID     NVARCHAR2(200),

  STARTTIME NVARCHAR2(32),

  SOURCETX  NUMBER(1),

  STATUS    NUMBER(1),

  ENDTIME   NVARCHAR2(32),

  DOMAIN    NVARCHAR2(50)

)

tablespace EFMIS

pctfree 10

initrans 1

maxtrans 255

storage

(

initial 64

next 8

minextents 1

maxextents unlimited

);

-- Create/Recreate indexes

create index IND_GUID_1 on T1 (GUID)

tablespace EFMIS

pctfree 10

initrans 2

maxtrans 255

storage

(

initial 64K

next 1M

minextents 1

maxextents unlimited

);

-- Create table T2

create table T2

(

GUID NVARCHAR2(32) not null,

  GTXID     NVARCHAR2(200),

  STARTTIME NVARCHAR2(32),

  SOURCETX  NUMBER(1),

  STATUS    NUMBER(1),

  ENDTIME   NVARCHAR2(32),

  DOMAIN    NVARCHAR2(50)

)

tablespace EFMIS

pctfree 0

initrans 1

maxtrans 255

storage

(

initial 64

next 8

minextents 1

maxextents unlimited

)

compress;  -------------------------------------------------------------------------------

-- Create/Recreate indexes

create index IND_GUID_2 on T2 (GUID)

tablespace EFMIS

pctfree 10

initrans 2

maxtrans 255

storage

(

initial 64K

next 1M

minextents 1

maxextents unlimited

)

compress; ---------------------------------------------------

-- Create table T3

create table T3

(

GUID NVARCHAR2(32) not null,

  GTXID     NVARCHAR2(200),

  STARTTIME NVARCHAR2(32),

  SOURCETX  NUMBER(1),

  STATUS    NUMBER(1),

  ENDTIME   NVARCHAR2(32),

  DOMAIN    NVARCHAR2(50)

)

tablespace EFMIS

pctfree 10

initrans 1

maxtrans 255

storage

(

initial 64

next 8

minextents 1

maxextents unlimited

);

-- Create/Recreate indexes

create index IND_GUID_3 on T3 (GUID)

tablespace EFMIS

pctfree 10

initrans 2

maxtrans 255

storage

(

initial 64K

next 1M

minextents 1

maxextents unlimited

)

compress;    ---------------------------------------------------------------------

6、收集3张表统计信息

begin

  dbms_stats.gather_table_stats(ownname          => ‘FASP_62‘,

                                tabname          => ‘T1‘,

                                estimate_percent => 30,

                                method_opt       => ‘FOR ALL COLUMNS SIZE 10‘,

degree => 4,

cascade => TRUE);

END;

7、测试具体查询语句效率:table access full

SQL> select count(*) from t1;

  COUNT(*)

----------

  37458112

Elapsed: 00:00:31.22

SQL> select count(*) from t2;

  COUNT(*)

----------

  37458112

Elapsed: 00:00:08.66

SQL> select count(*) from t3;

  COUNT(*)

----------

  37458112

Elapsed: 00:00:08.25

8、测试具体查询语句效率:index fasp full scan

SQL> select count(guid) from t1 where guid like ‘%BA92A682D9%‘;

COUNT(GUID)

-----------

32

Elapsed: 00:00:34.52

SQL> select count(guid) from t2 where guid like ‘%BA92A682D9%‘;

COUNT(GUID)

-----------

32

Elapsed: 00:00:18.27

SQL> select count(guid) from t3 where guid like ‘%BA92A682D9%‘;

COUNT(GUID)

-----------

32

Elapsed: 00:00:20.27

结论:t2\t3表的索引为压缩索引,从以上执行结果可知,索引重复率情况下,compress压缩对于select而言,具有一定的效果,提高速度一半以上。

9、结论

1、非唯一性索引可以建立compress索引。

create index IND_GUID_3 on T3 (GUID) tablespace EFMIS  compress;

2、可以通过以下命令查看索引或者表占据的硬盘容量:

select t.bytes/1024/1024/1024,t.blocks*8192 from dba_segments t where t.segment_name=‘IND_GUID_3‘;

技术分享

select t.bytes/1024/1024/1024,t.blocks*8192 from dba_segments t where t.segment_name=‘IND_GUID_1‘;

技术分享

以上sql查询出的索引大小与为压缩的索引大小相差悬殊,择证明压缩后可以提高查询效率。

表压缩及并行提高效率的测试