difference in space used
Ajeet, November 09, 2005 - 5:39 am UTC
Please allow me to ask this question here -this is not 100% related to thread but it is related to this thread somewhat.
I will describe the problem -start with table creation and data load scripts-
I have created 4 tables with exactly same structure except that -
Table T_CP is composite partitioned
Table T_P is composite partitioned
table t_p1 is compostie partitioned
table T_NP is not partitioned at all.
below is the table creation scripts and the script fot the tablespace I used - for the above tables.
create tablespace tts_ex4
datafile 'D:\ttsex4_01.dbf' size 3 m autoextend on next 2 m maxsize UNLIMITED
extent management local autoallocate
segment space management auto ;
create table t_cp(invoice_num number(9) NOT NULL,
invoice_qty number(9) not null,
invoice_amt number(14,2) not null,
fiscal_week number(2) not null,
fiscal_year number(4) not null
)
pctfree 10 pctused 80 INITRANS 1 MAXTRANS 255 TABLESPACE tts_ex4
partition by range (fiscal_year)
subpartition by list (fiscal_week)
SUBPARTITION TEMPLATE
(SUBPARTITION CWINVSCH_SUB01 VALUES (1),
SUBPARTITION CWINVSCH_SUB02 VALUES (2),
SUBPARTITION CWINVSCH_SUB03 VALUES (3),
SUBPARTITION CWINVSCH_SUB04 VALUES (4),
SUBPARTITION CWINVSCH_SUB05 VALUES (5),
SUBPARTITION CWINVSCH_SUB06 VALUES (6),
SUBPARTITION CWINVSCH_SUB07 VALUES (7),
SUBPARTITION CWINVSCH_SUB08 VALUES (8),
SUBPARTITION CWINVSCH_SUB09 VALUES (9),
SUBPARTITION CWINVSCH_SUB10 VALUES (10),
SUBPARTITION CWINVSCH_SUB11 VALUES (11),
SUBPARTITION CWINVSCH_SUB12 VALUES (12),
SUBPARTITION CWINVSCH_SUB13 VALUES (13),
SUBPARTITION CWINVSCH_SUB14 VALUES (14),
SUBPARTITION CWINVSCH_SUB15 VALUES (15),
SUBPARTITION CWINVSCH_SUB16 VALUES (16),
SUBPARTITION CWINVSCH_SUB17 VALUES (17),
SUBPARTITION CWINVSCH_SUB18 VALUES (18),
SUBPARTITION CWINVSCH_SUB19 VALUES (19),
SUBPARTITION CWINVSCH_SUB20 VALUES (20),
SUBPARTITION CWINVSCH_SUB21 VALUES (21),
SUBPARTITION CWINVSCH_SUB22 VALUES (22),
SUBPARTITION CWINVSCH_SUB23 VALUES (23),
SUBPARTITION CWINVSCH_SUB24 VALUES (24),
SUBPARTITION CWINVSCH_SUB25 VALUES (25),
SUBPARTITION CWINVSCH_SUB26 VALUES (26),
SUBPARTITION CWINVSCH_SUB27 VALUES (27),
SUBPARTITION CWINVSCH_SUB28 VALUES (28),
SUBPARTITION CWINVSCH_SUB29 VALUES (29),
SUBPARTITION CWINVSCH_SUB30 VALUES (30),
SUBPARTITION CWINVSCH_SUB31 VALUES (31),
SUBPARTITION CWINVSCH_SUB32 VALUES (32),
SUBPARTITION CWINVSCH_SUB33 VALUES (33),
SUBPARTITION CWINVSCH_SUB34 VALUES (34),
SUBPARTITION CWINVSCH_SUB35 VALUES (35),
SUBPARTITION CWINVSCH_SUB36 VALUES (36),
SUBPARTITION CWINVSCH_SUB37 VALUES (37),
SUBPARTITION CWINVSCH_SUB38 VALUES (38),
SUBPARTITION CWINVSCH_SUB39 VALUES (39),
SUBPARTITION CWINVSCH_SUB40 VALUES (40),
SUBPARTITION CWINVSCH_SUB41 VALUES (41),
SUBPARTITION CWINVSCH_SUB42 VALUES (42),
SUBPARTITION CWINVSCH_SUB43 VALUES (43),
SUBPARTITION CWINVSCH_SUB44 VALUES (44),
SUBPARTITION CWINVSCH_SUB45 VALUES (45),
SUBPARTITION CWINVSCH_SUB46 VALUES (46),
SUBPARTITION CWINVSCH_SUB47 VALUES (47),
SUBPARTITION CWINVSCH_SUB48 VALUES (48),
SUBPARTITION CWINVSCH_SUB49 VALUES (49),
SUBPARTITION CWINVSCH_SUB50 VALUES (50),
SUBPARTITION CWINVSCH_SUB51 VALUES (51),
SUBPARTITION CWINVSCH_SUB52 VALUES (52),
SUBPARTITION CWINVSCH_SUB53 VALUES (53),
SUBPARTITION CWINVSCH_SUBmax VALUES (default)
)
(PARTITION CWINVSCH_1999 VALUES LESS THAN ( 2000),
PARTITION CWINVSCH_2000 VALUES LESS THAN ( 2001),
PARTITION CWINVSCH_2001 VALUES LESS THAN ( 2002),
PARTITION CWINVSCH_2002 VALUES LESS THAN ( 2003),
PARTITION CWINVSCH_2003 VALUES LESS THAN ( 2004),
PARTITION CWINVSCH_2004 VALUES LESS THAN ( 2005),
PARTITION CWINVSCH_2005 VALUES LESS THAN (2006),
PARTITION CWINVSCH_2006 VALUES LESS THAN ( 2007),
PARTITION CWINVSCH_max VALUES LESS THAN ( maxvalue)
);
then
create table t_p(invoice_num number(9) NOT NULL,
invoice_qty number(9) not null,
invoice_amt number(14,2) not null,
fiscal_week number(2) not null,
fiscal_year number(4) not null
)
pctfree 10 pctused 80 INITRANS 1 MAXTRANS 255 TABLESPACE tts_ex4
partition by range (fiscal_year)
subpartition by list (fiscal_week)
SUBPARTITION TEMPLATE
(SUBPARTITION CWINVSCH_SUB01 VALUES (1,2,3,4,5,6,7,8,9,10,11,12,13),
SUBPARTITION CWINVSCH_SUB02 VALUES (14,15,16,17,18,19,20,21,22,23,24,25,26),
SUBPARTITION CWINVSCH_SUB03 VALUES (27,28,29,30,31,32,33,34,35,36,37,38,39),
SUBPARTITION CWINVSCH_SUB04 VALUES (40,41,42,43,44,45,46,47,48,49,50,51,52,53),
SUBPARTITION CWINVSCH_SUBmax VALUES (default)
)
(PARTITION CWINVSCH_1999 VALUES LESS THAN ( 2000),
PARTITION CWINVSCH_2000 VALUES LESS THAN ( 2001),
PARTITION CWINVSCH_2001 VALUES LESS THAN ( 2002),
PARTITION CWINVSCH_2002 VALUES LESS THAN ( 2003),
PARTITION CWINVSCH_2003 VALUES LESS THAN ( 2004),
PARTITION CWINVSCH_2004 VALUES LESS THAN ( 2005),
PARTITION CWINVSCH_2005 VALUES LESS THAN (2006),
PARTITION CWINVSCH_2006 VALUES LESS THAN ( 2007),
PARTITION CWINVSCH_max VALUES LESS THAN ( maxvalue)
);
--
create table t_p1(invoice_num number(9) NOT NULL,
invoice_qty number(9) not null,
invoice_amt number(14,2) not null,
fiscal_week number(2) not null,
fiscal_year number(4) not null
)
pctfree 10 pctused 80 INITRANS 1 MAXTRANS 255 TABLESPACE tts_ex4
partition by range (fiscal_year,fiscal_week)
(PARTITION CWINVSCH_1999 VALUES LESS THAN ( 2000,53),
PARTITION CWINVSCH_2000 VALUES LESS THAN ( 2001,53),
PARTITION CWINVSCH_2001 VALUES LESS THAN ( 2002,53),
PARTITION CWINVSCH_2002 VALUES LESS THAN ( 2003,53),
PARTITION CWINVSCH_2003 VALUES LESS THAN ( 2004,53),
PARTITION CWINVSCH_2004 VALUES LESS THAN ( 2005,53),
PARTITION CWINVSCH_2005 VALUES LESS THAN (2006,53),
PARTITION CWINVSCH_2006 VALUES LESS THAN ( 2007,53),
PARTITION CWINVSCH_max VALUES LESS THAN ( maxvalue,maxvalue)
);
create table t_np(invoice_num number(9) NOT NULL,
invoice_qty number(9) not null,
invoice_amt number(14,2) not null,
fiscal_week number(2) not null,
fiscal_year number(4) not null
)
pctfree 10 pctused 80 INITRANS 1 MAXTRANS 255 TABLESPACE tts_ex4
;
then I load data into the above tables using the following scripts -
(changed the table name for each table)
begin
for x in (select rownum r from all_objects where rownum <= 53) loop
insert /*+ append */ into t_cp
select rownum ,rownum*x.r ,rownum*x.r*10,x.r,'2002'
from all_objects where rownum <=101;
commit ;
end loop ;
for x in (select rownum r from all_objects where rownum <= 53) loop
insert /*+ append */ into t_cp
select rownum ,rownum*x.r ,rownum*x.r*10,x.r,'2003'
from all_objects where rownum <=101;
commit ;
end loop ;
for x in (select rownum r from all_objects where rownum <= 53) loop
insert /*+ append */ into t_cp
select rownum ,rownum*x.r ,rownum*x.r*10,x.r,'2004'
from all_objects where rownum <= 101 ;
commit ;
end loop ;
for x in (select rownum r from all_objects where rownum <= 53) loop
insert /*+ append */ into t_cp
select rownum ,rownum*x.r ,rownum*x.r*10,x.r,'2005'
from all_objects where rownum <= 101 ;
commit ;
end loop ;
end ;
/
then i run the dbms_stats on each of the 4 tables after the load of data...
using ..
begin
dbms_stats.gather_table_stats
( ownname => user,estimate_percent => 5,
tabname => 'T_CP',
method_opt => 'FOR ALL INDEXED COLUMNS size 1',
degree=>4,granularity=>'ALL',cascade=>TRUE );
end;
/
Now when I run this query -i got the results below :
ngta3zt@EVNODSD2> select table_name,blocks from user_tables where table_name in
('T_CP','T_P','T_P1', 'T_NP')
2 /
TABLE_NAME BLOCKS
------------------------------ ----------
T_CP 848
T_NP 224
T_P 264
T_P1 239
My first question is why the space used by these tables are so different -specially for the table T_CP - blocks are very high with respect to other tables in question ?
is it due to number of segments used by this table ?
my database is oracle 9i and block size is 8K.
then when I compress the above tables and run the dbms_stats again - i got the following results
ngta3zt@EVNODSD2> select table_name,blocks from user_tables where table_name in
2 ('T_CP','T_P','T_P1', 'T_NP');
TABLE_NAME BLOCKS
------------------------------ ----------
T_CP 848
T_NP 54
T_P 100
T_P1 64
To compress the subpartitioned table i use :
alter table t_cp compress ;
begin
for x in ( select * from user_tab_subpartitions where table_name = 'T_CP' )
loop
execute immediate 'alter table T_CP move subpartition ' || x.subpartition_name ;
end loop;
end;
/
to compress the partition table -i do the same thing except that i do a move partition...in the above script.
my questiones are again -
1. why there are so much difference in the space used by these tables - even they have same amount of data .
2. will the savings of space in a subpartitioned table will be less than the partitioned table -- assume that i can have the same table either partitioned or subpartitioned.
thanks again
Ajeet
November 10, 2005 - 5:16 pm UTC
each partition will have at least one extent - your tables have many different number of partitions (segments). Especially the first.
This accounts for the differences in sizes - a partition is a segment, a segment consumes some amount of space, the more partitions, the more 'wastage' you potentially observe.