Help needed with a SELECT statement. How can I make it run faster?

Hi,
not sure if my brain is just too tired but I can't seem to crack this problem today.
Here is my scenario.
I have 2 tables
TABLE1 (searchId INTEGER, routeId INTEGER);
TABLE2 (routeId INTEGER, cityId INTEGER);
There are indexes on all 4 columns.
(routeId on TABLE1 is a primary key).
In the data I am using, a given search has more than 500 routes, each route has between 10 and 300 cities among more than 4000 possible different cities.
Now, what I want to create is the list of route couple, within a certain search, that do not have a single city in common.
That list should populate a table with the following structure
TABLE3 (searchId INTEGER, routeId1 INTEGER, routeId2 INTEGER)
Here is the fastest select statement I have found so far.
SELECT :searchId, t1.routeId, t2.routeId FROM table1 t1, table1 t2
WHERE t1.searchId=:searchId AND t2.searchId=:searchId
AND t1.routeId>t2.routeId
AND NOT EXISTS (
SELECT cityId FROM table2
WHERE routeId=t1.routeId
INTERSECT
SELECT cityId FROM table2
WHERE routeId=t2.routeId);
But it still seem really slow to me.
Any suggestion for an improved version is welcome.
Thanks,
Martin.
Title was edited by:
user453358

I originaly posted this thread because I tought I was missing something "obvious" that would perform better that would make my SELECT statement perform better.
So I did not want to go as deep as using TKPROOF yet.
Here is the statistics I gets on my statement.
  1   SELECT t1.searchId,t1.routeId, t2.routeId id2
  2      FROM table1 t1, table1 t2
  3     WHERE t1.searchid=t2.searchid
  4      AND t1.searchId=91
  5      AND t1.routeId>t2.routeId
  6      AND NOT EXISTS (
  7             SELECT cityId FROM table2
  8              WHERE routeId=t1.routeId
  9             INTERSECT
10             SELECT cityId FROM table2
11*            WHERE routeId=t2.routeId)
SQL> /
43302 rows.
Tidsåtgång: 00:01:55.02
Körschema
   0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=9 Card=1 Bytes=14)         
   1    0   FILTER                                                             
   2    1     TABLE ACCESS (BY INDEX ROWID) OF 'table1' (TABLE) (Cost=1 Card=1 Bytes=7)                                                
   3    2       NESTED LOOPS (Cost=3 Card=1 Bytes=14)                          
   4    3         TABLE ACCESS (BY INDEX ROWID) OF 'table1' (TABLE) (Cost=2 Card=1 Bytes=7)
   5    4           INDEX (RANGE SCAN) OF 'table1_IDX1' (INDEX) (Cost=1 Card=1)                                                    
   6    3         INDEX (RANGE SCAN) OF 'table1_IDX1' (INDEX) (Cost=0 Card=1)                                                      
   7    1     INTERSECTION                                                     
   8    7       SORT (UNIQUE) (Cost=3 Card=108 Bytes=864)                      
   9    8         TABLE ACCESS (BY INDEX ROWID) OF 'table2' (TABLE) (Cost=2 Card=108 Bytes=864)                                 
  10    9           INDEX (RANGE SCAN) OF 'table2_IDX1' (INDEX) (Cost=1 Card=108)                                               
  11    7       SORT (UNIQUE) (Cost=3 Card=108 Bytes=864)                      
  12   11         TABLE ACCESS (BY INDEX ROWID) OF 'table2' (TABLE) (Cost=2 Card=108 Bytes=864)                                 
  13   12           INDEX (RANGE SCAN) OF 'table2_IDX1' (INDEX) (Cost=1 Card=108)                                               
Statistik
          1  recursive calls                                                   
          0  db block gets                                                     
    2872765  consistent gets                                                   
          0  physical reads                                                    
        812  redo size                                                         
     964172  bytes sent via SQL*Net to client                                  
      32245  bytes received via SQL*Net from client                            
       2888  SQL*Net roundtrips to/from client                                 
     860256  sorts (memory)                                                    
          0  sorts (disk)                                                      
      43302  rows processed  Looks like a big number of consistent gets! Any idea how to improve on that?
Martin.

