log;
SET DEF ON TERM OFF ECHO ON;
CL TIMI;
REM
REM $Header: coe_siebel_stats.sql 11.4.4.5 2012/05/17 carlos.sierra $
REM
REM Copyright (c) 1990-2012, Oracle. All rights reserved.
REM
REM The Programs (which include both the software and documentation) contain
REM proprietary information; they are provided under a license agreement contain
ing
REM restrictions on use and disclosure and are also protected by copyright, pate
nt,
REM and other intellectual and industrial property laws. Reverse engineering,
REM disassembly, or decompilation of the Programs, except to the extent required
to
REM obtain interoperability with other independently created software or as spec
ified
REM by law, is prohibited.
REM
REM Oracle, JD Edwards, PeopleSoft, and Siebel are registered trademarks of
REM Oracle Corporation and/or its affiliates. Other names may be trademarks
REM of their respective owners.
REM
REM If you have received this software in error, please notify Oracle Corporatio
n
REM immediately at 1.800.ORACLE1.
REM
REM AUTHOR
REM carlos.sierra@oracle.com
REM
REM SCRIPT
REM coe_siebel_stats.sql
REM
REM DESCRIPTION
REM Collects schema object statistics for Siebel on 10g and 11g.
REM
REM PARAMETERS
REM 1. Proces Type: (N)ormal or (B)ase Line. Default N.
REM 2. Auto Execute: (N)o or (Y)es. Default N.
REM 3. Schema Owner: Default SIEBEL.
REM
REM EXECUTION
REM 1. When executed for the first time, connect into SQL*Plus as SYSDBA
REM
and use baseline process type:
REM
# sqlplus / as sysdba
REM
SQL> START coe_siebel_stats.sql B Y SIEBEL
REM
or
REM
SQL> START coe_siebel_stats.sql B N SIEBEL
REM 2. After first execution (baseline), use daily as a script or PL/SQL libra
ry.
REM
2.1 Executed daily as a script:
REM
# sqlplus / as sysdba
REM
SQL> START coe_siebel_stats.sql N Y SIEBEL
REM
2.2 Executed as a PL/SQL library (scheduled daily through a job):
REM
siebel_stats.gather_siebel_stats;
REM
or
REM
siebel_stats.gather_siebel_stats('SIEBEL', 'N');
REM
REM NOTES
error
VARCHAR2(4000) );
table_count := table_count + 1;
-- count up to 101 rows for each table
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM "'||i.owner||'"."'||i.table_name||
'" WHERE ROWNUM <= 101' INTO num_rows;
IF p_commands_only = 'N' THEN
PIPE ROW('--'||CHR(10)||'-- '||table_count||' '||i.owner||'.'||i.table_n
ame||' temp='||i.temporary||' part='||i.partitioned||' rows='||i.num_rows||' anl
z='||i.last_analyzed||' lock='||i.stattype_locked||' stale='||i.stale_stats||' c
ount='||num_rows);
END IF;
IF i.temporary = 'Y' OR num_rows <= l_rows_threshold THEN -- small or temp
orary tables should have no stats
IF i.num_rows IS NOT NULL OR i.last_analyzed IS NOT NULL THEN -- if they
have stats then delete and lock them
IF i.stattype_locked IS NOT NULL THEN -- unlock first, but only if the
y were locked
PIPE ROW(l_exec||'DBMS_STATS.UNLOCK_TABLE_STATS(''"'||i.owner||'"'',
''"'||i.table_name||'"'');');
END IF;
-- delete stats and lock them
PIPE ROW(l_exec||'DBMS_STATS.DELETE_TABLE_STATS(''"'||i.owner||'"'', '
'"'||i.table_name||'"'', force => TRUE);');
PIPE ROW(l_exec||'DBMS_STATS.LOCK_TABLE_STATS(''"'||i.owner||'"'', ''"
'||i.table_name||'"'');');
ELSIF i.stattype_locked IS NULL THEN -- lock stats if they were empty bu
t unlocked
PIPE ROW(l_exec||'DBMS_STATS.LOCK_TABLE_STATS(''"'||i.owner||'"'', ''"
'||i.table_name||'"'');');
END IF;
ELSE -- bigger tables (num_rows > rows_threshold)
IF num_rows > 100 THEN
IF i.num_rows IS NULL OR i.last_analyzed IS NULL THEN -- no stats, the
n count rows (sample 1%)
EXECUTE IMMEDIATE 'SELECT COUNT(*) * 100 FROM "'||i.owner||'"."'||i.
table_name||'" SAMPLE(1)' INTO num_rows;
ELSE -- use num rows from prior stats gathering
num_rows := i.num_rows;
END IF;
END IF;
ency :=
ency :=
ency :=
ency :=
ency :=
size
'100'; frequ
'30'; frequ
'10'; frequ
'3'; frequ
'1'; frequ
-- if 11g then use auto sample size instead (ok only if gathering with n
o histograms)
-- this part has been eliminated due to bug 10174050: AUTO_SAMPLE_SIZE i
s causing some histograms to miss important buckets
tc.column_name
sys.dba_tab_cols tc
tc.owner = i.owner
tc.table_name = i.table_name
tc.last_analyzed IS NOT NULL
NOT EXISTS (
NULL
sys.dba_ind_columns ic
ic.table_owner = tc.owner
ic.table_name = tc.table_name
ic.column_name = tc.column_name)
BY
tc.column_id ASC NULLS LAST,
tc.column_name)
LOOP
PIPE ROW(l_exec||'DBMS_STATS.DELETE_COLUMN_STATS(''"'||i.owner||'"
'', ''"'||i.table_name||'"'', ''"'||j.column_name||'"'', no_invalidate => TRUE);
');
END LOOP;
END IF;
PIPE ROW(l_exec||'DBMS_STATS.GATHER_TABLE_STATS(''"'||i.owner||'"'', '
SET FEED OFF VER OFF SHOW OFF HEA OFF LIN 2000 NEWP NONE PAGES 0 TRIMS ON TIM OF
F NUMF "" RECSEP OFF SERVEROUT ON SIZE 1000000 FOR TRU;
SPO coe_gather_statistics.sql;
SELECT * FROM TABLE(siebel_stats.gather_siebel_stats(:schema_owner, :process_typ
e));
SPO coe_driver.sql;
BEGIN
IF :auto_execute = 'Y' THEN
DBMS_OUTPUT.PUT_LINE('PRO executing coe_gather_statistics.sql');
DBMS_OUTPUT.PUT_LINE('START coe_gather_statistics.sql');
ELSE
DBMS_OUTPUT.PUT_LINE('PRO review coe_gather_statistics.sql');
END IF;
END;
/
SPO OFF;
UNDEFINE default_rows_threshold default_schema_owner 1 process_type 2 auto_execu
te 3 schema_owner
SET DEF ON TERM ON ECHO OFF FEED 6 VER ON SHOW OFF HEA ON LIN 80 NEWP 1 PAGES 14
TRIMS OFF TIM OFF NUMF "" RECSEP WR SERVEROUT OFF;
WHENEVER SQLERROR CONTINUE;
START coe_driver.sql;