Oracle training, SQL tutorials, Oracle tutorials  and Oracle consulting

 

For Better, Faster, Smarter, Oracle Solutions

 

SQL Tutorial - Hints And Tips To OptimiseYour SQL (ctd)

4. Use Selective Indexes

Ensure that tables are accessed via selective indexes, unless the table is very small or very large, in which case it may be better not to use the indexes.

If the table were very small it could be cached completely, or all the columns could be indexed which means only the index would have to be read to satisfy any query.

Also make sure that you're not disabling the use of an index by:-

 

 

 

 

 

 



5. Use Full-Table Scans

If the table is very large, depending on how many blocks are read, using an index may remove everything else from the buffer cache and degrade the performance of all other queries. In which case a full-table scan is better - only the last few blocks read are kept in the buffer cache.

6. Optimise Joins

The final tip for this short tutorial is:

7. Name The Columns In A Query

There are three good reasons why it is better to name the columns in a query rather than to use "select * from ...".

  1. Network traffic is reduced. This can have a significant impact on performance if the table has a large number of columns, or the table has a long or long raw column or have in-line clob or blob columns (all of which can be up to 2 Gigabytes in length). These types of columns will take a long time to transfer over the network and so they should not be fetched from the database unless they are specifically required.
  2. The code is easier to understand, which means you need fewer comments!
  3. It could save the need for changes in the future. If you are using views, not only might columns be added to or removed from the view, but the order of the columns could well change - in which case using "SELECT *" at best would fetch the wrong data and at worst would fail with an Oracle error which might take a long while to understand.

This tutorial just scratches the surface of the subject, for more help see our Advanced SQL Tutorial

---------------------------------------

Subscribe to our Oracle ezine and sky-rocket your performance.

Smartsoft Computing Ltd
Bristol, England

Tel: 0845 0031320

Contact Us

Click here to view our privacy policy .

This site uses hitslink.com to gather statistical information about our visitors. View hitslink privacy policy .

Oracle is a registered trademark of Oracle Corporation and/or its affiliates. UNIX is a registered trademark of The Open Group in the United States and other countries.

© Copyright Smartsoft Computing Ltd 2001-2008. All rights reserved.


Search for: