Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

Free Oracle Tips

HTML Text

 Home
 E-mail Us
 Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB   


 

 

 


 

 

 

 
 

Oracle: removing expensive "merge join cartesian"

Oracle Tips by Burleson Consulting

 

 

Question:  I have this SQL which does a "Merge join Cartesian", and it takes forever to run.  It's consuming 60% of the database resources, and I've been told that the merge join cartesian is a bad execution plan.

SELECT DISTINCT A.CUSTOMER_REF, ATTRIBUTE_VALUE
FROM
G42PRODUCTATTRIBUTE E,
G42CUSTHASPACKAGE A,
G42CUSTHASPRODUCT C,
G42CUSTPRODUCTDETAILS B,
G42CUSTPRODUCTATTRDETAILS D
WHERE
A.CUSTOMER_REF = :B2
AND
B.ACCOUNT_NUM =:B1
AND
A.CUSTOMER_REF = B.CUSTOMER_REF
AND
B.CUSTOMER_REF = C.CUSTOMER_REF
AND
A.PACKAGE_SEQ = C.PACKAGE_SEQ
AND
B.PRODUCT_SEQ = C.PRODUCT_SEQ
AND
A.CUSTOMER_REF = D.CUSTOMER_REF
AND
C.PRODUCT_SEQ = D.PRODUCT_SEQ
AND
D.PRODUCT_ID+0 = 1
AND
D.PRODUCT_ATTRIBUTE_SUBID = E.PRODUCT _ATTRIBUTE_SUBID AND
D.PRODUCT_ID+0 = E.PRODUCT_ID
AND
E.ATTRIBUTE_UA_NAME = 'CUST_ORD_NUMBER'
AND
A.PACKAGE_ID
IN (1, 14, 15, 16, 19, 22, 23, 24, 26, 37)


PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost |
---------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 103 | 2068 |
| 1 | SORT UNIQUE | | 1 | 103 | 2068 |
| 2 | TABLE ACCESS BY INDEX ROWID | G42CUSTPRODUCTATTRDETAILS | 1 | 27 | 1
| 3 | NESTED LOOPS | | 1 | 103 | 2067 |
| 4 | NESTED LOOPS | | 1 | 76 | 2066 |
| 5 | NESTED LOOPS | | 4 | 236 | 2065 |
| 6 | MERGE JOIN CARTESIAN | | 4 | 148 | 2064 |
| 7 | TABLE ACCESS BY INDEX ROWID| G42PRODUCTATTRIBUTE | 2 | 42 | 1 |
| 8 | INDEX RANGE SCAN | G42PRODUCTATTRIBUTE_AK2 | 6 | | 1 |
| 9 | BUFFER SORT | | 2 | 32 | 2063 |
| 10 | INDEX FULL SCAN | G42CUSHASPKG_CUSREF_PKSQ_PKID | 2 | 32 | 6875 |
| 11 | TABLE ACCESS BY INDEX ROWID | G42CUSTPRODUCTDETAILS | 1 | 22 | 1 |
| 12 | INDEX RANGE SCAN | G42CUSTPRODUCTDETAILS_AK3 | 1 | | 1 |
| 13 | TABLE ACCESS BY INDEX ROWID | G42CUSTHASPRODUCT | 1 | 17 | 1 |
| 14 | INDEX RANGE SCAN | G42CUSTHASPRODUCT_PK1 | 1 | | 0 |
| 15 | INDEX RANGE SCAN | G42CUSTPRODUCTATTRDETAILS_PK1 | 1 | | 1 |

 

How to I remove the merge join cartesian?

 

Answer: There are several reasons that your SQL will do a merge join Cartesian.  Cartesian merge joins can also be caused by:

- Forgot to add a table join condition to WHERE clause
- Missing join indexes
- Bad/stale schema statistics (reanalyze with dbms_stats)

 

You have a 4-way table join, and I would start by using the ORDERED hint to force your optimal join order.

As for the cartesian merge join, first, carefully check your WHERE clause to ensure that you have provided the proper join conditions (e.g. where a.primary_key= b.foreign_key).

More information on disabling cartesian merge joins, if desirable, is available HERE


 

If you like Oracle tuning, see the book "Oracle Tuning: The Definitive Reference", with 950 pages of tuning tips and scripts. 

You can buy it direct from the publisher for 30%-off and get instant access to the code depot of Oracle tuning scripts.


 

 

  
 

 
 
 
 
Oracle performance tuning software
 
 

 

 
 
 
Oracle performance Tuning 10g reference poster
 
 
 
Oracle training in Linux commands
 
Oracle training Excel
 
Oracle training & performance tuning books
 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright © 1996 -  2011 by Burleson Enterprises

All rights reserved.

Oracle © is the registered trademark of Oracle Corporation.