Similar Messages

  • Hi, I have a iMac Tiger running slowly, how can I make it run faster?

    Hi, I have a iMac Tiger 10.4.11 running slowly, how can I make it run faster?

    Look at what is happenning with your Mac when you run Activity Monitor.
    Macintosh-HD -> Applications -> Utilities -> Activity Monitor
    Click on the CPU tab on the lower half of the window to see how much time you are using. 
    Click on System Memory to get statistics on memory usage.  You should have some free memory. 
    When you have lots of page outs more memory will be helpful.  My entry for entry for Page ins/outs is:
    Page ins/outs: 29163/0
    Notice I have 0 pageouts which says that I am not using my harddrive for extra memory space.  Thus, I have enough memory.
    Activity Monitor has a neat feature where it can display a dynamic dock icon.  In Activity Monitor View > Dock icon > Show cpu history.
    "Reading system memory usage in Activity Monitor :"
    http://docs.info.apple.com/article.html?artnum=107918
    <a href="http://developer.apple.com/documentation/Performance/Conceptual/ManagingMemory/A rticles/AboutMemory.html#//apple_ref/doc/uid/20001880"
    >Managing Memory</a>
    See   Kappy 
    http://discussions.apple.com/message.jspa?messageID=8025223#8025223
    Problems from insufficient RAM and free hard disk space
    http://thexlab.com/faqs/lackofram.html

  • My 2012 macbook pro is running really slow, how can I make it run faster?

    I ran the etrecheck, and this is what resulted:
    Hardware Information:
              MacBook Pro (13-inch, Mid 2012)
              MacBook Pro - model: MacBookPro9,2
              1 2.5 GHz Intel Core i5 CPU: 2 cores
              4 GB RAM
    Video Information:
              Intel HD Graphics 4000 - VRAM: 1024 MB
    System Software:
              OS X 10.9.2 (13C64) - Uptime: 0 days 8:0:27
    Disk Information:
              APPLE HDD TOSHIBA MK5065GSXF disk0 : (500.11 GB)
                        EFI (disk0s1) <not mounted>: 209.7 MB
                        Macintosh HD (disk0s2) / [Startup]: 499.25 GB (455.86 GB free)
                        Recovery HD (disk0s3) <not mounted>: 650 MB
              MATSHITADVD-R   UJ-8A8 
    USB Information:
              Apple Inc. FaceTime HD Camera (Built-in)
              Apple Inc. BRCM20702 Hub
                        Apple Inc. Bluetooth USB Host Controller
              Apple Computer, Inc. IR Receiver
              Apple Inc. Apple Internal Keyboard / Trackpad
    FireWire Information:
    Thunderbolt Information:
              Apple Inc. thunderbolt_bus
    Kernel Extensions:
              com.avast.PacketForwarder          (1.4 - SDK 10.9)
              com.avast.AvastFileShield          (2.1.0 - SDK 10.9)
    Launch Daemons:
              [System] com.adobe.fpsaud.plist 3rd-Party support link
              [System] com.avast.init.plist 3rd-Party support link
              [System] com.avast.uninstall.plist 3rd-Party support link
              [System] com.barebones.authd.plist 3rd-Party support link
              [System] com.google.keystone.daemon.plist 3rd-Party support link
              [System] com.microsoft.office.licensing.helper.plist 3rd-Party support link
    Launch Agents:
              [System] com.avast.userinit.plist 3rd-Party support link
              [System] com.google.keystone.agent.plist 3rd-Party support link
    User Launch Agents:
              [not loaded] com.avast.home.userinit.plist 3rd-Party support link
              [not loaded] com.spotify.webhelper.plist 3rd-Party support link
    User Login Items:
              None
    Internet Plug-ins:
              FlashPlayer-10.6: Version: 13.0.0.201 - SDK 10.6 3rd-Party support link
              Default Browser: Version: 537 - SDK 10.9
              AdobePDFViewerNPAPI: Version: 11.0.04 - SDK 10.6 3rd-Party support link
              AdobePDFViewer: Version: 11.0.04 - SDK 10.6 3rd-Party support link
              Flash Player: Version: 13.0.0.201 - SDK 10.6 3rd-Party support link
              o1dbrowserplugin: Version: 5.2.4.18058 3rd-Party support link
              QuickTime Plugin: Version: 7.7.3
              SharePointBrowserPlugin: Version: 14.1.0 3rd-Party support link
              googletalkbrowserplugin: Version: 5.2.4.18058 3rd-Party support link
              Silverlight: Version: 5.1.20125.0 - SDK 10.6 3rd-Party support link
    Safari Extensions:
              avast! Online Security: Version: 8
    Audio Plug-ins:
              BluetoothAudioPlugIn: Version: 1.0 - SDK 10.9
              AirPlay: Version: 2.0 - SDK 10.9
              AppleAVBAudio: Version: 203.2 - SDK 10.9
              iSightAudio: Version: 7.7.3 - SDK 10.9
    iTunes Plug-ins:
              Quartz Composer Visualizer: Version: 1.4 - SDK 10.9
    3rd Party Preference Panes:
              avast! Preferences  3rd-Party support link
              Flash Player  3rd-Party support link
    Old Applications:
              SLLauncher:          Version: 1.0 - SDK 10.5 3rd-Party support link
                        /Library/Application Support/Microsoft/Silverlight/OutOfBrowser/SLLauncher.app
              /Users/[redacted]/Downloads
                        Install Spotify 3:          Version: 1.0 - SDK 10.5 3rd-Party support link
                        Install Spotify:          Version: 1.0 - SDK 10.5 3rd-Party support link
                        Install Spotify 2:          Version: 1.0 - SDK 10.5 3rd-Party support link
    Time Machine:
              Time Machine not configured!
    Top Processes by CPU:
                   3%          WindowServer
                   2%          EtreCheck
                   0%          locationd
                   0%          aosnotifyd
    Top Processes by Memory:
              94 MB          Google Chrome
              82 MB          avast!
              82 MB          mds_stores
              60 MB          Google Chrome Helper
              53 MB          Finder
    Virtual Memory Information:
              33 MB          Free RAM
              1.38 GB          Active RAM
              1.47 GB          Inactive RAM
              590 MB          Wired RAM
              37.94 GB          Page-ins
              9 MB          Page-outs

    Look for possible solutions here:
    http://www.thesafemac.com/mpg/
    Ciao.

  • How can I make Garageband run faster?

    For drums, I use Addictive drum software, and use amp simulation such as guitar rig. However I also use some redwirez cab impulses and that seems to slow down the performance big time. Is there anyway to get around that and make performance better without doing things like locking tracks while recording on other tracks? Because I need to listen to all tracks while recording you know?

    BMF92 wrote:
    without doing things like locking tracks while recording on other tracks? Because I need to listen to all tracks while recording you know?
    locking tracks doesn't stop a track from playing
    other optimizing tips:
    http://www.bulletsandbones.com/GB/GBFAQ.html#optimize
    (Let the page FULLY load. The link to your answer is at the top of your screen)

  • Until the most recent update when the autocomplete location bar was selected, it "went" with no further clicking. Now I have to click the refresh arrow. It won't even work with the return. How can I make it work the old easier way?

    Until the most recent update when the url that I wanted in the autocomplete location bar was selected, it "went" with no further clicking. Now I have to click the refresh arrow. It won't even work with the return. How can I make it work the old easier way?

    cor-el, thank you so much. That fixed it, but does this mean I can't use AVG Safe Search.Is there a substitute? I do like the security (hopefully real) that it offers. What now? How do I get out of Safe Mode?
    Sherry

  • Why mails in iphone are not synchronize with my macbook? how can i make them synchronize?,

    Why mails in iphone are not synchronize with my macbook? how can i make them synchronize? I am a new user of apple product just then i had realized these problem, please somebody help me. Thank you in advance!

    Gmail can be setup as IMAP, however you have to set such up on all your devices:
    http://support.google.com/mail/bin/static.py?hl=en&ts=1668960&page=ts.cs

  • With the new iOS7 how can I make the picture on my lock screen smaller or is this a glitch with the new iOS7?

    With the new iOS7 how can I make the picture on my lock screen smaller or is this a glitch with the new iOS7?
    I got the 5s and everytime I try and change the picture on my lock screen the picture is 10x way to big. I try and resize it and make it smaller but it will nto get smaller.
    How can I fix this?

    See Empty/corrupt iTunes library after upgrade/crash.
    tt2

  • Compatibility of Firefox 6 with Trend Micro titanium - how can I make them work together? My OS is Win XP (service pack 2 & 3)

    Compatibility of Firefox 6 with Trend Micro titanium - how can I make them work together?
    I have not downloaded FF6 yet because it is not compatible with my virus software - has this changed? If not, is there a simple "fix" or workaround?
    Thanks.

    Found the following on the TrendMicro forum:
    *TrendMicro forum: http://community.trendmicro.com/
    *Found fix in this thread: http://community.trendmicro.com/t5/Home-and-Home-Office-Forum/Firefox-6-amp-TM-Firefox-Extension-6-5-0-1234/td-p/43735 (posted by PartyJetsetGo, Customer Service Manager)
    *[Hot Fix] B1306: http://esupport.trendmicro.com/solution/en-us/1059243.aspx
    '''If this reply solves your problem, please click "Solved It" next to this reply when <u>signed-in</u> to the forum.'''

  • My Macbook Pro has become slow and sometimes it hangs. How can I make it work fast and normal.

    My Macbook Pro has become very slow and it sometimes hangs. How can I make it work faster and normal? I  used Etrecheck and got the report below;
    EtreCheck version: 1.9.12 (48)
    Report generated June 16, 2014 at 18:05:25 GMT+1
    Hardware Information:
        MacBook Pro (13-inch, Mid 2012) (Verified)
        MacBook Pro - model: MacBookPro9,2
        1 2.5 GHz Intel Core i5 CPU: 2 cores
        4 GB RAM
    Video Information:
        Intel HD Graphics 4000 - VRAM: (null)
            Color LCD 1280 x 800
    System Software:
        OS X 10.9.3 (13D65) - Uptime: 0 days 1:50:52
    Disk Information:
        APPLE HDD TOSHIBA MK5065GSXF disk0 : (500.11 GB)
            EFI (disk0s1) <not mounted>: 209.7 MB
            Machintosh HD (disk0s2) / [Startup]: 499.25 GB (465.33 GB free)
            Recovery HD (disk0s3) <not mounted>: 650 MB
        MATSHITADVD-R   UJ-8A8 
    USB Information:
        Apple Inc. FaceTime HD Camera (Built-in)
        Apple Inc. Apple Internal Keyboard / Trackpad
        Apple Inc. BRCM20702 Hub
            Apple Inc. Bluetooth USB Host Controller
        Apple Computer, Inc. IR Receiver
    Thunderbolt Information:
        Apple Inc. thunderbolt_bus
    Gatekeeper:
        Mac App Store and identified developers
    Launch Daemons:
        [loaded]    com.adobe.fpsaud.plist Support
        [loaded]    com.microsoft.office.licensing.helper.plist Support
    User Login Items:
        iTunesHelper
        Dr.Web Light
        Dropbox
    Internet Plug-ins:
        SharePointBrowserPlugin: Version: 14.0.0 Support
        FlashPlayer-10.6: Version: 14.0.0.125 - SDK 10.6 Support
        Flash Player: Version: 14.0.0.125 - SDK 10.6 Support
        QuickTime Plugin: Version: 7.7.3
        Default Browser: Version: 537 - SDK 10.9
    Safari Extensions:
        iGetter Extension: Version: 2.9.2
    Audio Plug-ins:
        BluetoothAudioPlugIn: Version: 1.0 - SDK 10.9
        AirPlay: Version: 2.0 - SDK 10.9
        AppleAVBAudio: Version: 203.2 - SDK 10.9
        iSightAudio: Version: 7.7.3 - SDK 10.9
    iTunes Plug-ins:
        Quartz Composer Visualizer: Version: 1.4 - SDK 10.9
    User Internet Plug-ins:
        iGetter Plugin: Version: 2.9.2 Support
        iGetterScriptablePlugin: Version: 2.9.2 Support
    3rd Party Preference Panes:
        Flash Player  Support
    Time Machine:
        Time Machine not configured!
    Top Processes by CPU:
             4%    Dropbox
             3%    WindowServer
             0%    fontd
             0%    Microsoft Word
             0%    Microsoft Excel
    Top Processes by Memory:
        242 MB    drwebd
        176 MB    Dropbox
        147 MB    Dr.Web Light
        86 MB    WindowServer
        82 MB    App Store
    Virtual Memory Information:
        43 MB    Free RAM
        1.68 GB    Active RAM
        1.65 GB    Inactive RAM
        641 MB    Wired RAM
        421 MB    Page-ins
        0 B    Page-outs

    Meli070,
    uninstall Dr.Web Light.

  • After updating to mavericks on my MacBook, the screen keeps saying "setting up your mac." It has been like this for hours! How can I make it go faster?

    After updating to mavericks on my MacBook, the screen keeps saying "setting up your mac." It has been like this for hours! How can I make it go faster? It's has been like this for 4 hrs.

    I don't think your mac is setting up. It's stuck.
    I would:
    hold the power button until it shuts down
    unplug all peripherals
    do a safe boot (restart and hold down the shift key until you see the apple logo).
    If it starts up in a safe boot, then you can try restarting with a normal boot.
    If it does not start with a normal boot, then you probably have some incompatible third party software. Likely culprits are:
    MacKeeper
    CleanMyMac
    third-party antivirus software
    any other "cleaning" or "optimizing" or similar third party "utilities".
    A good place to start would be to uninstall any of those (while in safe mode) and then restart.

  • How can I make Privoxy load faster?

    I'm using vimb and it works well except the only way to block ads is to use privoxy. Privoxy takes about 5-10 minutes to start after my computer boots. This means I can't access the internet when I first start my computer. How can I make it load faster?

    https://wiki.archlinux.org/index.php/Hostsblock
    https://aur.archlinux.org/packages/hostsblock/
    Also e.g. https://aur.archlinux.org/packages/hosts-update/

  • How can i make my ipod faster

    HOw can i make my ipod faster

    - Close all apps in the recently used dock.
    - Power off and then back on the iPod.
    next ones are more drastic
    - Restore from backup. See:
    iOS: How to back up
    - Restore to factory settings/new iOS device.

  • How can I make Terminal run Java 7 downloaded from the Oracle Website?

    I've downloaded Java 7 from the Oracle website, and I want the Terminal application to run that Java 7 download. I try to run Java programs that require Java 7, but it runs with the Apple Internal Java 6 release. How can I make it so my MacBook Pro runs the download of Java that I downloaded? I know this sounds stupid, but am I routing my machine to run the internal Java 6 version? I have seen many videos in which people with the same software version as me run Java like this with no problem. Could you please let me know why this is happening and how I can fix it? I really want to be able to use the Java 7, particularly because I'm always getting this "Unsupported Major Minor Version 51.0" from many applications that are Terminal based.
    Thanks!

    I think I've answered your question. The Oracle JRE is a web plugin. The JDK is a development kit for applications with embedded Java. Neither one replaces the Apple-distributed Java frameworks for running standalone applications without embedded Java. Any other questions you have should be answered by the Oracle documentation.

  • How can i make my computer faster?

    I recently have gotten my macbook pro just last month in june, and now it seems that certain things are really really slow.  Comparitively, safari seems to be taking forever opening up normal pages that didnt take long earlier.  i was wondering if it might be a virus slowing it down, but i see that there arent any mac os viruses known of.  So i was wondering what i could do to make it run faster again.

    you don't have a virus in your macbook......
    you already have the best anti virus protection installed - it's called OS X Lion.
    open up activity monitor and under all processes, see what's using up most of your % CPU.  Hightlight the ones using a lot of your % CPU and hit quit process.
    also see what's loading in your login items - delete the ones you think you don't need.
    open disk utility and verify your disk then verify your disk permissions - repair if needed then restart your macbook.
    also, how much RAM have you got installed?
    good luck

