Documente Academic
Documente Profesional
Documente Cultură
and Histograms
DOs and DON Ts
Wolfgang Breitling
www.centrexcc.com
Who Am I
Independent Consultant since 1996
Specializing in Oracle and Peoplesoft Setup,
Administration, and Performance Tuning
Member of the Oaktable Network
30+ Years in Database Management
DL/1, IMS, ADABAS, SQL/DS, DB2, Oracle
Oracle since 1993 (7.0.12)
OCP Certified DBA - 7, 8, 8i, 9i
2
DOnts
Do not use ANALYZE ANYMORE
Do not use DBMS_UTILITY.ANALYZE_
{DATABASE | SCHEMA |PART_OBJECT}
DO
use DBMS_STATS.GATHER_xxx_STATS
from 11g on use auto_sample_size
in 10g or less
if you cant use estimate_percent 100,
estimate_percent=>100.
Effect Of Samplesize
OBJ# SAMPLESIZE
ROWCNT
BLKCNT ANALYZETIME
SAVE_TIME
------- ----------- --------- -------- ------------------- ------------------81504
39573017 39573017 1308033 2011-07-09 10:52:17 2011-07-16 10:54:15
81504
39698473 39698473 1316217 2011-07-16 10:54:15 2011-07-16 16:29:06
81504
7940776 39703880 1316217 2011-07-16 16:29:06 2011-07-23 10:53:36
81504
39815392 39815392 1316217 2011-07-23 10:53:36 2011-07-30 08:16:13
81504
7990753 39953765 1324401 2011-07-30 08:16:13 2011-07-30 10:58:37
OBJ# SAMPLESIZE
ROWCNT LVL LEAFCNT
DISTKEY LBLKKEY DBLKKEY
CLUFAC ANALYZETIME
SAVE_TIME
------- ---------- --------- ---- -------- --------- ------- ------- --------- ------------------- ------------------177197
432525 38212054
2
90202
16294
5
153
2507361 2011-07-09 10:52:18 2011-07-16 10:54:17
177197
451419 39881272
2
94266
16337
5
162
2660112 2011-07-16 10:54:17 2011-07-16 16:29:48
177197
7788338 38941690
2
92280
15622
5
162
2542045 2011-07-16 16:29:48 2011-07-23 10:53:37
177197
476255 42075445
2
100185
16369
6
173
2837600 2011-07-23 10:53:37 2011-07-30 08:16:40
177197
8132718 40663590
2
96885
15660
6
165
2598410 2011-07-30 08:16:40 2011-07-30 10:58:39
177225
177225
177225
177225
177225
199779
210652
8055319
215853
7981072
37600712
39647136
40276595
40626024
39905360
3
3
3
3
3
198563
210609
211595
216067
213145
1009304
1041176
225587
1021255
216277
1
1
1
1
1
15
16
73
16
76
15845153
16733511
16565200
16907983
16595720
2011-07-09
2011-07-16
2011-07-16
2011-07-23
2011-07-30
10:52:19
10:54:18
16:30:17
10:53:38
08:16:59
2011-07-16
2011-07-16
2011-07-23
2011-07-30
2011-07-30
10:54:18
16:30:17
10:53:38
08:16:59
10:58:39
Bind Peeking
A cursor will be moved out of the Shared Pool and therefore
subsequently requires a hard parse in a number of circumstances:
Database shutdown/restart
Cursor not in use by any session, and aged out by LRU algorithm
It will not get moved out by flushing the Shared Pool if it is
pinned (i.e. in use)
Change to the structure of any referenced object (e.g. alter table)
Granting/revoking privileges on a referenced object.
Change to the stats associated with any referenced object
(e.g. following a gather stats job).
However, that may not be immediate if no_invalidate is AUTO
10
export_table_stats
Since 10g whenever optimizer statistics are modified
using the DBMS_STATS package, old versions of the
statistics are saved automatically for future restoration,
so the above is not necessary
.
11
import_table_stats
DO delete object statistics before
importing them.
Always.
12
gather stale
other parameters specified will also be taken
does not gather statistics on objects which do not
have statistics. ( modifications can only be detected
relative to existing num_rows )
13
varchar2(n) n>32
command gathers incorrect num_distinct
in every release if the length of character column is
more than 32 bytes.
DBMS_STATS with METHOD_OPT => 'FOR ALL
COLUMNS SIZE 1' gathers correct num_distinct.
From 11g on, DBMS_STATS with
ANALYZE
>1)
15
16
Deleting Histograms
Prior to 11g there is no simple way to delete just the column
histogram statistics, leaving the basic column statistics, without
re-analyzing.
Workaround:
Use DBMS_STATS.GET_COLUMN_STATS to get all column stats,
change the bucket count in SREC to reflect no histogram and use
DBMS_STATS.SET_COLUMN_STATS to re-set them.
17
18
Wolfgang Breitling
breitliw@centrexcc.com