Why are two queries better than one

I'm trying to help out our developers who are struggling with the performance of a very simple select statmenent that for some reason is exhibiting some very inexplicable results.
I'll show the SQL as a single statement first.....
select * from transaction1 t where t.hid in (select distinct h.hid from history1 h,filter1 f where h.fid = f.fid and f.match='value');
transaction 1 has 250k records, history1 has about 100k as does filter1. We know generally the subselect will only return a total of half a dozen or less records (only 1 in our testing here).
Running the above query takes around 7 seconds.
Changing this to a with clause.....
WITH a as (select distinct h.hid from history1 h,filter1 f where h.fid = f.fid and f.match='value') select * from transaction1 t where t,hid in (select a.hid from a);
and the runtime drops to 3 seconds. But then re-running the first statement again also now takes 3 seconds (so I guess there's some caching going on there).
Now what really puzzles is if we split this into two queries.....
select distinct h.hid from history1 h,filter1 f where h.fid = f.fid and f.match='value';
This takes .1 of a second,
select * from transaction1 t where t.hid in (12345);
And this takes .1 of a second.
So why when run seperately are they so fast, yet combined they take so long. I'm a bit baffled by this. We've rewritten the same SQL in half a dozen different ways with the same result and also done the same thing with other tables as well. Is it an optimisation issue?

Appologies for not following protocol, my first time posting on here.
Oracle 10g clustered.
We have limited access as it's a customers server, but the explain plan comes back as....
PLAN_TABLE_OUTPUT
Plan hash value: 898894568
| Id  | Operation            | Name              | Rows  | Bytes | Cost (%CPU)|Time     |
PLAN_TABLE_OUTPUT
|   0 | SELECT STATEMENT     |                   | 49553 |    37M|  7075   (2)|00:01:25 |
|*  1 |  HASH JOIN RIGHT SEMI|                   | 49553 |    37M|  7075   (2)|00:01:25 |
|   2 |   VIEW               | VW_NSO_1          | 26131 |   331K|   476   (4)|00:00:06 |
|*  3 |    HASH JOIN         |                   | 26131 |   791K|   476   (4)|00:00:06 |
PLAN_TABLE_OUTPUT
|*  4 |     TABLE ACCESS FULL| FILTER1           | 26131 |   484K|   246   (4)|00:00:03 |
|   5 |     TABLE ACCESS FULL| HISTORY1          |   104K|  1225K|   227   (3)|00:00:03 |
|   6 |   TABLE ACCESS FULL  | TRANSACTION1      |   199K|   150M|  6593   (1)|00:01:20 |
PLAN_TABLE_OUTPUT
Predicate Information (identified by operation id):
   1 - access("T"."TID"="$nso_col_1")
   3 - access("H"."HID"="F"."ID")
   4 - filter("F"."MATCH"='value')
20 rows selectedI'll admit, I'm not completely clear on what I'm reading here, other than the fact there are some big differences in the timing values
We don't have privaleges to run trace, so I'm a bit stuffed there as I'm on the clients site, however I will get my developers to try this on our local server.
Edited by: user1410957 on 15-Sep-2009 06:14

Similar Messages

  • Why are Ipod Apps better than Iphone Apps?

    There are some really nice apps available to the ipod touch that aren't available to the Iphone. Go search Ipod apps in the Itunes store and you will see what I am talking about. How come the same apps aren't available for both devices?

    oops, they are not on the touch they are for the nano, and reg ipod. Still I am sure there is a way to develope them for the iphone.

  • Two is better than one, right?

    I was just wondering about something. I have a 30gb black iPod 5g. I also own a podsplus case that I've had it in since I got it. Could I also wrap it in an InvisibleShield to keep it from being scratched by dust that gets into the case? Or would it make it impossible to get out? Thanks

    I was just wondering about something. I have a 30gb
    black iPod 5g. I also own a podsplus case that I've
    had it in since I got it. Could I also wrap it in an
    InvisibleShield to keep it from being scratched by
    dust that gets into the case? Or would it make it
    impossible to get out? Thanks
    I have the Invisible Shield and the PDair case, which is exactly the same as the Podsplus, as far as I can tell. It's a snug fit, but they work fine together. I leave my iPod in the case when updating, but take it out it when charging the battery.

  • Why are two pages yoked when I prepare a newsletter in Pages?  How can I delete one without the other?

    Why are two pages yoked when I prepare a newletter?  How do I delete one without the other?

    They are all part of one Section. Just as you do not (hopefully) rip pages out at random from books, the pages of a Section are linked by the text that flows from one to the other.
    If you want to move or delete particular page/s Insert a Section Break at the end of the page before.
    Peter

  • Why do we need more than one retained earnings accounts & what is the use?

    Hi FI Experts,
    Why do we need more than one retained earnings accounts, what is the precise use of two?
    I know the retained earnings account is used to carry forward the balances during the year end to the balance sheet and there by making the p&L A/cs balances as zero.
    I guess the second one is used for different valueations for example  as depreciation accounts for different valuations will have different retained earnings accounts.
    Kindly correct me if I am wrong and eloborate on the use having more than one retained earnings accounts.
    with regards
    Ramesh Y

    Hi,
    Well, separate retained earnings accounts are used for parallel financial reporting, it means when you need to report in accordance with, for example, local GAAP and IFRS or US GAAP at the same time. Several retained earnings accounts  are necessary when the company chooses account based approach for parallel reporting. (GL accounts are broken down into several groups, for example you use different accounts for IFRS valuation, for local GAAP and they are also shared accounts common for both principles.)
    m.

  • HT5731 why is apple tv better than netflix?

    why is apple tv better than netflix?

    Hi s13579,
    Welcome to the Support Communities!
    The following information will explain what the Apple TV is.  Netflix is one of the services available on the Apple TV.
    Apple - Apple TV - HD iTunes content and more on your TV.
    http://www.apple.com/appletv/
    Apple - Apple TV - Access iTunes, Netflix, and more on your HDTV.
    http://www.apple.com/appletv/whats-on/
    Watch everything from classics to recent Hollywood blockbusters to original programming like House of Cards and Orange Is the New Black.5 Apple TV organizes the huge catalog of streaming titles from Netflix so you can find what you want fast.
    I hope this information helps ....
    Happy Holidays!
    - Judy

  • Are 2 drives better than 1

    I am not planning on doing any raid. My Question:
    If you have 2 drives: 1 for the boot and the other for data:
    (250g each). Would that setup be better than one 500g drive in terms of speed etc?
    Just looking for opinions?

    Beside of that purpose on the previous post, I prefered split that HD into two for back up and ease of restoring data and system purpose.
    So the next time you want to reinstall the OS and all programs I could concentrate on the Os system drive without having to much worry about data which is stored on other drive or if I want to back up data, just concentrate on data drive without worrying about accidently deleted system or part of program files.
    Good Luck.

  • Why cant i have more than one movie at a time

    why cant i have more than one movie at one time

    It may be how much space is available on your iPad. The average movie is around 2.5 gigabytes. If you reach your space limit then you can't download anything until you clear space.

  • IAC 3.1.1 users who are member of more than one OrgUnit are not able to order services?

    Hi,
    Power Down, Power Cycle, Take Snapshot and Decommission services are not working for users who are member of more than one organization!!
    Error Message:
    The service form could not be submitted because of following error: [newscale][SQLServer JDBC Driver][SQLServer]Conversion failed when converting the nvarchar value '1,2' to data type int.
    Thanks,
    Maz

    Hi,
    Power Down, Power Cycle, Take Snapshot and Decommission services are not working for users who are member of more than one organization!!
    Error Message:
    The service form could not be submitted because of following error: [newscale][SQLServer JDBC Driver][SQLServer]Conversion failed when converting the nvarchar value '1,2' to data type int.
    Thanks,
    Maz

  • If there are two synchronized methods in one class.

    If there are two synchronized methods in one class then what will be the beheviour of the threads accessing the methods.

    Synchronization is on objects, not methods or classes. A thread, entering a synchronized method, synchronizes on the object on which that method is called. Another thread, attempting to synchronize on that object, will be made to wait until the first thread releases it.

  • Why are my icons larger than normal when I turn on phone?

    Why are the icons larger than normal when turning on phone? How can I resize them back to normal?

    Double-tap the screen with THREE fingers. Then go to Settings/General/accessibility and turn off Zoom.

  • Why won't Index tags that are associated with more than one topic work on a Mac?

    I used RoboHelp 8 to generate a project for PCs and Macs. An index entry ("documentation", in the following examples) is associated with two topics. If I click that index entry in the output on a PC, the appropriate topic links appear and I can jump to the topics. On a Mac, any index entry that has more than one topic associated with it will not work. I just wondering if anyone else has experienced this.

    I suspect but cannot confirm it is a browser issue with output from an older version of Rh. Can you install the Rh10 trial on a machine other than your normal production machine?
    See www.grainge.org for RoboHelp and Authoring tips
    @petergrainge

  • Why SAP ERP is Better than ORACLE ERP?????

    Hi expert I need some help about the comparison study between SAP and Oracle.
    One of our WOOD plantation Client have some confusion between two ERP packages.Oracle have approached them . So how can we convince them to do SAP ERP. If you have some ppt or any material please send it to me . Its urgent.
    Another thing that how SAP FI is better than Oracle FI for any Wood Plantation Company.
    If you gyes have any win story over Wood Plantation company then please give it to me.
    Thnaks Experts for your kind Considuration

    Dear Pratik,
    You can find the points for your presentation from the link:
    http://searchoracle.techtarget.com/generic/0,295582,sid41_gci1173173,00.html#
    Well, you need to convince your client that ERP is not all about cost of implementation. There are many other areas that you need to look at - availabilty of trained staff - complexity of business processes - does your existing data/processes map into one better than the other - are you happy going Oracle Oracle or would you prefer SAP with some other database.
    You can add that the majority of transactions in vanilla Oracle are more difficult than in SAP. SAP can be configured to support most of the business processes without coding.
    Let me know in case of any specific queries.
    Regards,
    Rakesh

  • Why is hyper-v better than virtualbox?

    We have 4-5 people in a software development environment with access to 4 servers, each with 2 quad-core or dual-core cpu's (core-based, before nehalem), and 8gb or 16gb RAM, so I think we have a good amount of power for virtualization. Total, we have a
    team foundation server, oracle server, web server, 2 virtualization servers, and multiple workstations, some virtualized, some not.
    When we started virtualizing about a year ago, for whatever reason, and although everyone has an MSDN sub, we started using VirtualBox instead of Hyper-V. I'm no expert (and that's why I'm here) but I think they operate at different levels of interaction
    with the hardware, and that VirtualBox is a bad idea for this environment.
    Can someone give some good reasons why we should be using Hyper-V? Also is it possible to convert the virtual machines?
    And then I would like to know if it's okay to also be virtualizing our web server and oracle server, etc. We have only been virtualizing workstations. I think we really need to make good use of virtualization if we are going to be doing it at all.
    Advice welcome also for virtualization best practices, backups, management, infrastructure design, etc. I would like to start with a domain controller, and maybe a Lync server so we can share desktops, etc. Thanks for all input!

    In my opinion Hyper-V is only better if your using Hyper-V to host servers, like Microsoft SharePoint, Active Directory, Sql Server, or even MySql to provide resources.
    If you intend to be using Virtualizatio to develop software, like Working with SharePoint from a developer standpoint, building asp.net web applications, or even doing C++, desktop applications, or Android, Php etc, if you are going to be physically on the
    VM using it as your environment to write code and design, then Oracle VirtualBox is better than Hyper-V.
    With hyper-v your limited to using The Connect console, or Remote Desktop Protocol to see the virtual machine.  The RDP console leaves much to be desired.  It only gives you the option to use all of your monitors or one, it won't do 2 if you have
    3.  I like to use my third monitor to keep my email open, and pdf documentation, or word documents and use the other two monitors for my VM so I can see multiple code windows in Visual Studio at the same time (VS2010).  Oracle handles multi monitors
    so much better.  And if I want to surface an adroid phone through USB to my VM, oracle is the only way to go there, or maybe VMWare, but VirtualBox is free.
    However, Hyper-V is now native to Windows 8 desktop version and windows 8 server version.  And most companies dealing with microsoft products use Hyper-V for their VM's, so from a multi developer environment, it makes sense for us to use Hyper-V with
    windows 8 because all of our servers run on Hyper-V.  If we need to troubleshoot something we can grab a copy of the latest server VM backup and spin it up locally on Hyper-V with windows 8 without having to do any conversions.
    But from a developer standpoint it is really hard for me to leave VirtualBox.  If RDP could work my 2 of my monitors and not all 3 or 4 of them I would have no complaints.  Third part RDP sofware isn't any better, it could never compare to the
    deep integration and speed of windows RDP.  My main issue is, if RDP can do all of my monitors why can't it do just 2 of them, seems like a big thing to leave out in my opinion, it's so frustrating.  It's such an awesome part of windows with such
    a huge annoying handicap.  I've actually thought about just having another computer for my third monitor, like a tablet or something on a stand.  Sure you can SPAN a monitor in Windows so it acts like one monitor and I can tell RDP to go full screen
    but it has a width limit and then I need extra software on the VM to handle the big resolution like 2 screens instead of one.
    My Blog: http://www.thesug.org/Blogs/ryan_mann1/default.aspx Website: Under Construction

  • Why is LR5 catalog better than PSE 12 Organiser?

    Hi/
      I have started using a trial version of LR5.
    I have been a regular user of various versions of PSE over the years.
    Generally, I have been happy with the organiser, & have various tags nested in each-other.
    I have never had a problem with it being unstable, & can normally find what I am looking for,
    (provided that I have correctly tagged it in the first place :-)
    My first impression of the LR5 catalogue is that it is not as intuitive.
    I have searched on-line for how to set-up the catalogue & much of the discussion relates to how many catalogues to have. - I've already made that decision - Just the one:
    So?  What features am I missing in the LR5 catalogue that make it better than the Elements Organiser?
    What do you think?

    I am also a happy user of the Organizer, but I also use LR 4.4.
    What I find interesting in LR:
    - huge amount of possible customization and options (if you need them...)
    - Ability to manage jpegs just as raws (the organizer does not let you open jpegs in acr, )
    - Smart ways to manage variants without copying files (virtual copies)
    - More advanced metadata management
    - possibility to merge catalogs
    - Much more support by Adobe and user forums
    - More advanced options in output in the latest versions
    What can be debated is the difficulty of the learning curve as well as the 'robustness' of the software. The organizer was plagued with many bugs (it was already there many years before LR.) The problem is that having many more options makes LR much more complex. For instance the database has three times the number of tables. The result is that the LR forums are full of complaints about bugs or missing features... just because it is too rich and tries to satisfy everybody's needs.
    Many cases of problems with the Organizer are related to the backup function which backs up both pictures and catalogs. Lr only backup catalogs. Backing up pictures is your responsability. If you have problems, it's not LR's fault, it's yours .
    I can't find a post I made to show the possible advantages of the organizer, but that was just for the fun.

Maybe you are looking for

  • Vacancy Overview - No Objects Found

    Hi, I'm trying to implement the MSS Recruitment Workpackage in EP6 SR1. Position Overview works fine and displays the appropriate icon position when a position is desginated as vacant but I'm getting an error "No Objects Found" when looking at the Va

  • Sales Oreder Delivery Date Issue

    Dear Experts, In Sales Order Doc. i want that the Delivery date of two  Sales Orders should not be same. While generating  New Sales Order the Doc. Delivery Date should not pick same date of any Sales Order given before. e.g. I have a Sales Order wit

  • CS4 Sb Startup Error: dvaui.dll

    I am revisiting this issue since I had used an alternative program from what I bought to cover until this problem could be addressed again. I own the MC of CS4, have installed everything from the libraries and tutorials to all the programs and help p

  • Compressor only uses 30% of CPU : (

    I was not able to find any previous and recent discussions about this, but my version of Compressor 4.1 only uses, at most, 30% of CPU on my Mac Pro 2013. Any ideas as to why Compressor would use 30% only, whereas Handbrake maxes out at 100%? Graham

  • Will Time Machine backup 2 internal HDs and put the data back into them when restoring?

    Hello, I am going to be doing a clean install of Snow Leopard. I have a machine that has 2 internal HDs. If they are backup up using Time Machine, when restoring, will it put those files exactly as they were? Thanks!