Maybe you are looking for

  • Cannot send email

    I cannot send email from my iPhone 4 16GB OS v.4.3.3. A message come up saying: "..recipient was rejected by the server because it does not allow relaying". I have checked all settings with both my ISP and carrier and can find nothing wrong, but obvi

  • Could Not Sign In. An unknown error has occurred (App Store on iPad)

    Hi, I've just bought an iPad mini today. I have also created an Apple ID which is work fine with FaceTime and iMessage (already test call and sent text). But when I tried to login to App Store it said "Could Not Sign In. An unknown error has occurred

  • Mass updation of merchandise category in Billing doc.  ------  ( IS-Retail

    HI! My problem is in regard to the Merchandise Category Reclassification in SAP IS-Retail. My senario was that there were some Merchandise categories(MC) which were unallocated i.e they were not assigned to any Merchandise Cat. Heirarchy. Also there

  • Content filter not updating the Wod Doc

    Hi all I have created a content filter which updates the "author" value in a Word Doc. I have used Apache POI. public InputStream getInputStream() throws ContentException {      try           POIDocument pdoc;           IResource resource=this.getRes

  • Override default values for infotype 0009 (Bank Details)

    Dear all, When we create a new bank details, default value will populate. I would like to know how to override these value, dynamic action? User exist? Feature? Or something else? Thanks in advance Regards Bill