Solved

Join optimization

Posted on 2000-03-06
2
518 Views
Last Modified: 2012-06-27
How could I optimize this select?
select narusenigvd.narusenikod
from vlak, trasa, narusenigvd
where
vlak.dojezd >= to_date('01.03.2000 00:00','DD.MM.YYYY HH24:MI') and
vlak.denjizdy <= to_date('02.03.2000 00:00','DD.MM.YYYY HH24:MI') and
vlak.idvlak = trasa.idvlak and
trasa.idtrasa = narusenigvd.idtrasa;

Every attribute have his own index.

Here is plan of the select:
SELECT STATEMENT   Cost: 7152                                                  
  HASH JOIN                                                                    
    TABLE ACCESS FULL NARUSENIGVD                                              
    NESTED LOOPS                                                                
      TABLE ACCESS FULL VLAK                                                    
      TABLE ACCESS BY INDEX ROWID TRASA                                        
        INDEX RANGE SCAN TRASA_VLAK NON-UNIQUE                                  

Why there is full access to tables 'natusenigvd' and 'vlak'?
0
Comment
Question by:knill
2 Comments
 
LVL 3

Accepted Solution

by:
rkogelhe earned 100 total points
ID: 2586922
Knill,

Sometimes the optimizer is just ornery and one has to ritually sacrifice old oracle cds to get it to do what you want.

I suspect in this case that the vlak scans are because oracle has decided that the date ranges -might- hit >20% of the rows regardless. From a human perspective it sure looks like we're only talking about a day here, but the oo thinks it might have to look at half the data.

One suggestion is to create histograms on the date columns, another is to add criteria to the date conditions to limit to "between" conditions. You probably know if

vlak.dojezd >= to_date('01.03.2000 00:00','DD.MM.YYYY HH24:MI') and
vlak.dojezd <= to_date('02.03.2000 00:00','DD.MM.YYYY HH24:MI') and
vlak.denjizdy >= to_date('01.03.2000 00:00','DD.MM.YYYY HH24:MI') and
vlak.denjizdy <= to_date('02.03.2000 00:00','DD.MM.YYYY HH24:MI')  

is also a valid condition...

The narusenigvd problem is probably caused by the full on vlak. It probably suspects it will need all the values in the narusenigvd table, in which case a hash is faster. It may also think that the table is relatively small.

If this doesn't help, consider posting the main optimizer statistics for the tables and join columns.

Regards,

Ryan
0
 

Author Comment

by:knill
ID: 2586946
I added the conditions and cost is naw 201.
Thank you.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now