Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: Creating Histograms
Hi Donald I was in the same process, for the advanced tuning course I'm
doing, t his is what I found, I hope be useful, but what I found, is that
CBO is smarter (or bugged) and in more than one test I couldn't get to use
the histogram.
Any comment about this will be appreciated.
>From my new (and more serious ) paper, not like the previous
1.A Histograms
Histograms could affect nevatively performance, you have to verify they have
a positive effect in your system.
To create histograms you execute the following command, the size parameter
specifies the number of buckets, depending of the amount of distinct values
you give distinct value to bucket.
EXEC DBMS_STATS.GATHER_TABLE_STATS ('scott','emp', METHOD_OPT => 'FOR
COLUMNS SIZE 10 sal');
You can view histogram information with the following views DBA_HISTOGRAMS,
DBA_PART_HISTOGRAMS, DBA_SUBPART_HISTOGRAMS, DBA_TAB_COLSTATISTICS
1.A.i Bucket Size
Oracle divides the distinct value in bands, called buckets.
>From Documentation
“If the number of frequently occurring distinct values in a column is
relatively small, then set the number of buckets to be greater than that
number. The default number of buckets for a histogram is 75, This valuesp
rovides an appropiate level of detail for most data distributions however,
because the number of buckets in the histograms, and the data distribution,
bot affect a histogram’s usefulness, you might need to experiment with
different number of buckets to obtain optimal results.”
For example
We will create a test table, gather statistics and create two groups one
small of 3 records and other of 88713 records, we will run a test with and
without histograms.
create table test as
select * from dba_objects UNION ALL select * from dba_objects UNION ALL select * from dba_objects;
SQL> UPDATE TEST SET OWNER = 'XXX' WHERE NOT OWNER = 'CACHITO'; SQL> COMMIT; SQL> SELECT OWNER,COUNT(*) FROM TEST GROUP BY OWNER;OWNER COUNT(*)
SQL> EXEC DBMS_STATS.GATHER_TABLE_STATS ('ADM','TEST', METHOD_OPT => 'FOR
COLUMNS SIZE 75 OWNER');
Procedimiento PL/SQL terminado correctamente.
SQL> SELECT NUM_BUCKETS FROM DBA_TAB_COL_STATISTICS WHERE OWNER = 'ADM' AND
TABLE_NAME = 'TEST' AND COLUMN_NAME = 'OWNER';
As you can see there is only one bucket, because there are too few values in
the column.
NUM_BUCKETS
Now we will try again
SQL> SELECT * FROM TEST WHERE OWNER = 'CACHITO';
Execution Plan
SQL> SELECT * FROM TEST WHERE OWNER = 'XXX'; Execution Plan
Maybe this is a error in the CBO, so we will force a full scan in the table
SQL> SELECT /*+ FULL(TEST) */ * FROM TEST WHERE OWNER = 'XXX';
88713 filas seleccionadas.
Execution Plan
But it seems not to be, a full scan cost 40 more, so it seems this is not a
good place to use histograms.-
Meanwhile the CBO is becoming smarter, the more test one have to develop to
verify the things one do, are really improving the performance.
More about histograms you can read
http://www.dba-oracle.com/art_otn_cbo_p4.htm
-- Archives are at http://www.freelists.org/archives/oracle-l/ FAQ is at http://www.freelists.org/help/fom-serve/cache/1.htmlReceived on Wed Jul 21 2004 - 13:12:36 CDT
-----------------------------------------------------------------
![]() |
![]() |