Oracle Performance Tuning – Improvement After Table Analyze

oracleoracle-11g-r2performanceperformance-tuning

I used a function that contains 3 tables a,b, and c. Table a has an index ind1 on two columns.

I call a stored procedure that contains code and gets data using the above function. I analyzed my session it gives a direct path read event, and produces output in 1 minute.

When I analyze the above 3 tables, the procedure runs faster and generates data within 10 seconds. What is table analyze and what causes this performance difference?

Best Answer

Oracle's optimiser is clever, it makes decisions about how best to do certain things (e.g. joins) based on what the contents of the tables are. At least, it can do if it knows what the contents of the tables are.

The optimiser uses table statistics to achieve this. If it knows that there is a particular type of data, or a particular distribution of values, or any number of different things going on in the table, it can change the way it executes the query that's being asked of it.

If there are no statistics, the optimiser has to guess or use defaults, and while the optimiser's defaults may be suitable or not matter that much at small volumes of data, when the volume of data in the table increases or the skew changes, this can make a huge difference to how quickly a query runs.

By analysing the tables, the statistics for the tables are rebuilt, and the optimiser has up-to-date information on what the contents of the table are, and can make more informed decisions.

Have a look here (http://docs.oracle.com/cd/E25054_01/server.1111/e16638/stats.htm) for Oracle's documentation on optimiser statistics.