Free Newsletters:
Database Journal  
DBAnews  

DBASupport

 The Knowledge Center for Oracle Professionals

Search DBAsupport:
 
HOME 11g Central 10g Central 9i Central 8i Central Oracle News Scripts FAQ OCP Zone Resources Technical Docs Tools & Utilities Forums
internet.com

» HOME
» FEATURES
    11g Central
    10g Central
    9i Central
    8i Central
    Oracle News
» COMMUNITY
    Scripts
    Forums
    FAQ
    OCP Zone
» RESOURCES
    Resources
    Technical Docs
    Tools & Utilities
    Tech Jobs


internet.commerce
Be a Commerce Partner
Find Project Software
KVM Switch over IP
Find Software
Shop Online
Promotional Pens
Promotional Products
Car Donations
Home Improvement
Cell Phones
Compare Prices


internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


   DBAsupport.com > Oracle > Oracle 9i Central > Featured Stories


Solaris 8 Migration Assistant
Rapidly move your Solaris 8 application environments to new systems running Solaris 10 with the Solaris 8 Migration Assistant. Reduce migration risk while taking advantage of increased performance, reliability and security of the latest SPARC hardware platforms and Solaris 10 OS. »

 
Sun Partner Survey
Please take a quick 3 minute survey from Sun. Click here to take the survey. Your feedback will help Sun improve on their solution center and be more useful for you and your peers. Thank you for your time and consideration. »

 
Sun Eco Innovation: Power Calculators
Power consumption has increasingly become a priority in customer's minds when purchasing new systems or storage. Sun's Power Calculators provide data on power consumption of Sun products allowing IT managers to better plan the power requirements in the datacenter to achieve better energy and cost savings. »

 
Optimize the Web Tier: Consolidate to Get More Performance in Less Space and Lower Power Consumption
Expansion in the Web tier is generally accomplished by adding more servers whenever extra capacity is needed. As the pool of servers grows larger, however, the complexity of the environment can grow exponentially. »


Windows Server Catalog: Certified Hardware Devices. Search the Windows Server 2008 catalog to find solutions to deploy with confidence.

Sr. Oracle EBS Developer
Professional Technical Resources
US-OR-Forest Grove

Justtechjobs.com Post A Job | Post A Resume

Using Index Hints in SQL statements - 'Cause we know more about our application than Oracle does
Ajay Gursahani, ajay_gursahani@yahoo.com


Hints are used to give specific information that we know about our data and application, to Oracle. This further improves the performance of our system. There can be instances where the default optimizer may not be efficient for a certain SQL statements. We can specify HINTS with the SQL statements, to improve the efficiency of those SQL statements.

In this article, we shall see how to specify INDEX hints and what the advantages of the same are.

How to specify Hints

The Hints are enclosed in comment, /* comment */, in an SQL statement, and can only be specified with SELECT, DELETE and UPDATE keyword.

SELECT /* comment */ ........ ;

All hints should start with a + sign. This tells the SQL Parser that the SQL has a hint specified with it.

SELECT /*+{hint} */ ........ ;

Using INDEX Hints

When you specify an INDEX Hint, the optimizer knows that it has to use the INDEX specified in the hint. In this case, the optimizer does not go for a Full Table Scan nor does it use any other index. In addition, it does not calculate the cost of the Index to be used.

If no INDEX hint is specified the optimizer determines the cost of the each index that could be used to access the table and uses the one with the lower cost.

If there are multiple indexes specified with the Hint then the optimizer has to determine the cost of each index to be used with the specified table. Once that is determined, it uses the Index with the lower cost to access the table. In this case, the optimizer does not do a FULL Table Scan. Also note that, the optimizer may choose to use multiple indexes and then merge the result sets to access the table. This method is used if the cost is low.

Syntax:

/*+ INDEX ( table [index [index]...] ) */

Where:

  • table specifies the name or alias of the table associated with the index to be scanned.

  • index specifies an index on which an index scan is to be performed.

Examples:

select /*+ INDEX(emp_city idx_job_code) */ empname, 
job_code from emp where job_code = 'T';

In the above example we are querying the emp table to find employees who are Temporary (job_code = 'T') in the organization.

The above approach will be faster only if we know that less than 50% rows will be returned by the above query. If we know that there are more Temporary employees than the Permanent (job_code = 'P') employees, then the above approach will not be efficient. It is better that we do a FULL Table scan.


DELETE /*+ INDEX(emp_status idx_emp_status)*/ FROM 
emp_status WHERE status = 'T';

INDEX_ASC

/*+ INDEX_ASC(table index[index .. index]) */

INDEX_ASC is almost the same as INDEX Hint. The difference is that if INDEX Range is specified the entries are scanned in ascending order.

INDEX_DESC

/*+ INDEX_DESC (table index[index .. index]) */

INDEX_DESC is almost the same as INDEX Hint. The difference is that if INDEX Range is specified the entries are scanned in descending order.

FULL

You can use the FULL hint to bypass the use of the INDEX. For example if you have a table, which is indexed, and the value you are searching for has a large number of duplicates, then you can go in for a Full Table scan. If an index is used, in this case it will be inefficient. Using FULL hint will bypass the index(es).

Syntax:

/*+ FULL (table) */

Example:


select /*+ FULL(emp_status) */ empname, status from 
emp_status where status = 'P';

NO_INDEX

The NO_INDEX hint explicitly specifies which index cannot be used for the specified table.

Example:


select /*+ NO_INDEX(emp_status emp_status) */ empname, 
status from emp_status where status = 'P';
  • If this hint specifies single or multiple available index(es), then the optimizer does not consider a scan on these indexes. Other indexes not specified are still considered.

  • If this hint specifies no indexes, then the optimizer does not consider a scan on any index on the table. This is the same as a NO_INDEX hint that specifies a list of all available indexes for the table.

Summary

Since you know more about your application and data, you can pass on this information to Oracle to improve the performance of your system.

By using Hints, you can improve certain SQL statements that might otherwise be inefficient.


Back to DBAsupport.com







JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
IBM eBook: Planning a Service Oriented Architecture
IBM eBook: Choosing the Right Architecture--What It Means for You and Your Business
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Avaya Article: Using Intelligent Presence to Create Smarter Business Applications
Intel Go Parallel Article: Getting Started with TBB on Windows
Microsoft Article: 7.0, Microsoft's Lucky Version?
Avaya Article: How to Feed Data into the Avaya Event Processor
IBM Article: Developing a Software Policy for Your Organization
Microsoft Article: Managing Virtual Machines with Microsoft System Center
Intel Go Parallel Article: Intel Threading Tools and OpenMP
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
HP Video: StorageWorks EVA4400 and Oracle
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Red Gate Download: SQL Toolbelt and free High-Performance SQL Code eBook
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
Silverlight 2 App and Walkthrough: Leverage Silverlight 2 with SQL Server and XML
IBM Article: Enterprise Search--Do You Know What's Out There?
HP Demo: StorageWorks EVA4400
Microsoft Article: The Progress and Promise of Deep Zoom
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES