Saturday, July 31, 2010

Faster SQL performance with dbms_stats

While executing a SQL Query, the execution plan determines the best way to retrieve the data most efficiently. For Oracle, there are many way to retrieve the data from a SQL Query, like which index need to be use, order of joins to be performed and which internal join methods to be use like, hash joins, star joins, and sort merge join, etc. These execution plans are computed by the Oracle’s Cost-Based Optimizer, widely known as CBO.

The choice of executions plans made by the Oracle SQL Optimizer is only as good as the Oracle statistics. Always choose the best execution plan for a SQL query, Oracle depends on information about the tables and indexes in the query.

Using dbms_stats package, Oracle provides a simple way for the Oracle developer to collect statistics for the CBO. The dbms_stats utility does a far better job in estimating statistics, especially for large partitioned tables, and the better stats results in faster SQL execution plans.

The old-fashioned method is Analyzing a table and using methods of dbms_utility to generating CBO statistics are obsolete and somewhat dangerous to SQL performance because they don't always capture high-quality information about tables and indexes. The CBO determines using the the object statistics to choose the best execution plan for all SQL Queries.

The dbms_stats utility does a far better job in estimating statistics, especially for large partitioned tables, and the better stats result in faster SQL execution plans.

Tuesday, December 15, 2009

What is the difference between table & View?

View is a virtual table made of one or tables of the database using complex/simple join logic. The view has some useful purposes. Some are as under:

1. Simplification of database:

A schema may have hundreds of tables. Applications can be simplified if they can access predefined views which embed complex join logic.

2. Easy Maintenance:

Views can contain complex column expressions that are transparent in the views. Changes to these expressions need only be made in the view.

3. Change management:

Views can reduce maintenance to the application as they can hide schema changes that affect the view's query.

4. Security purpose:

Views can embed selection logic and present a subset of a table's content. You can create additional schema that contains just views of the main schema, limiting what may be accessed. Different user groups enter through one of these other schema, each group having a different view of the overall database.