You are on page 1of 4

OWNER

TABLE_NAME
------------------------------ -----------------------------WEBFOCUS.GRS_TLN_FIN_INVOICE_EXTRACT
WEBFOCUS.REP_WP_POSTED_RECAP
WEBFOCUS.GRS_TLN_FIN_EVENT_JOURNAL
select TABLE_NAME,NUM_ROWS from dba_tables where lower(table_name) in ('grs_tln_
fin_invoice_extract','grs_tln_fin_event_journal','rep_wp_posted_recap');
TABLE_NAME
NUM_ROWS
------------------------------ ---------GRS_TLN_FIN_INVOICE_EXTRACT
56292473
REP_WP_POSTED_RECAP
136440085
GRS_TLN_FIN_EVENT_JOURNAL
1282738
SQL> select SEGMENT_NAME,(BYTES/1024/1024) FROM dba_segments where lower(SEGMENT
_NAME) IN ('grs_tln_fin_invoice_extract','grs_tln_fin_event_journal','rep_wp_pos
ted_recap');
SEGMENT_NAME
----------------REP_WP_POSTED_RECAP

SIZE IN MB
-----------54424.875

GRS_TLN_FIN_INVOICE_EXTRACT

34676

GRS_TLN_FIN_EVENT_JOURNAL

121

COMPRESSION_RATIO('WEBFOCUS.GRS_TLN_FIN_INVOICE_EXTRACT')
--------------------------------------------------------4.04483837
SQL> select compression_ratio('WEBFOCUS.REP_WP_POSTED_RECAP') from dual;
COMPRESSION_RATIO('WEBFOCUS.REP_WP_POSTED_RECAP')
------------------------------------------------6.67687075

create or replace function compression_ratio (tabname varchar2)


return number is
pragma autonomous_transaction;
-- sample percentage
pct number := 0.000099;
-- original block count (should be less than 10k)
blkcnt number := 0;
-- compressed block count
blkcntc number;
begin
execute immediate ' create table TEMP_UNCOMPRESSED pctfree 0
as select * from ' || tabname ||
' where rownum < 1';
while ((pct < 100) and (blkcnt < 1000)) loop
execute immediate 'truncate table TEMP_UNCOMPRESSED';
execute immediate 'insert into TEMP_UNCOMPRESSED select * from ' ||
tabname || ' sample block (' || pct || ',10)';

execute immediate 'select


count(distinct(dbms_rowid.rowid_block_number(rowid)))
from TEMP_UNCOMPRESSED' into blkcnt;
pct := pct * 10;
end loop;
execute immediate 'create table TEMP_COMPRESSED compress as
select * from TEMP_UNCOMPRESSED';
execute immediate 'select
count(distinct(dbms_rowid.rowid_block_number(rowid)))
from TEMP_COMPRESSED' into blkcntc;
execute immediate 'drop table TEMP_COMPRESSED';
execute immediate 'drop table TEMP_UNCOMPRESSED';
return (blkcnt/blkcntc);
end;
/

===============================WORK DONE ON PRODUCTION=====================


Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn / as sysdba;
Connected.
SQL> select owner,table_name from dba_tables where lower(table_name) in ('grs_t
ln_fin_invoice_extract','grs_tln_fin_event_journal','rep_wp_posted_recap');
OWNER
-----------------------------WEBFOCUS
WEBFOCUS
WEBFOCUS

TABLE_NAME
-----------------------------GRS_TLN_FIN_INVOICE_EXTRACT
REP_WP_POSTED_RECAP
GRS_TLN_FIN_EVENT_JOURNAL

SQL> select TABLE_NAME,NUM_ROWS from dba_tables where lower(table_name) in ('grs


_tln_fin_invoice_extract','grs_tln_fin_event_journal','rep_wp_posted_recap');
TABLE_NAME
NUM_ROWS
------------------------------ ---------GRS_TLN_FIN_INVOICE_EXTRACT
56292473
REP_WP_POSTED_RECAP
136440085
GRS_TLN_FIN_EVENT_JOURNAL
1282738
SQL> select SEGMENT_NAME,(BYTES/1024/1024) FROM dba_segments where lower(SEGMENT
_NAME) IN ('grs_tln_fin_invoice_extract','grs_tln_fin_event_journal','rep_wp_pos
ted_recap');
SEGMENT_NAME
-------------------------------------------------------------------------------(BYTES/1024/1024)
----------------REP_WP_POSTED_RECAP
54424.875
GRS_TLN_FIN_INVOICE_EXTRACT
34676

GRS_TLN_FIN_EVENT_JOURNAL
121
SQL>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

create or replace function compression_ratio (tabname varchar2)


return number is
pragma autonomous_transaction;
-- sample percentage
pct number := 0.000099;
-- original block count (should be less than 10k)
blkcnt number := 0;
-- compressed block count
blkcntc number;
begin
execute immediate ' create table TEMP_UNCOMPRESSED pctfree 0
as select * from ' || tabname ||
' where rownum < 1';
while ((pct < 100) and (blkcnt < 1000)) loop
execute immediate 'truncate table TEMP_UNCOMPRESSED';
execute immediate 'insert into TEMP_UNCOMPRESSED select * from ' ||
tabname || ' sample block (' || pct || ',10)';
execute immediate 'select
count(distinct(dbms_rowid.rowid_block_number(rowid)))
from TEMP_UNCOMPRESSED' into blkcnt;
pct := pct * 10;
end loop;
execute immediate 'create table TEMP_COMPRESSED compress as
select * from TEMP_UNCOMPRESSED';
execute immediate 'select
count(distinct(dbms_rowid.rowid_block_number(rowid)))
from TEMP_COMPRESSED' into blkcntc;
execute immediate 'drop table TEMP_COMPRESSED';
execute immediate 'drop table TEMP_UNCOMPRESSED';
return (blkcnt/blkcntc);
end;
/

Function created.
SQL> select compression_ratio('WEBFOCUS.GRS_TLN_FIN_INVOICE_EXTRACT') from dual;
COMPRESSION_RATIO('WEBFOCUS.GRS_TLN_FIN_INVOICE_EXTRACT')
--------------------------------------------------------4.04483837
SQL> select compression_ratio('WEBFOCUS.REP_WP_POSTED_RECAP') from dual;
COMPRESSION_RATIO('WEBFOCUS.REP_WP_POSTED_RECAP')
------------------------------------------------6.67687075
SQL> select compression_ratio('WEBFOCUS.GRS_TLN_FIN_EVENT_JOURNAL') from dual;
COMPRESSION_RATIO('WEBFOCUS.GRS_TLN_FIN_EVENT_JOURNAL')
------------------------------------------------------1.875
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64
bit Production

With the Partitioning, OLAP and Data Mining options


bash-3.00$ sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Mar 19 16:31:34 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn / as sysdba;
Connected.
SQL> drop function compression_ratio;
Function dropped.
SQL>
================================================================================
========================s

You might also like