Home > Oracle Tips > Oracle Database Administrator > Improving performance with histograms
Oracle Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ORACLE DATABASE ADMINISTRATOR

Improving performance with histograms


James Giordano
08.02.2001
Rating: --- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


When dealing with a table that has highly skewed data distribution, histograms are an excellent way to improve performance by getting the optimizer to choose your index.

Recently I was tuning some SQL that used a column to flag whether a row should be processed or not. For example the table had a column called JOB_ID, 99% of the million rows in the table had a value of 0, and the other 1% of the rows had a JOB_ID of the PID of the job processing the data. There was an index built on JOB_ID, but the optimizer wouldn't use the index, because the cardinality of the index was so poor. In this case a histogram helped to get the optimizer to use the index. Histograms are created using the "FOR COLUMNS" option of the analyze command. For example, I used:

  ANALYZE TABLE INVENTORY_COST ESTIMATE STATISTICS SAMPLE 20 PERCENT FOR
 COLUMNS JOB_ID SIZE 10;

Determining where histograms are used in your database is a little tricky because Oracle considers all cost-based statistics as histograms, so if you look in DBA_HISTOGRAMS, you will find 2 rows for every table in the database. I have been using the following query to determine what table have histograms:

  select 
    distinct TABLE_NAME, COLUMN_NAME 
  from 
    dba_histograms 
  where 
    endpoint_number not in (1,0) 
  order by table_name, column_name ;

Follow-up note

After this tip was published, member Zach Friese offered this feedback: "Histograms are indeed very useful for addressing the problem of getting the optimizer to use a low cardinality index when the data distribution is skewed. However, this tip neglected a very important detail: the fact that histograms can only be used by the optimizer when literal variables are used in the sql, and not when bound variables are used. Given that many DBA's go to great lengths to encourage the use of bound variables due to the benefits of sharing sql in the shared pool, they also need to be aware of this one time when bound variables are not your friends.

About the Author

James Giordano is an Oracle database administrator. He has been working with Oracle for about seven years, and also has experience with UNIX and PeopleSoft/Oracle financials.

For More Information

  • What do you think about this tip? E-mail us at editor@searchDatabase.com with your feedback.
  • The Best SQL Web Links: tips, tutorials, scripts, and more.
  • Have an SQL tip to offer your fellow DBA's? The best tips submitted will receive a cool prize--submit your tip today!
  • Ask your technical SQL questions--or help out your peers by answering them--in our live discussion forums.
  • Check out our Ask the Experts feature: Our SQL, Database Design, Oracle, SQL Server, and DB2 gurus are waiting to answer your toughest questions.

Rate this Tip
To rate tips, you must be a member of SearchOracle.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
Oracle Database Administrator
What is the difference between a database engineer, architect and administrator?
Import on one table from dump file
Error during RMAN backup
Can I drop a column in SYS schema?
STATSPACK tool: transaction vs. execution measurement
Should I port from Microsoft Access?
Installing multiple Oracle homes
How can I find statistics on total memory usage and database connections?
Modifying SYS password in a RAC environment
How to create Datafiles in a Data Guard (10g) environment

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.

HomeNewsTopicsTipsAsk the ExpertsMultimediaWhite PapersProductsBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2003 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts