Solved

Join optimization

Posted on 2000-03-06
2
524 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PL SQL Developer 7 75
oracle DR - data guard failover. 18 60
Oracle cursor lifecycle inside procedure. 2 29
error doing substr 3 38
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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

730 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