Home > Ask the Oracle Experts > (Archive) Database Performance Tuning Questions & Answers > Clarification on explain plan statistics and used COST
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

Clarification on explain plan statistics and used COST

Paul Baumgartel EXPERT RESPONSE FROM: Paul Baumgartel

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site


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


>
QUESTION POSED ON: 14 March 2005
In the following SQL queries I have used four tables, all parent tables have primary key constraints and the same column in the child table is a foreign key column. I have created an index on the foreign key column. Before running these queries, I have analyzed the tables and indexes.

My questions are:

1. Why is it not using index join?
2. Are any changes required within the SQL query to use the index joins?
3. If the optimizer uses index join will it affect the COST?

This is sample data; in the production server these four tables have data in the millions. The optimizer is using so much COST
for this query. Is there any way to reduce the COST?

Example:

 
-------
Explain plan set statement_id = 'test1' for select sup.supplier_name, 
rem.supplier_remitter_name, acc.account_num, inv.invoice_number from supplier_hdr sup,
supplier_remit_hdr rem, acnt_info_hdr acc, inv_info_sum inv where SUP.SUPPLIER_HDR_SYS_ID(Primary Key) = REM.SUPPLIER_HDR_SYS_ID (Foreign Key) and REM.SUPPLIER_REMIT_SYS_HDR_ID (Primary Key) = ACC.SUPPLIER_REMIT_SYS_HDR_ID (Foreign Key)AND ACC.ACNT_INFO_HDR_SYS_ID (Primary Key) = INV.ACNT_INFO_HDR_SYS_ID (Foreign Key) / ---------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost | ---------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 353 | 33182 | 12 | | 1 | HASH JOIN | | 353 | 33182 | 12 | | 2 | TABLE ACCESS FULL | INV_INFO_SUM | 353 | 10943 | 3 | | 3 | HASH JOIN | | 265 | 16695 | 8 | | 4 | TABLE ACCESS FULL | SUPPLIER_HDR | 4 | 60 | 2 | | 5 | HASH JOIN | | 265 | 12720 | 5 | | 6 | TABLE ACCESS FULL| SUPPLIER_REMIT_HDR | 4 | 64 | 2 | | 7 | TABLE ACCESS FULL| ACNT_INFO_HDR | 265 | 8480 | 2 | ----------------------------------------------------------------------------

>
EXPERT RESPONSE
Hash joins are often faster than "index" (actually "nested loops") joins, because the number of consistent gets, and thus the CPU usage, is much lower. If you would like to compare the performance of the hash join to a nested loops join, use the optimizer hint USE_NL in the query. Also, remember that the optimizer uses statistics on data volume in determining a query plan. The plan you get on your production server, with production volumes, might be different (although I doubt it in this case). You can check that by using DBMS_STATS to export the statistics from production and import them into your development/test server; the optimizer plan produced will be the one you can expect to see in production. Finally, don't worry about the COST values in the plan output--just compare performance, i.e., elapsed time of the query.


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


RELATED CONTENT
(Archive) Database Performance Tuning
How tkprof works for tuning
Import of dump file took 20 hours
Optimize SQL query on table with 50 million records
Windows reporting high number of handles for oracle.exe processes
Performance problems in Unix vs. Windows
Insertion speed goes down with context index
Buffer busy waits on primary key index
Do indexes affect performance of updates and inserts?
Creating partitions on fastest area of disk
Application stops working when analyzing schema

Oracle database performance problems and tuning
Oracle 11g data compression
Varchar or number for better performance?
Do statistics on SYS-owned objects hurt performance in 10g?
Inside the Oracle 11g SQL Performance Advisor, part 1
Inside the Oracle 11g SQL Performance Advisor, part 2
Difference between driving table and driver table in Oracle
Best design for E-Business Suite on hard drive
20GB data dictionary causing performance problems
Using the cost-based optimizer to improve Database 10g performance
Online tablespace reorganization in Oracle 9i

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



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice

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